Compare commits
No commits in common. "326791b825f45833f68581482eb88184ffecf72e" and "71b87621f6eff0aff728f8e511375577402e69aa" have entirely different histories.
326791b825
...
71b87621f6
@ -22,29 +22,15 @@ 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:
|
query = 'from(bucket: "gas")\
|
||||||
newTime = pendulum.parse(timestamp)
|
|> range(start: -90d)\
|
||||||
print(newTime.to_atom_string())
|
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
||||||
# "2023-11-14T08:21:00.000Z"
|
|> filter(fn: (r) => r["_field"] == "odometer")\
|
||||||
query = 'from(bucket: "gas")\
|
|> sort(columns: ["_value"], desc: false)\
|
||||||
|> range(start: time(v: "' + str(newTime.subtract(seconds=1).to_atom_string()) + '"), stop: time(v: "' + str(newTime.add(seconds=1).to_atom_string()) + '"))\
|
|> yield(name: "last")\
|
||||||
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
|> limit(n:10)'
|
||||||
|> 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 = []
|
||||||
@ -76,14 +62,11 @@ 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])
|
||||||
@ -113,9 +96,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 = 1
|
winter = True
|
||||||
else:
|
else:
|
||||||
winter = 0
|
winter = False
|
||||||
|
|
||||||
json_body = [
|
json_body = [
|
||||||
{
|
{
|
||||||
@ -145,19 +128,17 @@ 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,73 +4,20 @@
|
|||||||
{% 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>
|
||||||
@ -127,9 +74,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
Last Mileage
|
Last Mileage
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
@ -143,7 +87,6 @@ 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