Last active
July 30, 2022 22:17
-
-
Save spestana/dfa9d0715b75201625dfe25b92756108 to your computer and use it in GitHub Desktop.
Script for archiving the previous 30 days of Ribbit Network observations from InfluxDB as textfiles. This is just a temporary solution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import matplotlib.dates as mdates | |
# duration for archive (30d is max on current influx db plan) | |
duration = '30d' | |
# sampling frequency (1 min is the maximum rate) | |
frequency = '1min' | |
# query database for all live sensors | |
map_data = db.get_map_data() | |
map_data.reset_index(inplace=True) | |
# Select each of the sensors using its host id | |
for host in map_data['host']: | |
print(f'Archiving host {host}') | |
lat = map_data.loc[map_data['host'] == host]['lat'].values[0] | |
lon = map_data.loc[map_data['host'] == host]['lon'].values[0] | |
# Query the database for this sensor and this duration | |
sensor_data = db.get_sensor_data(host, duration, frequency) | |
# set time column as dataframe index | |
sensor_data.set_index('_time', inplace=True) | |
# date string of earliest timestamp in the dataframe | |
date_str = str(sensor_data.index[0]).replace(':','').split('+')[0] | |
# save csv | |
sensor_data.to_csv(f'./archive/ribbitnetwork_{host}_{duration}_{date_str}.csv') | |
print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment