Rollup service code for Non academic cloud


#1

Is there anyone who made the service to work in their personal cloud?
I have trouble changing the code to work.
I have included the code below(The entity names might differ a bit). When I execute, I keep getting the error as :
Error executing service RollUp. Message :: JSON does not allow non-finite numbers. - See Script Error Log for more details.

/*********************************************************************
Get the current user so we can append _username to entity names
*********************************************************************/
//logger.warn(“Beginning Shipyard Rollup Service.”);
//var username = Resources[“CurrentSessionInfo”].GetCurrentUser();

/*********************************************************************
Using our GetPowerConsumers() service, get all power
consumers and store them in an infoTable
*********************************************************************/
var sysServThingName = “PowerSystemServices”;
var powerConsumers = Things[sysServThingName].GetPowerConsumer();
var totalPowerConsumed = 0;

/*********************************************************************
Iterate through the table one row at a time, adding to
totalPowerConsumed with each row. This code was derived
from Snippets > Infotable for loop
*********************************************************************/
var tableLength = powerConsumers.rows.length;
for (var x = 0; x < tableLength; x++) {
var row = powerConsumers.rows[x];
totalPowerConsumed = totalPowerConsumed + row.PowerConsumed;
}

//Set the Shipyard PowerConsumed property
me.PowerConsumed = totalPowerConsumed;

/*********************************************************************
Using our GetPowerProducers() service, get all power
consumers and store them in an infoTable
*********************************************************************/
var powerProducers = Things[sysServThingName].GetPowerProducer();

/*********************************************************************
Use the Aggregate function, available from
Snippets > InfoTableFunctions > Aggregate
to sum the column of the totalPowerProduced
InfoTable.
********************************************************************/
var params = {
t: powerProducers /
INFOTABLE /,
columns: “PowerProduced” /
STRING /,
aggregates: “SUM” /
STRING /,
groupByColumns: undefined /
STRING */
};
var resultTable = Resources[“InfoTableFunctions”].Aggregate(params);
var totalPowerProduced = resultTable.SUM_PowerProduced;

//Set the Shipyard PowerProduced property
me.PowerProduced = totalPowerProduced;

/*********************************************************************
Return info table of power produced/consumed/stored
Used Snippets > Create Infotable from Datashape and Snippets > Create infotable
entry from datashape as a basis for this code.
*********************************************************************/
params = {
infoTableName : “InfoTable”,
dataShapeName : “RollUpDS”
};
var result = Resources[“InfoTableFunctions”].CreateInfoTableFromDataShape(params);
var newEntry = new Object();
newEntry.powerConsumed = totalPowerConsumed; // NUMBER
newEntry.powerProduced = totalPowerProduced; // NUMBER
var powStorageThingname = “PowerStorage”;
newEntry.powerStored = Things[powStorageThingname].PowerStored; // NUMBER
result.AddRow(newEntry);
logger.warn("Shypyard Rollup: " + me.PowerConsumed + “C-” +
me.PowerProduced + “P-” + me.PowerStored + “S”);