Added most recent values to the dashboard

This commit is contained in:
Hendrik Borras 2017-10-20 15:25:51 +02:00
parent f3dda1b644
commit f76928bc74
3 changed files with 90 additions and 4 deletions

View file

@ -13,7 +13,10 @@
<link href="{{ url_for('static',filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static',filename='css/cosmicpi.css') }}" rel="stylesheet">
<link href="{{ url_for('static',filename='css/font-awesome.min.css') }}" rel="stylesheet" type="text/css">
{% block head_additions %}{% endblock %}
<script src="{{ url_for('static',filename='js/jquery.min.js') }}"></script>
{% block head_additions %}{% endblock %}
</head>
<body>

View file

@ -1,9 +1,40 @@
{% extends "cosmic_base.html" %}
{% block title %}Dashboard{% endblock %}
{% block head_additions %}
{% endblock %}
{% block content %}
<h1>Index</h1>
<img id="img" src="/histogram.png?start_time=-120&end_time=9000000000&bin_size_seconds=1"/>
<h1>Dashboard</h1>
<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading">
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<img id="img" src="/histogram.png?start_time=-120&end_time=9000000000&bin_size_seconds=1"/>
</div>
</div>
</div>
{% for value in values_to_display %}
<div class="col-lg-4 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="{{ value['icon'] }}"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge" style="font-size: 24px">{{ value['value'] }}</div>
<div>{{ value['name'] }}</div>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
{% endblock %}

View file

@ -27,10 +27,62 @@ def base():
'cosmic_base.html', **locals())
@app.route("/hw_serial.txt")
def getserial():
# Extract serial from cpuinfo file
cpuserial = "0000000000000000"
try:
f = open('/proc/cpuinfo','r')
for line in f:
if line[0:6]=='Serial':
cpuserial = line[10:26]
f.close()
except:
cpuserial = "ERROR000000000"
return cpuserial
icon_dict = {
'UTCUnixTime': "fa fa-clock-o fa-5x",
'TempreatureC': "fa fa-thermometer-half fa-5x",
'Humidity': "fa fa-tint fa-5x",
'AccelX': "fa fa-tachometer fa-5x",
'AccelY': "fa fa-tachometer fa-5x",
'AccelZ': "fa fa-tachometer fa-5x",
'MagX': "fa fa-compass fa-5x",
'MagY': "fa fa-compass fa-5x",
'MagZ': "fa fa-compass fa-5x",
'Pressure': "fa fa-thermometer-half fa-5x",
'Longitude': "fa fa-map-marker fa-5x",
'Latitude': "fa fa-map-marker fa-5x",
'DetectorName': "fa fa-info-circle fa-5x",
'DetectorVersion': "fa fa-info-circle fa-5x",
}
@app.route('/', methods=['GET', 'POST'])
@app.route('/dashboard/', methods=['GET', 'POST'])
def dashboard():
return render_template('dashboard.html', chart_json=0)
values_to_display =[{'name':'Hardware Serial', 'value':getserial(), 'icon':'fa fa-microchip fa-5x'}]
# get the latest datapoint
conn = sqlite3.connect(sqlite_location)
cursor = conn.cursor()
cursor.execute("SELECT * FROM Events ORDER BY UTCUnixTime DESC, SubSeconds DESC;")
latest_datapoint = cursor.fetchone()
# get collumn names
cursor.execute("PRAGMA table_info(Events);")
col_names = cursor.fetchall()
print latest_datapoint
print col_names
for i in range(0,len(col_names)):
# skip the subseconds
if i == 1:
continue;
values_to_display.append({'name':col_names[i][1], 'value':latest_datapoint[i], 'icon':icon_dict[col_names[i][1]]})
return render_template('dashboard.html', values_to_display=values_to_display)
@app.route('/histogram.png')