meta['station'] = station['name'] meta['start_date'] = startDateTime.strftime("%Y-%m-%d %H:%M:%S") meta['end_date'] = endDateTime.strftime("%Y-%m-%d %H:%M:%S") variables = station['variables'] units = station['units'] max_values = station['max_values'] min_values = station['min_values'] if 'run_name' in station: meta['name'] = station['run_name'] for i in range(0, len(variables)): meta['variable'] = variables[i] meta['unit'] = units[i] eventId = adapter.get_event_id(meta) if eventId is None: eventId = adapter.create_event_id(meta) print('HASH SHA256 created: ', eventId) else: print('HASH SHA256 exists: ', eventId) metaQuery = copy.deepcopy(metaData) metaQuery['station'] = station['name'] metaQuery['variable'] = variables[i] metaQuery['unit'] = units[i] if 'run_name' in station: metaQuery['name'] = station['run_name'] opts = { 'from': startDateTime.strftime("%Y-%m-%d %H:%M:%S"), 'to': endDateTime.strftime("%Y-%m-%d %H:%M:%S") } existingTimeseries = adapter.retrieve_timeseries( metaQuery, opts)
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)))