1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
22 * This file contains the exported symbol.
30 #include "DiscomfortIndexSensor.h"
34 #include "OCAndroid.h"
37 using namespace DiscomfortIndexSensorName;
39 #define SENSOR_NAME "DiscomfortIndexSensor"
42 { (char *)"temperature", (char *)"humidity" };
44 physicalInput DiscomfortIndexSensor::s_PHYSICAL_SOFTSENSORs[PHYSICAL_EA] =
46 { (char *)"Thing_TempHumSensor", 2, (void *) &inputName },
47 { (char *)"Thing_TempHumSensor1", 2, (void *) &inputName }
50 DiscomfortIndexSensor::DiscomfortIndexSensor()
52 m_result.m_timestamp = "";
53 m_result.m_humidity = "";
54 m_result.m_temperature = "";
55 m_result.m_discomfortIndex = "";
58 int DiscomfortIndexSensor::runLogic(std::vector< SensorData > &sensorData)
60 std::cout << "[DiscomfortIndexSensor] DiscomfortIndexSensor::" << __func__ << " is called."
65 if (getInput(sensorData, m_DI) == SUCCESS)
67 if ((result = makeDiscomfortIndex(m_DI)) != SUCCESS)
69 std::cout << "Error : makeDiscomfortIndex() result = " << result << std::endl;
73 //g_pSoftSensorCore->pushResults(setOutput(4, m_DI));
82 * Get Input data (temperature, humidity) using resource Client of Iotivity base.
84 DIResult DiscomfortIndexSensor::getInput(std::vector< SensorData > &sensorData, InValue *data)
86 //int result_flag = 0;
87 //int contextSize = 0;
89 //if ((contextSize = sensorData.size()) == 0)
91 // std::cout << "Physical Context data is not exist." << std::endl;
95 //for (int i = 0; i < contextSize; i++)
97 // for (int k = 0; k < PHYSICAL_EA; k++)
99 // if (sensorData[i].sensorName == s_PHYSICAL_SOFTSENSORs[k].m_thingName)
101 // std::vector < std::map< std::string, std::string > > lVector =
102 // sensorData[i].data;
103 // int requiredInputNum = s_PHYSICAL_SOFTSENSORs[k].m_inputNum;
104 // char **pchar = (char **) (s_PHYSICAL_SOFTSENSORs[k].m_pInputStruct);
105 // if (requiredInputNum == 0)
107 // std::cout << "No input List." << std::endl;
111 // for (unsigned int j = 0; j < lVector.size(); j++)
113 // std::string name = lVector[j]["name"];
115 // if (name.compare(*pchar) == 0)
117 // data->m_temperature = lVector[j]["value"];
118 // requiredInputNum--;
120 // else if (name.compare(*(++pchar)) == 0)
122 // data->m_humidity = lVector[j]["value"];
123 // requiredInputNum--;
127 // if (requiredInputNum == 0)
137 //if (result_flag == PHYSICAL_EA)
139 // std::cout << "Success : getInput()" << std::endl;
147 * Calculation of DiscomfortIndex with TEMP&HUMI of InValue.
149 DIResult DiscomfortIndexSensor::makeDiscomfortIndex(InValue *data)
151 int discomfortIndex = (int) ERROR;
154 m_result.m_temperature = "";
155 m_result.m_humidity = "";
157 for (int i = 0; i < PHYSICAL_EA; i++)
161 m_result.m_temperature += ", ";
162 m_result.m_humidity += ", ";
166 int t = std::stoi((data + i)->m_temperature);
167 int h = std::stoi((data + i)->m_humidity);
168 double F = (9.0 * (double) t) / 5.0 + 32.0;
170 std::cout << "Device Number : " << i << std::endl;
172 dI = F - (F - 58.0) * (double) ((100 - h) * 55) / 10000.0;
174 std::cout << "Discomfort level : " << dI << ", Temperature :" << t << ", Humidity :" << h
177 (data + i)->m_discomfortIndex = std::to_string(0);
178 m_result.m_temperature += std::to_string(t) + ", ";
179 m_result.m_humidity += std::to_string(h) + ", ";
183 sumDI = sumDI / PHYSICAL_EA;
184 std::cout << "[result] Avg. DI level : " << sumDI << std::endl;
187 discomfortIndex = (int) ALL_DISCOMPORT;
188 std::cout << "DI : " << discomfortIndex << " : All person discomfort. : " << sumDI
191 else if (sumDI >= 75.0)
193 discomfortIndex = (int) HALF_DISCOMPORT;
194 std::cout << "DI : " << discomfortIndex << " : Half of person discomfort. : " << sumDI
197 else if (sumDI >= 68.0)
199 discomfortIndex = (int) LITTLE_DISCOMPORT;
200 std::cout << "DI : " << discomfortIndex << " : A little person discomfort. : " << sumDI
205 discomfortIndex = (int) ALL_COMPORT;
206 std::cout << "DI : " << discomfortIndex << " : All person comfort. : " << sumDI
210 m_result.m_discomfortIndex = std::to_string(discomfortIndex);
211 std::cout << "[result] Discomfort Index : " << m_result.m_discomfortIndex << std::endl;
216 SensorData DiscomfortIndexSensor::setOutput(int property_count, InValue *data)
220 //std::map < std::string, std::string > output_property;
222 //out.sensorName = SENSOR_NAME;
224 //output_property.insert(std::make_pair("name", "timestamp"));
225 //output_property.insert(std::make_pair("type", "string"));
226 //output_property.insert(std::make_pair("value", m_result.m_timestamp));
228 //out.data.push_back(output_property);
230 //output_property.clear();
231 //output_property.insert(std::make_pair("name", "temperature"));
232 //output_property.insert(std::make_pair("type", "string"));
233 //output_property.insert(std::make_pair("value", m_result.m_temperature));
235 //out.data.push_back(output_property);
237 //output_property.clear();
238 //output_property.insert(std::make_pair("name", "humidity"));
239 //output_property.insert(std::make_pair("type", "string"));
240 //output_property.insert(std::make_pair("value", m_result.m_humidity));
242 //out.data.push_back(output_property);
244 //output_property.clear();
245 //output_property.insert(std::make_pair("name", "discomfortIndex"));
246 //output_property.insert(std::make_pair("type", "int"));
247 //output_property.insert(std::make_pair("value", m_result.m_discomfortIndex));
249 //out.data.push_back(output_property);