I updated the running log filter to the one given below. This allows me to generate the total running mileage of all the weeks. The changes are highlighted in this color:
jmaki.namespace("jmaki.filters");
myDays= ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
oneDay = 24*60*60*1000;
function addDays(myDate, days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}
function formatDate(myDate) {
var dateString = String (myDate.getDate());
dateString = (dateString.length == 1 ? "0" + dateString : dateString);
return (myDate.getMonth()+1) + "/" + dateString + "/" + myDate.getFullYear();
}
// convert Running blog feed to the jMaki table format
jmaki.filters.tableModelFilter2 = function(input) {
var startDate = new Date();
startDate.setFullYear(2007,1,12); // Feb 12, 2007
var _columns = [
{title: 'Title'},
{title: 'Day of The Week'},
{title: 'Date'},
{title: 'Mileage'}
];
var _rows = [];
var totalMileage = 0;
for (var _i=0; _i < input.channel.items.length;_i++) {
var weekNumber = input.channel.items[_i].title.split(' ')[1];
var weekStartDate = addDays(startDate, (weekNumber-1)*7);
var desc = input.channel.items[_i].description;
desc = desc.slice(0, desc.lastIndexOf("</span"));
var spanArray = desc.split("<span");
for (var _j=1; _j < spanArray.length; _j++) {
var span = spanArray[_j].split("</span>")[0];
if (span.search(/run/) == -1)
continue;
var runDay = myDays[_j-1];
var runDate = addDays(weekStartDate, _j-1);
mileageInt = parseInt(dayMileage);
totalMileage += mileageInt == "nan" ? 0 : mileageInt;
var row = [
'Week ' + weekNumber,
runDay,
formatDate(runDate),
span.split(': ')[1]
];
_rows.push(row);
}
}
var summaryRow = [
'Final Week',
'Last Day',
formatDate(new Date()),
totalMileage
];
_rows.push(summaryRow);
return {type : 'jmakiModelData', columns : _columns, rows : _rows};
}
The updated web page looks like given below. Notice the first row of the table gives the total mileage:
Technorati: jmaki mashup running web2.0