Skip to content

Commit

Permalink
Update for gov column order change - slight pain
Browse files Browse the repository at this point in the history
  • Loading branch information
scienceMiner committed Jul 12, 2021
1 parent 3612024 commit 889f1dc
Show file tree
Hide file tree
Showing 24 changed files with 1,066 additions and 431 deletions.
1 change: 1 addition & 0 deletions python.datascience.views/src/CaseDeathBarPlotByCountry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def barPlot(Country):
today = datetime.date.today()
#Countries = ['Brazil','India','United Kingdom','Croatia','Greece','Italy','US','Russia','Chile']
#Countries = ['Brazil','India','Japan','Croatia']
#Countries = ['United Kingdom']
Countries = ['India']

# plt.xticks(x, casesData6.index, rotation='vertical')
Expand Down
30 changes: 20 additions & 10 deletions python.datascience.views/src/UKCovidScripts/govDataRequestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Created on 30 Jan 2021
@author: ethancollopy
'''

import requests
import csv
import ast
Expand Down Expand Up @@ -44,11 +43,16 @@ def getUrlResponse(regionCode, metricType ):
npArray = np.array(output_array)
print(output_array)
npArray2 = np.delete(npArray, 0, axis=1)
print('deleted something')
print(npArray2)
newDataFrame = pd.DataFrame( npArray2, # values
index=npArray[:,[0]], # 1st column as index
index=npArray[:,[3]], # 1st column as index - this WAS 0th column but now its 3rd - OUCH
columns= ['areaType','areaCode','areaName', metricType ] )
newDataFrame.index = newDataFrame.index.map("".join)
newDataFrame = newDataFrame.drop(['date'])
# newDataFrame = newDataFrame.drop(['date'])
print('final data frame from getUrlResponse')
newDataFrame = newDataFrame.iloc[1:]
print(newDataFrame)
return (newDataFrame,response)


Expand Down Expand Up @@ -76,10 +80,15 @@ def turnCumulativeIntoDiffColumn(newDataFrame, metricType, regionTitle ):


def populateDataframe( newDataFrame , metricType ):
if metricType == 'cumDeaths28DaysByDeathDate' or metricType == 'cumDeaths28DaysByPublishDate':
newDataFrame = newDataFrame.sort_index(ascending=True)
print(newDataFrame)
# if metricType == 'cumDeaths28DaysByDeathDate' or metricType == 'cumDeaths28DaysByPublishDate':
newDataFrame = newDataFrame.sort_index(ascending=True)
newRegionTitle = str(newDataFrame['areaName'][0]).replace(" ","")
print('Before column drop with newRegionTitle: %s', newRegionTitle)
print(newDataFrame)
newDataFrame = newDataFrame.drop(columns=['areaType','areaCode','areaName'])
print('After column drop')
print(newDataFrame)
newDataFrame[[metricType ]] = newDataFrame[[metricType]].apply(pd.to_numeric)
newDataFrame = turnCumulativeIntoDiffColumn(newDataFrame, metricType, newRegionTitle )
return newDataFrame
Expand Down Expand Up @@ -140,10 +149,10 @@ def formatBarPlot(df,ax,date,metricName):

today = datetime.date.today()
print(today)
metricName = 'cumDeaths28DaysByDeathDate'
#metricName = 'cumDeaths28DaysByDeathDate'
MA = 'Moving Average'
#metricName = 'cumDeaths28DaysByPublishDate'
#metricName = 'newCasesByPublishDate'
metricName = 'newCasesByPublishDate'

regions = [ ("United Kingdom","K02000001") ]

Expand All @@ -152,10 +161,10 @@ def formatBarPlot(df,ax,date,metricName):
for region in regions:
(response,responseOriginal) = getUrlResponse(region[1], metricName )
# response = getFileResponse(region[0],metricName)
df = populateDataframe(response, metricName )
df = populateDataframe( response, metricName )

dataframeRegion_Dict[region[0]] = df
print('save file')
print( 'save file' )
saveFileName = str(region[0]) + "_" + str(metricName) + ".csv"
#targetfile = "/Users/ethancollopy/git/pythonPlotting/python.datascience.views/src/data/{}_{}Data.csv".format(region[0],metricName)
targetfile = "/Users/ethancollopy/git/pythonPlotting/python.datascience.views/src/data/{}".format(saveFileName)
Expand All @@ -175,7 +184,8 @@ def formatBarPlot(df,ax,date,metricName):
print(finalDataframe)
#finalDataframe.drop(finalDataframe.tail(3).index,inplace=True) # drop last n rows

ax = finalDataframe.plot.bar( y='UnitedKingdom' )
#ax = finalDataframe.plot.bar( y='UnitedKingdom' )
ax = finalDataframe.plot.bar( )
finalDataframe.plot( y = MA , ax=ax , color='red' )
formatBarPlot( finalDataframe, ax, today , metricName)
ax.legend(["7-day moving average", "United kingdom Deaths"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def turnCumulativeIntoDiffColumn(newDataFrame, metricType, regionTitle ):
def populateDataframe( newDataFrame , metricType ):
if metricType == 'cumDeaths28DaysByDeathDate':
newDataFrame = newDataFrame.sort_index(ascending=False)
else:
newDataFrame = newDataFrame.sort_index(ascending=True)
newRegionTitle = str(newDataFrame['areaName'][0]).replace(" ","")
newDataFrame = newDataFrame.drop(columns=['areaType','areaCode','areaName'])
newDataFrame[[metricType ]] = newDataFrame[[metricType]].apply(pd.to_numeric)
Expand All @@ -101,8 +103,9 @@ def formatPlot(ax,date,metricName):
ax.set_title(" UK COVID-19 Daily Deaths by Region as of %s" % date)
ax.set_ylabel('Number of Deaths')
else:
ax.set_title(" UK COVID-19 Daily Cases by Region as of %s" % date)
ax.set_ylabel('Number of Cases')
ax.set_title(" UK COVID-19 Daily Cases by Region as of %s" % date)
# ax.set_title(" UK COVID-19 Daily Cases Third Wave by Region as of %s" % date)
ax.set_ylabel('Number of Cases')
ax.set_xlabel('Date')
ax.grid(True)
ax.set_facecolor('gainsboro')
Expand Down Expand Up @@ -145,7 +148,8 @@ def formatPlot(ax,date,metricName):

print(finalDataframe.count)
#finalDataframe = finalDataframe.drop(finalDataframe.head(40).index,inplace=True) # drop last n rows
#finalDataframe = finalDataframe.iloc[70:]
# delete the first 340 days to highlight the third wave
# finalDataframe = finalDataframe.iloc[340:]
#finalDataframe = finalDataframe.drop(finalDataframe.index[[0,200]])

#print(finalDataframe.count)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python.datascience.views/src/charts/Spain_UK_Jan21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python.datascience.views/src/charts/covid19Cases_apr21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified python.datascience.views/src/charts/covid19Deaths_apr21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 889f1dc

Please sign in to comment.