Compare commits
No commits in common. "d2bda44411396cd37a2bea1d85445af17be5f60a" and "66a031d9a2148ee08513104a5d4143d8f7b84bc0" have entirely different histories.
d2bda44411
...
66a031d9a2
@ -12,29 +12,30 @@ config = dotenv_values(".env")
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
client = influxdb_client.InfluxDBClient(
|
client = influxdb_client.InfluxDBClient(
|
||||||
url=config['DB_URL'],
|
url=config['DB_URL'],
|
||||||
token=config['DB_TOKEN'],
|
token=config['DB_TOKEN'],
|
||||||
org=config['DB_ORG']
|
org=config['DB_ORG']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/success')
|
@app.route('/success')
|
||||||
def success():
|
def success():
|
||||||
return "Form success!"
|
return "Form success!"
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def main_page():
|
def main_page():
|
||||||
query_api = client.query_api()
|
query_api = client.query_api()
|
||||||
query = 'from(bucket: "gas")\
|
query = 'from(bucket: "gas")\
|
||||||
|> range(start: -30d)\
|
|> range(start: -30d)\
|
||||||
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\
|
||||||
|> filter(fn: (r) => r["_field"] == "odometer")\
|
|> filter(fn: (r) => r["_field"] == "odometer")\
|
||||||
|> sort(columns: ["_value"], desc: false)\
|
|> sort(columns: ["_value"], desc: false)\
|
||||||
|> yield(name: "last")\
|
|
||||||
|> limit(n:10)'
|
|> limit(n:10)'
|
||||||
|
|
||||||
result = query_api.query(org=config['DB_ORG'], query=query)
|
result = query_api.query(org=config['DB_ORG'], query=query)
|
||||||
|
print()
|
||||||
|
print()
|
||||||
|
print(result)
|
||||||
|
print()
|
||||||
results = []
|
results = []
|
||||||
for table in result:
|
for table in result:
|
||||||
for record in table.records:
|
for record in table.records:
|
||||||
@ -45,25 +46,15 @@ def main_page():
|
|||||||
temp['oilhealth'] = record['oilhealth']
|
temp['oilhealth'] = record['oilhealth']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
try:
|
|
||||||
temp['fuel'] = record['fuel']
|
|
||||||
temp['fuelcost'] = record['fuelcost']
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
results.append(temp)
|
results.append(temp)
|
||||||
# .append((record.get_time(), record.get_field(), record.get_value()))
|
# .append((record.get_time(), record.get_field(), record.get_value()))
|
||||||
|
print(results)
|
||||||
|
print(len(results))
|
||||||
|
print()
|
||||||
newlist = sorted(results, key=itemgetter('time'), reverse=True)
|
newlist = sorted(results, key=itemgetter('time'), reverse=True)
|
||||||
oldlist = newlist # temporary to strip the non-unique data
|
print(newlist)
|
||||||
newlist = []
|
data= results
|
||||||
for value in oldlist:
|
return render_template('index.html', data=newlist)
|
||||||
if value in newlist:
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
newlist.append(value)
|
|
||||||
|
|
||||||
# print(newlist)
|
|
||||||
return render_template('index.html', data=newlist[:10])
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/add_time', methods=['POST', 'GET'])
|
@app.route('/add_time', methods=['POST', 'GET'])
|
||||||
def add_time():
|
def add_time():
|
||||||
@ -78,7 +69,7 @@ def add_time():
|
|||||||
if time == '':
|
if time == '':
|
||||||
time = now
|
time = now
|
||||||
odometer = request.form['odometer']
|
odometer = request.form['odometer']
|
||||||
oilhealth = request.form['oilhealth']
|
oilhealth= request.form['oilhealth']
|
||||||
if oilhealth != '':
|
if oilhealth != '':
|
||||||
oilhealth = float(oilhealth)
|
oilhealth = float(oilhealth)
|
||||||
fuel = request.form['fuel']
|
fuel = request.form['fuel']
|
||||||
@ -94,17 +85,17 @@ def add_time():
|
|||||||
winter = False
|
winter = False
|
||||||
|
|
||||||
json_body = [
|
json_body = [
|
||||||
{
|
{
|
||||||
"time": date + "T" + time + "Z",
|
"time": date + "T" + time + "Z",
|
||||||
"measurement": "odyssey",
|
"measurement": "odyssey",
|
||||||
"fields": {
|
"fields": {
|
||||||
"odometer": float(odometer),
|
"odometer": float(odometer),
|
||||||
"oilhealth": oilhealth,
|
"oilhealth": oilhealth,
|
||||||
"fuel": fuel,
|
"fuel": fuel,
|
||||||
"fuelcost": fuelcost,
|
"fuelcost": fuelcost,
|
||||||
"winter": winter
|
"winter": winter
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
timestamp = date + "T" + time + "Z"
|
timestamp = date + "T" + time + "Z"
|
||||||
@ -116,12 +107,13 @@ def add_time():
|
|||||||
point = influxdb_client.Point("2016_odyssey").time(timestamp).tag("oilhealth", oilhealth)\
|
point = influxdb_client.Point("2016_odyssey").time(timestamp).tag("oilhealth", oilhealth)\
|
||||||
.tag("fuel", fuel).tag("fuelcost", fuelcost).tag("winter", winter).field("odometer", float(odometer))
|
.tag("fuel", fuel).tag("fuelcost", fuelcost).tag("winter", winter).field("odometer", float(odometer))
|
||||||
write_api.write(bucket="gas", org=config['DB_ORG'], record=point)
|
write_api.write(bucket="gas", org=config['DB_ORG'], record=point)
|
||||||
print("Submitting data to DB: {0}".format(json_body))
|
print ("Submitting data to DB: {0}".format(json_body))
|
||||||
# client.write_points(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>')
|
@app.route('/repeat_last_odometer/<odometer>')
|
||||||
def repeat_last_odometer(odometer):
|
def repeat_last_odometer(odometer):
|
||||||
'''Retrieve the passed in odometer value and submit as a new entry'''
|
'''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))
|
print("Putting %s to database for %s" % (odometer, timestamp))
|
||||||
|
|
||||||
write_api = client.write_api(write_options=SYNCHRONOUS)
|
write_api = client.write_api(write_options=SYNCHRONOUS)
|
||||||
point = influxdb_client.Point("2016_odyssey").time(
|
point = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(odometer))
|
||||||
timestamp).field("odometer", float(odometer))
|
|
||||||
write_api.write(bucket="gas", org=config['DB_ORG'], record=point)
|
write_api.write(bucket="gas", org=config['DB_ORG'], record=point)
|
||||||
return redirect(url_for('main_page'))
|
return redirect(url_for('main_page'))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin')
|
@app.route('/admin')
|
||||||
def admin_index():
|
def admin_index():
|
||||||
return 'admin'
|
return 'admin'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login')
|
@app.route('/login')
|
||||||
def login():
|
def login():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@app.route('/logout')
|
@app.route('/logout')
|
||||||
def logout():
|
def logout():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host='0.0.0.0', port='9001')
|
app.run(debug=True, host='0.0.0.0', port='9001')
|
||||||
|
@ -59,27 +59,11 @@
|
|||||||
</form>
|
</form>
|
||||||
<br>
|
<br>
|
||||||
Last Mileage
|
Last Mileage
|
||||||
<table class="table table-striped">
|
<ul>
|
||||||
<thead>
|
{% for point in data %}
|
||||||
<tr>
|
<li>
|
||||||
<th scope="col">Odometer</th>
|
{{ point['time'] }} = {{ point['odometer'] }}, {{point['oilhealth']}}
|
||||||
<th scope="col">Time</th>
|
</li>
|
||||||
<th scope="col">Oil</th>
|
{% endfor %}
|
||||||
<th scope="col">Litres</th>
|
|
||||||
<th scope="col">$/Litre</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% 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>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user