-
Notifications
You must be signed in to change notification settings - Fork 0
/
MASKeyWordProcessor.py
173 lines (150 loc) · 6.42 KB
/
MASKeyWordProcessor.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
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Text, MetaData
import sqlalchemy, json
import re
import csv, time
engine = create_engine("mysql+pymysql://$$$$:$$$$@$$$$/SciEx?charset=utf8mb4", echo=True)
sessionm = sessionmaker(bind=engine)
base = declarative_base()
class VPN_LOCATIONS(base):
__tablename__ = "VPN_LOCATIONS"
id = Column(Integer, primary_key=True, autoincrement=True)
VPN_LOCATION = Column(String(150), nullable=False)
INSTANCES = Column(Integer)
class STIMULI(base):
__tablename__ = "STIMULI"
id = Column(Integer, primary_key=True, autoincrement=True)
STIMULUS = Column(String(150), nullable=False)
INSTANCES = Column(Integer)
class NODES(base):
__tablename__ = "NODES"
id = Column(Integer, primary_key=True, autoincrement=True)
VPN_LOCATION = Column(String(150))
STIMULUS = Column(String(150))
ERRORS = Column(Text)
COMMAND_LIST = Column(String(400))
class RESULTS(base):
__tablename__ = "RESULTS"
id = Column(Integer, primary_key=True, autoincrement=True)
RESULT = Column(Text)
STIMULUS = Column(String(150))
LOCATION = Column(String(150))
class COUNTRESULT(base):
__tablename__ = "LINERESULTS"
id = Column(Integer, primary_key=True, autoincrement=True)
RESULTID = Column(Integer)
KEYCOUNT = Column(Integer)
LINES = Column(Integer)
STIMULUS = Column(String(150))
LOCATION = Column(String(150))
base.metadata.create_all(engine)
keyterms = ["tested", "positive", "testing", "isolation", "covid", "covld", "clinic", "pcr"]
locationcount = {}
locationcountall = {}
session = sessionm()
results = session.query(RESULTS).all()
for item in results:
itemcount = 0
itemlines = 0
itemlines += len(re.findall("(.+)", item.RESULT))
try:
locationcountall[item.LOCATION] = locationcountall[item.LOCATION] + len(re.findall("(.+)", item.RESULT))
except KeyError:
locationcountall[item.LOCATION] = 1
for string in keyterms:
if string in str(item.RESULT):
itemcount += len(re.findall(string, item.RESULT))
try:
locationcount[item.LOCATION] = locationcount[item.LOCATION] + len(re.findall(string, item.RESULT))
except KeyError:
locationcount[item.LOCATION] = 1
temp = COUNTRESULT(RESULTID = item.id, KEYCOUNT = itemcount, LINES = itemlines, STIMULUS = item.STIMULUS, LOCATION = item.LOCATION)
session.add(temp)
session.commit()
print(f"{len(results)} Autocomplete Searches processed.")
results = {}
country_mapper = {
"AE-Dubai-dxb": ["","","United Arab Emirates"],
"AL-Tirana-tia": ["","","Albania"],
"AR-Buenos-Aires-eze": ["","", "Argentina"],
"AU-Adelaide-adl": ["","South Australia", "Australia"],
"AU-Brisbane-bne": ["","Queensland", "Australia"],
"AU-Melbourne-mel": ["","Victoria", "Australia"],
"AU-Perth-per": ["","Western Australia", "Australia"],
"AU-Sydney-syd": ["","New South Wales", "Australia"],
"BR-Sao-Paulo-gru": ["","Sao Paulo", "Brazil"],
"CA-Montreal-yul": ["","Quebec", "Canada"],
"CA-Toronto-tor": ["","Ontario", "Canada"],
"CA-Vancouver-yvr": ["","British Columbia", "Canada"],
"CH-Zurich-zrh": ["","","Switzerland"],
"CL-Santiago-scl": ["","Metropolitana", "Chile"],
"CR-San-Jose-sjo": ["","", "Costa Rica"],
"FI-Helsinki-hel": ["","", "Finland"],
"HR-Zagreb-zag": ["","", "Croatia"],
"IN-Mumbai-bom": ["","Maharashtra", "India"],
"IN-New-Delhi-del": ["","Delhi", "India"],
"IS-Reykjavik-rkv": ["","", "Iceland"],
"JP-Tokyo-nrt": ["","Tokyo", "Japan"],
"KR-Seoul-sel": ["","", "Korea, South"],
"MD-Chisinau-kiv": ["","", "Moldova"],
"MX-Guadalajara-gdl": ["","Jalisco", "Mexico"],
"MY-Kuala-Lumpur-kul": ["","W.P. Kuala Lumpur", "Malaysia"],
"NZ-Auckland-akl": ["","", "New Zealand"],
"PE-Lima-lim": ["","Lima", "Peru"],
"RO-Bucharest-otp": ["","","Romania"],
"RS-Belgrade-beg": ["","", "Serbia"],
"SG-Singapore-sin": ["","","Singapore"],
"SI-Ljubljana-lju": ["","", "Slovenia"],
"US-Ashburn-iad": ["Loudoun", "Virginia", "US"],
"US-Atlanta-atl": ["Fulton", "Georgia", "US"],
"US-Boston-bos": ["Suffolk", "Massachusetts", "US"],
"US-Charlotte-clt": ["Mecklenburg", "North Carolina", "US"],
"US-Chicago-chi": ["Cook", "Illinois", "US"],
"US-Cincinnati-cvg": ["Hamilton", "Ohio", "US"],
"US-Dallas-dal": ["Dallas", "Texas", "US"],
"US-Denver-den": ["Denver", "Colorado", "US"],
"US-Houston-hou": ["Harris", "Texas", "US"],
"US-Las-Vegas-las": ["Clark", "Nevada", "US"],
"US-Los-Angeles-lax": ["Los Angeles", "California", "US"],
"US-Miami-mia": ["Miami-Dade", "Florida", "US"],
"US-New-Orleans-msy": ["Orleans", "Louisiana", "US"],
"US-New-York-nyc": ["New York", "New York", "US"],
"US-Phoenix-phx": ["Maricopa", "Arizona", "US"],
"US-San-Jose-sjc": ["Santa Clara", "California", "US"],
"US-Seattle-sea": ["King", "Washington", "US"],
}
covidFile = open("01-28-2022.csv", "r")
covidData = csv.reader(covidFile)
locList = []
outputFile = open("correlation.csv", "w", newline='')
outputCSV = csv.writer(outputFile, delimiter= ",", quoting=csv.QUOTE_MINIMAL)
outputCSV.writerow(["Location", "Count", "Samples", "Percentage", "InfectionRate"])
for row in covidData:
locList.append(row)
for key in sorted(locationcount, reverse=True):
value = locationcount[key]
totalcount = locationcountall[key]
percentage = value/totalcount
admin2 = country_mapper[key][0]
province_state = country_mapper[key][1]
country = country_mapper[key][2]
row_final = None
#print(f"Country: {country}; Province/State: {province_state}; LGA/Locality: {admin2}")
for row in locList:
if row[3] == country:
if row[1] == admin2:
if row[2] == province_state:
row_final = row
#print(f"{key}: {value} out of {totalcount}: {percentage}")
outputCSV.writerow([key, value, totalcount, percentage, row_final[12]])
lineresult = session.query(COUNTRESULT).all()
outputFile.close()
rawFile = open("raw.csv", "w", newline='')
rawCSV = csv.writer(rawFile, delimiter= ",", quoting=csv.QUOTE_MINIMAL)
rawCSV.writerow(["ID", "Count", "Samples", "Stimulus", "Location"])
for item in lineresult:
rawCSV.writerow([item.id, item.KEYCOUNT, item.LINES, item.STIMULUS, item.LOCATION])
time.sleep(5)
rawFile.close()