Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
COVID-19-Data-Integration
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ivy Wang
COVID-19-Data-Integration
Commits
dee5369c
Commit
dee5369c
authored
3 years ago
by
Ivy Wang
Browse files
Options
Downloads
Patches
Plain Diff
add data for brazil
parent
998a0df6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
daily_data_scripts/daily_sa.py
+75
-0
75 additions, 0 deletions
daily_data_scripts/daily_sa.py
initial_data_scripts/init_asia.py
+8
-0
8 additions, 0 deletions
initial_data_scripts/init_asia.py
initial_data_scripts/init_south_america.py
+79
-0
79 additions, 0 deletions
initial_data_scripts/init_south_america.py
with
162 additions
and
0 deletions
daily_data_scripts/daily_sa.py
0 → 100644
+
75
−
0
View file @
dee5369c
import
pandas
as
pd
import
sqlite3
import
sys
import
datetime
from
datetime
import
date
import
requests
sys
.
path
.
append
(
"
..
"
)
from
util
import
*
def
toint
(
s
):
if
pd
.
isna
(
s
):
s
=
"
NULL
"
else
:
s
=
int
(
s
)
return
s
def
update_brazil
():
conn
=
sqlite3
.
connect
(
'
prototype_db
'
)
c
=
conn
.
cursor
()
# get country_code for brazil
br_code
=
get_country_code
(
"
Brazil
"
,
c
)
#insert and get source id for brazil data
br_src_url
=
"
https://github.com/wcota/covid19br
"
br_src
=
get_source_id
(
br_src_url
,
c
)
br
=
pd
.
read_csv
(
"
https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv
"
)
br_city
=
pd
.
read_csv
(
"
https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-cities.csv
"
)
#insert country, state case vaccination data
for
index
,
row
in
br
.
iterrows
():
region
=
row
[
"
state
"
]
case
=
row
[
"
newDeaths
"
]
death
=
row
[
"
newDeaths
"
]
recover
=
row
[
"
recovered
"
]
first
=
toint
(
row
[
"
vaccinated
"
])
second
=
toint
(
row
[
"
vaccinated_second
"
])
third
=
toint
(
row
[
"
vaccinated_third
"
])
if
region
==
"
TOTAL
"
:
c
.
execute
(
'
SELECT * FROM Cases_Per_Country WHERE country_code =
"'
+
br_code
+
'"
AND date_collected =
"'
+
str
(
date1
)
+
'"'
)
result
=
c
.
fetchall
()
if
len
(
result
)
==
0
:
sql
=
'''
INSERT INTO Cases_Per_Country (country_code, date_collected, source_id, death_numbers, case_numbers, recovery_numbers) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
br_code
,
row
[
"
date
"
],
br_src
,
death
,
case
,
recover
))
if
(
first
!=
"
NULL
"
):
sql
=
'''
INSERT INTO Vaccinations_Per_Country (date_collected, first_vaccination_number, second_vaccination_number, third_vaccination_number, country_code, source_id) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
row
[
"
date
"
],
first
,
second
,
third
,
br_code
,
br_src
))
else
:
break
else
:
region_code
=
get_region_code
(
br_code
,
region
,
c
)
c
.
execute
(
'
SELECT * FROM Cases_Per_Region WHERE region_code =
"'
+
region_code
+
'"
AND date_collected =
"'
+
str
(
date1
)
+
'"'
)
result
=
c
.
fetchall
()
if
len
(
result
)
==
0
:
sql
=
'''
INSERT INTO Cases_Per_Region (region_code, date_collected, source_id, death_numbers, case_numbers, recovery_numbers) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
region_dict
[
region
],
row
[
"
date
"
],
br_src
,
death
,
case
,
recover
))
if
(
first
!=
"
NULL
"
):
sql
=
'''
INSERT INTO Vaccinations_Per_Region (date_collected, first_vaccination_number, second_vaccination_number, third_vaccination_number, region_code, source_id) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
row
[
"
date
"
],
first
,
second
,
third
,
region_dict
[
region
],
br_src
))
else
:
break
conn
.
commit
()
#insert new city case data for brazil
for
index
,
row
in
br_city
.
iterrows
():
region
=
row
[
"
state
"
]
city
=
row
[
"
city
"
]
region_code
=
get_region_code
(
br_code
,
region
,
c
)
city_dict
[
region
][
city
]
=
get_district_code
(
region_code
,
city
,
c
)
sql
=
'''
INSERT INTO Cases_Per_District (district_code, date_collected, source_id, death_numbers, case_numbers) VALUES (?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
city_code
,
row
[
"
date
"
],
br_src
,
row
[
"
newDeaths
"
],
row
[
"
newCases
"
]))
conn
.
commit
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
initial_data_scripts/init_asia.py
+
8
−
0
View file @
dee5369c
...
...
@@ -463,6 +463,9 @@ def init_india():
#slow to run
def
init_china
():
conn
=
sqlite3
.
connect
(
'
prototype_db
'
)
c
=
conn
.
cursor
()
# get country_code for china
cn_code
=
get_country_code
(
"
China
"
,
c
)
...
...
@@ -511,3 +514,8 @@ def init_china():
sql
=
'''
INSERT INTO Cases_Per_District (district_code, date_collected, source_id, death_numbers, case_numbers, recovery_numbers) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
city_dict
[
region
][
city
],
date1
,
cn_src
,
row
[
"
city_deadCount
"
],
row
[
"
city_confirmedCount
"
],
row
[
"
city_curedCount
"
]))
conn
.
commit
()
#insert population data for china
sql
=
'''
INSERT INTO Population_Per_Country (country_code, population_amount, date_collected) VALUES (?, ?, ?)
'''
c
.
execute
(
sql
,(
cn_code
,
1412600000
,
datetime
.
datetime
(
2021
,
5
,
1
).
date
()))
conn
.
commit
()
This diff is collapsed.
Click to expand it.
initial_data_scripts/init_south_america.py
0 → 100644
+
79
−
0
View file @
dee5369c
import
pandas
as
pd
import
sqlite3
import
sys
import
datetime
from
datetime
import
date
import
requests
sys
.
path
.
append
(
"
..
"
)
from
util
import
*
def
toint
(
s
):
if
pd
.
isna
(
s
):
s
=
"
NULL
"
else
:
s
=
int
(
s
)
return
s
def
init_brazil
():
conn
=
sqlite3
.
connect
(
'
prototype_db
'
)
c
=
conn
.
cursor
()
# get country_code for brazil
br_code
=
get_country_code
(
"
Brazil
"
,
c
)
#insert and get source id for brazil data
br_src_url
=
"
https://github.com/wcota/covid19br
"
set_source
(
br_src_url
,
c
,
conn
)
br_src
=
get_source_id
(
br_src_url
,
c
)
br
=
pd
.
read_csv
(
"
https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv
"
)
br_city
=
pd
.
read_csv
(
"
https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-cities.csv
"
)
#insert country, state case vaccination data
region_dict
=
{}
city_dict
=
{}
for
index
,
row
in
br
.
iterrows
():
region
=
row
[
"
state
"
]
case
=
row
[
"
newDeaths
"
]
death
=
row
[
"
newDeaths
"
]
recover
=
row
[
"
recovered
"
]
first
=
toint
(
row
[
"
vaccinated
"
])
second
=
toint
(
row
[
"
vaccinated_second
"
])
third
=
toint
(
row
[
"
vaccinated_third
"
])
if
region
==
"
TOTAL
"
:
sql
=
'''
INSERT INTO Cases_Per_Country (country_code, date_collected, source_id, death_numbers, case_numbers, recovery_numbers) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
br_code
,
row
[
"
date
"
],
br_src
,
death
,
case
,
recover
))
if
(
first
!=
"
NULL
"
):
sql
=
'''
INSERT INTO Vaccinations_Per_Country (date_collected, first_vaccination_number, second_vaccination_number, third_vaccination_number, country_code, source_id) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
row
[
"
date
"
],
first
,
second
,
third
,
br_code
,
br_src
))
else
:
if
region
not
in
region_dict
:
sql
=
'''
INSERT INTO Regions (region_name, country_code) VALUES (?, ?)
'''
c
.
execute
(
sql
,(
region
,
br_code
))
region_dict
[
region
]
=
get_region_code
(
br_code
,
region
,
c
)
city_dict
[
region
]
=
{}
sql
=
'''
INSERT INTO Cases_Per_Region (region_code, date_collected, source_id, death_numbers, case_numbers, recovery_numbers) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
region_dict
[
region
],
row
[
"
date
"
],
br_src
,
death
,
case
,
recover
))
if
(
first
!=
"
NULL
"
):
sql
=
'''
INSERT INTO Vaccinations_Per_Region (date_collected, first_vaccination_number, second_vaccination_number, third_vaccination_number, region_code, source_id) VALUES (?, ?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
row
[
"
date
"
],
first
,
second
,
third
,
region_dict
[
region
],
br_src
))
conn
.
commit
()
#insert population for brazil
sql
=
'''
INSERT INTO Population_Per_Country (country_code, population_amount, date_collected) VALUES (?, ?, ?)
'''
c
.
execute
(
sql
,(
br_code
,
210147125
,
datetime
.
datetime
(
2018
,
8
,
30
).
date
()))
conn
.
commit
()
#insert city case data for brazil
for
index
,
row
in
br_city
.
iterrows
():
region
=
row
[
"
state
"
]
city
=
row
[
"
city
"
]
if
city
not
in
city_dict
[
region
]:
sql
=
'''
INSERT INTO Districts (district_name, region_code) VALUES (?, ?)
'''
c
.
execute
(
sql
,(
city
,
region_dict
[
region
]))
city_dict
[
region
][
city
]
=
get_district_code
(
region_dict
[
region
],
city
,
c
)
sql
=
'''
INSERT INTO Cases_Per_District (district_code, date_collected, source_id, death_numbers, case_numbers) VALUES (?, ?, ?, ?, ?)
'''
c
.
execute
(
sql
,(
city_dict
[
region
][
city
],
row
[
"
date
"
],
br_src
,
row
[
"
newDeaths
"
],
row
[
"
newCases
"
]))
conn
.
commit
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment