gams / openkongqi

Outdoor air quality data
Apache License 2.0
3 stars 6 forks source link

Use a more advance station format for more meta data #66

Open hrbonz opened 3 years ago

hrbonz commented 3 years ago

Use a more advanced station format that would allow to carry:

hrbonz commented 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.

libokj commented 3 years ago

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/

libokj commented 3 years ago

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

libokj commented 3 years ago

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: {
        ...
    },
    ...
} 
hrbonz commented 3 years ago

What are the parts of code that will be impacted by this change?

hrbonz commented 3 years ago

AFAICT, pieces of code impacted by that change:

The easiest way to implement your data structure changes is to alter that method to use the following self._station_map[name]["uuid"])

hrbonz commented 3 years ago

Changes: