-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
70 lines (62 loc) · 2.33 KB
/
models.py
File metadata and controls
70 lines (62 loc) · 2.33 KB
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
from zou.app import db
from zou.app.models.serializer import SerializerMixin
from zou.app.models.base import BaseMixin
# CO2e emission factors by country (g CO2e per hour)
# Source: IEA emission factors + typical workstation power consumption
CARBON_FACTORS_DATA = [
("AU", "Australia", 150.0, 85.0),
("BE", "Belgium", 35.0, 25.0),
("BR", "Brazil", 20.0, 15.0),
("CA", "Canada", 25.0, 20.0),
("CN", "China", 180.0, 100.0),
("DE", "Germany", 80.0, 50.0),
("DK", "Denmark", 25.0, 18.0),
("ES", "Spain", 50.0, 35.0),
("FI", "Finland", 20.0, 15.0),
("FR", "France", 12.0, 10.0),
("GB", "United Kingdom", 55.0, 38.0),
("IN", "India", 200.0, 110.0),
("IT", "Italy", 70.0, 45.0),
("JP", "Japan", 120.0, 70.0),
("KR", "South Korea", 130.0, 75.0),
("MX", "Mexico", 100.0, 60.0),
("NL", "Netherlands", 75.0, 48.0),
("NO", "Norway", 8.0, 6.0),
("NZ", "New Zealand", 25.0, 18.0),
("PL", "Poland", 180.0, 100.0),
("SE", "Sweden", 10.0, 8.0),
("US", "United States", 95.0, 58.0),
("ZA", "South Africa", 220.0, 120.0),
]
class CarbonFactor(db.Model, BaseMixin, SerializerMixin):
"""
Carbon emission factors by country.
Stores CO2e emission rates for rendering and workbench activities.
"""
__tablename__ = "plugin_carbon_factors"
__table_args__ = {"extend_existing": True}
country_code = db.Column(db.String(2), unique=True, nullable=False)
country_name = db.Column(db.String(80), nullable=False)
rendering_co2e = db.Column(db.Float, nullable=False)
workbench_co2e = db.Column(db.Float, nullable=False)
def present(self):
return {
"country_code": self.country_code,
"country_name": self.country_name,
"rendering_co2e": self.rendering_co2e,
"workbench_co2e": self.workbench_co2e,
}
@classmethod
def seed_initial_data(cls):
"""
Seed the database with initial carbon factor data for 23 countries.
"""
for code, name, rendering, workbench in CARBON_FACTORS_DATA:
if not cls.get_by(country_code=code):
cls.create_no_commit(
country_code=code,
country_name=name,
rendering_co2e=rendering,
workbench_co2e=workbench,
)
cls.commit()