File size: 2,797 Bytes
dac3297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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()