Compare commits

..

No commits in common. "326791b825f45833f68581482eb88184ffecf72e" and "71b87621f6eff0aff728f8e511375577402e69aa" have entirely different histories.

2 changed files with 23 additions and 99 deletions

View File

@ -22,22 +22,8 @@ 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")\
@ -76,14 +62,11 @@ 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])
@ -113,9 +96,9 @@ def add_time():
fuelcost = float(fuelcost)
winter = request.form['winter']
if winter == 'TRUE':
winter = 1
winter = True
else:
winter = 0
winter = False
json_body = [
{
@ -145,19 +128,17 @@ 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'''

View File

@ -4,73 +4,20 @@
{% if page_title %}
<h3> {{ page_title }}</h3>
{% endif %}
{% if timestamp_data %}
{% for point in timestamp_data %}
<b>{{ point['time']}}</b>
<form method="POST" action="{{ url_for('add_time') }}" class=add-time>
<div class="form group">
<div class="row">
<div class="col-xs-4">
<label for="date">Date:</label>
<input type=date name="date" class="form-control" placeholder="Ex: 2009-11-10" value="{{ point['time'].strftime('%Y-%m-%d')}}">
</div>
<div class="col-xs-4">
<label for="time">Time:</label>
<input type=time name="time" class="form-control" placeholder="Ex: 17:59:03" step="1" value="{{ point['time'].strftime('%H:%M:%S')}}">
</div>
</div>
<div class="row">
<div class="col-xs-4">
<label for="odometer">Odometer:</label>
<input type=number name="odometer" class="form-control" placeholder="Ex: 3008" value="{{ point['odometer']}}"></input>
</div>
<div class="col-xs-4">
<label for="oilhealth">Oil Health:</label>
<input type=number name="oilhealth" class="form-control" placeholder="Ex: 80" value="{{ point['oilhealth']}}">
</div>
</div>
<div class="row">
<div class="col-xs-4">
<label for="fuel">Fuel (L):</label>
<input type=number step="0.001" name="fuel" class="form-control" placeholder="Ex: 70.175" value="{{ point['fuel']}}">
</div>
<div class="col-xs-4">
<label for="fuelcost">Fuel Cost ($/L):</label>
<input type=number step="0.001" name="fuelcost" class="form-control" placeholder="Ex: 1.059" value="{{ point['fuelcost']}}">
</div>
</div>
<div class="row">
<div class="col-xs-4">
<label for="winter">Winter Tires:</label>
<select name="winter" class="form-control">
{% if data %}
{% if data[0]['winter'] == "True" %}
<option value="TRUE" selected>True</option>
<option value="FALSE">False</option>
{% else %}
<option value="TRUE">True</option>
<option value="FALSE" selected>False</option>
{% endif %}
{% else %}
<option value="TRUE">True</option>
<option value="FALSE" selected>False</option>
{% endif %}
</select>
</div>
</div><br>
<input type="submit" value="Go">
{% if data %}
<a href="{{ url_for('repeat_last_odometer', odometer=data[0]['odometer'], winter=data[0]['winter'] ) }}">Repeat</a>
{% endif %}
</div>
</form>
{% endfor %}
{% else %}
<form method="POST" action="{{ url_for('add_time') }}" class=add-time>
<div class="form group">
<!-- <div class="row">
<div class="col-xs-4">
<label for="db">Database:</label>
<input type=text name="db" class="form-control" placeholder="Ex: Gas">
</div>
<div class="col-xs-4">
<label for="table">Table:</label>
<input type=text name="table" class="form-control" placeholder="Ex: Odyssey">
</div>
</div>
-->
<div class="row">
<div class="col-xs-4">
<label for="date">Date:</label>
@ -127,9 +74,6 @@
{% endif %}
</div>
</form>
{% endif %}
<br>
Last Mileage
<table class="table table-striped">
@ -143,7 +87,6 @@ Last Mileage
<th scope="col">$ Total</th>
</tr>
</thead>
<tbody>
{% for point in data %}
<tr>