| ... | ... | @@ -60,9 +60,9 @@ Some of the important functions in the `views.py` module are: |
|
|
|
|
|
|
|
All interactions with the Sensor Reading Database occur through the `BMSdata` class located in the [[bmsdata.py module|https://github.com/alanmitchell/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.
|
|
|
|
|
|
|
|
To use a different database technology, the only part of the BMON application that would need to be changed is the `bmsdata.py` file, as all access to the database occurrs through that file.
|
|
|
|
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 Classes
|
|
|
|
### 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|https://github.com/alanmitchell/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:
|
|
|
|
|
| ... | ... | @@ -80,9 +80,9 @@ BLDG_CHART_TYPES = [ |
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
The last constructor parameter 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`|https://github.com/alanmitchell/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`|https://github.com/alanmitchell/bmon/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|https://github.com/alanmitchell/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|https://github.com/alanmitchell/bmon/blob/master/bmsapp/models.py]], in the definition of the `MultiBuildingChart` class:
|
|
|
|
|
|
|
|
```python
|
|
|
|
class MultiBuildingChart(models.Model):
|
| ... | ... | @@ -103,4 +103,9 @@ class MultiBuildingChart(models.Model): |
|
|
|
|
|
|
|
You can see that the Multi-building Current Sensor Values report is produced by the [[`currentvalues_multi.CurrentValuesMulti`|https://github.com/alanmitchell/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.
|
|
|
|
|
|
|
|
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 HTML div element with `id="results"` 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]]. |
|
|
\ No newline at end of file |
|
|
|
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 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|https://github.com/alanmitchell/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|https://github.com/alanmitchell/bmon/blob/master/bmsapp/calcs/calcreadings.py]]. The specific calculated field functions are currently found in the [[calcfuncs01.py|https://github.com/alanmitchell/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|https://github.com/alanmitchell/bmon/blob/master/bmsapp/scripts/main_cron.py]] which in turn runs [[calc_readings.py|https://github.com/alanmitchell/bmon/blob/master/bmsapp/scripts/calc_readings.py]] to control the process of creating calculated fields.
|
|
|
|
|