-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataPrepare_ori.py
83 lines (74 loc) · 2.3 KB
/
DataPrepare_ori.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
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
class AllData:
def Data(self):
self.ConfirmedData = []
self.DeathData = []
self.RecoverData = []
self.AreaName = []
class Data:
def Data(self):
self.ConfirmedData = 0
self.DeathData = 0
self.RecoverData = 0
self.AreaName = ''
def LoadData(filename):
df = pd.read_csv(filename, header=None)
data = df.values
res = AllData()
res.ConfirmedData = data[:, 2][1:]
res.ConfirmedData = res.ConfirmedData.astype('float32')
res.DeathData = data[:, 4][1:]
res.DeathData = res.DeathData.astype('float32')
res.RecoverData = data[:, 6][1:]
res.RecoverData = res.RecoverData.astype('float32')
res.AreaName = data[:,12][1:]
arr = []
dic = {}
now = []
#print(res.ConfirmedData.shape)
for _ in range(res.ConfirmedData.shape[0]):
if res.AreaName[_] in dic:
x = Data()
x.ConfirmedData = res.ConfirmedData[_]
x.DeathData = res.DeathData[_]
x.RecoverData = res.RecoverData[_]
x.AreaName = res.AreaName[_]
now.append(x)
else:
dic[res.AreaName[_]] = 1
if len(now) != 0:
arr.append(now)
now = []
arr.append(now)
return arr
def Patch(data, size):
data = [0] * (size - len(data)) + data
return data
#This will return a (size-2) shape vector, where each element is (d^2 f \ dx^2) \ (df\dx)
def GetRate(data, size):
ret = []
res = []
for i in range(len(data)):
for j in range(1, size - 2):
deri1 = (data[i][j+1] - data[i][j-1]) / 2
deri2 = (data[i][j+1] - data[i][j]) - (data[i][j] - data[i][j-1])
if deri1 == 0:
res.append(0)
else:
res.append(deri2 / deri1)
ret.append(res)
res = []
return ret
def GetConfirmed(data, size):
res = []
for i in range(len(data[0])):
res.append(data[0][i].ConfirmedData)
ret = []
for i in range(len(data[0]) - size):
ret.append(Patch(res[max(0, i-size):i], size))
return ret
if __name__ == "__main__":
LoadData('data.csv')