Locations db setup
Database setup.
Setup file to create a locations SQLITE database and load location information into the database to allow for queries.
create_connection(db_path)
Create connection.
Create a SQLite3 connection object and return it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path |
str
|
Path string to db directory location. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
conn |
sqlite3.Connection
|
SQLite3 connection object |
Source code in report_generator/project_setup/locations_db_setup.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
create_tables(conn)
Create SQL table strings.
Create SQL table strings for the locations database.
Use SQLite3 connection object to create tables in locations database with table strings.
Tables
country_codes: table representing country data geocode: table representing geocode data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
sqlite3.Connection
|
SQLite3 connection object |
required |
Source code in report_generator/project_setup/locations_db_setup.py
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 | |
insert_country_data(conn, csv_path)
Insert country data.
Inserts country data into the country_codes table
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
sqlite3.Connection
|
SQLite3 connection object |
required |
Source code in report_generator/project_setup/locations_db_setup.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
insert_country_data_row(conn, row_values)
Insert country data row.
Inserts row of country data into country table in locations database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
object
|
SQLite3 connection object |
required |
row_values |
list
|
List of values from the Pandas dataframe row. |
required |
Source code in report_generator/project_setup/locations_db_setup.py
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 | |
insert_geocode_data(conn, csv_path)
Insert geocode data.
Inserts geocode data into locations database.
Opens the csv files that contain the geocode data directory and iterates through to insert the geocode data by section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
object
|
SQLite3 connection object |
required |
csv_path |
str
|
Path string to csv directory |
required |
Source code in report_generator/project_setup/locations_db_setup.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
insert_geocode_data_section(conn, file_path)
Insert geocode data section.
Opens ands processes geocode data section csv file and then inserts it into the geocode_data table in the locations database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn |
object
|
SQLite3 connection object |
required |
file_path |
str
|
string of filepath to section csv |
required |
Source code in report_generator/project_setup/locations_db_setup.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
locations_database_setup(location_path)
Location database setup.
Sets up database for locations data. Creates database, loads data from csv. Creates tables in database. Inserts csv data into the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location_path |
str
|
Path string to project location. |
required |
Source code in report_generator/project_setup/locations_db_setup.py
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 | |
main()
Locations db main method.
Source code in report_generator/project_setup/locations_db_setup.py
216 217 218 | |