Open hrbonz opened 3 years ago
Add country, region, city and longitude/latitude if available. Get the proper utility functions to get a station UUID but also its meta data.
https://github.com/dr5hn/countries-states-cities-database We could use this well-developed project as an example for our format. A glimpse into it:
[
...
{
"id": 45,
"name": "China",
"iso3": "CHN",
"iso2": "CN",
"phone_code": "86",
"capital": "Beijing",
"currency": "CNY",
"native": "中国",
"region": "Asia",
"subregion": "Eastern Asia",
"emoji": "🇨🇳",
"emojiU": "U+1F1E8 U+1F1F3",
"states": [
{
"id": 2251,
"name": "Anhui",
"state_code": "AH",
"cities": [
{
"id": 19284,
"name": "Anqing",
"latitude": "30.51365000",
"longitude": "117.04723000"
},
...
]
Its menu implementation demo: https://dr5hn.github.io/countries-states-cities-database/
A suggestion:
[
...
{
"id": 45,
"name": "China",
"native": "中国",
"states": [
{
"id": 2251,
"name": "Anhui",
"native": "安徽", #optional entry for an original name that is not in Latin alphabet
"state_code": "AH",
"cities": [
{
"id": 19284,
"name": "Anqing",
"native": "安庆", #optional entry for an original name that is not in Latin alphabet
"stations": [
{
"id": 0155762,
"name": "Anqing Daguan Station",
"native": "安庆大观监测站", #optional entry for an original name that is not in Latin alphabet
"latitude": "30.51365000",
"longitude": "117.04723000"
},
...
]
A uuid for a station can be made up of country id:state id:city id:station id
For now, it's best to make changes that have as little impact on the overall code structure as possible. So, we would simply keep the original system of having folders for different countries, subfolders for different regions (state/province), and a JSON file for each city. For example, a city JSON file would look like:
.../data/stations/cn/shanghai.json
{
station_code_1: {
"uuid": station_code_1,
"name": "Yangpu Monitoring Station",
"native": "杨浦监测站",
"region": "Shanghai",
"country": "China",
"latitude": "31.2595",
"longitude": "121.526"
},
station_code_2: {
...
},
...
}
What are the parts of code that will be impacted by this change?
AFAICT, pieces of code impacted by that change:
openkongqi/source/base.py:get_station_uuid()
The easiest way to implement your data structure changes is to alter that method to use the following self._station_map[name]["uuid"])
Changes:
Use a more advanced station format that would allow to carry: