Commit 45cc3a19 authored by Hive's avatar Hive

Ajout de fusioncharts

parent 947dc171

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

from django.http import HttpResponse
import json
from collections import OrderedDict
# Common base class for FC
class FusionCharts:
baseTemplate = """
<script type="text/javascript">
FusionCharts.ready(function () {
__FC__
});
</script>"""
constructorTemplate = """new FusionCharts(__constructorOptions__);"""
renderTemplate = """FusionCharts("__chartId__").render();"""
eventTemplate = """FusionCharts("__chartId__").addEventListener("_fceventname_",_fceventbody_);"""
# constructor
def __init__(self, type, id, width, height, renderAt, dataFormat, dataSource):
self.eventOptions = OrderedDict()
self.constructorOptions = {}
self.constructorOptions['type'] = type
self.constructorOptions['id'] = id
self.constructorOptions['width'] = width
self.constructorOptions['height'] = height
self.constructorOptions['renderAt'] = renderAt
self.constructorOptions['dataFormat'] = dataFormat
#dataSource = unicode(dataSource, errors='replace')
self.constructorOptions['dataSource'] = dataSource
def addEvent(self, eventName, funcName):
self.eventOptions[eventName] = funcName
def addMessage(self, messageName, messageValue):
self.constructorOptions[messageName] = messageValue
# render the chart created
# It prints a script and calls the FusionCharts javascript render method of created chart
def render(self):
# Serialize constructorOptions to a JSON formatted
self.readyJson = json.dumps(self.constructorOptions, ensure_ascii=False)
# Create Fusioncharts constructor from template and insert JSON data in it
self.readyJson = FusionCharts.constructorTemplate.replace('__constructorOptions__', self.readyJson)
# Iterate and attach EventHandler from template
for key, value in self.eventOptions.items():
self.readyJson = self.readyJson + FusionCharts.eventTemplate.replace('__chartId__', self.constructorOptions['id'])
self.readyJson = self.readyJson.replace("_fceventname_", key).replace("_fceventbody_", value)
# FusionCharts Render method will create chart
self.readyJson = self.readyJson + FusionCharts.renderTemplate.replace('__chartId__', self.constructorOptions['id'])
self.readyJson = FusionCharts.baseTemplate.replace("__FC__", self.readyJson)
self.readyJson = self.readyJson.replace('\\n', '')
self.readyJson = self.readyJson.replace('\\t', '')
if(self.constructorOptions['dataFormat'] == 'json'):
self.readyJson = self.readyJson.replace('\\', '')
self.readyJson = self.readyJson.replace('"{', "{")
self.readyJson = self.readyJson.replace('}"', "}")
return self.readyJson
\ No newline at end of file
# Generated by Django 2.1.2 on 2018-11-25 15:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0008_auto_20181030_0828'),
]
operations = [
migrations.CreateModel(
name='Data',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('timestamp', models.DateField()),
('value', models.IntegerField()),
],
),
]
# Generated by Django 2.1.2 on 2018-11-25 16:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0009_data'),
]
operations = [
migrations.AlterField(
model_name='data',
name='timestamp',
field=models.DateTimeField(),
),
]
# Generated by Django 2.1.2 on 2018-11-25 20:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0010_auto_20181125_1626'),
]
operations = [
migrations.AlterField(
model_name='data',
name='timestamp',
field=models.CharField(max_length=300),
),
]
......@@ -25,3 +25,8 @@ class Raspi(models.Model):
]
ip = models.CharField(max_length=50)
status = models.CharField(max_length=5, choices=STATUS_CHOICES, default="UP")
class Data(models.Model):
timestamp = models.CharField(max_length=300)
value = models.IntegerField()