Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
import logging
|
|
import json
|
|
import os
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
class JSONResearchHandler:
|
|
def __init__(self, json_file):
|
|
self.json_file = json_file
|
|
self.research_data = {
|
|
"timestamp": datetime.now().isoformat(),
|
|
"events": [],
|
|
"content": {
|
|
"query": "",
|
|
"sources": [],
|
|
"context": [],
|
|
"report": "",
|
|
"costs": 0.0
|
|
}
|
|
}
|
|
|
|
def log_event(self, event_type: str, data: dict):
|
|
self.research_data["events"].append({
|
|
"timestamp": datetime.now().isoformat(),
|
|
"type": event_type,
|
|
"data": data
|
|
})
|
|
self._save_json()
|
|
|
|
def update_content(self, key: str, value):
|
|
self.research_data["content"][key] = value
|
|
self._save_json()
|
|
|
|
def _save_json(self):
|
|
with open(self.json_file, 'w') as f:
|
|
json.dump(self.research_data, f, indent=2)
|
|
|
|
def setup_research_logging():
|
|
# Create logs directory if it doesn't exist
|
|
logs_dir = Path("logs")
|
|
logs_dir.mkdir(exist_ok=True)
|
|
|
|
# Generate timestamp for log files
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
# Create log file paths
|
|
log_file = logs_dir / f"research_{timestamp}.log"
|
|
json_file = logs_dir / f"research_{timestamp}.json"
|
|
|
|
# Configure file handler for research logs
|
|
file_handler = logging.FileHandler(log_file)
|
|
file_handler.setLevel(logging.INFO)
|
|
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
|
|
# Get research logger and configure it
|
|
research_logger = logging.getLogger('research')
|
|
research_logger.setLevel(logging.INFO)
|
|
|
|
# Remove any existing handlers to avoid duplicates
|
|
research_logger.handlers.clear()
|
|
|
|
# Add file handler
|
|
research_logger.addHandler(file_handler)
|
|
|
|
# Add stream handler for console output
|
|
console_handler = logging.StreamHandler()
|
|
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
research_logger.addHandler(console_handler)
|
|
|
|
# Prevent propagation to root logger to avoid duplicate logs
|
|
research_logger.propagate = False
|
|
|
|
# Create JSON handler
|
|
json_handler = JSONResearchHandler(json_file)
|
|
|
|
return str(log_file), str(json_file), research_logger, json_handler
|
|
|
|
def get_research_logger():
|
|
return logging.getLogger('research')
|
|
|
|
def get_json_handler():
|
|
return getattr(logging.getLogger('research'), 'json_handler', None)
|