aqhome-cgi: choose graph params according to modality.
This commit is contained in:
@@ -54,7 +54,7 @@ struct MY_GRAPH_PARAMS {
|
||||
|
||||
|
||||
|
||||
static MY_GRAPH_PARAMS _graphParams[]={
|
||||
static MY_GRAPH_PARAMS _graphParamsAny[]={
|
||||
{"4h", "last 4 hours", "Lm5", 4*60*60, 2*60},
|
||||
{"1d", "last 24 hours", "Lm30", 24*60*60, 5*60},
|
||||
{"1w", "last 7 days", "Lm240", 7*24*60*60, 15*60},
|
||||
@@ -66,6 +66,18 @@ static MY_GRAPH_PARAMS _graphParams[]={
|
||||
|
||||
|
||||
|
||||
static MY_GRAPH_PARAMS _graphParamsBool[]={
|
||||
{"4h", "last 4 hours", "Sa5", 4*60*60, 2*60},
|
||||
{"1d", "last 24 hours", "Sa30", 24*60*60, 5*60},
|
||||
{"1w", "last 7 days", "Sa240", 7*24*60*60, 15*60},
|
||||
{"1m", "last 30 days", "Sa480", 30*24*60*60, 60*60},
|
||||
{"6m", "last 6 months", "Sa720", 182*24*60*60, 60*60},
|
||||
{"12m","last 12 months", "Sa1440", 365*24*60*60, 60*60},
|
||||
{NULL, NULL, NULL, 0, 0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
@@ -84,7 +96,7 @@ static void _createGraph(AQH_DATACLIENT *dc,
|
||||
const char *sImgFile, int imgWidth, int imgHeight, uint64_t numDataPoints);
|
||||
static AQDG_GRAPH *_mkGraphObjectWithTitle(const char *graphTitle, const MY_GRAPH_PARAMS *graphParams, int precision);
|
||||
static void _mkPathForValueAndPeriod(AQH_MODULE *m, const AQH_VALUE *v, const MY_GRAPH_PARAMS *graphParams, GWEN_BUFFER *dbuf);
|
||||
static const MY_GRAPH_PARAMS *_getParamsByName(const char *s);
|
||||
static const MY_GRAPH_PARAMS *_getParamsByName(const char *s, int modality);
|
||||
|
||||
|
||||
|
||||
@@ -138,9 +150,6 @@ void _runGraphValueWithArgs(AQH_MODULE *m,
|
||||
DBG_DEBUG(NULL, "GraphValue with args");
|
||||
dbQuery=AQCGI_Request_GetDbQuery(rq);
|
||||
sPeriod=GWEN_DB_GetCharValue(dbQuery, "period", 0, NULL);
|
||||
graphParams=_getParamsByName(sPeriod);
|
||||
if (graphParams==NULL)
|
||||
graphParams=&_graphParams[0];
|
||||
DBG_DEBUG(NULL, "Device=%s, value=%s, period=%s",
|
||||
sDeviceName?sDeviceName:"<empty>", sValueName?sValueName:"<empty>",
|
||||
sPeriod?sPeriod:"<empty>");
|
||||
@@ -149,6 +158,7 @@ void _runGraphValueWithArgs(AQH_MODULE *m,
|
||||
if (value) {
|
||||
GWEN_BUFFER *fbuf;
|
||||
|
||||
graphParams=_getParamsByName(sPeriod, AQH_Value_GetModality(value));
|
||||
fbuf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
_mkPathForValueAndPeriod(m, value, graphParams, fbuf);
|
||||
if (!AQH_ModService_FileIsCurrent(GWEN_Buffer_GetStart(fbuf), graphParams->acceptedAgeInSeconds)) {
|
||||
@@ -261,18 +271,26 @@ void _mkPathForValueAndPeriod(AQH_MODULE *m, const AQH_VALUE *v, const MY_GRAPH_
|
||||
|
||||
|
||||
|
||||
const MY_GRAPH_PARAMS *_getParamsByName(const char *s)
|
||||
const MY_GRAPH_PARAMS *_getParamsByName(const char *s, int modality)
|
||||
{
|
||||
const MY_GRAPH_PARAMS *startP;
|
||||
const MY_GRAPH_PARAMS *p;
|
||||
|
||||
p=_graphParams;
|
||||
switch(modality) {
|
||||
case AQH_ValueModality_Door:
|
||||
case AQH_ValueModality_Motion:
|
||||
case AQH_ValueModality_OnOff: startP=_graphParamsBool; break;
|
||||
default: startP=_graphParamsAny; break;
|
||||
}
|
||||
|
||||
p=startP;
|
||||
while(p->name) {
|
||||
if (strcasecmp(p->name, s)==0)
|
||||
return p;
|
||||
p++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return startP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user