|
|
BMON is an application that stores sensor data primarily from buildings and provides tools for users to analyze that data. The application is built with the [[Python Django|https://www.djangoproject.com/]] web framework. Most of the code for the application executes on the web server, although some JavaScript code runs in the user's browser to update the user interface and make data requests to the server. The JavaScript code is actually written in [[Coffeescript|http://coffeescript.org/]] and then compiled into Javascript. Charts and dashboard gauges utilize the [[Highcharts|http://www.highcharts.com/]] and [[Highstock|http://www.highcharts.com/products/highstock]] charting libraries; these libraries are not open source and have [[licensing requirements|http://shop.highsoft.com/highcharts.html]].
|
|
BMON is an application that stores sensor data primarily from buildings and provides tools for users to analyze that data. The application is built with the [Python Django](https://www.djangoproject.com/) web framework. Most of the code for the application executes on the web server, although some JavaScript code runs in the user's browser to update the user interface and make data requests to the server. The JavaScript code is actually written in [Coffeescript](http://coffeescript.org/) and then compiled into Javascript. Charts and dashboard gauges utilize the [Highcharts](http://www.highcharts.com/) and [Highstock](http://www.highcharts.com/products/highstock) charting libraries; these libraries are not open source and have [licensing requirements](http://shop.highsoft.com/highcharts.html).
|
|
|
|
|
|
|
|
The diagram below shows the overall structure of the application.
|
|
The diagram below shows the overall structure of the application.
|
|
|
|
|
|
|
|
[[images/BMON_architecture.png]]
|
|
!(images/BMON_architecture.png)
|
|
|
|
|
|
|
|
Sensors such as [[Monnit Wireless Sensors|http://www.monnit.com/]] post data across the Internet to the BMON Django application located on the web server. The sensor readings are stored in a [[SQLite|https://www.sqlite.org/]] database dedicated to those readings. The Django application utilizes a separate database to store other objects needed by the BMON system, such as building information, sensor descriptions, alert conditions, etc. This database is the standard Django database that is generated from the [[Models|https://docs.djangoproject.com/en/1.8/topics/db/models/]] in the Django application.
|
|
Sensors such as [Monnit Wireless Sensors](http://www.monnit.com/) post data across the Internet to the BMON Django application located on the web server. The sensor readings are stored in a [SQLite](https://www.sqlite.org/) database dedicated to those readings. The Django application utilizes a separate database to store other objects needed by the BMON system, such as building information, sensor descriptions, alert conditions, etc. This database is the standard Django database that is generated from the [Models](https://docs.djangoproject.com/en/1.8/topics/db/models/) in the Django application.
|
|
|
|
|
|
|
|
The User interacts with the BMON applicaton through a web browser. The Django server app supplies HTML documents and associated JavaScript to the user's browser. The browser application issues AJAX requests back to the server to supply data to the charts and reports used to analyze the sensor data. As well as viewing and analyzing sensor data, a user can log into the BMON application through the [[Django Admin interface|https://docs.djangoproject.com/en/1.8/intro/tutorial02/]] and configure the applcation. Adding buildings, sensors, alert conditions, etc. is done through the Admin interface.
|
|
The User interacts with the BMON applicaton through a web browser. The Django server app supplies HTML documents and associated JavaScript to the user's browser. The browser application issues AJAX requests back to the server to supply data to the charts and reports used to analyze the sensor data. As well as viewing and analyzing sensor data, a user can log into the BMON application through the [Django Admin interface](https://docs.djangoproject.com/en/1.8/intro/tutorial02/) and configure the applcation. Adding buildings, sensors, alert conditions, etc. is done through the Admin interface.
|
|
|
|
|
|
|
|
## Details on Django Server Application
|
|
## Details on Django Server Application
|
|
|
|
|
|
|
|
This section presents some further details on the Django Server application. In Django vocabulary, the BMON Django Project consists of one [[application|https://docs.djangoproject.com/en/1.8/ref/applications/]], the `bmsapp` application. Thus, the important code files for the application are found in the `bmon/bmsapp` directory. Here is a list of the directories contained in the `bmsapp` application:
|
|
This section presents some further details on the Django Server application. In Django vocabulary, the BMON Django Project consists of one [application](https://docs.djangoproject.com/en/1.8/ref/applications/), the `bmsapp` application. Thus, the important code files for the application are found in the `bmon/bmsapp` directory. Here is a list of the directories contained in the `bmsapp` application:
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
. : Main directory with Django models.py, views.py, urls.py files
|
|
. : Main directory with Django models.py, views.py, urls.py files
|
| ... | @@ -50,7 +50,7 @@ Some of the important functions in the `views.py` module are: |
... | @@ -50,7 +50,7 @@ Some of the important functions in the `views.py` module are: |
|
|
|
|
|
|
|
**`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).
|
|
**`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.
|
|
|
|
|
|
|
|
**`bldg_list()`**: Returns a list of buildings to display to the user for selection.
|
|
**`bldg_list()`**: Returns a list of buildings to display to the user for selection.
|
|
|
|
|
|
| ... | @@ -103,15 +103,15 @@ class MultiBuildingChart(models.Model): |
... | @@ -103,15 +103,15 @@ class MultiBuildingChart(models.Model): |
|
|
|
|
|
|
|
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.
|
|
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](../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.
|
|
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
|
|
|
|
|
|
|
|
BMON utilizes the Linux Cron utility to run a script that performs a number of tasks that are repeated at equal time intervals. (A better design may have been to start a separate thread in BMON to perform this repetitive task.) As shown in the [[BMON Installation Guide|How to Install BMON on a Web Server]], the Cron job entry looks like the following (the directory paths are dependent on your specific install):
|
|
BMON utilizes the Linux Cron utility to run a script that performs a number of tasks that are repeated at equal time intervals. (A better design may have been to start a separate thread in BMON to perform this repetitive task.) As shown in the [BMON Installation Guide](How to Install BMON on a Web Server), the Cron job entry looks like the following (the directory paths are dependent on your specific install):
|
|
|
|
|
|
|
|
*/5 * * * * ~/webapps/bmon_django/bmon/manage.py runscript main_cron > /dev/null 2>&1
|
|
*/5 * * * * ~/webapps/bmon_django/bmon/manage.py runscript main_cron > /dev/null 2>&1
|
|
|
|
|
|
| ... | @@ -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](../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.
|
|
|
|
|
|
|
|
---
|
|
---
|
|
|
|
|
|
| ... | @@ -155,7 +155,7 @@ BMSAPP_NAV_LINKS = ( ('Map', 'map'), |
... | @@ -155,7 +155,7 @@ BMSAPP_NAV_LINKS = ( ('Map', 'map'), |
|
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
The main Charts/Reports page is the core of the application. It functions as a [[Single Page Application|https://en.wikipedia.org/wiki/Single-page_application]]. With the initial loading of that page, all of the static HTML of the page and all of HTML Input elements are downloaded from the server. As the user changes inputs, AJAX calls are made to the server to update the contents of various selection inputs (e.g. update the sensor selection dropdown due to a new building being selected) and to update the final chart or report results.
|
|
The main Charts/Reports page is the core of the application. It functions as a [Single Page Application](https://en.wikipedia.org/wiki/Single-page_application). With the initial loading of that page, all of the static HTML of the page and all of HTML Input elements are downloaded from the server. As the user changes inputs, AJAX calls are made to the server to update the contents of various selection inputs (e.g. update the sensor selection dropdown due to a new building being selected) and to update the final chart or report results.
|
|
|
|
|
|
|
|
### User Interface Configuration based on Chart/Report Type
|
|
### User Interface Configuration based on Chart/Report Type
|
|
|
|
|
|
| ... | | ... | |