1
0
Fork 0
Browse Source

implement home page status report feature.

pull/7/head
Craig Oates 4 years ago
parent
commit
1008d3e2e4
  1. 5
      app/app.py
  2. 8
      app/models/devices.py
  3. BIN
      app/readings.db
  4. 14
      app/services/get_services.py
  5. 13
      app/templates/home.html

5
app/app.py

@ -1,6 +1,7 @@
from flask import Flask, render_template
import connexion
import config
from services import get_services
# The application instance.
app = config.connex_app
@ -10,7 +11,9 @@ app.add_api("swagger.yml")
@app.route("/")
def home ():
return render_template("home.html")
data = get_services.get_latest_status_for_all_devices()
print(data)
return render_template("home.html", data=data)
@app.route("/robots.txt")
@app.route("/robots")

8
app/models/devices.py

@ -45,7 +45,7 @@ class Device3(db.Model):
class Device3Schema(ma.ModelSchema):
class Meta:
model = Device1
model = Device3
sqla_session = db.session
class Device4(db.Model):
@ -56,7 +56,7 @@ class Device4(db.Model):
class Device4Schema(ma.ModelSchema):
class Meta:
model = Device1
model = Device4
sqla_session = db.session
class Device5(db.Model):
@ -67,7 +67,7 @@ class Device5(db.Model):
class Device5Schema(ma.ModelSchema):
class Meta:
model = Device1
model = Device5
sqla_session = db.session
class Device6(db.Model):
@ -78,5 +78,5 @@ class Device6(db.Model):
class Device6Schema(ma.ModelSchema):
class Meta:
model = Device1
model = Device6
sqla_session = db.session

BIN
app/readings.db

Binary file not shown.

14
app/services/get_services.py

@ -72,6 +72,9 @@ def get_all_status_logs_from_table(device):
def get_all_status_changes_from_database():
return get_all_status_logs()
def get_latest_status_for_all_devices():
return get_all_latest_logs()
'''
The Nitty-Gritty Functions
======================================================================
@ -198,3 +201,14 @@ def get_all_status_changes_from_database():
logs = {"device 1": d1, "device 2": d2, "device 3": d3,
"device 4": d4, "device 5": d5, "device 6": d6}
return logs
def get_all_latest_logs():
d1 = get_d1_latest()
d2 = get_d2_latest()
d3 = get_d3_latest()
d4 = get_d4_latest()
d5 = get_d5_latest()
d6 = get_d6_latest()
logs = {"device 1": d1, "device 2": d2, "device 3": d3,
"device 4": d4, "device 5": d5, "device 6": d6}
return logs

13
app/templates/home.html

@ -1,6 +1,7 @@
{% extends "layout.html" %}
{% block content %}
<main>
<div>
<div class="header">
@ -13,32 +14,32 @@
<div class="status-bar">
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 1"].status) }}" alt="logo"/>
<p>Factory 1</p>
</div>
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 2"].status) }}" alt="logo"/>
<p>Factory 2</p>
</div>
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 3"].status) }}" alt="logo"/>
<p>Factory 3</p>
</div>
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 4"].status) }}" alt="logo"/>
<p>Gallery 1</p>
</div>
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 5"].status) }}" alt="logo"/>
<p>Gallery 2</p>
</div>
<div class="meter">
<img src="{{ url_for('static', filename='images/off.png') }}" alt="logo"/>
<img src="{{ url_for('static', filename='images/%s.png' % data["device 6"].status) }}" alt="logo"/>
<p>Gallery 3</p>
</div>