Compare commits
No commits in common. "d2bda44411396cd37a2bea1d85445af17be5f60a" and "66a031d9a2148ee08513104a5d4143d8f7b84bc0" have entirely different histories.
d2bda44411
...
66a031d9a2
@ -17,12 +17,10 @@ client = influxdb_client.InfluxDBClient(
|
||||
org=config['DB_ORG']
|
||||
)
|
||||
|
||||
|
||||
@app.route('/success')
|
||||
def success():
|
||||
return "Form success!"
|
||||
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def main_page():
|
||||
query_api = client.query_api()
|
||||
@ -31,10 +29,13 @@ def main_page():
|
||||
|> 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)
|
||||
print()
|
||||
print()
|
||||
print(result)
|
||||
print()
|
||||
results = []
|
||||
for table in result:
|
||||
for record in table.records:
|
||||
@ -45,25 +46,15 @@ def main_page():
|
||||
temp['oilhealth'] = record['oilhealth']
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
temp['fuel'] = record['fuel']
|
||||
temp['fuelcost'] = record['fuelcost']
|
||||
except KeyError:
|
||||
pass
|
||||
results.append(temp)
|
||||
# .append((record.get_time(), record.get_field(), record.get_value()))
|
||||
print(results)
|
||||
print(len(results))
|
||||
print()
|
||||
newlist = sorted(results, key=itemgetter('time'), reverse=True)
|
||||
oldlist = newlist # temporary to strip the non-unique data
|
||||
newlist = []
|
||||
for value in oldlist:
|
||||
if value in newlist:
|
||||
continue
|
||||
else:
|
||||
newlist.append(value)
|
||||
|
||||
# print(newlist)
|
||||
return render_template('index.html', data=newlist[:10])
|
||||
|
||||
print(newlist)
|
||||
data= results
|
||||
return render_template('index.html', data=newlist)
|
||||
|
||||
@app.route('/add_time', methods=['POST', 'GET'])
|
||||
def add_time():
|
||||
@ -119,9 +110,10 @@ def add_time():
|
||||
print ("Submitting data to DB: {0}".format(json_body))
|
||||
#client.write_points(json_body)
|
||||
|
||||
return redirect(url_for('main_page'))
|
||||
|
||||
|
||||
return redirect(url_for('main_page'))
|
||||
|
||||
@app.route('/repeat_last_odometer/<odometer>')
|
||||
def repeat_last_odometer(odometer):
|
||||
'''Retrieve the passed in odometer value and submit as a new entry'''
|
||||
@ -131,26 +123,21 @@ def repeat_last_odometer(odometer):
|
||||
print("Putting %s to database for %s" % (odometer, timestamp))
|
||||
|
||||
write_api = client.write_api(write_options=SYNCHRONOUS)
|
||||
point = influxdb_client.Point("2016_odyssey").time(
|
||||
timestamp).field("odometer", float(odometer))
|
||||
point = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(odometer))
|
||||
write_api.write(bucket="gas", org=config['DB_ORG'], record=point)
|
||||
return redirect(url_for('main_page'))
|
||||
|
||||
|
||||
@app.route('/admin')
|
||||
def admin_index():
|
||||
return 'admin'
|
||||
|
||||
|
||||
@app.route('/login')
|
||||
def login():
|
||||
pass
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
def logout():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port='9001')
|
||||
|
@ -59,27 +59,11 @@
|
||||
</form>
|
||||
<br>
|
||||
Last Mileage
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Odometer</th>
|
||||
<th scope="col">Time</th>
|
||||
<th scope="col">Oil</th>
|
||||
<th scope="col">Litres</th>
|
||||
<th scope="col">$/Litre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<ul>
|
||||
{% for point in data %}
|
||||
<tr>
|
||||
<th scope="row">{{ point['odometer'] }}</th>
|
||||
<td>{{ point['time'] }}</td>
|
||||
<td>{{ point['oilhealth'] }}</td>
|
||||
<td>{{ point['fuel'] }}</td>
|
||||
<td>{{ point['fuelcost'] }}</td>
|
||||
</tr>
|
||||
<li>
|
||||
{{ point['time'] }} = {{ point['odometer'] }}, {{point['oilhealth']}}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user