Thursday, August 20, 2009

GSoC09: Statistics module final weekly update: Javascript fireworks and Code Swarm! :)

It's not a secret that I truly love Javascript language :)

So, as the last week of GSoC went by, I wanted to finish some of the work about Melange Javascript refactoring that I begun on May/June, just to give a real starting point and solid bases for a renewed Javascript layer for Melange.

So, first of all, I've learnt some advanced bash programming, thanks to the awesome Mendel's Cooper online book, "Advanced Bash-Scripting Guide" (PDF version). I found it very well written and really useful. Having learnt at least enough to deal with variables, loops, conditionals, exit statuses and functions, I've made a script to run shrinksafe over all our Javascript files during build and before deploying. In this way we can shrink our JS files to a half, and so it'll download faster once live.

Then, as we're using pylint to check proper style of Python files, I've made a bash script file to run JSLint over all our JS files, and also I've coded a big-mega patch to make all our JS files JSLint compliant! And here the final result..!

Furthermore, I've written JSDoc style comments in melange.js and melange.graph.js files, to let the community have an example on how to document JS files properly (it's very difficult to communicate semanthic of JS files to JSDoc Toolkit!). Running JSDoc Toolkit over those two files made documentation for private (developer) and public (only API) purposes. Following a sample excerpt of the final result.

Apart from that, I've also achieved this:

Seems not so exciting, huh? Well, what this alert box, behind the scenes, means is that Melange now has a facility to expose public JS API more or less like Google does (with Maps API and so on). Using this facility, I've made possible an up-to-date live embedding of statistics data to any web page, by inserting only a a script tag (and a div where the visualization needs to be shown).
There are two kind of exporting:
  • LIVE: this connects the web page to a widget in the statistics dashboard. This means that if you change the visualization to a pie chart or the "virtual statistic" to another one, the visualization in your web page will be changed as well.
  • FREEZED: this exports the current visualization in the widget, and it will never change.
So, more things can happen in the future with this new opportunity (manage a wiki of visualizations, for example), but also embedding statistics into document pages in Melange (this is very straightforward to achieve now). And, now, exposing JS APIs, we can think of many exciting new features (what about something to be embedded in the organizations' real home pages?). Along with JS refactoring and seed_db frontend these could be the next steps for my post-GSoC participation in Melange community.

During the beginning of this week I've also made two simple code swarm videos (coloured by programming language).
This one is for our main branch Melange repository:

And this one is for Melange statistics branch repository (which is merged with main repository).

Before ending the post, I would like to thank everyone involved in Melange community, my mentor Pawel Solyga, our project lead Lennard De Rijk, Sverre Rabbelier, my "in-place guide" James Crook (which I met several times here in Dublin, thank you again for everything!) the other GSoC students (Daniel Hans, with whom the statistics module has been possible, Madhusudan C.S. and James Alexander Levy), not forgetting the great Daniel Diniz.
And obviously Google for making GSoC possible, and Leslie Hawthorn and Ellen Ko for their hard work on it.

Also, last but not least, I would like to give a huge hug to OpenStreetMap community (and my former-year mentor Frederik Ramm), with which I've shared GSoC 2008, and with which I've had the opportunity to learn Javascript language in depth. Surely, as I've done during this year, I'm going to stick around and contribute to OSM community as well.

Tuesday, August 18, 2009

Twelfth Week NewsFeed Update

As the GSOC program wraps up, I'm finishing with refactoring and testing, and have added a couple new important features in the last week:

* Subscribe-By-Star. The subscribe-by-star pattern allows for an e-mail subscription for a particular entity to be added or removed by toggling a star on the news feed box on or off. Aside from the popup help message explaining how the feature work, the subscribe-by-star is working on

The ajax itself is simple. After using jQuery.ajax() to make the call, I first process the POST data so that it is suitable for logic (converting byte strings to native types, mostly):

def edit_subscription(request, *args, **kwargs):
if request.GET.get('entity_key'):
entity_key = request.GET.get('entity_key')
return http.HttpResponseServerError()
if request.GET.get('subscribe') == 'true':
subscribe = True
elif request.GET.get('subscribe') == 'false':
subscribe = False
return http.HttpResponseServerError()
subscription_logic.editEntitySubscription(entity_key, subscribe)
return http.HttpResponse('OK')

I then call the editEntitySubscription subscription logic method:

entity_key = db.Key(entity_key)
user = user_logic.getForCurrentAccount()
subscriber = self.getSubscriberForUser(user)
if subscribe and entity_key not in subscriber.subscriptions:
subscriber.subscriptions.append(entity_key)'added subscription for entity_key %s for user %s'
% (entity_key, user.key().name()))
elif not subscribe and entity_key in subscriber.subscriptions:
subscriber.subscriptions.remove(entity_key)'removed subscription for entity_key %s for user %s'
% (entity_key, user.key().name()))
else: return

I've also added a model-based class method for determining auto-subscriptions, which will help for what I've found to be the hardest part of this project. While the goal is simply to get all users with at least read-access to an arbitrary Linkable entity, it is actually very difficult, and when possible it's only from manually creating logic. Essentially, this list of users should be sharded into its own relational entity (just a reference to the Linkable and a ListProperty of users). And I've also made various other rafactorings of the subscription code.

I look forward to committing code this week! At almost 2,000 lines, this will be a big commit, but worth the effort.

GSoC 2009: GHOP - The work begins now!

Hello everyone,
That was the last week of GSoC. Worked on very few things last week. Last week, I mostly worked on creating menus for easy accessibility of GHOP Tasks per organizations for general public and students. I also worked on Student data store model conversion to introduce School Type for students and wrote a Appengine task to convert the existing Student entities. I also added another field to hold the student grade if he is a High School Student. All other things like cleaners for these fields and views were already written during the beginning days of GSoC. Just merged them together.

Also made some modifications to module to accommodate program logic as parameter than hard coded logic. Also have fixed the bugs Lennie had noted and made some changes to the subscription star toggling among other things accordingly. My demo instance is up and running at and includes all the above said features.

Have also started writing the Starter Manual on how to use GHOP features for its users. I have setup a wiki page at It is a work in progress. I will complete it soon.

And coming to the reason why I said "The work begins now!" is that, I really want to see this programme happen. If that happens I am quite sure there will be many feature requests for GHOP, which I am looking forward to implement. We want to listen to the community for the feedback on how we can improve GHOP and make it better and make it happen.

Last but not the least, I would like to thank Lennie a lot, my mentor in particular for extending his helping hand in every way possible and to have spent so much time for mentoring me. He was there every time I had a doubt or I had a question or I had a problem or I was feeling like pulling out my hair trying to resolve a bug. He spent much more time in mentoring me than I expected at the start of the programme. Thank you so much Lennie. Also I would like to thank Sverre and Pawel and everyone else on the Melange team who helped me to get this project going.

-- Thank you,

P.S When can I call myself a Melange developer :P ?