Created
July 17, 2020 21:42
-
-
Save RKursatV/43c4f39e1b3576d8e0e824e8b15c5d91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import xlrd | |
from code3to2 import convert2 | |
tree = ET.parse('data.xml') | |
root = tree.getroot() | |
wld = [] | |
wldGdp = [] | |
res = [] | |
for i in range(1960,2020): | |
res.append({'date': str(i), 'list': []}) | |
for data in root: | |
for record in data: | |
year = record[2].text | |
key = record[0].attrib['key'] | |
gdp = record[3].text | |
tmp = {} | |
tmp['id'] = key | |
tmp['confirmed'] = "{:.2f}".format(float(gdp)/((10**9))) if (gdp != None) else 0 | |
tmp['deaths'] = 0 | |
tmp['coup'] = 0 | |
if key == 'WLD': | |
wldGdp.append(gdp) | |
try: | |
a = convert2(key) | |
except: | |
continue | |
res[int(year)-1960]['list'].append(tmp) | |
break | |
tre = ET.parse('enf.xml') | |
rot = tre.getroot() | |
for data in rot: | |
for record in data: | |
year = record[2].text | |
key = record[0].attrib['key'] | |
enf = record[3].text | |
if key == 'WLD': | |
wld.append(enf) | |
for tmp in res[int(year)-1960]['list']: | |
if tmp['id'] == key: | |
tmp['recovered'] = "{:.2f}".format(float(enf)) if (enf != None) else "" | |
break | |
break | |
df = xlrd.open_workbook('coup.xls', on_demand = True) | |
sheet = df.sheet_by_index(0) | |
for i in range(1,852): | |
key = sheet.cell(i,1).value | |
year = int(sheet.cell(i,4).value) | |
death = sheet.cell(i,7).value | |
death = 0 if(death == '' or death == 999) else int(death) | |
#day = sheet.cell(i,2).value | |
#mount = sheet.cell(i,3).value | |
if year >= 1960: | |
for tmp in res[year-1960]['list']: | |
if tmp['id'] == key: | |
tmp['deaths'] += death | |
tmp['coup'] += 1 | |
break | |
totalDict = [] | |
for tt in res: | |
tmp = {} | |
totalDeath = 0 | |
totalCoup = 0 | |
for t in tt['list']: | |
t['id'] = convert2(t['id']) | |
totalDeath += t['deaths'] | |
totalCoup += t['coup'] | |
tmp['coup'] = totalCoup | |
tmp['deaths'] = totalDeath | |
tmp['date'] = tt['date'] | |
tmp['recovered'] = "{:.2f}".format(float(wld[int(tt['date'])-1960])) if wld[int(tt['date'])-1960] else 0 | |
tmp["confirmed"] = "{:.2f}".format(float(wldGdp[int(tt['date'])-1960])/(10**12)) if wldGdp[int(tt['date'])-1960] else 0 | |
totalDict.append(tmp) | |
print(totalDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment