Commit 3f34cd67 authored by wwr's avatar wwr

add water history data

parent 34522890
...@@ -140,6 +140,10 @@ def quantize_3(value: Decimal) -> Decimal: ...@@ -140,6 +140,10 @@ def quantize_3(value: Decimal) -> Decimal:
return value.quantize(Decimal("0.001"), rounding=ROUND_HALF_UP) return value.quantize(Decimal("0.001"), rounding=ROUND_HALF_UP)
def non_negative(value: Decimal) -> Decimal:
return value if value >= 0 else Decimal("0")
def normalize_items(items: List[dict]) -> List[Tuple[pendulum.DateTime, Decimal]]: def normalize_items(items: List[dict]) -> List[Tuple[pendulum.DateTime, Decimal]]:
points = [] points = []
for item in items: for item in items:
...@@ -396,6 +400,7 @@ class WaterPgDailyBackfill: ...@@ -396,6 +400,7 @@ class WaterPgDailyBackfill:
sum((value for _, value in points), Decimal("0")) sum((value for _, value in points), Decimal("0"))
/ Decimal(len(points)) / Decimal(len(points))
) )
avg_value = non_negative(avg_value)
pg_rows.append(( pg_rows.append((
device["device_id"], device["device_id"],
device["mtid"], device["mtid"],
...@@ -406,7 +411,7 @@ class WaterPgDailyBackfill: ...@@ -406,7 +411,7 @@ class WaterPgDailyBackfill:
read_time_str, read_time_str,
)) ))
else: else:
water_vol = last_value - first_value water_vol = non_negative(last_value - first_value)
water_rows.append(( water_rows.append((
device["device_id"], device["device_id"],
device["mtid"], device["mtid"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment