Compare commits
2 Commits
71b87621f6
...
326791b825
Author | SHA1 | Date | |
---|---|---|---|
326791b825 | |||
be94b0e373 |
@ -22,8 +22,22 @@ 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()
|
||||||
|
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")\
|
query = 'from(bucket: "gas")\
|
||||||
|> range(start: -90d)\
|
|> range(start: -90d)\
|
||||||
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
||||||
@ -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'''
|
||||||
|
@ -4,20 +4,73 @@
|
|||||||
{% if page_title %}
|
{% if page_title %}
|
||||||
<h3> {{ page_title }}</h3>
|
<h3> {{ page_title }}</h3>
|
||||||
{% endif %}
|
{% 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>
|
<form method="POST" action="{{ url_for('add_time') }}" class=add-time>
|
||||||
<div class="form group">
|
<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="row">
|
||||||
<div class="col-xs-4">
|
<div class="col-xs-4">
|
||||||
<label for="date">Date:</label>
|
<label for="date">Date:</label>
|
||||||
@ -74,6 +127,9 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Last Mileage
|
Last Mileage
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
@ -87,6 +143,7 @@ Last Mileage
|
|||||||
<th scope="col">$ Total</th>
|
<th scope="col">$ Total</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for point in data %}
|
{% for point in data %}
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user