Commit 76aa0734 authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Merge branch 'task13'

parents cd75a0aa 38f8298e
This diff is collapsed.
"""
This module contains formatting functions for sensor values
"""
import formatter_codes
def alarm_formatter(coded_value):
"""Code of 0 indicates OK, and anything else indicates an
Alarm. Can be used to format 0/1 values from alarm contacts.
"""
return 'OK' if coded_value==0 else 'Alarm!'
def _bitmask_to_list(encoded_value, bitmask_dictionary):
output_list = []
for bit_offset in bitmask_dictionary.keys():
if int(encoded_value) & (1 << bit_offset):
output_list.append(bitmask_dictionary[bit_offset])
return output_list
def aerco_fault_code_formatter(coded_value):
value_list = _bitmask_to_list(coded_value, formatter_codes.aerco_fault_code_bitmask_dictionary)
return '; '.join(map(str, value_list))
def aerco_io_status_formatter(coded_value):
value_list = _bitmask_to_list(coded_value, formatter_codes.aerco_io_status_bitmask_dictionary)
return '; '.join(map(str, value_list))
def aerco_boiler_status_formatter(coded_value):
if 1 <= coded_value <= 40:
return 'Fired, sequence = ' + str(coded_value)
elif coded_value in formatter_codes.aerco_boiler_status_dictionary:
return formatter_codes.aerco_boiler_status_dictionary[coded_value]
else:
return 'Unknown (invalid value)'
def sage_limits_sensor_formatter(coded_value):
value_list = _bitmask_to_list(coded_value, formatter_codes.sage_limits_bitmask_dictionary)
return '; '.join(map(str, value_list))
def sage_demand_on_off_formatter(coded_value):
if coded_value == 0:
return 'Off'
else:
return 'On'
def sage_alarm_reason_formatter(coded_value):
if coded_value in formatter_codes.sage_alarm_reason_dictionary:
return formatter_codes.sage_alarm_reason_dictionary[coded_value]
else:
return 'Unknown (invalid value)'
def sage_demand_source_formatter(coded_value):
if coded_value in formatter_codes.sage_demand_source_dictionary:
return formatter_codes.sage_demand_source_dictionary[coded_value]
else:
return 'Unknown (invalid value)'
def sage_lockout_code_formatter(coded_value):
if coded_value in formatter_codes.sage_lockout_code_dictionary:
return formatter_codes.sage_lockout_code_dictionary[coded_value]
else:
return 'Unknown (invalid value)'
def sage_alert_code_formatter(coded_value):
if coded_value in formatter_codes.sage_alert_code_dictionary:
return formatter_codes.sage_alert_code_dictionary[coded_value]
else:
return 'Unknown (invalid value)'
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('bmsapp', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='sensor',
name='formatting_function',
field=models.CharField(max_length=50, verbose_name=b'Formatting Function Name', blank=True),
preserve_default=True,
),
]
......@@ -69,6 +69,10 @@ class Sensor(models.Model):
# first, make sure the calculation_order for this field is higher than the fields it depends on.
calculation_order = models.IntegerField(default=0)
# the name of the formatting function for the value, if any.
# Formatting functions must be located in the "formatters.py" module.
formatting_function = models.CharField("Formatting Function Name", max_length=50, blank=True)
def __unicode__(self):
return self.sensor_id + ": " + self.title
......
import time
from django.template import Context, loader
import bmsapp.models, bmsapp.data_util
import bmsapp.formatters
import basechart
class CurrentValues(basechart.BaseChart):
"""Class that creates the Current Values report.
"""
......@@ -23,11 +25,15 @@ class CurrentValues(basechart.BaseChart):
cur_group = b_to_sen.sensor_group.title
cur_group_sensor_list = []
last_read = self.reading_db.last_read(b_to_sen.sensor.sensor_id)
cur_value = bmsapp.data_util.formatCurVal(last_read['val']) if last_read else ''
if b_to_sen.sensor.formatting_function.strip():
format_function = getattr(bmsapp.formatters, b_to_sen.sensor.formatting_function.strip())
cur_value = format_function(last_read['val']) if last_read else ''
else:
cur_value = bmsapp.data_util.formatCurVal(last_read['val']) if last_read else ''
minutes_ago = '%.1f' % ((cur_time - last_read['ts'])/60.0) if last_read else ''
cur_group_sensor_list.append( {'title': b_to_sen.sensor.title,
'cur_value': cur_value,
'unit': b_to_sen.sensor.unit.label,
'unit': b_to_sen.sensor.unit.label,
'minutes_ago': minutes_ago,
'sensor_id': b_to_sen.sensor.id} )
# add the last group
......
import time
import bmsapp.models, bmsapp.data_util
import bmsapp.models
import bmsapp.data_util
import bmsapp.formatters
import basechart
class Dashboard(basechart.BaseChart):
......@@ -27,6 +29,12 @@ class Dashboard(basechart.BaseChart):
if dash_item.sensor is not None:
last_read = self.reading_db.last_read(dash_item.sensor.sensor.sensor_id)
cur_value = float(bmsapp.data_util.formatCurVal(last_read['val'])) if last_read else None
formatter_name = dash_item.sensor.sensor.formatting_function.strip()
if cur_value is not None and formatter_name:
format_function = getattr(bmsapp.formatters, formatter_name)
new_widget['value_label'] = format_function(cur_value)
else:
new_widget['value_label'] = ''
age_secs = time.time() - last_read['ts'] if last_read else None # how long ago reading occurred
minAxis, maxAxis = dash_item.get_axis_range()
new_widget.update( {'units': dash_item.sensor.sensor.unit.label,
......
......@@ -18,7 +18,7 @@
width: 50px;
height: 50px;
background-color: #00BB00;
margin: 25px auto;
margin: 5px auto;
}
.dash-label {
width: 130px;
......@@ -37,4 +37,10 @@
text-align: center;
font-family: arial,sans-serif;
font-size: 18px;
}
.value-label {
padding: 5px;
text-align: center;
font-family: arial,sans-serif;
font-size: 14px;
}
\ No newline at end of file
......@@ -136,7 +136,8 @@ addLED = (jqParent, LED_info) ->
widgetID = "widget#{++widgetCounter}" # this increments the counter as well
jqParent.append "<div id=\"#{widgetID}\" class=\"led\">
<h2>#{LED_info.title}</h2>
<div class=\"led-circle\"></div>&nbsp;
<div class=\"led-circle\"></div>
<div class=\"value-label\">#{LED_info.value_label}</div>
</div>"
jqWidget = $("##{widgetID}") # make a jQuery element
......
......@@ -141,7 +141,7 @@
addLED = function(jqParent, LED_info) {
var jqWidget, widgetID;
widgetID = "widget" + (++widgetCounter);
jqParent.append("<div id=\"" + widgetID + "\" class=\"led\"> <h2>" + LED_info.title + "</h2> <div class=\"led-circle\"></div>&nbsp; </div>");
jqParent.append("<div id=\"" + widgetID + "\" class=\"led\"> <h2>" + LED_info.title + "</h2> <div class=\"led-circle\"></div> <div class=\"value-label\">" + LED_info.value_label + "</div> </div>");
jqWidget = $("#" + widgetID);
if (LED_info.value < LED_info.minNormal || LED_info.value > LED_info.maxNormal) {
jqWidget.children(".led-circle").css('background-color', '#FF0000');
......
......@@ -4,7 +4,7 @@
{% block pagetitle %}Reports/Charts{% endblock %}
{% block head %}
<link rel="stylesheet" type="text/css" href="{% static 'bmsapp/css/jquery.multiselect.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'bmsapp/css/dashboard.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'bmsapp/css/dashboard.css' %}?t={{ curtime }}">
<script src="https://code.highcharts.com/stock/2/highstock.js"></script>
<script src="https://code.highcharts.com/3.0.10/highcharts.js"></script>
<script src="https://code.highcharts.com/3.0.10/highcharts-more.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment