forked from j4k0bk/test-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_convert.py
93 lines (74 loc) · 2.58 KB
/
dummy_convert.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
import csv
from datetime import datetime, timezone, timedelta
# -- MeteringPoints ----------------------------------------------------------
production_gsrn = []
consumption_gsrn = []
meteringpoints = []
with open('dummy_solar_production.csv', newline='') as f1:
for gsrn in set(row['id'] for row in csv.DictReader(f1)):
meteringpoints.append({
'gsrn': f'X-test-{gsrn}',
'sector': 'DK1',
'type': 'production',
'postcode': '8000',
'technology_code': 'T010000',
'fuel_code': 'F01040100',
})
with open('dummy_consumption.csv', newline='') as f2:
for gsrn in set(row['id'] for row in csv.DictReader(f2)):
meteringpoints.append({
'gsrn': f'X-test-{gsrn}',
'sector': 'DK1',
'type': 'consumption',
'postcode': '8000',
})
with open('meteringpoints.csv', 'w', newline='') as f3:
writer = csv.DictWriter(f3, fieldnames=(
'gsrn',
'type',
'sector',
'technology_code',
'fuel_code',
'street_code',
'street_name',
'building_number',
'city_name',
'postcode',
'municipality_code'
))
writer.writeheader()
for meteringpoint in sorted(meteringpoints, key=lambda m: m['gsrn']):
writer.writerow(meteringpoint)
# -- Measurements ------------------------------------------------------------
with open('measurements.csv', 'w', newline='') as f3:
writer = csv.DictWriter(f3, fieldnames=(
'gsrn',
'begin',
'end',
'amount'
))
writer.writeheader()
with open('dummy_solar_production.csv', newline='') as f4:
for row in csv.DictReader(f4):
begin = datetime \
.fromisoformat(row['time']) \
.replace(tzinfo=timezone.utc)
end = begin + timedelta(hours=1)
writer.writerow({
'gsrn': f'X-test-{row["id"]}',
'begin': str(begin),
'end': str(end),
'amount': int(float(row['production']) * 1000),
})
with open('dummy_consumption.csv', newline='') as f4:
for row in csv.DictReader(f4):
begin = datetime \
.fromisoformat(row['time']) \
.replace(tzinfo=timezone.utc)
end = begin + timedelta(hours=1)
writer.writerow({
'gsrn': f'X-test-{row["id"]}',
'begin': str(begin),
'end': str(end),
'amount': int(float(row['consumption']) * 1000),
})