Estimation of a value¶
A model is able to estimate a concentration of a carbon dioxide or humidity in certain time.
The configuration parameters in the examples below can be changed
in the configuration file config.ini
that is described in section Configuration file.
CO2¶
The estimation of a concentration of a carbon dioxide is based on a calculation of a line direction using several values that have been recently measured.
The example of an estimation of a carbon dioxide concentration in certain time follows.
"""Estimation of a value - CO2.
"""
from os.path import dirname, abspath, join
import sys
sys.path.append(abspath(join(dirname(__file__), '../..', '')))
from dm.ConnectionUtil import ConnectionUtil as cu
from dm.models.ModelsUtil import ModelsUtil
from dm.DateTimeUtil import DateTimeUtil
if __name__ == '__main__':
cu.setup_logging()
cls = cu.setup_clients()
actual_time = int(DateTimeUtil.local_time_str_to_utc('2019/02/20 03:00:00').timestamp())
devs = [
{
'db_column_name': 'co2_in_ppm',
'gateway_id': '1816820318180747',
'device_id': '0xa900811026800001',
'module_id': 2,
'server_name': 'ant-work',
}
]
notification = ModelsUtil.estimate_co2(devs, cls, actual_time)
ModelsUtil.json_to_file(notification, 'co2_notification.doc.json', log_notification=True)
It is necessary to set clients that can communicate with a remote server using the function setup_clients
.
Estimation is performed on the basis of data measured during a given time interval. Time that defines
end of a time interval is stored in the variable actual_time
. The sensor used to gather data is stored
in the variable devs
. Estimation of a carbon dioxide concentration in certain time is performed by
the function estimate_co2
and the result is stored in the variable notification
.
All configuration parameters are saved in the configuration file config.ini
that is described in the section Configuration file.
An output of the estimation is a notification that contains basic information described in the section Notifications and the following information:
current_value - current value of CO2 [ppm],
es_level - a value of a carbon dioxide concentration that will be probably reached in
es_time
[ppm],es_time - a time when an estimation of a carbon dioxide concentration will be performed [s],
estimate_time - a time when an upper limit of a given level of the concentration will be reached [min],
level - a level of the concentration whose upper limit will be used to compute the
es_time
,0 – 0 - 499 - decreased concentration,
1 – 500 - 1499 - optimal concentration,
2 – 1500 - 2499 - increased concentration,
3 – 2500 - 3999 - high concentration,
4 – 4000 - too high concentration,
level_value - a value of
level
[ppm],type - a notification type.
The example of a notification follows.
{
"data": {
"current_value": 2000,
"es_level": 2000,
"es_time": 60,
"estimate_time": 0,
"level": 2,
"level_value": 2500,
"type": "co2_estimate"
},
"device_id": "0xa900811026800001",
"event": "env-notification-pre",
"gateway_id": "1816820318180747",
"raise": false,
"raise_catch": false,
"readable": "2019-02-20 03:00:00",
"timestamp": 1550628000
}
The example of a command that can be used to estimate a carbon dioxide concentration in certain time is below.
python examples2/0301_estimate/co2_estimate.py
Temperature and humidity¶
The estimation of humidity is based on a calculation of a line direction using several values that have been recently measured.
The example of an estimation of humidity in certain time follows.
"""Estimation of a value - temperature and humidity.
"""
from os.path import dirname, abspath, join
import sys
sys.path.append(abspath(join(dirname(__file__), '../..', '')))
from dm.ConnectionUtil import ConnectionUtil as cu
from dm.models.ModelsUtil import ModelsUtil
from dm.DateTimeUtil import DateTimeUtil
if __name__ == '__main__':
cu.setup_logging()
cls = cu.setup_clients()
actual_time = int(DateTimeUtil.local_time_str_to_utc('2019/02/20 03:00:00').timestamp())
devs = [
{
'db_column_name': 'temperature_in2_celsius',
'gateway_id': '1816820318180747',
'device_id': '0xa900811026800001',
'module_id': 0,
'server_name': 'ant-work',
},
{
'db_column_name': 'rh_in2_percentage',
'gateway_id': '1816820318180747',
'device_id': '0xa900811026800001',
'module_id': 1,
'server_name': 'ant-work',
}
]
notification = ModelsUtil.estimate_t_h(devs, cls, actual_time)
ModelsUtil.json_to_file(notification, 't_h_notification.doc.json', log_notification=True)
It is necessary to set clients that can communicate with a remote server using the function setup_clients
.
Estimation is performed on the basis of data measured during a given time interval. Time that defines
end of a time interval is stored in the variable actual_time
. The sensors used to gather data are stored
in the variable devs
. Estimation of humidity in certain time is performed by
the function estimate_t_h
and the result is stored in the variable notification
.
All configuration parameters are saved in the configuration file config.ini
that is described in the section Configuration file.
An output of the estimation is a notification that contains basic information described in the section Notifications and the following information:
current_value - current value of humidity [%],
es_level - a value of humidity that will be probably reached in
es_time
[%],es_time - a time when an estimation of humidity will be performed [s],
estimate_time - a time when an upper limit of a given level of the humidity will be reached [min],
level - a level of the humidity whose upper limit will be used to compute the
es_time
,0 – 0% - 29% - too low humidity,
1 – 30% - 39% - decreased humidity,
2 – 40% - 59% - optimal humidity,
3 – 60% - 69% - increased humidity,
4 – 70% - 100% - too high humidity,
level_value - a value of
level
[%],type - a notification type.
The example of a notification follows.
{
"data": {
"current_value": 41,
"es_level": 41,
"es_time": 60,
"estimate_time": 796,
"level": 2,
"level_value": 60,
"type": "co2_estimate"
},
"device_id": "0xa900811026800001",
"event": "env-notification-pre",
"gateway_id": "1816820318180747",
"raise": false,
"raise_catch": false,
"readable": "2019-02-20 03:00:00",
"timestamp": 1550628000
}
The example of a command that can be used to estimate humidity in certain time is below.
python examples2/0301_estimate/t_h_estimate.py