| ... | @@ -36,7 +36,7 @@ This section presents some further details on the Django Server application. In |
... | @@ -36,7 +36,7 @@ This section presents some further details on the Django Server application. In |
|
|
|
|
|
|
|
### views.py Module
|
|
### views.py Module
|
|
|
|
|
|
|
|
As is the convention in Django, the [views.py](../blob/master/bmsapp/views.py) module provides functions that are accessed by HTTP requests; the [urls.py module](../../../bmon/blob/master/bmsapp/urls.py) maps URLs to these functions.
|
|
As is the convention in Django, the [views.py](../blob/master/bmsapp/views.py) module provides functions that are accessed by HTTP requests; the [urls.py module](../blob/master/bmsapp/urls.py) maps URLs to these functions.
|
|
|
|
|
|
|
|
Some of the important functions in the `views.py` module are:
|
|
Some of the important functions in the `views.py` module are:
|
|
|
|
|
|
| ... | @@ -48,7 +48,7 @@ Some of the important functions in the `views.py` module are: |
... | @@ -48,7 +48,7 @@ Some of the important functions in the `views.py` module are: |
|
|
|
|
|
|
|
**For Providing Content to the Browser Application**
|
|
**For Providing Content to the Browser Application**
|
|
|
|
|
|
|
|
**`reports()`**: Returns the main Reports page which is used to configure and view all of the charts and reports provided by the BMON application. The Django template used to create the page is the [`reports.html` template](../../../bmon/blob/master/bmsapp/templates/bmsapp/reports.html).
|
|
**`reports()`**: Returns the main Reports page which is used to configure and view all of the charts and reports provided by the BMON application. The Django template used to create the page is the [`reports.html` template](../blob/master/bmsapp/templates/bmsapp/reports.html).
|
|
|
|
|
|
|
|
**`get_report_results()`**: The Reports page in the browser is a [[Single Page Application|https://en.wikipedia.org/wiki/Single-page_application]]. When the User makes a change to the input controls on that page that affects the report or chart, this function is called by the browser to request the new report or chart content. More explanation of the data format returned is provided later in this document.
|
|
**`get_report_results()`**: The Reports page in the browser is a [[Single Page Application|https://en.wikipedia.org/wiki/Single-page_application]]. When the User makes a change to the input controls on that page that affects the report or chart, this function is called by the browser to request the new report or chart content. More explanation of the data format returned is provided later in this document.
|
|
|
|
|
|
| ... | @@ -58,13 +58,13 @@ Some of the important functions in the `views.py` module are: |
... | @@ -58,13 +58,13 @@ Some of the important functions in the `views.py` module are: |
|
|
|
|
|
|
|
### Sensor Reading Database
|
|
### Sensor Reading Database
|
|
|
|
|
|
|
|
All interactions with the Sensor Reading Database occur through the `BMSdata` class located in the [bmsdata.py module](../../../bmon/blob/master/bmsapp/readingdb/bmsdata.py). The class contains methods for storage of sensor readings, retrieval of sensor readings, and database backup operations. For an installed BMON system, the first sensor reading database operation will cause the creation of the SQLite database, which will be stored in the `bmon/bmsapp/readingdb/data` directory. When the `BMSdata.backup_db()` method is called, the backup files of the SQLite database are placed in the `bmon/bmsapp/readingdb/data/bak` directory; backup files older than a certain number of days (a method parameter) are deleted when a new backup file is stored.
|
|
All interactions with the Sensor Reading Database occur through the `BMSdata` class located in the [bmsdata.py module](../blob/master/bmsapp/readingdb/bmsdata.py). The class contains methods for storage of sensor readings, retrieval of sensor readings, and database backup operations. For an installed BMON system, the first sensor reading database operation will cause the creation of the SQLite database, which will be stored in the `bmon/bmsapp/readingdb/data` directory. When the `BMSdata.backup_db()` method is called, the backup files of the SQLite database are placed in the `bmon/bmsapp/readingdb/data/bak` directory; backup files older than a certain number of days (a method parameter) are deleted when a new backup file is stored.
|
|
|
|
|
|
|
|
To use a different database technology, the only part of the BMON application that would need to be changed is the `bmsdata.py` module, as all access to the database occurrs through that module.
|
|
To use a different database technology, the only part of the BMON application that would need to be changed is the `bmsdata.py` module, as all access to the database occurrs through that module.
|
|
|
|
|
|
|
|
### Report/Chart Creation
|
|
### Report/Chart Creation
|
|
|
|
|
|
|
|
Each report or chart type provided by BMON is mapped to a Python class located in the `bmon/bmsapp/reports` directory that generates the report or chart. In the [basechart.py file](../../../bmon/blob/master/bmsapp/reports/basechart.py), you can see how each single building chart is mapped to a particular class that is used to render the chart:
|
|
Each report or chart type provided by BMON is mapped to a Python class located in the `bmon/bmsapp/reports` directory that generates the report or chart. In the [basechart.py file](../blob/master/bmsapp/reports/basechart.py), you can see how each single building chart is mapped to a particular class that is used to render the chart:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
# These are the possible chart types currently implemented, in the order they will be
|
|
# These are the possible chart types currently implemented, in the order they will be
|
| ... | @@ -80,9 +80,9 @@ BLDG_CHART_TYPES = [ |
... | @@ -80,9 +80,9 @@ BLDG_CHART_TYPES = [ |
|
|
]
|
|
]
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
The last constructor parameter for BldgChartType gives the class that is used to create the chart. For example, the Histogram chart is created by the `Histogram` class located in the [`histogram`](../../../bmon/blob/master/bmsapp/reports/histogram.py) module.
|
|
The last constructor parameter for BldgChartType gives the class that is used to create the chart. For example, the Histogram chart is created by the `Histogram` class located in the [`histogram`](../blob/master/bmsapp/reports/histogram.py) module.
|
|
|
|
|
|
|
|
For charts/reports that present data from *multiple buildings*, the mapping from chart type to class occurs in the [models.py file](../../../bmon/blob/master/bmsapp/models.py), in the definition of the `MultiBuildingChart` class:
|
|
For charts/reports that present data from *multiple buildings*, the mapping from chart type to class occurs in the [models.py file](../blob/master/bmsapp/models.py), in the definition of the `MultiBuildingChart` class:
|
|
|
|
|
|
|
|
```python
|
|
```python
|
|
|
class MultiBuildingChart(models.Model):
|
|
class MultiBuildingChart(models.Model):
|
| ... | @@ -101,13 +101,13 @@ class MultiBuildingChart(models.Model): |
... | @@ -101,13 +101,13 @@ class MultiBuildingChart(models.Model): |
|
|
... more code
|
|
... more code
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
You can see that the Multi-building Current Sensor Values report is produced by the [`currentvalues_multi.CurrentValuesMulti`](../../../bmon/blob/master/bmsapp/reports/currentvalues_multi.py) class. If you wish to create an additional type of multi-building report, you need to add a new choice in `MULTI_CHART_CHOICES` and then create the class that the new report is mapped to in the `bmon/bmsapp/reports` directory.
|
|
You can see that the Multi-building Current Sensor Values report is produced by the [`currentvalues_multi.CurrentValuesMulti`](../blob/master/bmsapp/reports/currentvalues_multi.py) class. If you wish to create an additional type of multi-building report, you need to add a new choice in `MULTI_CHART_CHOICES` and then create the class that the new report is mapped to in the `bmon/bmsapp/reports` directory.
|
|
|
|
|
|
|
|
These chart classes all must have a `result()` method that returns the report/chart content. This report/chart content is used to fill out the `id="results"` HTML div element on the Reports page in the browser. The return value from the `result()` function is generally a Python dictionary with two keys: an `html` key and an `objects` key. The value of the `html` key is the HTML that is inserted into the `results` div on the browser page. The value of the `objects` key is a list of two-tuples, one two-tuple for each object that the browser needs to create. Objects that the BMON client app knows how to create are Highcharts charts, Highstock charts, and Dashboards. The fist element of the two-tuple is the object type that the browser should create (`highcharts`, `highstock`, or `dashboard`), and the second element is a configuration dictionary for that particular object. For the Highchart and Highstock charts, this configuation dictionary is exactly the standard [[Highcharts options object|http://www.highcharts.com/docs/getting-started/how-to-set-options]].
|
|
These chart classes all must have a `result()` method that returns the report/chart content. This report/chart content is used to fill out the `id="results"` HTML div element on the Reports page in the browser. The return value from the `result()` function is generally a Python dictionary with two keys: an `html` key and an `objects` key. The value of the `html` key is the HTML that is inserted into the `results` div on the browser page. The value of the `objects` key is a list of two-tuples, one two-tuple for each object that the browser needs to create. Objects that the BMON client app knows how to create are Highcharts charts, Highstock charts, and Dashboards. The fist element of the two-tuple is the object type that the browser should create (`highcharts`, `highstock`, or `dashboard`), and the second element is a configuration dictionary for that particular object. For the Highchart and Highstock charts, this configuation dictionary is exactly the standard [[Highcharts options object|http://www.highcharts.com/docs/getting-started/how-to-set-options]].
|
|
|
|
|
|
|
|
### Transforms and Calculated Fields
|
|
### Transforms and Calculated Fields
|
|
|
|
|
|
|
|
Transforms are used to convert incoming sensor readings to different units and are described in [[this document|Transform Expressions]]. All code related to transforms is present in [this module](../../../bmon/blob/master/bmsapp/calcs/transforms.py). [[Calculated Fields]] allow for new sensor readings to be created from mathematical combinations of other readings or from acquistion from the Internet. The general code for creating calculated fields is in [this module](../../../bmon/blob/master/bmsapp/calcs/calcreadings.py). The specific calculated field functions are currently found in the [calcfuncs01.py](../../../bmon/blob/master/bmsapp/calcs/calcfuncs01.py) module, although other modules could be created to hold specific calculated field functions. A Cron job runs [main_cron.py](../../../bmon/blob/master/bmsapp/scripts/main_cron.py) which in turn runs [calc_readings.py](../../../bmon/blob/master/bmsapp/scripts/calc_readings.py) to control the process of creating calculated fields.
|
|
Transforms are used to convert incoming sensor readings to different units and are described in [[this document|Transform Expressions]]. All code related to transforms is present in [this module](../blob/master/bmsapp/calcs/transforms.py). [[Calculated Fields]] allow for new sensor readings to be created from mathematical combinations of other readings or from acquistion from the Internet. The general code for creating calculated fields is in [this module](../blob/master/bmsapp/calcs/calcreadings.py). The specific calculated field functions are currently found in the [calcfuncs01.py](../blob/master/bmsapp/calcs/calcfuncs01.py) module, although other modules could be created to hold specific calculated field functions. A Cron job runs [main_cron.py](../blob/master/bmsapp/scripts/main_cron.py) which in turn runs [calc_readings.py](../blob/master/bmsapp/scripts/calc_readings.py) to control the process of creating calculated fields.
|
|
|
|
|
|
|
|
### Main Cron Job
|
|
### Main Cron Job
|
|
|
|
|
|
| ... | @@ -122,7 +122,7 @@ This cron job: |
... | @@ -122,7 +122,7 @@ This cron job: |
|
|
* creates a backup of the main Django database every day, and
|
|
* creates a backup of the main Django database every day, and
|
|
|
* creates a backup of the reading database every three days.
|
|
* creates a backup of the reading database every three days.
|
|
|
|
|
|
|
|
The Cron job executes the [main_cron.py](../../../bmon/blob/master/bmsapp/scripts/main_cron.py) script by using the [[Django Extensions runscript feature|http://django-extensions.readthedocs.org/en/latest/runscript.html]]. This runscript command allows the scripts to operate within the Django context, having full access to Django models and the settings file, for example.
|
|
The Cron job executes the [main_cron.py](../blob/master/bmsapp/scripts/main_cron.py) script by using the [[Django Extensions runscript feature|http://django-extensions.readthedocs.org/en/latest/runscript.html]]. This runscript command allows the scripts to operate within the Django context, having full access to Django models and the settings file, for example.
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
| ... | @@ -194,7 +194,7 @@ class BaseChart(object): |
... | @@ -194,7 +194,7 @@ class BaseChart(object): |
|
|
TIMED_REFRESH = 0
|
|
TIMED_REFRESH = 0
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
These class properties are converted to HTML attributes and sent to the browser client; [The main JavaScript file for the browser app](../../../bmon/blob/master/bmsapp/static/bmsapp/scripts/bmsapp.coffee) reads these attributes and controls the user interface accordingly.
|
|
These class properties are converted to HTML attributes and sent to the browser client; [The main JavaScript file for the browser app](../blob/master/bmsapp/static/bmsapp/scripts/bmsapp.coffee) reads these attributes and controls the user interface accordingly.
|
|
|
|
|
|
|
|
### Updating the Main Chart/Report Content
|
|
### Updating the Main Chart/Report Content
|
|
|
|
|
|
| ... | @@ -225,4 +225,4 @@ update_results = -> |
... | @@ -225,4 +225,4 @@ update_results = -> |
|
|
alert "Error Occurred: " + err
|
|
alert "Error Occurred: " + err
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
If an object is a 'dashboard', it is created by the CoffeeScript code in the [dashboard.coffee file](../../../bmon/blob/master/bmsapp/static/bmsapp/scripts/dashboard.coffee). |
|
If an object is a 'dashboard', it is created by the CoffeeScript code in the [dashboard.coffee file](../blob/master/bmsapp/static/bmsapp/scripts/dashboard.coffee). |