added some more data functions.
- AQDG_Data_DayAverage() average data over days - AQDG_Data_MinutesAverage() average data over variable minutes
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
#include <gwenhywfar/gwendate.h>
|
#include <gwenhywfar/gwendate.h>
|
||||||
#include <gwenhywfar/debug.h>
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DaySums(const AQDG_GRAPH_DATAPAIR_LIST *dpList)
|
AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DaySums(const AQDG_GRAPH_DATAPAIR_LIST *dpList)
|
||||||
@@ -97,7 +99,6 @@ AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dp
|
|||||||
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(lastDate));
|
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(lastDate));
|
||||||
AQDG_Graph_DataPair_SetValueY(newDp, AQDG_Graph_DataPair_GetValueY(dp));
|
AQDG_Graph_DataPair_SetValueY(newDp, AQDG_Graph_DataPair_GetValueY(dp));
|
||||||
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
DBG_ERROR(NULL, "Added first value: %.2f", AQDG_Graph_DataPair_GetValueY(dp));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GWEN_DATE *dt;
|
GWEN_DATE *dt;
|
||||||
@@ -114,7 +115,6 @@ AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dp
|
|||||||
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(lastDate));
|
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(lastDate));
|
||||||
AQDG_Graph_DataPair_SetValueY(newDp, AQDG_Graph_DataPair_GetValueY(dp));
|
AQDG_Graph_DataPair_SetValueY(newDp, AQDG_Graph_DataPair_GetValueY(dp));
|
||||||
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
DBG_ERROR(NULL, "Added value: %.2f", AQDG_Graph_DataPair_GetValueY(dp));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
double v2;
|
double v2;
|
||||||
@@ -122,7 +122,6 @@ AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dp
|
|||||||
/* add to existing date value */
|
/* add to existing date value */
|
||||||
v2=AQDG_Graph_DataPair_GetValueY(newDp);
|
v2=AQDG_Graph_DataPair_GetValueY(newDp);
|
||||||
AQDG_Graph_DataPair_SetValueY(newDp, v2+v);
|
AQDG_Graph_DataPair_SetValueY(newDp, v2+v);
|
||||||
DBG_ERROR(NULL, "Added %.2f to existing value: %.2f", v, v2);
|
|
||||||
GWEN_Date_free(newDate);
|
GWEN_Date_free(newDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,3 +135,132 @@ AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dp
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DayAverage(const AQDG_GRAPH_DATAPAIR_LIST *dpList)
|
||||||
|
{
|
||||||
|
if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) {
|
||||||
|
AQDG_GRAPH_DATAPAIR_LIST *newList;
|
||||||
|
const AQDG_GRAPH_DATAPAIR *dp;
|
||||||
|
GWEN_DATE *currentDate=NULL;
|
||||||
|
double currentSum;
|
||||||
|
int currentCount;
|
||||||
|
|
||||||
|
newList=AQDG_Graph_DataPair_List_new();
|
||||||
|
dp=AQDG_Graph_DataPair_List_First(dpList);
|
||||||
|
while(dp) {
|
||||||
|
if (currentDate==NULL) {
|
||||||
|
/* first value */
|
||||||
|
currentDate=GWEN_Date_fromLocalTime(AQDG_Graph_DataPair_GetValueX(dp));
|
||||||
|
currentSum=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount=1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
GWEN_DATE *newDate;
|
||||||
|
|
||||||
|
newDate=GWEN_Date_fromLocalTime(AQDG_Graph_DataPair_GetValueX(dp));
|
||||||
|
if (GWEN_Date_Compare(newDate, currentDate)!=0) {
|
||||||
|
AQDG_GRAPH_DATAPAIR *newDp;
|
||||||
|
|
||||||
|
/* new date */
|
||||||
|
newDp=AQDG_Graph_DataPair_new();
|
||||||
|
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(currentDate));
|
||||||
|
AQDG_Graph_DataPair_SetValueY(newDp, currentSum/(double)currentCount);
|
||||||
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
|
|
||||||
|
currentSum=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount=1;
|
||||||
|
GWEN_Date_free(currentDate);
|
||||||
|
currentDate=newDate;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* add to existing date value */
|
||||||
|
currentSum+=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount++;
|
||||||
|
GWEN_Date_free(newDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dp=AQDG_Graph_DataPair_List_Next(dp);
|
||||||
|
}
|
||||||
|
if (currentCount && currentDate) {
|
||||||
|
AQDG_GRAPH_DATAPAIR *newDp;
|
||||||
|
|
||||||
|
/* store data for last value */
|
||||||
|
newDp=AQDG_Graph_DataPair_new();
|
||||||
|
AQDG_Graph_DataPair_SetValueX(newDp, GWEN_Date_toLocalTime(currentDate));
|
||||||
|
AQDG_Graph_DataPair_SetValueY(newDp, currentSum/(double)currentCount);
|
||||||
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
|
}
|
||||||
|
GWEN_Date_free(currentDate);
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MinutesAverage(const AQDG_GRAPH_DATAPAIR_LIST *dpList, int minutes)
|
||||||
|
{
|
||||||
|
if (dpList && AQDG_Graph_DataPair_List_GetCount(dpList)) {
|
||||||
|
AQDG_GRAPH_DATAPAIR_LIST *newList;
|
||||||
|
const AQDG_GRAPH_DATAPAIR *dp;
|
||||||
|
double currentTimeMinutes=0;
|
||||||
|
double currentTimeValue;
|
||||||
|
double currentSum;
|
||||||
|
int currentCount=0;
|
||||||
|
|
||||||
|
newList=AQDG_Graph_DataPair_List_new();
|
||||||
|
dp=AQDG_Graph_DataPair_List_First(dpList);
|
||||||
|
while(dp) {
|
||||||
|
if (currentCount==0) {
|
||||||
|
|
||||||
|
/* first value */
|
||||||
|
currentTimeValue=AQDG_Graph_DataPair_GetValueX(dp);
|
||||||
|
currentTimeMinutes=floor(currentTimeValue/60.0);
|
||||||
|
currentSum=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount=1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
double newTimeValue;
|
||||||
|
double newTimeMinutes;
|
||||||
|
|
||||||
|
newTimeValue=AQDG_Graph_DataPair_GetValueX(dp);
|
||||||
|
newTimeMinutes=floor(newTimeValue/60.0);
|
||||||
|
if ((newTimeMinutes-currentTimeMinutes)<(double)minutes) {
|
||||||
|
/* add to existing sum */
|
||||||
|
currentSum+=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AQDG_GRAPH_DATAPAIR *newDp;
|
||||||
|
|
||||||
|
/* new date */
|
||||||
|
newDp=AQDG_Graph_DataPair_new();
|
||||||
|
AQDG_Graph_DataPair_SetValueX(newDp, (floor(currentTimeMinutes/(double) minutes)*(double) minutes)*60.0);
|
||||||
|
// AQDG_Graph_DataPair_SetValueX(newDp, floor(currentTimeMinutes*60.0));
|
||||||
|
AQDG_Graph_DataPair_SetValueY(newDp, currentSum/(double)currentCount);
|
||||||
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
|
|
||||||
|
currentSum=AQDG_Graph_DataPair_GetValueY(dp);
|
||||||
|
currentCount=1;
|
||||||
|
currentTimeValue=newTimeValue;
|
||||||
|
currentTimeMinutes=newTimeMinutes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dp=AQDG_Graph_DataPair_List_Next(dp);
|
||||||
|
}
|
||||||
|
if (currentCount) {
|
||||||
|
AQDG_GRAPH_DATAPAIR *newDp;
|
||||||
|
|
||||||
|
/* store data for last value */
|
||||||
|
newDp=AQDG_Graph_DataPair_new();
|
||||||
|
AQDG_Graph_DataPair_SetValueX(newDp, (floor(currentTimeMinutes/(double) minutes)*(double) minutes)*60.0);
|
||||||
|
// AQDG_Graph_DataPair_SetValueX(newDp, floor(currentTimeMinutes*60.0));
|
||||||
|
AQDG_Graph_DataPair_SetValueY(newDp, currentSum/(double)currentCount);
|
||||||
|
AQDG_Graph_DataPair_List_Add(newDp, newList);
|
||||||
|
}
|
||||||
|
return newList;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DaySums(const AQDG_GRAPH_DATAPAIR_LIST *dpList);
|
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DaySums(const AQDG_GRAPH_DATAPAIR_LIST *dpList);
|
||||||
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dpList);
|
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MonthSums(const AQDG_GRAPH_DATAPAIR_LIST *dpList);
|
||||||
|
|
||||||
|
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_DayAverage(const AQDG_GRAPH_DATAPAIR_LIST *dpList);
|
||||||
|
|
||||||
|
AQDG_API AQDG_GRAPH_DATAPAIR_LIST *AQDG_Data_MinutesAverage(const AQDG_GRAPH_DATAPAIR_LIST *dpList, int minutes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user