Update Queries to enable editing records
Change Winter values to 1 or 0
This commit is contained in:
parent
be94b0e373
commit
326791b825
@ -22,15 +22,29 @@ client = influxdb_client.InfluxDBClient(
|
|||||||
def success():
|
def success():
|
||||||
return "Form success!"
|
return "Form success!"
|
||||||
|
|
||||||
|
|
||||||
def fetch_timeseries_data(timestamp=None):
|
def fetch_timeseries_data(timestamp=None):
|
||||||
query_api = client.query_api()
|
query_api = client.query_api()
|
||||||
query = 'from(bucket: "gas")\
|
if timestamp is not None:
|
||||||
|> range(start: -90d)\
|
newTime = pendulum.parse(timestamp)
|
||||||
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
print(newTime.to_atom_string())
|
||||||
|> filter(fn: (r) => r["_field"] == "odometer")\
|
# "2023-11-14T08:21:00.000Z"
|
||||||
|> sort(columns: ["_value"], desc: false)\
|
query = 'from(bucket: "gas")\
|
||||||
|> yield(name: "last")\
|
|> range(start: time(v: "' + str(newTime.subtract(seconds=1).to_atom_string()) + '"), stop: time(v: "' + str(newTime.add(seconds=1).to_atom_string()) + '"))\
|
||||||
|> limit(n:10)'
|
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
||||||
|
|> filter(fn: (r) => r["_field"] == "odometer")\
|
||||||
|
|> sort(columns: ["_value"], desc: false)\
|
||||||
|
|> yield(name: "last")\
|
||||||
|
|> limit(n:10)'
|
||||||
|
print("searching for fixed time")
|
||||||
|
else:
|
||||||
|
query = 'from(bucket: "gas")\
|
||||||
|
|> range(start: -90d)\
|
||||||
|
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
||||||
|
|> filter(fn: (r) => r["_field"] == "odometer")\
|
||||||
|
|> sort(columns: ["_value"], desc: false)\
|
||||||
|
|> yield(name: "last")\
|
||||||
|
|> limit(n:10)'
|
||||||
|
|
||||||
result = query_api.query(org=config['DB_ORG'], query=query)
|
result = query_api.query(org=config['DB_ORG'], query=query)
|
||||||
results = []
|
results = []
|
||||||
@ -62,11 +76,14 @@ def fetch_timeseries_data(timestamp=None):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
newlist.append(value)
|
newlist.append(value)
|
||||||
|
print(newlist)
|
||||||
|
print()
|
||||||
return newlist
|
return newlist
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def main_page():
|
def main_page():
|
||||||
### Call fetch function
|
# Call fetch function
|
||||||
newlist = fetch_timeseries_data()
|
newlist = fetch_timeseries_data()
|
||||||
# print(newlist)
|
# print(newlist)
|
||||||
return render_template('index.html', data=newlist[:10])
|
return render_template('index.html', data=newlist[:10])
|
||||||
@ -96,9 +113,9 @@ def add_time():
|
|||||||
fuelcost = float(fuelcost)
|
fuelcost = float(fuelcost)
|
||||||
winter = request.form['winter']
|
winter = request.form['winter']
|
||||||
if winter == 'TRUE':
|
if winter == 'TRUE':
|
||||||
winter = True
|
winter = 1
|
||||||
else:
|
else:
|
||||||
winter = False
|
winter = 0
|
||||||
|
|
||||||
json_body = [
|
json_body = [
|
||||||
{
|
{
|
||||||
@ -128,17 +145,19 @@ def add_time():
|
|||||||
|
|
||||||
return redirect(url_for('main_page'))
|
return redirect(url_for('main_page'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/edit/<timestamp>')
|
@app.route('/edit/<timestamp>')
|
||||||
def edit_odometer_entry(timestamp):
|
def edit_odometer_entry(timestamp):
|
||||||
'''Retrieve the time entry from influxdb'''
|
'''Retrieve the time entry from influxdb'''
|
||||||
print('Fetching data!')
|
print('Fetching data!')
|
||||||
### Call fetch function
|
# Call fetch function
|
||||||
newlist = fetch_timeseries_data()
|
newlist = fetch_timeseries_data()
|
||||||
|
|
||||||
# Fill entry_data with timestamp based data
|
# Fill entry_data with timestamp based data
|
||||||
entry_data = fetch_timeseries_data(timestamp)
|
entry_data = fetch_timeseries_data(timestamp)
|
||||||
return render_template('index.html', page_title="Edit Entry", timestamp_data=entry_data, data=newlist[:10])
|
return render_template('index.html', page_title="Edit Entry", timestamp_data=entry_data, data=newlist[:10])
|
||||||
|
|
||||||
|
|
||||||
@app.route('/repeat_last_odometer/<odometer>/<winter>')
|
@app.route('/repeat_last_odometer/<odometer>/<winter>')
|
||||||
def repeat_last_odometer(odometer, winter=False):
|
def repeat_last_odometer(odometer, winter=False):
|
||||||
'''Retrieve the passed in odometer value and submit as a new entry'''
|
'''Retrieve the passed in odometer value and submit as a new entry'''
|
||||||
|
Loading…
Reference in New Issue
Block a user