+
+ # calc hn24, if applicable
+ hn24 = None
+
+ if station['hn24']:
+ hn24_values = []
+
+ if element_cd == "SNWD":
+ for idx, _ in enumerate(values):
+ val = values[idx]
+ if val is None:
+ continue
+ hn24_values.append(val['value'])
+
+ 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)
+ else:
+ # this case represents HS settlement
+ hn24 = 0.0
+
+ # finally, if user wants hn24 and it's set to None at this
+ # point, then force it to 0.0
+ if hn24 is None:
+ hn24 = 0.0
+
+ if hn24 is not None:
+ remote_data['hn24'] = hn24
+