-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data.py
executable file
·112 lines (85 loc) · 3.05 KB
/
generate_data.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
import sys
from som_opendata.queries import (
plantPowerSeries,
plantProductionSeries,
membersSeries,
newMembersSeries,
canceledMembersSeries,
contractsSeries,
newContractsSeries,
canceledContractsSeries,
selfConsumptionContractsSeries,
newSelfConsumptionContractsSeries,
canceledSelfConsumptionContractsSeries,
publicContractsSeries,
newPublicContractsSeries,
canceledPublicContractsSeries,
entityContractsSeries,
newEntityContractsSeries,
canceledEntityContractsSeries,
homeownerCommunityContractsSeries,
newHomeownerCommunityContractsSeries,
canceledHomeownerCommunityContractsSeries,
publicMembersSeries,
newPublicMembersSeries,
canceledPublicMembersSeries,
entityMembersSeries,
newEntityMembersSeries,
canceledEntityMembersSeries,
)
from som_opendata.common import dateSequenceMonths
from yamlns.dateutils import Date
from dbutils import csvTable
import io
import os
from consolemsg import step, u
def nextFirstOfMonth():
today = Date.today()
if today.month == 12:
return Date(today.year + 1, 1, 1)
return Date(today.year, today.month+1, 1)
fromdate = Date('2010-01-01')
todate = nextFirstOfMonth()
dates=dateSequenceMonths(fromdate, todate)
metricGenerators = dict(
plantpower=plantPowerSeries,
plantproduction=plantProductionSeries,
members=membersSeries,
publicmembers=publicMembersSeries,
entitymembers=entityMembersSeries,
contracts=contractsSeries,
selfconsumptioncontracts=selfConsumptionContractsSeries,
publiccontracts=publicContractsSeries,
entitycontracts=entityContractsSeries,
homeownercommunitycontracts=homeownerCommunityContractsSeries,
newmembers=newMembersSeries,
newpublicmembers=newPublicMembersSeries,
newentitymembers=newEntityMembersSeries,
newcontracts=newContractsSeries,
newpubliccontracts=newPublicContractsSeries,
newentitycontracts=newEntityContractsSeries,
newselfconsumptioncontracts=newSelfConsumptionContractsSeries,
newhomeownercommunitycontracts=newHomeownerCommunityContractsSeries,
canceledmembers=canceledMembersSeries,
canceledpublicmembers=canceledPublicMembersSeries,
canceledentitymembers=canceledEntityMembersSeries,
canceledcontracts=canceledContractsSeries,
canceledpubliccontracts=canceledPublicContractsSeries,
canceledentitycontracts=canceledEntityContractsSeries,
canceledselfconsumptioncontracts=canceledSelfConsumptionContractsSeries,
canceledhomeownercommunitycontracts=canceledHomeownerCommunityContractsSeries,
)
for metric, generator in metricGenerators.items():
step("Generating {}...", metric)
filename = '{metric}{frm}{to}.tsv'.format(
metric = metric,
frm = '-'+str(fromdate) if fromdate else '',
to = '-'+str(todate) if todate else '',
)
result = generator(dates)
with io.open(filename,'w') as f:
f.write(u(result))
linkname = 'data/metrics/{}.tsv'.format(metric)
with io.open(linkname,'w') as f:
f.write(u(result))