Skip to content

Commit

Permalink
updated csv file download handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Blackburn committed Aug 15, 2018
1 parent f62bb53 commit f7dc6e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"# VariableCode: {variable_code} | VariableName: {v.variable_name} | ValueType: {v.variable_type_id} | DataType: {v.variable_type} | GeneralCategory: {r.result_type_id} | SampleMedium: {r.sampled_medium} | VariableUnitsName: {u.unit_name} | VariableUnitsType: {u.unit_type_id} | VariableUnitsAbbreviation: {u.unit_abbreviation} | NoDataValue: {v.no_data_value} | TimeSupport: {r.timeseriesresult.intended_time_spacing} | TimeSupportUnitsAbbreviation: {r.timeseriesresult.intended_time_spacing} | TimeSupportUnitsName: {r.timeseriesresult.intended_time_spacing_unit} | TimeSupportUnitsType: {r.timeseriesresult.intended_time_spacing_unit_id} | MethodDescription: {r.feature_action.action.method.method_description} | MethodLink: {r.feature_action.action.method.method_link}"
"# VariableCode: {variable_code} | VariableName: {v.variable_name} | ValueType: {v.variable_type_id} | DataType: {v.variable_type} | GeneralCategory: {r.result_type_id} | SampleMedium: {r.sampled_medium} | VariableUnitsName: {u.unit_name} | VariableUnitsType: {u.unit_type_id} | VariableUnitsAbbreviation: {u.unit_abbreviation} | NoDataValue: {v.no_data_value} | TimeSupport: {r.timeseriesresult.intended_time_spacing} | TimeSupportUnitsAbbreviation: {r.timeseriesresult.intended_time_spacing} | TimeSupportUnitsName: {r.timeseriesresult.intended_time_spacing_unit} | TimeSupportUnitsType: {r.timeseriesresult.intended_time_spacing_unit_id} | MethodDescription: {r.feature_action.action.method.method_description} | MethodLink: {r.feature_action.action.method.method_link} | VerticalOffset: {s.height} | SensorNotes: {s.sensor_notes}"
7 changes: 6 additions & 1 deletion src/dataloaderservices/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ def generate_metadata(time_series_results, request=None): # type: (QuerySet, an
# column names can be distinguished easily.
tsr = time_series_results_as_list[i]

sensor = SiteSensor.objects.select_related('registration').filter(
result_id=tsr.result.result_id).first()

# Why use `varcodes[i]` instead of simply `tsr.result.variable`? Because
# there is a possibility of having duplicate variable codes, and
# `varcodes` is passed into `CSVDataApi.clean_variable_codes(*arg)`
Expand All @@ -508,7 +511,8 @@ def generate_metadata(time_series_results, request=None): # type: (QuerySet, an
variable_code=varcodes[i],
r=tsr.result,
v=tsr.result.variable,
u=tsr.result.unit
u=tsr.result.unit,
s=sensor
)

metadata += "#\n"
Expand All @@ -517,6 +521,7 @@ def generate_metadata(time_series_results, request=None): # type: (QuerySet, an
# If there's only one timeseriesresult, add the variable and unit information block.
# When there are multiple timeseriesresults, this part of the CSV becomes cluttered
# and unreadable.
tsr = time_series_results.first()
metadata += CSVDataApi.read_file('variable_and_unit_information.txt').format(
variable=tsr.result.variable,
unit=tsr.result.unit,
Expand Down

0 comments on commit f7dc6e8

Please sign in to comment.