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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 7 |
+
# Helpful function
|
| 8 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 9 |
+
# Set up the Files
|
| 10 |
+
def SetUpFile(flag):
|
| 11 |
+
# print(flag)
|
| 12 |
+
file =0
|
| 13 |
+
if flag:
|
| 14 |
+
file= pd.read_csv('data.csv',index_col=0)
|
| 15 |
+
else:
|
| 16 |
+
file=pd.read_csv('data-3 (2).csv',index_col=0)
|
| 17 |
+
|
| 18 |
+
return file
|
| 19 |
+
# Convert from week Type to date type and return string
|
| 20 |
+
def ConvertWeektoDate(Year_week):
|
| 21 |
+
import datetime
|
| 22 |
+
d = Year_week
|
| 23 |
+
r = datetime.datetime.strptime(d + '-1', "%Y-W%W-%w").date()
|
| 24 |
+
return r.strftime('%Y/%m/%d')
|
| 25 |
+
# This function get flag (true for file 1) and country name and colum
|
| 26 |
+
# and return kind of list
|
| 27 |
+
def GetCleanData(flag,country,colum):
|
| 28 |
+
if flag:
|
| 29 |
+
file1=SetUpFile(flag)
|
| 30 |
+
# print(file1.head())
|
| 31 |
+
return file1.loc[[country],colum]
|
| 32 |
+
|
| 33 |
+
else:
|
| 34 |
+
file2=SetUpFile(flag)
|
| 35 |
+
return file2.loc[[country],colum]
|
| 36 |
+
def GetDatesFromFile1(country):
|
| 37 |
+
file1=SetUpFile(True)
|
| 38 |
+
date_list = file1.loc[[country],'year_week'].values
|
| 39 |
+
Array_toreturn=[]
|
| 40 |
+
for x in date_list:
|
| 41 |
+
# print(x)
|
| 42 |
+
real_date=ConvertWeektoDate(x)
|
| 43 |
+
# print(real_date)
|
| 44 |
+
Array_toreturn.append(real_date)
|
| 45 |
+
# print(Array_toreturn)
|
| 46 |
+
return Array_toreturn
|
| 47 |
+
|
| 48 |
+
def TopN(list1, N):
|
| 49 |
+
final_list = []
|
| 50 |
+
|
| 51 |
+
for i in range(0, N):
|
| 52 |
+
max1 = 0
|
| 53 |
+
|
| 54 |
+
for j in range(len(list1)):
|
| 55 |
+
if list1[j] > max1:
|
| 56 |
+
max1 = list1[j]
|
| 57 |
+
|
| 58 |
+
list1.remove(max1)
|
| 59 |
+
final_list.append(max1)
|
| 60 |
+
|
| 61 |
+
return(final_list)
|
| 62 |
+
|
| 63 |
+
def Sum_Of_Var_In_Country(country):
|
| 64 |
+
date_list = GetCleanData(True, country, 'year_week')
|
| 65 |
+
the_lastOne = '2020'
|
| 66 |
+
filtersDate = []
|
| 67 |
+
for x in date_list:
|
| 68 |
+
filtersDate.append(x[0:4])
|
| 69 |
+
UniqList = set(filtersDate)
|
| 70 |
+
UniqList = list(UniqList)
|
| 71 |
+
UniqList.sort()
|
| 72 |
+
# print(UniqList)
|
| 73 |
+
data = GetCleanData(True, country, 'tests_done')
|
| 74 |
+
# print(len(data))
|
| 75 |
+
filedate = sorted(date_list)
|
| 76 |
+
array_ofSum = []
|
| 77 |
+
sum = 0
|
| 78 |
+
for x in range(len(data)):
|
| 79 |
+
# print(x, data.values[x], sum, filedate[x][0:4])
|
| 80 |
+
if x != 0:
|
| 81 |
+
the_lastOne = filedate[x - 1][0:4]
|
| 82 |
+
if the_lastOne == filedate[x][0:4]:
|
| 83 |
+
sum += data.values[x]
|
| 84 |
+
if the_lastOne != filedate[x][0:4] or x == len(data) - 1:
|
| 85 |
+
array_ofSum.append(sum)
|
| 86 |
+
sum = 0
|
| 87 |
+
|
| 88 |
+
# print((array_ofSum), (UniqList))
|
| 89 |
+
return ((array_ofSum), (UniqList))
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 93 |
+
# The Hw
|
| 94 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 100 |
+
# Part 1
|
| 101 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 102 |
+
#Q1
|
| 103 |
+
def Display_Test_Rate(country):
|
| 104 |
+
data=GetCleanData(True,country,'testing_rate')
|
| 105 |
+
Cyprus_Test_rate_list=data.values.tolist()
|
| 106 |
+
xpoints = list(range(len(Cyprus_Test_rate_list)))
|
| 107 |
+
XDate=GetDatesFromFile1(country)
|
| 108 |
+
plt.plot(xpoints,Cyprus_Test_rate_list)
|
| 109 |
+
plt.title('Testing Rate in '+country)
|
| 110 |
+
plt.ylabel('testing rate')
|
| 111 |
+
plt.xlabel('week number')
|
| 112 |
+
# plt.xticks(rotation=-45)
|
| 113 |
+
plt.show()
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
#Q2
|
| 117 |
+
def Display_postive_rate(country):
|
| 118 |
+
Sweeden=GetCleanData(True,country,'positivity_rate')
|
| 119 |
+
# print(Sweeden.values)
|
| 120 |
+
xpoints = list(range(len(Sweeden.values)))
|
| 121 |
+
plt.plot(xpoints,Sweeden.values)
|
| 122 |
+
plt.title('positivity_rate in '+country)
|
| 123 |
+
plt.ylabel('R ratio')
|
| 124 |
+
plt.xlabel('week number')
|
| 125 |
+
# plt.xticks(rotation=-45)
|
| 126 |
+
plt.axhline(y=2, color='green', linestyle='-')
|
| 127 |
+
plt.text(0,4,'GOOD ratio')
|
| 128 |
+
plt.axhline(y=15, color='orange', linestyle='-')
|
| 129 |
+
plt.text(0, 17, 'satisfy ratio')
|
| 130 |
+
plt.axhline(y=30, color='red', linestyle='-')
|
| 131 |
+
plt.text(0, 32, 'Very BAD ratio')
|
| 132 |
+
|
| 133 |
+
plt.show()
|
| 134 |
+
|
| 135 |
+
#Q3
|
| 136 |
+
def Display_SumOfTest(country):
|
| 137 |
+
date_list=GetDatesFromFile1(country)
|
| 138 |
+
the_lastOne=''
|
| 139 |
+
filtersDate=[]
|
| 140 |
+
for x in date_list:
|
| 141 |
+
filtersDate.append(x[0:7])
|
| 142 |
+
UniqList=set(filtersDate)
|
| 143 |
+
UniqList=list(UniqList)
|
| 144 |
+
UniqList.sort()
|
| 145 |
+
# print(UniqList)
|
| 146 |
+
data=GetCleanData(True,country,'tests_done')
|
| 147 |
+
filedate = GetDatesFromFile1(country)
|
| 148 |
+
array_ofSum=[]
|
| 149 |
+
# print(data.values)
|
| 150 |
+
# print(filedate)
|
| 151 |
+
sum=0
|
| 152 |
+
for x in range(len(data)):
|
| 153 |
+
# print(x,data.values[x],filedate[x][0:7],UniqList[x])
|
| 154 |
+
print(x, data.values[x], filedate[x][0:7])
|
| 155 |
+
if x!=0:
|
| 156 |
+
the_lastOne = filedate[x - 1][0:7]
|
| 157 |
+
print(the_lastOne)
|
| 158 |
+
if the_lastOne==filedate[x][0:7]:
|
| 159 |
+
sum+=data.values[x]
|
| 160 |
+
print(sum)
|
| 161 |
+
else:
|
| 162 |
+
array_ofSum.append(sum)
|
| 163 |
+
sum=0
|
| 164 |
+
print('skip')
|
| 165 |
+
|
| 166 |
+
# xpoints = list(range(len(Sweeden.values)))
|
| 167 |
+
colors = ['red', 'green']
|
| 168 |
+
plt.bar(UniqList,array_ofSum,color=colors)
|
| 169 |
+
plt.xticks(rotation=-90)
|
| 170 |
+
plt.ylabel('Sum of Test done')
|
| 171 |
+
plt.xlabel('Year/month')
|
| 172 |
+
plt.title('Sum of test done by month in '+country)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
plt.show()
|
| 176 |
+
|
| 177 |
+
#Q4
|
| 178 |
+
def Display_SumOfPostive(country):
|
| 179 |
+
date_list = GetDatesFromFile1(country)
|
| 180 |
+
the_lastOne = ''
|
| 181 |
+
filtersDate = []
|
| 182 |
+
for x in date_list:
|
| 183 |
+
filtersDate.append(x[0:7])
|
| 184 |
+
UniqList = set(filtersDate)
|
| 185 |
+
UniqList = list(UniqList)
|
| 186 |
+
UniqList.sort()
|
| 187 |
+
# print(UniqList)
|
| 188 |
+
data = GetCleanData(True, country, 'new_cases')
|
| 189 |
+
filedate = GetDatesFromFile1(country)
|
| 190 |
+
array_ofSum = []
|
| 191 |
+
# print(data.values)
|
| 192 |
+
# print(filedate)
|
| 193 |
+
sum = 0
|
| 194 |
+
for x in range(len(data)):
|
| 195 |
+
# print(x,data.values[x],filedate[x][0:7],UniqList[x])
|
| 196 |
+
print(x, data.values[x], filedate[x][0:7])
|
| 197 |
+
if x != 0:
|
| 198 |
+
the_lastOne = filedate[x - 1][0:7]
|
| 199 |
+
print(the_lastOne)
|
| 200 |
+
if the_lastOne == filedate[x][0:7]:
|
| 201 |
+
sum += data.values[x]
|
| 202 |
+
print(sum)
|
| 203 |
+
else:
|
| 204 |
+
array_ofSum.append(sum)
|
| 205 |
+
sum = 0
|
| 206 |
+
print('skip')
|
| 207 |
+
|
| 208 |
+
# xpoints = list(range(len(Sweeden.values)))
|
| 209 |
+
colors = ['red', 'green']
|
| 210 |
+
plt.bar(UniqList, array_ofSum, color=colors)
|
| 211 |
+
plt.xticks(rotation=-90)
|
| 212 |
+
plt.ylabel('Sum of new cases')
|
| 213 |
+
plt.xlabel('Year/month')
|
| 214 |
+
plt.title('Sum of new cases by month in '+country)
|
| 215 |
+
|
| 216 |
+
plt.show()
|
| 217 |
+
|
| 218 |
+
#Q5
|
| 219 |
+
def Display_Death(country):
|
| 220 |
+
dataY=GetCleanData(False,country,'value')
|
| 221 |
+
dataX=GetCleanData(False,country,'date')
|
| 222 |
+
xpoints = list(range(len(dataX.values)))
|
| 223 |
+
plt.plot(xpoints,dataY.values)
|
| 224 |
+
plt.ylabel('Amount of Death')
|
| 225 |
+
plt.xlabel('Index')
|
| 226 |
+
plt.title('Amount of Death in '+country)
|
| 227 |
+
plt.show()
|
| 228 |
+
|
| 229 |
+
#Q6
|
| 230 |
+
def Display_DeathPie(country):
|
| 231 |
+
|
| 232 |
+
date_list=GetCleanData(False,country,'date')
|
| 233 |
+
the_lastOne='2020'
|
| 234 |
+
filtersDate=[]
|
| 235 |
+
for x in date_list:
|
| 236 |
+
filtersDate.append(x[0:4])
|
| 237 |
+
UniqList=set(filtersDate)
|
| 238 |
+
UniqList=list(UniqList)
|
| 239 |
+
UniqList.sort()
|
| 240 |
+
# print(UniqList)
|
| 241 |
+
data=GetCleanData(False,country,'value')
|
| 242 |
+
print(len(data))
|
| 243 |
+
filedate = sorted(date_list)
|
| 244 |
+
array_ofSum=[]
|
| 245 |
+
# print(data.values)
|
| 246 |
+
print('sort Date',filedate)
|
| 247 |
+
sum=0
|
| 248 |
+
for x in range(len(data)):
|
| 249 |
+
print(x,data.values[x],sum,filedate[x][0:4])
|
| 250 |
+
# print(x, data.values[x], filedate[x][0:4])
|
| 251 |
+
if x!=0:
|
| 252 |
+
the_lastOne = filedate[x - 1][0:4]
|
| 253 |
+
# print(the_lastOne)
|
| 254 |
+
if the_lastOne==filedate[x][0:4]:
|
| 255 |
+
sum+=data.values[x]
|
| 256 |
+
# print(sum)
|
| 257 |
+
if the_lastOne!=filedate[x][0:4] or x==len(data)-1:
|
| 258 |
+
array_ofSum.append(sum)
|
| 259 |
+
sum=0
|
| 260 |
+
print('skip')
|
| 261 |
+
|
| 262 |
+
print((array_ofSum),(UniqList))
|
| 263 |
+
colors=['r','g','b','y']
|
| 264 |
+
|
| 265 |
+
plt.pie(array_ofSum, labels=UniqList, colors=colors,
|
| 266 |
+
startangle=90, shadow=True,
|
| 267 |
+
radius=1.2, autopct='%1.1f%%')
|
| 268 |
+
plt.text(-0.5,1.5,'The death in '+country)
|
| 269 |
+
plt.legend()
|
| 270 |
+
plt.show()
|
| 271 |
+
|
| 272 |
+
#Q7
|
| 273 |
+
def Display_TestRatio(country):
|
| 274 |
+
tests_done = GetCleanData(True,country,'tests_done').values
|
| 275 |
+
new_cases = GetCleanData(True,country,'new_cases').values
|
| 276 |
+
Ratio =[]
|
| 277 |
+
|
| 278 |
+
# print(len(tests_done),len(new_cases))
|
| 279 |
+
for i in range(len(tests_done)):
|
| 280 |
+
if tests_done[i]!=0:
|
| 281 |
+
Ratio.append(new_cases[i]/tests_done[i])
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
xpoints = list(range(len(Ratio)))
|
| 285 |
+
print(xpoints,Ratio)
|
| 286 |
+
plt.plot(xpoints,Ratio,marker='o')
|
| 287 |
+
plt.title('The Ratio new_cases/test_done in '+country)
|
| 288 |
+
plt.ylabel('ratio')
|
| 289 |
+
plt.xlabel('weeks')
|
| 290 |
+
plt.show()
|
| 291 |
+
|
| 292 |
+
#Q8
|
| 293 |
+
def Display_DeathAvrage(country):
|
| 294 |
+
deathList=GetCleanData(False,country,'value')
|
| 295 |
+
date_list=GetCleanData(False,country,'date')
|
| 296 |
+
the_lastOne=''
|
| 297 |
+
filtersDate=[]
|
| 298 |
+
for x in date_list:
|
| 299 |
+
filtersDate.append(x[0:7])
|
| 300 |
+
UniqList=set(filtersDate)
|
| 301 |
+
UniqList=list(UniqList)
|
| 302 |
+
UniqList.sort()
|
| 303 |
+
# print(UniqList)
|
| 304 |
+
# print(len(deathList))
|
| 305 |
+
filedate = sorted(date_list)
|
| 306 |
+
array_ofSum=[]
|
| 307 |
+
# print(data.values)
|
| 308 |
+
# print('sort Date',filedate)
|
| 309 |
+
count=0
|
| 310 |
+
sum=0
|
| 311 |
+
for x in range(len(deathList)):
|
| 312 |
+
print(x,deathList.values[x],sum,filedate[x][0:7])
|
| 313 |
+
# print(x, data.values[x], filedate[x][0:4])
|
| 314 |
+
if x!=0:
|
| 315 |
+
the_lastOne = filedate[x - 1][0:7]
|
| 316 |
+
# print(the_lastOne)
|
| 317 |
+
if the_lastOne==filedate[x][0:7]:
|
| 318 |
+
count=count+1
|
| 319 |
+
sum+=deathList.values[x]
|
| 320 |
+
# print(sum)
|
| 321 |
+
if the_lastOne!=filedate[x][0:7] or x==len(deathList)-1:
|
| 322 |
+
if count==0:
|
| 323 |
+
continue
|
| 324 |
+
array_ofSum.append(sum/count)
|
| 325 |
+
sum=0
|
| 326 |
+
count=0
|
| 327 |
+
print('skip')
|
| 328 |
+
|
| 329 |
+
print(len(array_ofSum),len(UniqList))
|
| 330 |
+
print((array_ofSum),(UniqList))
|
| 331 |
+
colors=['r','g','b']
|
| 332 |
+
plt.bar(UniqList,array_ofSum,color=colors)
|
| 333 |
+
plt.xticks(rotation=-90)
|
| 334 |
+
plt.title('The avarge of death in '+country)
|
| 335 |
+
plt.ylabel('avg of death')
|
| 336 |
+
plt.show()
|
| 337 |
+
#Q9
|
| 338 |
+
def Display_freqSource(country):
|
| 339 |
+
all=SetUpFile(False)
|
| 340 |
+
print(len(all['source'].values))
|
| 341 |
+
colors=['r','g','b']
|
| 342 |
+
plt.hist(all['source'].values,color='pink',alpha=1,width=0.8)
|
| 343 |
+
plt.xticks(rotation=-45)
|
| 344 |
+
plt.title('The frequency of source data')
|
| 345 |
+
plt.ylabel('frequency')
|
| 346 |
+
plt.show()
|
| 347 |
+
|
| 348 |
+
#Q10
|
| 349 |
+
def Display_NegtiveTest(country):
|
| 350 |
+
tests_done = GetCleanData(True, country, 'tests_done').values
|
| 351 |
+
new_cases = GetCleanData(True, country, 'new_cases').values
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
date_list = GetDatesFromFile1(country)
|
| 355 |
+
the_lastOne = '2020'
|
| 356 |
+
filtersDate = []
|
| 357 |
+
for x in date_list:
|
| 358 |
+
filtersDate.append(x[0:4])
|
| 359 |
+
UniqList = set(filtersDate)
|
| 360 |
+
UniqList = list(UniqList)
|
| 361 |
+
UniqList.sort()
|
| 362 |
+
# print(UniqList)
|
| 363 |
+
print(len(tests_done),len(new_cases))
|
| 364 |
+
filedate = sorted(date_list)
|
| 365 |
+
array_ofSum = []
|
| 366 |
+
# print(data.values)
|
| 367 |
+
# print('sort Date', filedate)
|
| 368 |
+
sum = 0
|
| 369 |
+
sumOfTest=0
|
| 370 |
+
for x in range(len(new_cases)):
|
| 371 |
+
print(x, new_cases[x],tests_done[x], sum, filedate[x][0:4])
|
| 372 |
+
# print(x, data.values[x], filedate[x][0:4])
|
| 373 |
+
if x != 0:
|
| 374 |
+
the_lastOne = filedate[x - 1][0:4]
|
| 375 |
+
# print(the_lastOne)
|
| 376 |
+
if the_lastOne == filedate[x][0:4]:
|
| 377 |
+
sum += tests_done[x]-new_cases[x]
|
| 378 |
+
sumOfTest+=tests_done[x]
|
| 379 |
+
# print(sum)
|
| 380 |
+
if the_lastOne != filedate[x][0:4] or x == len(new_cases) - 1:
|
| 381 |
+
array_ofSum.append(sum/sumOfTest)
|
| 382 |
+
sum = 0
|
| 383 |
+
sumOfTest=0
|
| 384 |
+
print('skip')
|
| 385 |
+
|
| 386 |
+
print((array_ofSum), (UniqList))
|
| 387 |
+
colors = ['r', 'g', 'b', 'y']
|
| 388 |
+
plt.barh(UniqList,array_ofSum,color='Yellowgreen',height=0.6)
|
| 389 |
+
plt.title('The negtive precentage of tests in '+country)
|
| 390 |
+
plt.show()
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 402 |
+
# Part2
|
| 403 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 404 |
+
|
| 405 |
+
#guy
|
| 406 |
+
def Compare_avg_pr_by_two_countries(year, country1, country2):
|
| 407 |
+
data = pd.read_csv('data.csv', index_col=0)
|
| 408 |
+
file1 = data.loc[country1, ['positivity_rate', 'year_week']]
|
| 409 |
+
file2 = data.loc[country2, ['positivity_rate', 'year_week']]
|
| 410 |
+
sum1 = 0
|
| 411 |
+
sum2 = 0
|
| 412 |
+
filteredData1 = file1[file1['year_week'].str.startswith(str(year))]['positivity_rate'].values
|
| 413 |
+
filteredData2 = file2[file2['year_week'].str.startswith(str(year))]['positivity_rate'].values
|
| 414 |
+
for i in filteredData1:
|
| 415 |
+
sum1+=i
|
| 416 |
+
for i in filteredData2:
|
| 417 |
+
sum2+=i
|
| 418 |
+
|
| 419 |
+
colors = ['r', 'g']
|
| 420 |
+
array_ofSum = [sum1, sum2]
|
| 421 |
+
UniqList = [country1, country2]
|
| 422 |
+
plt.pie(array_ofSum, labels=UniqList, colors=colors,
|
| 423 |
+
startangle=90, shadow=True, autopct='%1.1f%%')
|
| 424 |
+
plt.title('Compare positive rate average between ' + country1 + ' and ' + country2 + ' in ' + str(year))
|
| 425 |
+
plt.legend()
|
| 426 |
+
plt.show()
|
| 427 |
+
#guy
|
| 428 |
+
def Compare_positive_rate(year, country1, country2):
|
| 429 |
+
data = pd.read_csv('data.csv', index_col=0)
|
| 430 |
+
file1 = data.loc[country1, ['positivity_rate', 'year_week']]
|
| 431 |
+
file2 = data.loc[country2, ['positivity_rate', 'year_week']]
|
| 432 |
+
|
| 433 |
+
filteredData1 = file1[file1['year_week'].str.startswith(str(year))]['positivity_rate'].values
|
| 434 |
+
filteredData2 = file2[file2['year_week'].str.startswith(str(year))]['positivity_rate'].values
|
| 435 |
+
|
| 436 |
+
xpoints = list(range(len(filteredData1)))
|
| 437 |
+
ypoints = list(range(len(filteredData2)))
|
| 438 |
+
plt.bar(ypoints, filteredData2, label=country1,color='g')
|
| 439 |
+
|
| 440 |
+
plt.bar(xpoints, filteredData1, label=country1, color='r')
|
| 441 |
+
|
| 442 |
+
plt.title('Comparing positivity rate between {} and {} for {}'.format(country1, country2, year))
|
| 443 |
+
plt.xlabel('Week number')
|
| 444 |
+
plt.ylabel('Positivity Rate')
|
| 445 |
+
plt.legend()
|
| 446 |
+
|
| 447 |
+
plt.show()
|
| 448 |
+
|
| 449 |
+
#guy
|
| 450 |
+
def Compare_deaths_based_indicator_in_a_given_year(year):
|
| 451 |
+
data = SetUpFile(False)
|
| 452 |
+
data['year'] = data['year_week'].str[:4]
|
| 453 |
+
data_year = data[data['year'] == year]
|
| 454 |
+
deaths_by_indicator = data_year.groupby('indicator')['value'].sum()
|
| 455 |
+
print(deaths_by_indicator.keys())
|
| 456 |
+
colors = ['r', 'g','y','b']
|
| 457 |
+
|
| 458 |
+
plt.bar(deaths_by_indicator.keys(), deaths_by_indicator.values, label=deaths_by_indicator.keys(),color=colors)
|
| 459 |
+
|
| 460 |
+
plt.title('Compare deaths based on info from each indicator_in '+year)
|
| 461 |
+
|
| 462 |
+
plt.legend()
|
| 463 |
+
plt.show()
|
| 464 |
+
|
| 465 |
+
#dor
|
| 466 |
+
def compare_new_cases(country1, country2, year):
|
| 467 |
+
|
| 468 |
+
date_list1=GetCleanData(True,country1,'year_week')
|
| 469 |
+
|
| 470 |
+
data1=GetCleanData(True,country1,'new_cases')
|
| 471 |
+
print(data1)
|
| 472 |
+
filedate1 = sorted(date_list1)
|
| 473 |
+
sum1=0
|
| 474 |
+
count=0
|
| 475 |
+
for x in range(len(data1)):
|
| 476 |
+
if filedate1[x - 1][0:4]==year:
|
| 477 |
+
# print(the_lastOne,' ', data1.values[x])
|
| 478 |
+
sum1+=data1.values[x-1]
|
| 479 |
+
count+=1
|
| 480 |
+
|
| 481 |
+
print(sum1)
|
| 482 |
+
|
| 483 |
+
date_list2=GetCleanData(True,country2,'year_week')
|
| 484 |
+
data2=GetCleanData(True,country2,'new_cases')
|
| 485 |
+
filedate2 = sorted(date_list2)
|
| 486 |
+
sum2=0
|
| 487 |
+
for x in range(len(data1)):
|
| 488 |
+
if filedate2[x - 1][0:4]==year:
|
| 489 |
+
the_lastOne = filedate2[x - 1][0:4]
|
| 490 |
+
sum2+=data2.values[x-1]
|
| 491 |
+
print(sum2)
|
| 492 |
+
colors=['r','g']
|
| 493 |
+
array_ofSum=[sum1,sum2]
|
| 494 |
+
UniqList=[country1,country2]
|
| 495 |
+
plt.pie(array_ofSum, labels=UniqList, colors=colors,
|
| 496 |
+
startangle=90, shadow=True,
|
| 497 |
+
radius=1.2, autopct='%1.1f%%')
|
| 498 |
+
plt.text(-1,1.5,'Comparation of new cases between '+country1+ ' and '+ country2+' in '+year)
|
| 499 |
+
plt.legend()
|
| 500 |
+
plt.show()
|
| 501 |
+
#Dor
|
| 502 |
+
def Display_Tests_Done_Comparation(country1, country2):
|
| 503 |
+
sumCounty1=Sum_Of_Var_In_Country(country1)[0]
|
| 504 |
+
sumCounty2=Sum_Of_Var_In_Country(country2)[0]
|
| 505 |
+
years=Sum_Of_Var_In_Country(country1)[1]
|
| 506 |
+
print(sumCounty1,sumCounty2)
|
| 507 |
+
arrOfSums=(sumCounty1,sumCounty2)
|
| 508 |
+
print(years)
|
| 509 |
+
|
| 510 |
+
plt.bar(years,sumCounty2,color='b')
|
| 511 |
+
plt.bar(years,sumCounty1,color='r')
|
| 512 |
+
plt.ylabel('amount of tests')
|
| 513 |
+
plt.xlabel('years')
|
| 514 |
+
plt.title('Comparation of test done between '+country1+' and '+country2)
|
| 515 |
+
plt.show()
|
| 516 |
+
#dor
|
| 517 |
+
def plot_top_months_with_deaths(year,NumOfMonth):
|
| 518 |
+
data = SetUpFile(False)
|
| 519 |
+
#return the relevent data by wanted year
|
| 520 |
+
data_year = data[data['date'].str[:4] == year]
|
| 521 |
+
#return sum of death for all month
|
| 522 |
+
deaths_by_month = data_year.groupby(data_year['date'].str[5:7])['value'].sum().reset_index()
|
| 523 |
+
#sort month and take 3 largest
|
| 524 |
+
sorted_months = deaths_by_month.sort_values('value', ascending=False).head(NumOfMonth)
|
| 525 |
+
|
| 526 |
+
months = sorted_months['date']
|
| 527 |
+
deaths = sorted_months['value']
|
| 528 |
+
|
| 529 |
+
plt.bar(months, deaths)
|
| 530 |
+
plt.xlabel('Month')
|
| 531 |
+
plt.ylabel('Number of Deaths')
|
| 532 |
+
plt.title(f'Top Three Months with Highest Deaths in {year}')
|
| 533 |
+
plt.show()
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
#Q12
|
| 537 |
+
def Display_TheMostTestAmount(year,N):
|
| 538 |
+
countries=GetUniqCountry()
|
| 539 |
+
SumOfTestbyYear=[]
|
| 540 |
+
SumOfTestbyYear2=[]
|
| 541 |
+
for country in countries:
|
| 542 |
+
test_Done_per_country=GetCleanData(True,country,'tests_done').values
|
| 543 |
+
Years_per_country = GetCleanData(True, country, 'year_week').values
|
| 544 |
+
# print(len(test_Done_per_country),len(Years_per_country))
|
| 545 |
+
sum=0
|
| 546 |
+
for i in range(len(test_Done_per_country)):
|
| 547 |
+
if Years_per_country[i][:4]==year:
|
| 548 |
+
sum+=test_Done_per_country[i]
|
| 549 |
+
SumOfTestbyYear.append(sum)
|
| 550 |
+
SumOfTestbyYear2.append(sum)
|
| 551 |
+
|
| 552 |
+
print(len(SumOfTestbyYear),SumOfTestbyYear)
|
| 553 |
+
temp=SumOfTestbyYear
|
| 554 |
+
topn=TopN(temp,N)
|
| 555 |
+
print(topn)
|
| 556 |
+
print(len(SumOfTestbyYear), SumOfTestbyYear)
|
| 557 |
+
listLabels=[]
|
| 558 |
+
for i in range(len(SumOfTestbyYear2)):
|
| 559 |
+
for j in range(len(topn)):
|
| 560 |
+
if topn[j]==SumOfTestbyYear2[i]:
|
| 561 |
+
listLabels.append(countries[i])
|
| 562 |
+
print(listLabels)
|
| 563 |
+
|
| 564 |
+
plt.bar(listLabels,topn,width=0.8,color=['r','g','b'])
|
| 565 |
+
plt.title('Top '+str(N)+' countries with the most test amount')
|
| 566 |
+
plt.ylabel('Test amount (in 10 millions)')
|
| 567 |
+
plt.legend()
|
| 568 |
+
plt.show()
|
| 569 |
+
#Q15
|
| 570 |
+
def Display_popdeath_ratio(year,N):
|
| 571 |
+
file=SetUpFile(False)
|
| 572 |
+
countries=list(set(file['value'].keys()))
|
| 573 |
+
dates=file['date'].values
|
| 574 |
+
Death = file['value'].values
|
| 575 |
+
print(len(countries),countries)
|
| 576 |
+
ValuesSumsPerCountry=[]
|
| 577 |
+
ValuesSumsPerCountry2=[]
|
| 578 |
+
|
| 579 |
+
popList=[]
|
| 580 |
+
popTopList=[]
|
| 581 |
+
for i in range(len(countries)):
|
| 582 |
+
popList.append(GetCleanData(True,countries[i],'population')[0])
|
| 583 |
+
date_country=GetCleanData(False,countries[i],'date').values
|
| 584 |
+
death_country=GetCleanData(False,countries[i],'value').values
|
| 585 |
+
# print(len(date_country), date_country)
|
| 586 |
+
# print(len(death_country), death_country)
|
| 587 |
+
sumDeathPer = 0
|
| 588 |
+
for a in range(len(death_country)):
|
| 589 |
+
if date_country[a][:4]==str(year):
|
| 590 |
+
sumDeathPer+=death_country[a]
|
| 591 |
+
ValuesSumsPerCountry.append(sumDeathPer)
|
| 592 |
+
ValuesSumsPerCountry2.append(sumDeathPer)
|
| 593 |
+
|
| 594 |
+
labelList=[]
|
| 595 |
+
newRatioList=[]
|
| 596 |
+
newRatioList2 = []
|
| 597 |
+
andDeathValueTop=[]
|
| 598 |
+
for i in range(len(ValuesSumsPerCountry)):
|
| 599 |
+
newRatioList.append(ValuesSumsPerCountry[i]/popList[i])
|
| 600 |
+
newRatioList2.append(ValuesSumsPerCountry[i] / popList[i])
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
topn=TopN(newRatioList,N)
|
| 606 |
+
for i in range(len(ValuesSumsPerCountry2)):
|
| 607 |
+
if topn.__contains__(newRatioList2[i]):
|
| 608 |
+
labelList.append(countries[i])
|
| 609 |
+
popTopList.append(popList[i])
|
| 610 |
+
andDeathValueTop.append(ValuesSumsPerCountry2[i])
|
| 611 |
+
|
| 612 |
+
print(len(ValuesSumsPerCountry2),ValuesSumsPerCountry2)
|
| 613 |
+
print(len(popTopList), popTopList)
|
| 614 |
+
print(len(topn), topn)
|
| 615 |
+
print(len(labelList), labelList)
|
| 616 |
+
|
| 617 |
+
plt.bar(labelList,popTopList,label='Population amount')
|
| 618 |
+
plt.bar(labelList,andDeathValueTop,label='Death amount')
|
| 619 |
+
plt.title('Top '+str(N)+' countries with the most Death amount vs population amount')
|
| 620 |
+
plt.ylabel('in 10 millions')
|
| 621 |
+
plt.legend()
|
| 622 |
+
plt.show()
|
| 623 |
+
|
| 624 |
+
#Q18
|
| 625 |
+
def DisplayTestRatio(country1,country2,year):
|
| 626 |
+
datesList=GetDatesFromFile1(country1)
|
| 627 |
+
tests_done1=GetCleanData(True,country1,'tests_done').values
|
| 628 |
+
new_cases1=GetCleanData(True,country1,'new_cases').values
|
| 629 |
+
tests_done2=GetCleanData(True,country2,'tests_done').values
|
| 630 |
+
new_cases2=GetCleanData(True,country2,'new_cases').values
|
| 631 |
+
|
| 632 |
+
tests_done1F=[]
|
| 633 |
+
new_cases1F=[]
|
| 634 |
+
tests_done2F=[]
|
| 635 |
+
new_cases2F=[]
|
| 636 |
+
|
| 637 |
+
for i in range(len(datesList)):
|
| 638 |
+
if datesList[i][:4]==str(year):
|
| 639 |
+
tests_done1F.append(tests_done1[i])
|
| 640 |
+
new_cases1F.append(new_cases1[i])
|
| 641 |
+
tests_done2F.append(tests_done2[i])
|
| 642 |
+
new_cases2F.append(new_cases2[i])
|
| 643 |
+
|
| 644 |
+
print(len(tests_done1F),sum(tests_done1F))
|
| 645 |
+
print(len(new_cases1F), sum(new_cases1F))
|
| 646 |
+
print(len(tests_done2F),sum(tests_done2F) )
|
| 647 |
+
print(len(new_cases2F),sum(new_cases2F) )
|
| 648 |
+
plt.pie([sum(tests_done1F),sum(tests_done2F)],labels=['tests done in '+country1,'tests done in '+country2],radius=0.75, center=(1.7,0),colors=['r','b'], shadow = True ,autopct='%1.1f%%')
|
| 649 |
+
plt.pie([sum(new_cases1F),sum(new_cases2F)],labels=['new cases in '+country1,'new cases in '+country2],radius=0.75, center=(-1.7, 0), colors=['y','g'], shadow = True,autopct='%1.1f%%')
|
| 650 |
+
plt.pie([1],radius=0.001,center=(0,0))
|
| 651 |
+
plt.title('compare test done vs new cases in '+country1+' vs '+ country2+' ('+year+')')
|
| 652 |
+
|
| 653 |
+
plt.show()
|
| 654 |
+
|
| 655 |
+
#Dor
|
| 656 |
+
def compar_Death_between_three_countries(country1,country2,country3):
|
| 657 |
+
countries = [country1, country2, country3]
|
| 658 |
+
data = pd.read_csv('data-3 (2).csv')
|
| 659 |
+
# Convert 'date' column to datetime type
|
| 660 |
+
data['date'] = pd.to_datetime(data['date'], format='%Y-%m-%d') # Specify the date format if needed
|
| 661 |
+
|
| 662 |
+
# Filter the data for the selected countries
|
| 663 |
+
filtered_data = data[data['country'].isin(countries)]
|
| 664 |
+
|
| 665 |
+
# Extract year and month from the 'date' column
|
| 666 |
+
filtered_data['year'] = filtered_data['date'].dt.year
|
| 667 |
+
|
| 668 |
+
# Group the data by country, year, and month, and calculate the sum of values
|
| 669 |
+
grouped_data = filtered_data.groupby(['country', 'year'])['value'].sum().reset_index()
|
| 670 |
+
|
| 671 |
+
# Set up the figure and axis
|
| 672 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 673 |
+
|
| 674 |
+
# Get unique years from the data
|
| 675 |
+
years = grouped_data['year'].unique()
|
| 676 |
+
|
| 677 |
+
# Plot data for each country
|
| 678 |
+
for country in countries:
|
| 679 |
+
country_data = grouped_data[grouped_data['country'] == country]
|
| 680 |
+
ax.plot(country_data['year'], country_data['value'], label=f"{country} ")
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
# Customize the plot
|
| 684 |
+
ax.set_xlabel('Year')
|
| 685 |
+
ax.set_ylabel('Death')
|
| 686 |
+
ax.set_title('Comparison of Death between '+country1+' '+country2+' '+country3+' '+ 'by Year ')
|
| 687 |
+
ax.legend()
|
| 688 |
+
|
| 689 |
+
# Show the plot
|
| 690 |
+
plt.show()
|
| 691 |
+
|
| 692 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 693 |
+
# Dashboard
|
| 694 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 695 |
+
|
| 696 |
+
def DeathPieYears(country):
|
| 697 |
+
date_list = GetCleanData(False, country, 'date')
|
| 698 |
+
the_lastOne = '2020'
|
| 699 |
+
filtersDate = []
|
| 700 |
+
for x in date_list:
|
| 701 |
+
filtersDate.append(x[0:4])
|
| 702 |
+
UniqList = set(filtersDate)
|
| 703 |
+
UniqList = list(UniqList)
|
| 704 |
+
UniqList.sort()
|
| 705 |
+
# print(UniqList)
|
| 706 |
+
data = GetCleanData(False, country, 'value')
|
| 707 |
+
print(len(data))
|
| 708 |
+
filedate = sorted(date_list)
|
| 709 |
+
array_ofSum = []
|
| 710 |
+
# print(data.values)
|
| 711 |
+
print('sort Date', filedate)
|
| 712 |
+
sum = 0
|
| 713 |
+
for x in range(len(data)):
|
| 714 |
+
print(x, data.values[x], sum, filedate[x][0:4])
|
| 715 |
+
# print(x, data.values[x], filedate[x][0:4])
|
| 716 |
+
if x != 0:
|
| 717 |
+
the_lastOne = filedate[x - 1][0:4]
|
| 718 |
+
# print(the_lastOne)
|
| 719 |
+
if the_lastOne == filedate[x][0:4]:
|
| 720 |
+
sum += data.values[x]
|
| 721 |
+
# print(sum)
|
| 722 |
+
if the_lastOne != filedate[x][0:4] or x == len(data) - 1:
|
| 723 |
+
array_ofSum.append(sum)
|
| 724 |
+
sum = 0
|
| 725 |
+
print('skip')
|
| 726 |
+
|
| 727 |
+
print((array_ofSum), (UniqList))
|
| 728 |
+
return [array_ofSum,UniqList]
|
| 729 |
+
def PostiveSumbyMonth(country):
|
| 730 |
+
date_list = GetDatesFromFile1(country)
|
| 731 |
+
the_lastOne = ''
|
| 732 |
+
filtersDate = []
|
| 733 |
+
for x in date_list:
|
| 734 |
+
filtersDate.append(x[0:7])
|
| 735 |
+
UniqList = set(filtersDate)
|
| 736 |
+
UniqList = list(UniqList)
|
| 737 |
+
UniqList.sort()
|
| 738 |
+
# print(UniqList)
|
| 739 |
+
data = GetCleanData(True, country, 'new_cases')
|
| 740 |
+
filedate = GetDatesFromFile1(country)
|
| 741 |
+
array_ofSum = []
|
| 742 |
+
# print(data.values)
|
| 743 |
+
# print(filedate)
|
| 744 |
+
sum = 0
|
| 745 |
+
for x in range(len(data)):
|
| 746 |
+
# print(x,data.values[x],filedate[x][0:7],UniqList[x])
|
| 747 |
+
print(x, data.values[x], filedate[x][0:7])
|
| 748 |
+
if x != 0:
|
| 749 |
+
the_lastOne = filedate[x - 1][0:7]
|
| 750 |
+
print(the_lastOne)
|
| 751 |
+
if the_lastOne == filedate[x][0:7]:
|
| 752 |
+
sum += data.values[x]
|
| 753 |
+
print(sum)
|
| 754 |
+
else:
|
| 755 |
+
array_ofSum.append(sum)
|
| 756 |
+
sum = 0
|
| 757 |
+
print('skip')
|
| 758 |
+
return [array_ofSum,UniqList]
|
| 759 |
+
|
| 760 |
+
def TestRatioWeekly(country):
|
| 761 |
+
tests_done = GetCleanData(True,country,'tests_done').values
|
| 762 |
+
new_cases = GetCleanData(True,country,'new_cases').values
|
| 763 |
+
Ratio =[]
|
| 764 |
+
|
| 765 |
+
# print(len(tests_done),len(new_cases))
|
| 766 |
+
for i in range(len(tests_done)):
|
| 767 |
+
if tests_done[i]!=0:
|
| 768 |
+
Ratio.append(new_cases[i]/tests_done[i])
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
xpoints = list(range(len(Ratio)))
|
| 772 |
+
print(xpoints,Ratio)
|
| 773 |
+
return[Ratio,xpoints]
|
| 774 |
+
|
| 775 |
+
def SumofTestMonthly(country):
|
| 776 |
+
date_list = GetDatesFromFile1(country)
|
| 777 |
+
the_lastOne = ''
|
| 778 |
+
filtersDate = []
|
| 779 |
+
for x in date_list:
|
| 780 |
+
filtersDate.append(x[0:7])
|
| 781 |
+
UniqList = set(filtersDate)
|
| 782 |
+
UniqList = list(UniqList)
|
| 783 |
+
UniqList.sort()
|
| 784 |
+
# print(UniqList)
|
| 785 |
+
data = GetCleanData(True, country, 'tests_done')
|
| 786 |
+
filedate = GetDatesFromFile1(country)
|
| 787 |
+
array_ofSum = []
|
| 788 |
+
# print(data.values)
|
| 789 |
+
# print(filedate)
|
| 790 |
+
sum = 0
|
| 791 |
+
for x in range(len(data)):
|
| 792 |
+
# print(x,data.values[x],filedate[x][0:7],UniqList[x])
|
| 793 |
+
print(x, data.values[x], filedate[x][0:7])
|
| 794 |
+
if x != 0:
|
| 795 |
+
the_lastOne = filedate[x - 1][0:7]
|
| 796 |
+
print(the_lastOne)
|
| 797 |
+
if the_lastOne == filedate[x][0:7]:
|
| 798 |
+
sum += data.values[x]
|
| 799 |
+
print(sum)
|
| 800 |
+
else:
|
| 801 |
+
array_ofSum.append(sum)
|
| 802 |
+
sum = 0
|
| 803 |
+
print('skip')
|
| 804 |
+
|
| 805 |
+
# xpoints = list(range(len(Sweeden.values)))
|
| 806 |
+
# colors = ['red', 'green']
|
| 807 |
+
# plt.bar(UniqList, array_ofSum, color=colors)
|
| 808 |
+
return[array_ofSum,UniqList]
|
| 809 |
+
|
| 810 |
+
def SumOfDeathRatioEurop(country):
|
| 811 |
+
# Death=GetCleanData(False,country,'value')
|
| 812 |
+
AllDeath=SetUpFile(False)
|
| 813 |
+
AllDeath=AllDeath['value']
|
| 814 |
+
print(AllDeath)
|
| 815 |
+
print(len(AllDeath.keys().values))
|
| 816 |
+
print(len(AllDeath.values))
|
| 817 |
+
OurSum=0
|
| 818 |
+
AllEurop=0;
|
| 819 |
+
for i in range(len(AllDeath.values)):
|
| 820 |
+
if AllDeath.keys().values[i]==country:
|
| 821 |
+
OurSum+=AllDeath.values[i]
|
| 822 |
+
AllEurop+=AllDeath.values[i]
|
| 823 |
+
# print(OurSum,AllEurop,round(OurSum/AllEurop,3))
|
| 824 |
+
return[OurSum,AllEurop,round(OurSum/AllEurop,3)*100]
|
| 825 |
+
|
| 826 |
+
def calculate_country_population_ratio(country):
|
| 827 |
+
data = SetUpFile(True)
|
| 828 |
+
country_population = data.loc[data.index == country, 'population'].sum()
|
| 829 |
+
total_population = data['population'].sum()
|
| 830 |
+
ratio = country_population / total_population
|
| 831 |
+
print(ratio)
|
| 832 |
+
return ratio
|
| 833 |
+
def getPopulationBycountry(country):
|
| 834 |
+
population=GetCleanData(True,country,'population')
|
| 835 |
+
return population[0]
|
| 836 |
+
def display_Dashborad(country):
|
| 837 |
+
|
| 838 |
+
|
| 839 |
+
resPie=DeathPieYears(country)
|
| 840 |
+
resPlotMonth=PostiveSumbyMonth(country)
|
| 841 |
+
resplotTestRatio=TestRatioWeekly(country)
|
| 842 |
+
barData=SumofTestMonthly(country)
|
| 843 |
+
resForTextDeath=SumOfDeathRatioEurop(country)
|
| 844 |
+
resPop=getPopulationBycountry(country)
|
| 845 |
+
resPopR=calculate_country_population_ratio(country)
|
| 846 |
+
# Initialise the subplot function using number of rows and columns
|
| 847 |
+
figure, axis = plt.subplots(2, 2)
|
| 848 |
+
|
| 849 |
+
# For Sine Function
|
| 850 |
+
axis[0, 0].plot(resPlotMonth[1], resPlotMonth[0],color='r')
|
| 851 |
+
axis[0, 0].tick_params(axis='x', rotation=-90)
|
| 852 |
+
# plt.xticks(rotation=-90)
|
| 853 |
+
axis[0, 0].set_title("Sum of postive cases in "+country+" by month and year")
|
| 854 |
+
|
| 855 |
+
# For Cosine Function
|
| 856 |
+
axis[1, 1].plot(resplotTestRatio[1], resplotTestRatio[0],color='y')
|
| 857 |
+
# axis[1, 1].set_title("Ratio test done / new cases in "+country+" weekly")
|
| 858 |
+
|
| 859 |
+
# For Tangent Function
|
| 860 |
+
axis[1, 0].pie(resPie[0],labels=resPie[1],autopct='%1.1f%%')
|
| 861 |
+
# axis[0, 0].set_title("Death in "+country+" by years")
|
| 862 |
+
|
| 863 |
+
# For Tanh Function
|
| 864 |
+
axis[0, 1].bar(barData[1], barData[0])
|
| 865 |
+
axis[0, 1].set_title("Sum of Test in "+country+" by month")
|
| 866 |
+
axis[0, 1].tick_params(axis='x', rotation=-90)
|
| 867 |
+
|
| 868 |
+
# axis[2,2].text(0,0,"This is the Avarge",fontsize=300)
|
| 869 |
+
axis[-1,0].text(-3.95,0.2,"Sum of death in Europ: "+str(round(resForTextDeath[1]))+"\nThe sum of death in "+country+": "+str(round(resForTextDeath[0]))+"\nThe ratio is: "+str(round(resForTextDeath[2],3))+"%",fontsize=14, color='r')
|
| 870 |
+
axis[-1,0].text(-3.95,-0.4,"The population in "+country+": "+str(round(resPop))+"\n The Ratio vs All Europ: "+str(round(resPopR*100,4))+" %",fontsize=14, color='g')
|
| 871 |
+
axis[-1,0].text(4.4,-1.7,"Test Ratio (test done / new cases) in "+country,fontsize=18, color='black')
|
| 872 |
+
axis[-1, 0].text(-1.2, -1.7, "Sum Of Death in "+ country+" By Years", fontsize=18, color='black')
|
| 873 |
+
|
| 874 |
+
|
| 875 |
+
# Combine all the operations and display
|
| 876 |
+
plt.show()
|
| 877 |
+
|
| 878 |
+
|
| 879 |
+
|
| 880 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 881 |
+
# Main interFace
|
| 882 |
+
# ----------------------------------------------------------------------------------------------------------------------------
|
| 883 |
+
|
| 884 |
+
|
| 885 |
+
|
| 886 |
+
|
| 887 |
+
def GetUniqCountry():
|
| 888 |
+
keys=SetUpFile(True)
|
| 889 |
+
setkeys=set(keys.index)
|
| 890 |
+
listkeys = list(setkeys)
|
| 891 |
+
return listkeys
|
| 892 |
+
|
| 893 |
+
def App(fn,country1,country2,country3,year,N):
|
| 894 |
+
if fn == 1:
|
| 895 |
+
Display_Test_Rate(country1)
|
| 896 |
+
elif fn == 2:
|
| 897 |
+
Display_postive_rate(country1)
|
| 898 |
+
elif fn == 3:
|
| 899 |
+
Display_SumOfTest(country1)
|
| 900 |
+
elif fn == 4:
|
| 901 |
+
Display_SumOfPostive(country1)
|
| 902 |
+
elif fn == 5:
|
| 903 |
+
Display_Death(country1)
|
| 904 |
+
elif fn == 6:
|
| 905 |
+
Display_DeathPie(country1)
|
| 906 |
+
elif fn == 7:
|
| 907 |
+
Display_TestRatio(country1)
|
| 908 |
+
elif fn == 8:
|
| 909 |
+
Display_DeathAvrage(country1)
|
| 910 |
+
elif fn == 9:
|
| 911 |
+
Display_freqSource(country1)
|
| 912 |
+
elif fn == 10:
|
| 913 |
+
Display_NegtiveTest(country1)
|
| 914 |
+
elif fn == 11:
|
| 915 |
+
Compare_avg_pr_by_two_countries(year,country1,country2)
|
| 916 |
+
elif fn == 12:
|
| 917 |
+
Compare_positive_rate(year,country1,country2)
|
| 918 |
+
elif fn == 13:
|
| 919 |
+
Compare_deaths_based_indicator_in_a_given_year(year)
|
| 920 |
+
elif fn == 14:
|
| 921 |
+
compare_new_cases(country1,country2,year)
|
| 922 |
+
elif fn == 15:
|
| 923 |
+
Display_Tests_Done_Comparation(country1,country2)
|
| 924 |
+
elif fn == 16:
|
| 925 |
+
plot_top_months_with_deaths(year,N)
|
| 926 |
+
elif fn == 17:
|
| 927 |
+
Display_TheMostTestAmount(year,N)
|
| 928 |
+
elif fn == 18:
|
| 929 |
+
Display_popdeath_ratio(year,N)
|
| 930 |
+
elif fn == 19:
|
| 931 |
+
DisplayTestRatio(country1,country2,year)
|
| 932 |
+
elif fn == 20:
|
| 933 |
+
compar_Death_between_three_countries(country1,country2,country3)
|
| 934 |
+
else:
|
| 935 |
+
display_Dashborad(country1)
|
| 936 |
+
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
|
| 940 |
+
|
| 941 |
+
def interFaceLaunch():
|
| 942 |
+
demo = gr.Interface(fn=App, inputs=[gr.Dropdown([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,'Dashboard'],label='function number'),gr.Dropdown(GetUniqCountry(),label='Countries1'),gr.Dropdown(GetUniqCountry(),label='Countries2'),gr.Dropdown(GetUniqCountry(),label='Countries3'),gr.Dropdown(['2020','2021','2022','2023'],label='Year'),gr.Dropdown(list(range(len(GetUniqCountry()))),label='N')], outputs="plot")
|
| 943 |
+
demo.launch()
|
| 944 |
+
|
| 945 |
+
interFaceLaunch()
|
| 946 |
+
|
| 947 |
+
|
data-3 (2).csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|