Location updater
Location updater.
Module used to take locations data from a DataFrame object and update that data to provide better information.
load_location_json(file_path)
Load location json.
Opens and returns location object from json file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
file path string |
required |
Returns:
| Name | Type | Description |
|---|---|---|
location_data |
object
|
location data python object |
Source code in report_generator/location_formatter/location_updater.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
load_locations_data()
Load locations data.
Opens json file and loads locations data from json and returns locations object.
Returns:
| Name | Type | Description |
|---|---|---|
locations_data |
dict
|
Python dict containing location info |
Source code in report_generator/location_formatter/location_updater.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
save_locations_data(locations_data)
Save locations data.
Takes the locations data object and uses json.dumps to write the data to a json file.
Source code in report_generator/location_formatter/location_updater.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
search_for_unknowns(unknowns)
Search for unknowns.
Takes list of unidentified locations and searches locations database for results matching the unknown location string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unknowns |
list
|
list of unknown location strings. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
results | list of results from searching locations database |
Source code in report_generator/location_formatter/location_updater.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
update_location(data_frame)
Update location.
Takes a pandas data frame object and runs the location finder on each cell of the Location column/series
Updates the data frames values for the Location column then returns the updated data frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_frame |
pandas.DataFrame
|
Pandas DataFrame object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
updated_data_frame |
pandas.DataFrame
|
Pandas DataFrame object |
Source code in report_generator/location_formatter/location_updater.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
update_location_entries(data_frame, LOCATIONS_DATA)
Update location entries.
Takes pandas data frame object and calls lambda function on each entry in 'GeographicRegion' to update the entry. Then returns updated data frame object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_frame |
pandas.DataFrame
|
Pandas DataFrame object |
required |
LOCATIONS_DATA |
object)
|
location data |
required |
Returns:
| Name | Type | Description |
|---|---|---|
data_frame |
pandas.DataFrame
|
Pandas DataFrame object |
Source code in report_generator/location_formatter/location_updater.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
update_location_entry(location_str, LOCATIONS_DATA)
Update location entry.
Takes the 'GeographicRegion' cell string value. Splits it into sections. Attempts to transform into a more robust location value
'continent-country-region/continent-country-region/etc'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location_str |
str
|
string location value |
required |
LOCATIONS_DATA |
object)
|
location data |
required |
Returns:
| Name | Type | Description |
|---|---|---|
updated_location_str |
str
|
string updated location value |
Source code in report_generator/location_formatter/location_updater.py
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 | |
update_locations_data(results, locations_data)
Update locations data.
Updates the locations data with results of unknown location search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results |
list
|
list of results from unknown locaiton search |
required |
locations_data |
object
|
Object containing locations data |
required |
Source code in report_generator/location_formatter/location_updater.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
update_locations_unknowns(locs, locations_data)
Update unknown locations.
Takes list of unknown locations and passes to the find unknown method. If data is still unknown passes to the search for unknowns method. Takes these results and passes to the update locations data method to update the location data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
locs |
list
|
list of locations |
required |
locations |
data
|
Object containing location data |
required |
Returns:
| Name | Type | Description |
|---|---|---|
locations_data |
object
|
Object containing location data |
Source code in report_generator/location_formatter/location_updater.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |