This document includes documentation on the included core models to aid development of Apps with the Data Server platform. The core included models are all Django Model objects. See the Django model layer documentation for more information.
The Data Server (version 3.0) is built with Python 2.5.2 and Django 1.1.1 on Windows platforms.
There are four included HTTP Apps to exploit:
The Data Server also includes the Matplotlib a 2D plotting library, NumPy packages which are used in the Unit graph views.
The Units Application is the main model definition and administration interface definition for the Units. This application also has the unit detail and graphing client facing views and templates.
Import this App's models like so:
from texmatedse.core.units.models import Unit
Unit:Database Properties:
pk Primary Key (Integer)
TTP Connection information:
code CharField unique, max_length=24, 2 chars min: no spaces, alphanumeric
characters only
key CharField, max_length=128, Stored as an sha1 hexdigest (with no salt)
Naming and visibility:
name CharField, max_length=64, A descriptive name for the Unit
description TextField, blank=True
is_public BooleanField Show to public, default=True
TTP UP/DL Request Specs:
num_data_fields IntegerField Number of data fields, default=4, The number of data fields the
unit will be sending 1-128
use_labels BooleanField Use labels in download, default=False
is_downloadable BooleanField, default=True, Can data from this unit be downloaded on the the
public website?
Channel labels:
chan_1_label CharField max_length=8, blank=True
...
chan_128_label CharField max_length=8, blank=True
Graphing details:
num_axes IntegerField Number of graph axes, default=1, choices=1-6
axis_1_channels CharField max_length=32, blank=True, default=1-32
...
axis_6_channels CharField max_length=32, blank=True
axis_1_label CharField max_length=32, blank=True
...
axis_6_label CharField max_length=32, blank=True
graph_width IntegerField default=960, Size in Pixels
graph_height IntegerField default=600, Size in Pixels
Properties:
axis_1_channel_list list of channels for axis 1. A list version of axis_1_channels.
...
axis_1_channel_list list of channels for axis 6. A list version of axis_6_channels.
labels list of available channel-labels (limited to num_data_fields)
data_field_labels comma separated string of available channel-labels
first_datetime Earliest (first in the unit_data table) datetime for the unit.
Is a datetime.datetime instance.
last_datetime Latest (last in the unit_data table) datetime for the unit.
Is a datetime.datetime instance.
last_sample Latest Sample for the unit (if it exists).
Instance Methods:
check_key(raw_key): Returns a boolean of whether the raw_key was correct.
set_key(raw_key): Sets the key for the Unit. Does not return.
get_absolute_url: models.permalink:
view name='dse-unit-detail'
view kwargs: 'object_id': self.pk
The Data Application holds the model definitions for the stored Samples sent by each unit to the TTP Interface. It also provides the administration interface definition where all of the data can be viewed online in a tabular format.
Import this App's models like so:
from texmatedse.core.data.models import Alarm, Sample, LastTime
Alarm:Database Properties:
pk Primary Key (Integer)
unit ForeignKey Unit, related_name=alarms
datetime FloatField default=0.0 floating point number which represents
the number of days since 0001-01-01 UTC.
See the date property for the datetime.datetime instance
representation.
level PositiveIntegerField max_digits=2, default=1
Properties:
date datetime.datetime representation of self.datetime
Sample:Database Properties:
pk Primary Key (Integer)
unit ForeignKey Unit, related_name=samples
datetime FloatField default=0.0 floating point number which represents
the number of days since 0001-01-01 UTC.
See the date property for the datetime.datetime instance
representation.
val_1 DecimalField blank=True, null=True, max_digits=16, decimal_places=6
...
val_128 DecimalField blank=True, null=True, max_digits=16, decimal_places=6
Properties:
date datetime.datetime representation of self.datetime
LastTime:Provides super-quick access to the last uploaded sample time for the Data Server. Used in the download of samples from the Data Server via TTP.
Database Properties:
unit ForeignKey Unit, primary_key=True, related_name=last_time
datetime FloatField default=0.0 floating point number which represents
the number of days since 0001-01-01 UTC.
See the date property for the datetime.datetime instance
representation.
Properties:
date datetime.datetime representation of self.datetime
The Mailer Application handles the Unit Mailing Lists and email sending from each Unit to the configured recipients (Users).
Import this App's models like so:
from texmatedse.core.mailer.models import UnitMailingList, AlarmList, Email
UnitMailingList:Each unit gets a single mailing list - consisting of Users which are created in the normal Django way, and then email can be sent to their email addresses on demand via a TTP command.
Database Properties:
unit OneToOneField Unit, related_name=mailing_list
is_sendable BooleanField default=True, Enable or disable sending email to users in this
emailing list.
users ManyToManyField User
Instance Methods:
email_users(subject, message) Send subject/message to the Users in this mailing list.
``new`` is used to mark whether we are tring this for the first time, or not.
Can't be called directly in templates.
email_alarm_users(level, data=None) Send preconfigured Alarm of level level to the
Users in this mailing list.
AlarmList:Each unit gets multiple alarm messages of differing levels. These messages are then sent out to the UnitMailingList for the Unit on demand via a TTP command.
Database Properties:
unit ForeignKey Unit, related_name=alarm_list
level PositiveIntegerField max_digits=2, default=1
subject CharField max_length=100
message TextField
Instance Methods:
email_alarm(level, data=None) Send alarm (via Email) to the Users in the Unit mailing list.
Can't be called directly in templates.
Email:For sent mail - saves a copy of the message that was sent, and whether it sent successfully or not.
Database Properties:
unit_mailing_list ForeignKey UnitMailingList
subject CharField max_length=100
message TextField
datetime DateTimeField auto_now_add=True
is_sent BooleanField default=False, Did the email send successfully?
Marked as true even if only one sends successfully.
Managers:
objects EmailManager()
Instance Methods:
resend Attempts to resend this message
If:
is_sent is False and
unit_mailing_list.is_sendable is True
Can't be called directly in templates.
EmailManager:Provides some custom methods for the Email object. Installed at Email.objects
delete_sent_email() Deletes all the successfully sent mail records from the database.
delete_all_email() Deletes all email records from the database.
retry_unsent_email() Retries all the unsent/failed mail records.
The Views Application handles the Multiple-Unit display models, client facing views, and the administration interface definitions.
Import this App's models like so:
from texmatedse.httpserver.views.models import MultiMeterView, MultiMeterViewUnit
MultiMeterView:Database Properties:
name CharField max_length=20, Used to identify the view in lists of many of
these configured views.
refresh IntegerField default=10, Number of seconds to refresh the display
(client web browser)
is_public BooleanField Show this view in the website?, default=True
Instance Methods:
get_absolute_url models.permalink:
view name 'dse-multimeterview-detail',
view kwargs 'object_id': self.pk
MultiMeterViewUnit:Building Block for MultiMeterView. Controls which meters (units) are displayed on screen, and which channels each meter will show.
Database Properties:
view ForeignKey MultiMeterView, related_name='units'
unit ForeignKey Unit
channels CharField, max_length=32, default=1-2
Properties:
data Dictionary consisting of:
'channel': integer,
'label': self.unit.chan_x_label,
'value': DecimalField or string '------' if no sample