#include "stdafx.h" #include "TemperCheckImp.h" TemperCheckImp::TemperCheckImp() { //ofstream ocout; //ocout.open("D:\\default constructor.txt"); //ocout << "begin" << endl; //ocout << "end" << endl; //ocout.close(); } TemperCheckImp::TemperCheckImp(float fSetTempHigh, float fSetTempLow, float fSetTempStdDev, float fSetGradientMean, float fSetGradientStdDev, int nSetQueueSize, char* path) { m_fTempHigh = fSetTempHigh; m_fTempLow = fSetTempLow; m_fTempStdDev = fSetTempStdDev; m_nQueueSize = nSetQueueSize; m_fGradientMean = fSetGradientMean; m_fGradientStdDev = fSetGradientStdDev; m_strLogPath = path; m_dqTemp.clear();// = new deque ; m_dqTempGradient.clear(); //= new deque ; m_mapTemp.clear();// = new map ; //ofstream ocout; //string file = "TempeCheckMethod2.log"; //string Path = *LogPath + file; //ocout.open(Path); ////ocout.open(Path, ios::app); //PrintTime(); //ocout << "test begin:" << endl; //PrintTime(); //ocout << "the example of temperature map is:(time, temperature)" << endl; } TemperCheckImp::~TemperCheckImp(void) { m_dqTemp.clear(); m_dqTempGradient.clear(); m_mapTemp.clear(); //ofstream ocout; //ocout.open("D:\\destructor.txt"); //ocout << "begin" << endl; //if (LogPath) //{ // delete LogPath; //} //if (dqTemp) //{ // delete dqTemp; //} //if (dqTempGradient) //{ // delete dqTempGradient; //} //if (mapTemp) //{ // delete mapTemp; //} //ocout << "end" << endl; //ocout.close(); } int TemperCheckImp::TempeCheckMethod1(float fTemp) { if (m_fTempHigh < m_fTempLow || m_fTempStdDev < 0 || m_nQueueSize < 1) return -1; int nFlag = m_nQueueSize - (int)m_dqTemp.size(); if (nFlag > 1) { m_dqTemp.push_back(fTemp); return -2; } else if (nFlag == 1) { m_dqTemp.push_back(fTemp); } else if (nFlag == 0) { m_dqTemp.pop_front(); m_dqTemp.push_back(fTemp); } else { m_dqTemp.clear(); return -3; } //#pragma omp parallel for for (int i = 0; i < m_nQueueSize; i++) { if (m_dqTemp[i] < m_fTempLow || m_dqTemp[i] > m_fTempHigh) return 0; } float fSum = 0.0f; //#pragma omp parallel for for (int i = 0; i < m_nQueueSize; i++) { fSum += m_dqTemp[i]; } float fMean = fSum / m_nQueueSize; float fStdDev = 0.0f; //#pragma omp parallel for for (int i = 0; i < m_nQueueSize; i++) { fStdDev += (m_dqTemp[i] - fMean)*(m_dqTemp[i] - fMean); } fStdDev = sqrt(fStdDev / m_nQueueSize); if (fStdDev < m_fTempStdDev) return 1; else return 0; } int TemperCheckImp::TempeCheckMethod2(float fTemp, double dTime) { SYSTEMTIME obSysetmTime; SYSTEMTIME obSysetmTime1; SYSTEMTIME obSysetmTime2; const time_t t = time(NULL); struct tm* current_time = localtime( &t); ofstream ocout; string file = "TemperatureCheck"; string time; stringstream stream1; stringstream stream2; stringstream stream3; stream1 << (current_time->tm_year + 1900); stream2 << (current_time->tm_mon + 1); stream3 << (current_time->tm_mday); time = stream1.str() + stream2.str() + stream3.str() + +".log"; string Path = m_strLogPath + file + time; //ocout.open(Path); ocout.open(Path, ios::app); if (!ocout) return -11; //const time_t t = time(NULL); //struct tm* current_time = localtime(&t); //ocout << "test begin:" << endl; //ocout << "the example of temperature map is:(time--- temperature)" << endl; if (m_fTempHigh < m_fTempLow || m_fTempStdDev < 0 || m_nQueueSize < 2 || dTime < 43022 || dTime > 50000 || m_fGradientStdDev < 0) { PrintTime(); ocout << "end = -1" << endl; ocout.close(); return -1; } if (fTempm_fTempHigh) { PrintTime(); ocout << "end = -2" << endl; ocout.close(); return -2; } int nFlag = m_nQueueSize - (int)m_mapTemp.size(); if (nFlag > 1) { m_mapTemp.insert(make_pair(dTime, fTemp)); VariantTimeToSystemTime(dTime, &obSysetmTime); PrintTime(); ocout << "added to the temprature list:"; ocout << "("; ocout << obSysetmTime.wYear; ocout << "-"; ocout << obSysetmTime.wMonth; ocout << "-"; ocout << obSysetmTime.wDay; ocout << " "; ocout << obSysetmTime.wHour; ocout << ":"; ocout << obSysetmTime.wMinute; ocout << ":"; ocout << obSysetmTime.wSecond; ocout << ", "; ocout << fTemp; ocout << ")" << endl; ocout.close(); return -3; } else if (nFlag == 1) //队列正好满了 { m_mapTemp.insert(make_pair(dTime, fTemp)); VariantTimeToSystemTime(dTime, &obSysetmTime); PrintTime(); ocout << "added to the temprature list:"; ocout << "("; ocout << obSysetmTime.wYear; ocout << "-"; ocout << obSysetmTime.wMonth; ocout << "-"; ocout << obSysetmTime.wDay; ocout << " "; ocout << obSysetmTime.wHour; ocout << ":"; ocout << obSysetmTime.wMinute; ocout << ":"; ocout << obSysetmTime.wSecond; ocout << ", "; ocout << fTemp; ocout << ")" << endl; } else if (nFlag == 0) //队列多了 替换 { map< double, float>::iterator iter = m_mapTemp.begin(); m_mapTemp.erase(iter); PrintTime(); ocout << "Remove the first element" << endl; m_mapTemp.insert(make_pair(dTime, fTemp)); VariantTimeToSystemTime(dTime, &obSysetmTime); PrintTime(); ocout << "added to the temprature list:"; ocout << "("; ocout << obSysetmTime.wYear; ocout << "-"; ocout << obSysetmTime.wMonth; ocout << "-"; ocout << obSysetmTime.wDay; ocout << " "; ocout << obSysetmTime.wHour; ocout << ":"; ocout << obSysetmTime.wMinute; ocout << ":"; ocout << obSysetmTime.wSecond; ocout << ", "; ocout << fTemp; ocout << ")" << endl; } else { m_mapTemp.clear(); PrintTime(); ocout << "end = -4" << endl; ocout.close(); return -4; } map< double, float>::iterator iter = m_mapTemp.begin(); map< double, float>::iterator iter1 = m_mapTemp.begin(); iter1 = ++iter1; CTime time1; CTime time2; if (iter == iter1) { PrintTime(); ocout << "end = -10" << endl; ocout.close(); return -10; } float fMean = 0.0f; for (iter, iter1; iter != m_mapTemp.end() && iter1 != m_mapTemp.end(); iter++, iter1++) { //cout << "iter1->second=" << iter1->second << endl; //cout << "iter->second=" << iter->second << endl; VariantTimeToSystemTime(iter1->first, &obSysetmTime1); time1 = CTime((int)obSysetmTime1.wYear, (int)obSysetmTime1.wMonth, (int)obSysetmTime1.wDay, (int)obSysetmTime1.wHour, (int)obSysetmTime1.wMinute, (int)obSysetmTime1.wSecond, (int)obSysetmTime1.wMilliseconds); VariantTimeToSystemTime(iter->first, &obSysetmTime2); time2 = CTime((int)obSysetmTime2.wYear, (int)obSysetmTime2.wMonth, (int)obSysetmTime2.wDay, (int)obSysetmTime2.wHour, (int)obSysetmTime2.wMinute, (int)obSysetmTime2.wSecond, (int)obSysetmTime2.wMilliseconds); CTimeSpan timeSpan = time1 - time2; if (timeSpan.GetTotalSeconds() < 1) { //d << "timeSpan.GetTotalSeconds()" << timeSpan.GetTotalSeconds() << endl; return -12; } fMean += fabs((iter1->second - iter->second) / (timeSpan.GetTotalSeconds())); m_dqTempGradient.push_back(fMean); } fMean = fMean / m_dqTempGradient.size(); float fStdDev = 0.0f; for (unsigned int i = 0; i tm_year + 1900); stream2 << (current_time->tm_mon + 1); stream3 << (current_time->tm_mday); timelog = stream1.str() + stream2.str() + stream3.str() + +".log"; string Path = m_strLogPath + file + timelog; ocout.open(Path); //PrintTime(); //ocout << "clear map and log" << endl; ocout.close(); return true; } void TemperCheckImp::PrintTime() { const time_t t = time(NULL); struct tm* current_time = localtime(&t); ofstream ocout; string file = "TemperatureCheck"; string timelog; stringstream stream1; stringstream stream2; stringstream stream3; stream1 << (current_time->tm_year + 1900); stream2 << (current_time->tm_mon + 1); stream3 << (current_time->tm_mday); timelog = stream1.str() + stream2.str() + stream3.str() + +".log"; string Path = m_strLogPath + file + timelog; ocout.open(Path, ios::app); ocout << (current_time->tm_year + 1900) << "-" << (current_time->tm_mon + 1) << "-" << current_time->tm_mday << " " << current_time->tm_hour << ":" << current_time->tm_min << ":" << current_time->tm_sec << "[INFO]: "; }