Spaces:
Runtime error
Runtime error
| class ImpactsTracker: | |
| """Simple tracker for environmental impacts""" | |
| def __init__(self): | |
| self.reset() | |
| def reset(self): | |
| """Reset all counters to zero""" | |
| self.total_energy = 0.0 | |
| self.total_carbon = 0.0 # GWP in CO2 equivalent | |
| self.generation_count = 0 | |
| self.last_energy = 0.0 | |
| self.last_carbon = 0.0 | |
| def add_impact(self, impacts): | |
| """Add new impact data from API response""" | |
| # Calculate energy impact (use average of min/max) | |
| energy_impact = (impacts.energy.value.min + impacts.energy.value.max) / 2 | |
| # Calculate carbon impact (use average of min/max) | |
| carbon_impact = (impacts.gwp.value.min + impacts.gwp.value.max) / 2 | |
| # Store last impact for display | |
| self.last_energy = energy_impact | |
| self.last_carbon = carbon_impact | |
| # Add to totals | |
| self.total_energy += energy_impact | |
| self.total_carbon += carbon_impact | |
| self.generation_count += 1 | |
| def get_summary(self): | |
| """Get a simple summary of impacts""" | |
| return { | |
| 'last_energy': self.last_energy, | |
| 'last_carbon': self.last_carbon, | |
| 'total_energy': self.total_energy, | |
| 'total_carbon': self.total_carbon, | |
| 'generation_count': self.generation_count | |
| } | |