roseyshi commited on
Commit
e402e66
·
verified ·
1 Parent(s): 4af8302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -21,17 +21,32 @@ def refresh(site):
21
  s = df[df["site"] == site]
22
  line = px.line(s, x="time", y="temp_c", title=f"Temperature at {site} (°C)")
23
  rain = px.bar(s, x="time", y="rain_mm", title=f"Rainfall at {site} (mm)")
24
- cutoff = df["time"].max() - pd.Timedelta(hours=24)
25
  recent = df[df["time"] >= cutoff]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  if recent.empty or recent["rain_mm"].max() == 0:
27
- highlight = "No rainfall was recorded at any site in the stored data from the last 24 hours."
28
  else:
29
  top = recent.loc[recent["rain_mm"].idxmax()]
30
- highlight = (
31
- f"**Highest rainfall reading in the last 24 hours:** {top['rain_mm']:.1f} mm "
32
- f"at {top['site']}."
33
  )
34
- stamp = f"{highlight} \nLatest data point: {df['time'].max()} UTC"
 
35
  return fmap, line, rain, stamp
36
 
37
  sites = ["Nairobi", "Muranga", "Kisumu", "Mombasa", "Eldoret", "Nakuru", "Garissa", "Kitale"]
 
21
  s = df[df["site"] == site]
22
  line = px.line(s, x="time", y="temp_c", title=f"Temperature at {site} (°C)")
23
  rain = px.bar(s, x="time", y="rain_mm", title=f"Rainfall at {site} (mm)")
24
+ cutoff = df["time"].max() - pd.Timedelta(hours=24)
25
  recent = df[df["time"] >= cutoff]
26
+
27
+ # Line for the selected town
28
+ mine = recent[recent["site"] == site]
29
+ if mine.empty:
30
+ site_line = f"**{site}:** no data stored for the last 24 hours yet."
31
+ else:
32
+ last = mine.iloc[-1] # df is already sorted by time
33
+ site_line = (
34
+ f"**{site}:** latest reading {last['temp_c']:.1f} °C, "
35
+ f"{last['rain_mm']:.1f} mm rain. Highest rainfall reading in the last "
36
+ f"24 hours: {mine['rain_mm'].max():.1f} mm."
37
+ )
38
+
39
+ # Line for all towns
40
  if recent.empty or recent["rain_mm"].max() == 0:
41
+ all_line = "Across all towns: no rainfall recorded in the last 24 hours."
42
  else:
43
  top = recent.loc[recent["rain_mm"].idxmax()]
44
+ all_line = (
45
+ f"Across all towns, the highest rainfall reading in the last 24 hours "
46
+ f"was {top['rain_mm']:.1f} mm at {top['site']}."
47
  )
48
+
49
+ stamp = f"{site_line} \n{all_line} \nLatest data point: {df['time'].max()} UTC"
50
  return fmap, line, rain, stamp
51
 
52
  sites = ["Nairobi", "Muranga", "Kisumu", "Mombasa", "Eldoret", "Nakuru", "Garissa", "Kitale"]