Beispiel #1
0
    # IF station does not exist in the database create one with given station configs details.
    station_info = get_station_info(station_id)
    station_details_in_db = mysql_adapter.get_station({
        'stationId':
        station_info['stationId'],
        'name':
        station_info['name']
    })
    if station_details_in_db is None:
        print(
            "Station: {stationId: %s, name: %s} does not exist in the DB. Creating station in the DB..."
            % (station_info['stationId'], station_info['name']))
        station_meta_list = station_info['station_meta']
        station_meta_list.insert(0, Station.CUrW)
        row_count = mysql_adapter.create_station(station_meta_list)
        if row_count > 0:
            print("Created new station: ", station_meta_list)
        else:
            print("Unable to create new station: ", station_meta_list)
            continue

    # Create event metadata. Event metadata is used to create timeseries id (event_id) for the timeseries.
    timeseries_meta = copy.deepcopy(timeseries_meta_struct)
    timeseries_meta['station'] = station_info['name']
    timeseries_meta['variable'] = 'Precipitation'
    timeseries_meta['unit'] = 'mm'
    timeseries_meta['type'] = station_info['type']
    timeseries_meta['source'] = station_info['source']
    timeseries_meta['name'] = station_info['run_name']
Beispiel #2
0
    adapter = MySQLAdapter(host=MYSQL_HOST,
                           user=MYSQL_USER,
                           password=MYSQL_PASSWORD,
                           db=MYSQL_DB)

    for station in stations:
        print('station:', station)
        #  Check whether station exists
        is_station_exists = adapter.get_station({'name': station['name']})
        if is_station_exists is None:
            print('Station %s does not exists.', station['name'])
            if 'station_meta' in station and 'station_type' in station:
                station_meta = station['station_meta']
                station_meta.insert(0,
                                    Station.getType(station['station_type']))
                row_count = adapter.create_station(station_meta)
                if row_count > 0:
                    print('Created new station %s', station_meta)
                    is_station_exists = adapter.get_station(
                        {'name': station['name']})
                else:
                    print("Unable to create station %s", station_meta)
                    continue
            else:
                print(
                    "Could not find station meta data or station_type to create new ",
                    station['name'])
                continue

        dataLocation = station['data_location']
        timeseries = getTimeseries(dataLocation, {