replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / resource-container / examples / DiscomfortIndexSensorBundle / src / DiscomfortIndexSensor.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /**
22  * This file contains the exported symbol.
23  */
24
25 #include "DiscomfortIndexSensor.h"
26
27 #include <iostream>
28 #include "SysTimer.h"
29
30 #ifdef __ANDROID__
31 #include "OCAndroid.h"
32 #endif
33
34 using namespace DiscomfortIndexSensorName;
35
36 DiscomfortIndexSensor::DiscomfortIndexSensor()
37 {
38     m_humidity = "";
39     m_temperature = "";
40     m_discomfortIndex = "";
41 }
42
43 DiscomfortIndexSensor::~DiscomfortIndexSensor()
44 {
45
46 }
47
48 int DiscomfortIndexSensor::executeDISensorLogic(std::map<std::string, std::string> *pInputData,
49         std::string *pOutput)
50 {
51     std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called."
52               << std::endl;
53
54     DIResult result = ERROR;
55
56     m_temperature = pInputData->at("temperature");
57     m_humidity = pInputData->at("humidity");
58
59     if ((result = makeDiscomfortIndex()) != SUCCESS)
60     {
61         std::cout << "Error : makeDiscomfortIndex() result = " << result << std::endl;
62         return -1;
63     }
64
65     (*pOutput) = m_discomfortIndex;
66
67     return 0;
68 }
69
70 /**
71  * Calculation of DiscomfortIndex with TEMP&HUMI.
72  */
73 DIResult DiscomfortIndexSensor::makeDiscomfortIndex()
74 {
75     int DILevel = (int) ERROR;
76     double dDI = 0.0;
77
78     int t = std::stoi(m_temperature);
79     int h = std::stoi(m_humidity);
80     double F = (9.0 * (double) t) / 5.0 + 32.0;
81
82     // calculation of discomfortIndex
83     dDI = F - (F - 58.0) * (double)((100 - h) * 55) / 10000.0;
84
85     std::cout << "Discomfort level : " << dDI << ", Temperature :" << t << ", Humidity :" << h <<
86               std::endl;
87
88     std::cout << "[result] Discomfort Index : " << m_discomfortIndex << std::endl;
89     if (dDI >= 80.0)
90     {
91         DILevel = (int)ALL_DISCOMPORT;
92         std::cout << "DI : " << DILevel << " : All person discomfort. : " << dDI
93                   << std::endl;
94     }
95     else if (dDI >= 75.0)
96     {
97         DILevel = (int)HALF_DISCOMPORT;
98         std::cout << "DI : " << DILevel << " : Half of person discomfort. : " << dDI
99                   << std::endl;
100     }
101     else if (dDI >= 68.0)
102     {
103         DILevel = (int)LITTLE_DISCOMPORT;
104         std::cout << "DI : " << DILevel << " : A little person discomfort. : " << dDI
105                   << std::endl;
106     }
107     else
108     {
109         DILevel = (int)ALL_COMPORT;
110         std::cout << "DI : " << DILevel << " : All person comfort. : " << dDI
111                   << std::endl;
112     }
113
114     std::cout << std::endl;
115
116     m_discomfortIndex = std::to_string(DILevel);
117
118     return SUCCESS;
119 }