Spaces:
Paused
Paused
Download modules/csv_exporter.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 2.8 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/modules/csv_exporter.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/modules/csv_exporter.py
-
curl -L -o csv_exporter.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/modules/csv_exporter.py
2.8 kB
| # modules/csv_exporter.py | |
| import pandas as pd | |
| from pathlib import Path | |
| from typing import Dict, List, Any | |
| from datetime import datetime | |
| class HVACCSVExporter: | |
| """Export HVAC analysis to CSV files""" | |
| def __init__(self, output_dir: str = "./outputs"): | |
| self.output_dir = Path(output_dir) | |
| self.output_dir.mkdir(exist_ok=True) | |
| def export_all(self, analysis_data: Dict, task_id: str) -> Dict[str, Path]: | |
| """Export all CSV files""" | |
| return { | |
| 'floors_units': self.export_floors_units(analysis_data, task_id), | |
| 'equipment_schedule': self.export_equipment_schedule(analysis_data, task_id), | |
| 'reconciliation': self.export_reconciliation(analysis_data, task_id), | |
| } | |
| def export_floors_units(self, data: Dict, task_id: str) -> Path: | |
| """Export floor and units breakdown""" | |
| rows = [] | |
| for floor in data.get('floors', []): | |
| for unit in floor.get('units', []): | |
| rows.append({ | |
| 'Floor': floor['floor_number'], | |
| 'Unit_ID': unit['tag'], | |
| 'Unit_Type': unit['type'], | |
| 'Quantity': unit['quantity'], | |
| 'Capacity_BTU': unit.get('capacity_btu', ''), | |
| 'Capacity_kW': unit.get('capacity_kw', ''), | |
| 'Status': unit.get('detection_status', 'Detected'), | |
| 'Location': unit.get('location', ''), | |
| 'Notes': unit.get('notes', ''), | |
| }) | |
| if not rows: | |
| rows = [{'Floor': '', 'Unit_ID': '', 'Unit_Type': ''}] | |
| df = pd.DataFrame(rows) | |
| path = self.output_dir / f"{task_id}_floors_units.csv" | |
| df.to_csv(path, index=False) | |
| return path | |
| def export_equipment_schedule(self, data: Dict, task_id: str) -> Path: | |
| """Export equipment schedule""" | |
| schedule = data.get('equipment_schedule', []) | |
| if not schedule: | |
| schedule = [{'Equipment_ID': '', 'Manufacturer': ''}] | |
| df = pd.DataFrame(schedule) | |
| path = self.output_dir / f"{task_id}_equipment_schedule.csv" | |
| df.to_csv(path, index=False) | |
| return path | |
| def export_reconciliation(self, data: Dict, task_id: str) -> Path: | |
| """Export reconciliation report""" | |
| issues = data.get('reconciliation', {}).get('issues', []) | |
| if not issues: | |
| issues = [{'Issue_Type': 'No issues', 'Severity': 'None'}] | |
| df = pd.DataFrame(issues) | |
| path = self.output_dir / f"{task_id}_reconciliation.csv" | |
| df.to_csv(path, index=False) | |
| return path | |
| # Quick function for FastAPI | |
| def create_exporter() -> HVACCSVExporter: | |
| return HVACCSVExporter() | |