+ # val is what will make it into the dataset, after
+ # conversions... it gets defined here because in certain
+ # cases we need to look at all of the data to calculate HN24
+ # or wind averages, but for the rest of the data, we only
+ # take the most recent
+ val = None
+
+ # loop through all observations for this key_name
+ # record relevant values for wind averaging or hn24, but
+ # otherwise only persist the data if it's the last datum in
+ # the set
+ for idx, _ in enumerate(observations[key_name]):
+ val = observations[key_name][idx]
+
+ # skip bunk vals
+ if val is None:
+ continue
+
+ # mesowest by default provides wind_speed in m/s, but
+ # we specify 'english' units in the request; either way,
+ # we want mph
+ if element_cd in ('wind_speed', 'wind_gust'):
+ val = kn_to_mph(val)
+
+ # mesowest provides HS in mm, not cm; we want cm
+ if element_cd == 'snow_depth' and station['units'] == 'metric':
+ val = mm_to_cm(val)
+
+ # HN24 / wind_mode transformations, once the data has
+ # completed unit conversions
+ if station['wind_mode'] == "average":
+ if element_cd == 'wind_speed' and val is not None:
+ wind_speed_values.append(val)
+ elif element_cd == 'wind_gust' and val is not None:
+ wind_gust_speed_values.append(val)
+ elif element_cd == 'wind_direction' and val is not None:
+ wind_direction_values.append(val)
+
+ if element_cd == 'snow_depth':
+ hn24_values.append(val)
+
+ # again, only persist this datum to the final data if
+ # it's from the most recent date
+ if idx == pos:
+ remote_data[element_cd] = val
+
+ # ensure that the data is filled out
+ if not observations[key_name][pos]:
+ remote_data[element_cd] = None
+ else:
+ remote_data[element_cd] = None
+
+ if len(hn24_values) > 0:
+ # instead of taking MAX - MIN, we want the first value (most
+ # distant) - the last value (most recent)
+ #
+ # if the result is positive, then we have settlement; if it's not,
+ # then we have HN24
+ hn24 = hn24_values[0] - hn24_values[len(hn24_values)-1]
+
+ if hn24 < 0.0:
+ hn24 = abs(hn24)