Commit cd75a0aa authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Remove Multi Building Chart Type Model

Also added a new multi-building chart type skeleton for showing sensor
values across multiple buildings.
parent 75dd9b42
......@@ -3,7 +3,7 @@ This file configures the Admin interface, which allows for editing of the Models
'''
from bmsapp.models import Building, Sensor, SensorGroup, BldgToSensor, DashboardItem, Unit
from bmsapp.models import MultiBuildingChartType, MultiBuildingChart, ChartBuildingInfo
from bmsapp.models import MultiBuildingChart, ChartBuildingInfo
from bmsapp.models import BuildingGroup
from django.contrib import admin
from django.forms import TextInput, Textarea
......@@ -62,13 +62,6 @@ class UnitAdmin(admin.ModelAdmin):
list_display = ('id', 'label', 'measure_type')
list_editable = ('label', 'measure_type')
class MultiBuildingChartTypeAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'widget': TextInput(attrs={'size':'50'})},
}
list_display = ('id', 'title', 'class_name', 'sort_order')
list_editable = ('title', 'class_name', 'sort_order')
class ChartBuildingInfoInline(admin.TabularInline):
model = ChartBuildingInfo
formfield_overrides = {
......@@ -87,5 +80,4 @@ admin.site.register(BuildingGroup, BuildingGroupAdmin)
admin.site.register(Sensor, SensorAdmin)
admin.site.register(SensorGroup, SensorGroupAdmin)
admin.site.register(Unit, UnitAdmin)
admin.site.register(MultiBuildingChartType, MultiBuildingChartTypeAdmin)
admin.site.register(MultiBuildingChart, MultiBuildingChartAdmin)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('bmsapp', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='multibuildingchart',
name='chart_type',
),
migrations.DeleteModel(
name='MultiBuildingChartType',
),
migrations.AddField(
model_name='multibuildingchart',
name='chart_class',
field=models.CharField(max_length=60, null=True, choices=[(b'currentvalues_multi.CurrentValuesMulti', b'Current Sensor Values'), (b'normalizedbyddbyft2.NormalizedByDDbyFt2', b'Energy / Degree-Day / ft2'), (b'normalizedbyft2.NormalizedByFt2', b'Energy / ft2')]),
preserve_default=True,
),
migrations.AlterField(
model_name='chartbuildinginfo',
name='parameters',
field=models.TextField(verbose_name=b'Chart Parameters in YAML Form', blank=True),
preserve_default=True,
),
migrations.AlterField(
model_name='multibuildingchart',
name='parameters',
field=models.TextField(verbose_name=b'General Chart Parameters in YAML Form', blank=True),
preserve_default=True,
),
migrations.AlterField(
model_name='sensor',
name='function_parameters',
field=models.TextField(verbose_name=b'Function Parameters in YAML form', blank=True),
preserve_default=True,
),
]
......@@ -76,29 +76,6 @@ class Sensor(models.Model):
ordering = ['sensor_id']
class MultiBuildingChartType(models.Model):
'''
A type of chart that uses data from multiple buildings
'''
# descriptive title of the Chart Type
title = models.CharField(max_length=50, unique=True)
# the name of the Django chart class in the 'reports' Python package
# that will return the data necessary to render the chart. The format
# of this field must be: <module name>.<class name>
class_name = models.CharField(max_length=60, unique=True)
# determines order of Chart Type displayed in Admin interface
sort_order = models.IntegerField(default=999)
def __unicode__(self):
return self.title
class Meta:
ordering = ['sort_order']
class Building(models.Model):
'''
A building that contains sensors.
......@@ -258,8 +235,17 @@ class MultiBuildingChart(models.Model):
# descriptive title of the Chart
title = models.CharField(max_length=60, unique=True)
MULTI_CHART_CHOICES = (
('currentvalues_multi.CurrentValuesMulti', 'Current Sensor Values'),
('normalizedbyddbyft2.NormalizedByDDbyFt2', 'Energy / Degree-Day / ft2'),
('normalizedbyft2.NormalizedByFt2', 'Energy / ft2'),
)
# the type of chart
chart_type = models.ForeignKey(MultiBuildingChartType)
chart_class = models.CharField("Type of Chart",
max_length=60,
null=True,
choices=MULTI_CHART_CHOICES)
# the general parameters for this chart, if any. These are parameters that are
# *not* associated with a particular building. The parameters are
......
......@@ -78,7 +78,7 @@ def get_chart_object(request_params):
if bldg_id=='multi':
chart_info = bmsapp.models.MultiBuildingChart.objects.get(id=chart_id)
class_name = chart_info.chart_type.class_name
class_name = chart_info.chart_class
else:
chart_info = find_chart_type(chart_id)
class_name = chart_info.class_name
......
import yaml
import basechart
class CurrentValuesMulti(basechart.BaseChart):
"""Explanation of report
"""
def result(self):
html = '<p>Results Go Here</p>'
return {'html': html, 'objects': []}
"""Converts my original keyword parameters to YAML parameters
"""
import bmsapp.models
import yaml
def makeKeywordArgs(keyword_str):
'''Original function to convert keyword string into dictionary, except special
handling of 'id_' keywords was removed.
'''
result = {}
keyword_str = keyword_str.strip()
# need to exit if this is a blank string
if len(keyword_str)==0:
return result
for it in keyword_str.strip().split(','):
kw, val = it.split('=')
kw = kw.strip()
val = val.strip()
try:
val = float(val)
except:
if val in ('True', 'true', 'Y', 'y', 'Yes', 'yes'):
val = True
elif val in ('False', 'false', 'N', 'n', 'No', 'no'):
val = False
else:
# must be a string.
# get rid of surrounding quotes of both types.
val = val.strip('"\'')
result[kw] = val
return result
def run():
for sen in bmsapp.models.Sensor.objects.exclude(function_parameters=''):
print sen.function_parameters
obj = makeKeywordArgs(str(sen.function_parameters))
sen.function_parameters = yaml.dump(obj, default_flow_style=False)
sen.save()
print
for sen in bmsapp.models.Sensor.objects.exclude(function_parameters=''):
print sen.function_parameters
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