I have json object return from the web service. Web service Object :
var seriesData = [{
feederId: "PTS113T",
businessEventCode: "LowVoltage",
servicePointEventCount: 6,
startDayID: 20130812,
}, {
feederId: "PTS113T",
businessEventCode: "HighVoltage",
servicePointEventCount: 2,
startDayID: 20130812,
}, {
feederId: "PTS113T",
businessEventCode: "LowVoltage",
servicePointEventCount: 7,
startDayID: 20130814,
}, {
feederId: "PTS113T",
businessEventCode: "HighVoltage",
servicePointEventCount: 5,
startDayID: 20130815,
}];
I want to modified that object into..
I have startDayID for every startDayID there will be two value or single value for businessEventCode: "LowVoltage", or businessEventCode: "HighVoltage",
Want to :
var seriesData = [{
feederId: "PTS113T",
servicePointEventLowCount: 6,
servicePointEventHighCount: 2,
startDayID: 20130812,
}, {
feederId: "PTS113T",
servicePointEventLowCount: 7,
startDayID: 20130814,
}, {
feederId: "PTS113T",
servicePointEventHighCount: 5,
startDayID: 20130815,
}];
What i am doing :
if (seriesData) {
var mockdata = [];
for (var i = 0; i < seriesData.length; i += 2) {
var data = {};
//data.feederId = seriesData[i].feederId;
if ((seriesData[i].startDayID) == (seriesData[i + 1].startDayID)) {
data.feederId = seriesData[i].feederId;
data.servicePointEventLowCount = seriesData[i].servicePointEventCount;
data.servicePointEventHighCount = seriesData[i + 1].servicePointEventCount;
data.startDayID = seriesData[i].startDayID;
} else {
data.feederId = seriesData[i].feederId;
data.startDayID = seriesData[i].startDayID;
if (seriesData[i].businessEventCode == 'LowVoltage') {
data.servicePointEventLowCount = seriesData[i].servicePointEventCount;
data.servicePointEventHighCount = 0;
} else {
data.servicePointEventHighCount = seriesData[i].servicePointEventCount;
data.servicePointEventLowCount = 0;
}
}
mockdata.push(data);
}