Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
76aa0734
Commit
76aa0734
authored
Feb 04, 2015
by
Alan Mitchell
Browse files
Merge branch 'task13'
parents
cd75a0aa
38f8298e
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
930 additions
and
7 deletions
+930
-7
bmsapp/formatter_codes.py
bmsapp/formatter_codes.py
+800
-0
bmsapp/formatters.py
bmsapp/formatters.py
+78
-0
bmsapp/migrations/0002_sensor_formatting_function.py
bmsapp/migrations/0002_sensor_formatting_function.py
+20
-0
bmsapp/models.py
bmsapp/models.py
+4
-0
bmsapp/reports/currentvalues.py
bmsapp/reports/currentvalues.py
+8
-2
bmsapp/reports/dashboard.py
bmsapp/reports/dashboard.py
+9
-1
bmsapp/static/bmsapp/css/dashboard.css
bmsapp/static/bmsapp/css/dashboard.css
+7
-1
bmsapp/static/bmsapp/scripts/dashboard.coffee
bmsapp/static/bmsapp/scripts/dashboard.coffee
+2
-1
bmsapp/static/bmsapp/scripts/dashboard.js
bmsapp/static/bmsapp/scripts/dashboard.js
+1
-1
bmsapp/templates/bmsapp/reports.html
bmsapp/templates/bmsapp/reports.html
+1
-1
No files found.
bmsapp/formatter_codes.py
0 → 100644
View file @
76aa0734
This diff is collapsed.
Click to expand it.
bmsapp/formatters.py
0 → 100644
View file @
76aa0734
"""
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)'
bmsapp/migrations/0002_sensor_formatting_function.py
0 → 100644
View file @
76aa0734
# -*- 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
,
),
]
bmsapp/models.py
View file @
76aa0734
...
...
@@ -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
...
...
bmsapp/reports/currentvalues.py
View file @
76aa0734
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
...
...
bmsapp/reports/dashboard.py
View file @
76aa0734
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
,
...
...
bmsapp/static/bmsapp/css/dashboard.css
View file @
76aa0734
...
...
@@ -18,7 +18,7 @@
width
:
50px
;
height
:
50px
;
background-color
:
#00BB00
;
margin
:
2
5px
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
bmsapp/static/bmsapp/scripts/dashboard.coffee
View file @
76aa0734
...
...
@@ -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>
<div class=
\"
led-circle
\"
></div>
<div class=
\"
value-label
\"
>
#{
LED_info
.
value_label
}
</div>
</div>"
jqWidget
=
$
(
"#
#{
widgetID
}
"
)
# make a jQuery element
...
...
bmsapp/static/bmsapp/scripts/dashboard.js
View file @
76aa0734
...
...
@@ -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>
</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
'
);
...
...
bmsapp/templates/bmsapp/reports.html
View file @
76aa0734
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment