This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_generator.py
366 lines (327 loc) · 8.8 KB
/
data_generator.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
from datetime import datetime, timedelta
import era
class data_generator:
# datetime型のオブジェクトから短い日付を返す
def get_shorted_date(self, datetime_obj):
return (
str(datetime_obj.year).zfill(4)
+ "-" +
str(datetime_obj.month).zfill(2)
+ "-" +
str(datetime_obj.day).zfill(2)
)
# 陽性者の一覧を生成
def get_patients_data(self, sheet):
patients_data = []
for i in range(sheet.max_row) :
date = (
era.reiwa_to_datetime(
sheet.cell(
row=sheet.max_row - i,
column=2
).value
) + timedelta(hours=8)
)
shorted_date = self.get_shorted_date(date)
patient = str(
sheet.cell(
row=sheet.max_row - i,
column=1
).value
).replace("例目", "")
patient_number = (
int(patient) if (patient == "-") == False else None
)
patient_address = (
sheet.cell(
row=sheet.max_row - i,
column=5
).value
)
patient_age_data = (
str(
sheet.cell(
row=sheet.max_row - i,
column=3
).value
)
)
if patient_age_data == "-" :
patient_age = ""
elif "以上" in patient_age_data :
patient_age = patient_age_data.replace("以上", "歳以上")
elif (patient_age_data == "園児") or ("未満" in patient_age_data) :
patient_age = patient_age_data
else :
patient_age = patient_age_data + "代"
patient_gender_data = (
sheet.cell(
row=sheet.max_row - i,
column=4
).value
)
if patient_gender_data == "-" :
patient_gender = ""
else :
patient_gender = patient_gender_data
# 退院日
left_hospital = (
(
sheet.cell(
row=sheet.max_row - i,
column=6
).value
) if (
sheet.cell(
row=sheet.max_row - i,
column=6
).value
) != None else None
)
patients_data.append(
{
"No": patient_number,
"リリース日": shorted_date + "T08:00:00.000Z",
"居住地": patient_address,
"年代と性別": patient_age + patient_gender,
"退院": left_hospital,
"date": shorted_date,
}
)
print(f'{i + 1}件処理しました')
return patients_data
def get_patients_summary(self, patients):
patient_count = 0
patients_summary = []
patients_sorted = sorted(
patients,
key=lambda x: datetime.strptime(x["リリース日"], "%Y-%m-%dT%H:%M:%S.000Z")
)
for i in range(len(patients_sorted)) :
date = datetime.strptime(
patients_sorted[i]["リリース日"], "%Y-%m-%dT%H:%M:%S.000Z"
)
if i == 0 :
recent_patient_date = date
if (recent_patient_date != date) :
patients_summary.append(
{
"日付":
str(recent_patient_date.year).zfill(4) + "-" +
str(recent_patient_date.month).zfill(2) + "-" +
str(recent_patient_date.day).zfill(2) + "T08:00:00.000Z",
"小計": patient_count
}
)
patient_count = 0
patient_count += 1
if i + 1 == len(patients) :
patients_summary.append(
{
"日付":
str(date.year).zfill(4) + "-" +
str(date.month).zfill(2) + "-" +
str(date.day).zfill(2) + "T08:00:00.000Z",
"小計": patient_count
}
)
zero_days = (date - recent_patient_date).days
if zero_days >= 2 :
for j in range(zero_days - 1) :
zero_date = recent_patient_date + timedelta(days=j+1)
patients_summary.append(
{
"日付": str(zero_date.year).zfill(4) + "-" + str(zero_date.month).zfill(2) + "-" + str(zero_date.day).zfill(2) + "T08:00:00.000Z",
"小計": 0
}
)
recent_patient_date = date
return patients_summary
def get_today_inspections_summary(self, sheet):
inspected = None
patients = None
icu = None
other = None
in_hospital = None
in_hotel = None
in_home = None
dead = None
left = None
adjustment = None
for i in range(sheet.max_row):
if (
(inspected != None) and
(patients != None) and
(icu != None) and
(other != None) and
(in_hospital != None) and
(in_hotel != None) and
(in_home != None) and
(dead != None) and
(left != None) and
(adjustment != None)
):
break
# 検査実施人数
inspected = (
sheet.cell(row=i + 1, column=2).value
if inspected == None
else inspected
)
# 陽性者
patients = (
sheet.cell(row=i + 1, column=3).value
if patients == None
else patients
)
# 高度重症病床
icu = (
sheet.cell(row=i + 1, column=6).value
if icu == None
else icu
)
# その他
other = (
sheet.cell(row=i + 1, column=7).value
if other == None
else other
)
# 入院中
in_hospital = (
sheet.cell(row=i + 1, column=5).value
if in_hospital == None
else in_hospital
)
# 施設療養
in_hotel = (
sheet.cell(row=i + 1, column=8).value
if in_hotel == None
else in_hotel
)
# 自宅療養
in_home = (
sheet.cell(row=i + 1, column=9).value
if in_home == None
else in_home
)
# 死亡
dead = (
sheet.cell(row=i + 1, column=10).value
if dead == None
else dead
)
# 退院
left = (
sheet.cell(row=i + 1, column=4).value
if left == None
else left
)
# 調整中
adjustment = (
sheet.cell(row=i + 1, column=11).value
if adjustment == None
else adjustment
)
return {
"attr": "検査実施人数",
"value": inspected if inspected != None else 0,
"children": [
{
"attr": "陽性患者数",
"value": patients if patients != None else 0,
"children": [
{
"attr": "入院中・入院調整中",
"value": in_hospital if in_hospital != None else 0
},
{
"attr": "高度重症病床",
"value": icu if icu != None else 0
},
{
"attr": "その他",
"value": other if other != None else 0
},
{
"attr": "宿泊施設",
"value": in_hotel if in_hotel != None else 0
},
{
"attr": "自宅療養",
"value": in_home if in_home != None else 0
},
{
"attr": "死亡",
"value": dead if dead != None else 0
},
{
"attr": "退院・解除",
"value": left if left != None else 0
},
{
"attr": "調整中",
"value": adjustment if adjustment != None else 0
},
]
}
],
"last_update": None
}
def get_inspections_summary(self, sheet):
inspections_summary = []
last_inspected = 0
for i in range(sheet.max_row):
inspctions_date = (
sheet.cell(
row=sheet.max_row - i,
column=1
).value + timedelta(hours=8)
)
inspected = (
sheet.cell(
row=sheet.max_row - i,
column=2
).value
)
if inspected != None:
inspections_summary.append(
{
"日付":
str(inspctions_date.year).zfill(4) + "-" +
str(inspctions_date.month).zfill(2) + "-" +
str(inspctions_date.day).zfill(2) + "T08:00:00.000Z",
"小計": inspected - last_inspected
}
)
if inspected != None:
last_inspected = inspected
return inspections_summary
def get_news(self, sheet):
news_items = []
for i in range(sheet.max_row):
date = (
(
sheet.cell(
row=i + 1,
column=1
).value
) + timedelta(hours=8)
)
news_items.append(
{
"date": str(date.year).zfill(4) + "/" +
str(date.month).zfill(2) + "/" +
str(date.day).zfill(2),
"text": sheet.cell(
row=i + 1,
column=2
).value,
"url": str(
sheet.cell(
row=i + 1,
column=3
).value
)
}
)
return news_items