-
Notifications
You must be signed in to change notification settings - Fork 0
/
writing.py
46 lines (39 loc) · 1.21 KB
/
writing.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
import json
def write_json(data, filename='AppData/slope.json'):
f = open("AppData/slope.json","w+")
f.write("[]")
f.close()
with open(filename,'w') as f:
json.dump(data, f, indent=4)
def update(date, slope_ic, ins_ic, slope_h, ins_h):
with open('AppData/slope.json') as json_file:
data = json.load(json_file)
n = len(data) - 1
if(n != -1):
last = data[n]
if(date == last['date']):
return
temp = data
y = {
"date": date,
"slope_ic": slope_ic,
"ins_ic": ins_ic,
"slope_h": slope_h,
"ins_h": ins_h
}
temp.append(y)
write_json(data)
def restore():
with open('AppData/slope.json','w') as f:
tmp = []
json.dump(tmp,f)
def write_sat(saturations):
f = open("AppData/saturations.txt", "w")
f.write("Name, Value\n")
for i in saturations:
f.write(i['name'] + ", " + str(i['saturation']) + "\n")
def write_cap(regions):
f = open("AppData/capacities.txt", "w")
f.write("Name, Value\n")
for i in regions:
f.write(i['nome'] + ", " + str(i['terapie_intensive']) + "\n")