Exemple #1
0
                existingTimeseries = adapter.retrieve_timeseries(
                    metaQuery, opts)
                if len(existingTimeseries[0]
                       ['timeseries']) > 0 and not forceInsert:
                    print('\n')
                    continue

            extractedTimeseries = extractSigleTimeseries(
                timeseries, variables[i],
                {'WUndergroundMeta': WUndergroundMeta})
            validationObj = {
                'max_value': max_values[i],
                'min_value': min_values[i],
            }
            newTimeseries = validateTimeseries(extractedTimeseries,
                                               variables[i], validationObj)
            # print(newTimeseries[:20])
            # continue

            for l in newTimeseries[:3] + newTimeseries[-2:]:
                print(l)

            rowCount = adapter.insert_timeseries(eventId, newTimeseries,
                                                 forceInsert)
            print('%s rows inserted.\n' % rowCount)

except Exception as e:
    traceback.print_exc()
finally:
    os.chdir(INIT_DIR)
Exemple #2
0
            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']

    # At this point station exists. Check whether there is a timeseries_id (or event-id).
    # If does not exist create an id.
    timeseries_id = mysql_adapter.get_event_id(timeseries_meta)
    if timeseries_id is None:
        print(
            "No timeseries for the '%s' of the station: %s in the DB. Creating timeseries-id..."
            % (timeseries_meta['variable'],
               station_info['stationId'] + '/' + station_info['name']))
        timeseries_id = mysql_adapter.create_event_id(timeseries_meta)

    timeseries = prepare_timeseries(df)

    # Insert timeseries.
    print("Pushing to timeseries: %s of size %d" %
          (timeseries_id, len(timeseries)))
    inserted_rows = mysql_adapter.insert_timeseries(timeseries_id, timeseries,
                                                    True, Data.data)
    print("Inserted %d rows from %d timeseries_id values successfully..." %
          (inserted_rows, len(timeseries)))