Apiarist Dev commited on
Commit
b378fd6
·
1 Parent(s): 3bf4d3f

fix: PDF notes wrap inside table; hide trend chart until 2+ inspections (no empty box)

Browse files
Files changed (2) hide show
  1. app.py +14 -7
  2. report.py +14 -4
app.py CHANGED
@@ -520,21 +520,20 @@ def add_hive_action(name, location, marker, notes):
520
  )
521
 
522
 
523
- def _empty_trend():
524
- import pandas as pd
525
- return pd.DataFrame({"inspection": [], "count": [], "metric": []})
526
 
527
 
528
  def view_hive_history(hive_name):
529
  import pandas as pd
530
  if not hive_name:
531
- return [], "_Pick a hive above to see its inspection history._", _empty_trend()
532
  hive = next((h for h in db.list_hives() if h["name"] == hive_name), None)
533
  if not hive:
534
- return [], "_Hive not found._", _empty_trend()
535
  inspections = db.get_inspections_for_hive(hive["id"])
536
  if not inspections:
537
- return [], f"_No inspections recorded for **{hive_name}** yet._", _empty_trend()
538
  rows = []
539
  for i in inspections:
540
  rows.append(
@@ -568,7 +567,14 @@ def view_hive_history(hive_name):
568
  bees = 0
569
  trend_rows.append({"inspection": n, "count": bees, "metric": "bees"})
570
  trend_rows.append({"inspection": n, "count": mites, "metric": "varroa mites"})
571
- return rows, summary, pd.DataFrame(trend_rows)
 
 
 
 
 
 
 
572
 
573
 
574
  # ---------------------------------------------------------------- UI
@@ -980,6 +986,7 @@ def build_ui() -> gr.Blocks:
980
  color="metric",
981
  title="Colony trend (bees & varroa mites over inspections)",
982
  height=240,
 
983
  )
984
  history_table = gr.Dataframe(
985
  headers=[
 
520
  )
521
 
522
 
523
+ def _hidden_trend():
524
+ return gr.update(visible=False)
 
525
 
526
 
527
  def view_hive_history(hive_name):
528
  import pandas as pd
529
  if not hive_name:
530
+ return [], "_Pick a hive above to see its inspection history._", _hidden_trend()
531
  hive = next((h for h in db.list_hives() if h["name"] == hive_name), None)
532
  if not hive:
533
+ return [], "_Hive not found._", _hidden_trend()
534
  inspections = db.get_inspections_for_hive(hive["id"])
535
  if not inspections:
536
+ return [], f"_No inspections recorded for **{hive_name}** yet._", _hidden_trend()
537
  rows = []
538
  for i in inspections:
539
  rows.append(
 
567
  bees = 0
568
  trend_rows.append({"inspection": n, "count": bees, "metric": "bees"})
569
  trend_rows.append({"inspection": n, "count": mites, "metric": "varroa mites"})
570
+
571
+ # Only show the trend chart when there are at least 2 inspections to plot.
572
+ # With fewer, a line chart is just an awkward empty/single-dot box.
573
+ if len(chrono) >= 2:
574
+ trend_update = gr.update(value=pd.DataFrame(trend_rows), visible=True)
575
+ else:
576
+ trend_update = gr.update(visible=False)
577
+ return rows, summary, trend_update
578
 
579
 
580
  # ---------------------------------------------------------------- UI
 
986
  color="metric",
987
  title="Colony trend (bees & varroa mites over inspections)",
988
  height=240,
989
+ visible=False,
990
  )
991
  history_table = gr.Dataframe(
992
  headers=[
report.py CHANGED
@@ -67,19 +67,29 @@ def _date(epoch: float | None) -> str:
67
 
68
 
69
  def _hive_table(inspections: list[dict]) -> Table:
70
- rows = [["Date", "Queen?", "Mites", "Swarm?", "Health", "Notes"]]
 
 
 
 
 
 
 
 
 
 
71
  for i in inspections:
72
  rows.append(
73
  [
74
- _date(i["created_at"]),
75
  "Y" if i["queen_detected"] else "N",
76
  str(i["varroa_mites_visible"] or 0),
77
  "Y" if i["swarm_cells_detected"] else "N",
78
  i["frame_health"] or "-",
79
- (i["notes"] or "")[:80],
80
  ]
81
  )
82
- t = Table(rows, repeatRows=1, colWidths=[1.2 * inch] + [0.7 * inch] * 4 + [2.7 * inch])
83
  t.setStyle(
84
  TableStyle(
85
  [
 
67
 
68
 
69
  def _hive_table(inspections: list[dict]) -> Table:
70
+ # Wrap the long Notes text in a Paragraph so it wraps inside the column
71
+ # instead of overflowing the table edge.
72
+ cell_style = ParagraphStyle(
73
+ name="cell", fontSize=8, leading=10,
74
+ textColor=colors.HexColor("#1a1410"),
75
+ )
76
+ hdr = [
77
+ Paragraph(f"<b>{h}</b>", ParagraphStyle("h", fontSize=9, textColor=colors.HexColor("#1a1410")))
78
+ for h in ["Date", "Queen?", "Mites", "Swarm?", "Health", "Notes"]
79
+ ]
80
+ rows = [hdr]
81
  for i in inspections:
82
  rows.append(
83
  [
84
+ Paragraph(_date(i["created_at"]), cell_style),
85
  "Y" if i["queen_detected"] else "N",
86
  str(i["varroa_mites_visible"] or 0),
87
  "Y" if i["swarm_cells_detected"] else "N",
88
  i["frame_health"] or "-",
89
+ Paragraph((i["notes"] or "")[:160], cell_style),
90
  ]
91
  )
92
+ t = Table(rows, repeatRows=1, colWidths=[1.05 * inch] + [0.6 * inch] * 4 + [2.9 * inch])
93
  t.setStyle(
94
  TableStyle(
95
  [