void myTest::checkResult() { double g = 4.16666666666667; double array[] = {1,2,3,4,5,10}; std::vector<double> vec = std::vector<double>(array, array+sizeof(array)/sizeof(double)); CPPUNIT_ASSERT_DOUBLES_EQUAL(g, CalcAverage(vec), 0.001); }
/// @param[in] Next measurement. /// @param[out] Average value. void Next(T * arr) { if (m_vectors.size() == m_count) m_vectors.pop_front(); m_vectors.push_back({}); std::memcpy(m_vectors.back().data(), arr, Dim * sizeof(T)); if (m_vectors.size() > 1) CalcAverage(arr); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer int Max; int Min; int range; int numbers[] = {174, 162, 149, 85, 130, 149, 153, 164, 169, 173}; int sampleArray[N_AVG_SAMPLES]; //Array that numbers are moved into and out of Max = -256; // Lowest number possible for 1 byte, easily overwritten Min = 255; // Highest number possible for 1 byte, easily overwritten int i = 0; int x = 0; int avg; int avgs[SIZE+2]; //Sets up array to store moving average //I had to do this so that the program would not overwrite SizeOfArray //Variable x keeps track of i and stores its value for(i = 0; i <= N_AVG_SAMPLES; i++){ x = i; sampleArray[i] = 0; i = x; } //Determine size of array // int SizeOfArray = sizeof(numbers)/sizeof(int); //Number of bytes in numbers divided by number of bytes in int int SizeOfArray = SIZE; //Can get by with only //Finds the average for(i = 0; i<= SizeOfArray +1; i++){ avg = CalcAverage(sampleArray, N_AVG_SAMPLES); avgs[i] = avg; shiftarray(numbers[i], sampleArray, N_AVG_SAMPLES); } //Calculate max, min, and range of set Max = maximum(numbers, Max, SizeOfArray); Min = minimum(numbers, Min, SizeOfArray); range = CalculateRange(Max, Min); while(1){} //Trap CPU return 0; }
void CHZDLReport::GetData(string deviceName, string & sIP, bool & useCPU, bool & useMemory, float & CPUUtl, float & MemoryUtl) { list<string> getMonList; list<string>::iterator getMonItem; string MonitorID; OBJECT tmpObjMonitor = NULL; OBJECT tmpObjTempMonitor = NULL; MAPNODE tmpMonitorNode = NULL; MAPNODE tmpMonitorTempNode = NULL; MAPNODE tempParamNode = NULL; LISTITEM ParamItem; bool bFind; string tmpMonitorTempName; useCPU = false; useMemory = false; CPUUtl = 0; MemoryUtl = 0; bFind = GetSubMonitorsIDByEntity(GetEntity(deviceName), getMonList); if (!bFind) return; MAPNODE tmpEntityNode = NULL; tmpEntityNode = GetEntityMainAttribNode(GetEntity(deviceName)); string v; bFind = FindNodeValue(tmpEntityNode, "_MachineName", v); if (bFind) { sIP = v; } getMonItem = getMonList.begin(); while ( (getMonItem != getMonList.end()) && ( (!useCPU) || (!useMemory) ) ) { MonitorID = *getMonItem; tmpObjMonitor = GetMonitor(MonitorID); if (tmpObjMonitor != INVALID_VALUE) { tmpMonitorNode = GetMonitorMainAttribNode(tmpObjMonitor); string TypeID; bFind = FindNodeValue(tmpMonitorNode, "sv_monitortype", TypeID); int iType = atoi(TypeID.c_str()); tmpObjTempMonitor = GetMonitorTemplet(iType); if(tmpObjTempMonitor!=INVALID_VALUE) { tmpMonitorTempNode = GetMTMainAttribNode(tmpObjTempMonitor); bFind = FindNodeValue(tmpMonitorTempNode, "sv_name", tmpMonitorTempName); if (!useCPU) { string stmp1 = "CPU"; string stmp2 = "Cpu"; string stmp3 = "cpu"; if ( findString(tmpMonitorTempName, stmp1) || findString(tmpMonitorTempName, stmp2) || findString(tmpMonitorTempName, stmp3) ) { bFind = FindMTReturnFirst(tmpObjTempMonitor, ParamItem); bool findPrimary = false; while( ((tempParamNode=::FindNext(ParamItem)) != INVALID_VALUE) && !findPrimary ) { string szPrimary; FindNodeValue(tempParamNode, "sv_primary",szPrimary); if(strcmp(szPrimary.c_str(), "1") == 0) { findPrimary = true; string tmpFieldName; FindNodeValue(tempParamNode, "sv_name", tmpFieldName); CPUUtl = CalcAverage(MonitorID, tmpFieldName); } } useCPU = true; } } if (!useMemory) { string stmp = "Memory"; if ( findString(tmpMonitorTempName, stmp) ) { bFind = FindMTReturnFirst(tmpObjTempMonitor, ParamItem); bool findPrimary = false; while( ((tempParamNode=::FindNext(ParamItem)) != INVALID_VALUE) && !findPrimary ) { string szPrimary; FindNodeValue(tempParamNode, "sv_primary",szPrimary); if(strcmp(szPrimary.c_str(), "1") == 0) { findPrimary = true; string tmpFieldName; FindNodeValue(tempParamNode, "sv_name", tmpFieldName); MemoryUtl = CalcAverage(MonitorID, tmpFieldName); } } useMemory = true; } } } } getMonItem++; } }