Commit 555b59d2 authored by Nelso Jost's avatar Nelso Jost

FIX: workaround for wrong Date month in Dygraph.js

parent 5f1e0773
......@@ -144,8 +144,27 @@ class Sensor(db.Model, DBUtils):
def row_generator(sensor):
for rawdata in sensor.rawdata.all():
dt = rawdata.datetime
yield '[new Date({Y}, {M}, {D}, {h}, {m}, {s}), {y_value}]'\
.format(Y=dt.year, M=dt.month, D=dt.day, h=dt.hour,
yield '[new Date({Y}, {M}, {D}, {h}, {m}, {s}, 0), {y_value}]'\
.format(Y=(dt.year if dt.month != 1 else dt.year -1),
M=(dt.month-1 if dt.month != 1 else 12),
D=dt.day, h=dt.hour,
m=dt.minute, s=dt.second, y_value=rawdata.value)
# for some reason Dygraph.js render the month 1 month on the future!
return '[{}]'.format(','.join(r for r in row_generator(self)))
# def get_dygraph_data(self):
# ''' Returns a string containing Javascript array code with values from
# all the RawSensorData belonging to the given sensor.
# '''
# def row_generator(sensor):
# for rawdata in sensor.rawdata.all():
# dt = rawdata.datetime
# yield '"{Y}/{M}/{D} {h}:{m}:{s},{y_value}\\n"'\
# .format(Y=dt.year, M=dt.month, D=dt.day, h=dt.hour,
# m=dt.minute, s=dt.second, y_value=rawdata.value)
# return '"Data,{}\\n" + \n{}'.format(
# self.unity_measurement.measurement.name,
# '+ \n'.join(r for r in row_generator(self)))
......@@ -3,7 +3,9 @@
{% block title %}CTA-EMM-WEB{% endblock %}
{% block head %}
{{ super() }}
{{ super() }}
<meta charset="UTF-8">
<!-- <script type="text/javascript"> -->
<!-- function storePagePosition() -->
......
......@@ -6,8 +6,10 @@
{{ super() }}
<script src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script src="{{ url_for('static', filename='js/dygraph-combined-dev.js') }}"></script>
<!-- <script src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script> -->
<!-- <script src="{{ url_for('static', filename='js/dygraph-combined-dev.js') }}"></script> -->
<script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.1/dygraph-combined.js"></script>
<script language="javascript">
function refresh_dygraph(g_dygraph_obj){
......@@ -69,8 +71,10 @@ http://dygraphs.com/tutorial.html
g_{{ the_sensor.nickname }} = new Dygraph(
document.getElementById(
"{{ the_sensor.nickname + '_graphdiv' }}"),
{{ the_sensor.get_dygraph_data() }}
);
{{ the_sensor.get_dygraph_data()|safe }},
{labelsUTC: true,
labels: ["Data", "{{ the_sensor.unity_measurement.measurement.name }}"]
});
</script>
</div>
<div>
......
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