TEZv commited on
Commit
25fef09
·
verified ·
1 Parent(s): 4ca8ba9

Create journal.py

Browse files
Files changed (1) hide show
  1. journal.py +80 -0
journal.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # journal.py
2
+ import os
3
+ import csv
4
+ import pandas as pd
5
+ import datetime
6
+
7
+ JOURNAL_FILE = "./lab_journal.csv"
8
+ JOURNAL_CATEGORIES = [
9
+ # S1-A Genomics
10
+ "S1-A·R1a", # Real Variant Lookup
11
+ "S1-A·R1b", # Variant Concepts
12
+ "S1-A·R2a", # Gray Zones Explorer
13
+ "S1-A·R2b", # Understudied Target Finder
14
+ "S1-A·R2c", # Literature Gap Finder
15
+ "S1-A·R2d", # Druggable Orphans
16
+ "S1-A·R2e", # Research Assistant
17
+ # S1-C Drug Discovery
18
+ "S1-C·R1a", # FGFR3 RNA Drug
19
+ "S1-C·R1b", # SL Drug Mapping
20
+ "S1-C·R2a", # m6A × Ferroptosis × Circadian
21
+ # S1-D LNP
22
+ "S1-D·R1a", # LNP Corona ML
23
+ "S1-D·R2a", # Flow Corona
24
+ "S1-D·R3a", # LNP Brain / BBB
25
+ "S1-D·R4a", # AutoCorona NLP
26
+ "S1-D·R5a", # CSF/Vitreous/BM
27
+ "S1-D·R6a", # Corona Database
28
+ # S1-E Biomarkers
29
+ "S1-E·R1a", # Liquid Biopsy Classifier
30
+ "S1-E·R1b", # Protein Panel Validator
31
+ "S1-E·R2a", # Multi-protein Biomarkers
32
+ # S1-F Rare Cancers
33
+ "S1-F·R1a", # DIPG Toolkit
34
+ "S1-F·R2a", # UVM Toolkit
35
+ "S1-F·R3a", # pAML Toolkit
36
+ # Learning Sandbox
37
+ "S1-B·R1a", # miRNA Explorer
38
+ "S1-B·R2a", # siRNA Targets
39
+ "S1-G·General", # 3D Models
40
+ "Manual"
41
+ ]
42
+
43
+ def journal_log(category: str, action: str, result: str, note: str = ""):
44
+ """Log an entry with category."""
45
+ ts = datetime.datetime.utcnow().isoformat()
46
+ row = [ts, category, action, result[:200], note]
47
+ write_header = not os.path.exists(JOURNAL_FILE)
48
+ with open(JOURNAL_FILE, "a", newline="", encoding="utf-8") as f:
49
+ w = csv.writer(f)
50
+ if write_header:
51
+ w.writerow(["timestamp", "category", "action", "result_summary", "note"])
52
+ w.writerow(row)
53
+ return ts
54
+
55
+ def journal_read(category: str = "All") -> str:
56
+ """Read journal entries, optionally filtered by category. Returns markdown."""
57
+ if not os.path.exists(JOURNAL_FILE):
58
+ return "No entries yet."
59
+ try:
60
+ df = pd.read_csv(JOURNAL_FILE)
61
+ if df.empty:
62
+ return "No entries yet."
63
+ if category != "All":
64
+ df = df[df["category"] == category]
65
+ if df.empty:
66
+ return f"No entries for category: {category}"
67
+ df_display = df[["timestamp", "category", "action", "result_summary"]].tail(50)
68
+ return df_display.to_markdown(index=False)
69
+ except Exception as e:
70
+ print(f"Journal read error: {e}")
71
+ return "Error reading journal."
72
+
73
+ def clear_journal():
74
+ try:
75
+ if os.path.exists(JOURNAL_FILE):
76
+ os.remove(JOURNAL_FILE)
77
+ return "Journal cleared."
78
+ except Exception as e:
79
+ print(f"Clear journal error: {e}")
80
+ return "Error clearing journal."