X

Total Running Mileage Mashup with jMaki

Guest Author
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

Join the discussion

Comments ( 3 )
  • Arun Gupta's Blog Tuesday, July 31, 2007
    [Trackback] As reported earlier jMaki and GlassFish, along with a host of other Sun-led open source technologies (NetBeans, OpenJDK, OpenDS, Project Indiana, etc.), were present at OSCON 2007 last week. I spent my entire 2 days at the jMaki booth...
  • Arun Gupta's Blog Friday, August 24, 2007
    [Trackback] jMaki is a light-weight framework for build Web 2.0 applications. It provides support for multiple languages - Java (1, 2, 3, 4, 5, 6) , PHP, Ruby (1, 2), Phobos (1). The numbers in parentheses indicate the entries that I've...
  • LAPTOP BATTERY Thursday, November 27, 2008

    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.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.