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