Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Oracle.
« Screencast #Web4:... | Main | Ready For San Franci... »

http://blogs.sun.com/arungupta/date/20070725 Wednesday July 25, 2007

Total Running Mileage Mashup with jMaki

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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
Comments:

[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...

Posted by Arun Gupta's Blog on July 31, 2007 at 03:07 PM PDT #

[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...

Posted by Arun Gupta's Blog on August 24, 2007 at 06:08 AM PDT #

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.

Posted by LAPTOP BATTERY on November 27, 2008 at 05:04 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
« Screencast #Web4:... | Main | Ready For San Franci... »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.