Hi ,
i want to convert a string of dateTime format as given below
“2025-03-21T23:59:00.000Z” to seconds since epoch in EPL.
tried referring the document but didn’t found anything convenient.
Need a solution to achieve this in EPL
Hi ,
i want to convert a string of dateTime format as given below
“2025-03-21T23:59:00.000Z” to seconds since epoch in EPL.
tried referring the document but didn’t found anything convenient.
Need a solution to achieve this in EPL
The parseTimeXYZ() functions here should help:
@Harald_Meyer ,
thanks for the reply.
and i also interested in knowing the working of event.
i have a event as
event test{
string name;
}
i am doing like:
action onload(){
test n := getEvent();
n.name // here its not populating the name i added
}
action getEvent() return test{
test t = new test;
t.name := “testName”; //adding value
return t;
}
pls help me in this ,if i am doing anything wrong
can you show the actual code that is not working as expected? The following is giving the expected outcome:
monitor MySampleMonitor {
event test{
string name;
}
action onload(){
test n := getEvent();
log n.name at INFO;
}
action getEvent() returns test {
test t := new test;
t.name := "testName";
return t;
}
}
please find the below code
MeaUnitandValue uv := getLastDayLastMeaValue(“mea2”,“sol_test”,“321369571927”,“2025-03-21”);
log "Unit +++++++++++++++++++++"+ uv.unit at INFO;
log "Value +++++++++++++++++++++"+ uv.value.toString() at INFO;
action getLastDayLastMeaValue(string measurement1, string meaType,string deviceId, string fromDate) returns MeaUnitandValue {
MeaUnitandValue unitValue := new MeaUnitandValue;
try{
string fromDateTime := fromDate + "T00:00:00.000Z";
string toDateTime := fromDate + "T23:59:00.000Z";
float epochSecondsFrom := TimeFormat.parseTimeUTC(format, fromDateTime);
float epochSecondsTo := TimeFormat.parseTimeUTC(format, toDateTime);
dictionary<string, string> params := new dictionary<string,string>;
params.add("pageSize","1");
params.add("source",deviceId);
params.add("currentPage","1");
params.add("pageSiz","1");
params.add("dateFrom",epochSecondsFrom.toString());
params.add("dateTo", epochSecondsTo.toString());
// params.add("dateFrom","2025-03-21T00:00:00.000Z");
// params.add("dateTo", "2025-03-21T23:59:00.000Z");
params.add("revert","true");
GenericRequest request := new GenericRequest;
request.reqId := com.apama.cumulocity.Util.generateReqId();
request.method := "GET";
request.isPaging := true;
request.queryParams := params;
request.path := "/measurement/measurements";
monitor.subscribe(GenericResponse.SUBSCRIBE_CHANNEL);
on all GenericResponse(reqId=request.reqId) as response
and not GenericResponseComplete(reqId=request.reqId)
{
AnyExtractor dict := AnyExtractor(response.getBody());
AnyExtractor source := AnyExtractor(dict.getDictionary("source"));
try{
AnyExtractor meaData :=
AnyExtractor(dict.getDictionary(meaType)[measurement1]);
log "Found measurement of type: ========== "+ meaType +" with id : " +
dict.getString("id") + " and source id :" + source.getString("id") +"of measurement :"+measurement1+
" and value "+meaData.getFloat("value").toString()+
" "+meaData.getString("unit")
at INFO;
unitValue.unit := meaData.getString("unit");
unitValue.value := meaData.getFloat("value");
}
catch(Exception e){
log "Failed to parse unexpected measurement : " +
dict.toString() at WARN;
}
}
on GenericResponseComplete(reqId=request.reqId)
{
monitor.unsubscribe(GenericResponse.SUBSCRIBE_CHANNEL);
}
send request to GenericRequest.SEND_CHANNEL;
}catch(Exception e){
log "Exception occured============>" at INFO;
}
return unitValue;
}
@jkpatil1010 Is there a reason why you are using GenericRequest and not FindMeasurement?
This would not solve your problem but make the code a bit easier for you. The challenge that you are facing is because the request-response pattern is asynchronous. Anything in a listener (a block starting with a “on”) is invoked asynchronously. So your action returns with the default values for “unitValue” before the response arrives. The typical pattern are that you route/send your own event in the listener and have a separate listener for that event in the caller of the action or you provide a callback action as a parameter to your action and call that when you receive the data in a listener.
I do not have a good example at hand but will check with colleagues.