CSC/ECE 517 Fall 2013/oss fmv

From Expertiza_Wiki
Revision as of 16:44, 30 October 2013 by Mjoshi (talk | contribs) (→‎References)
Jump to navigation Jump to search

History

Sahana software was originally developed by members of the Sri Lankan IT community who wanted to find a way to apply their talents towards n helping their country recover in the immediate aftermath of the 2004 Indian Ocean earthquake and tsunami. The word “Sahana” means “relief” in Sinhalese, one of the national languages of Sri Lanka. Sahana community has since grown to include experts in emergency and disaster management as full partners in the software development process. This is extremely unique in the governance of software projects, and a unique strength of the Sahana Software Foundation.

Under the stewardship of The Lanka Software Foundation (LSF) Sahana software grew into a global free and open source software project supported by hundreds of volunteer contributors from dozens of countries and it supported national and local authorities and relief agencies in their response to numerous large-scale, sudden-onset disasters. The Sahana Software Foundation was established in 2009 by an initial board of directors as a non-profit organization registered in the State of California to serve the needs and requirements of a diverse group of customers. SSF partners with disaster and technologies experts, technology, professional services and disaster response organizations and to better address information needs and the following questions:

How can conditions and urgent requirement be effectively communicated to the international donor community? How can responsible authorities understand where hospitals that can accommodate additional patients are located? How can family members remaining in villages be reunited with their parents, spouses, and children separated by evacuation?

Description

Sahana Eden can be used to collect and manage a large variety of data. For this data to add value it needs to be processed and shared in a way in which it can present the information people need to make decisions and plan activities. To achieve this Sahana Eden should be able to produce reports which analyse and visualize data in a flexible, user friendly and configurable way. The types of the report can be Pivot Table, Bar Chart, or Pie chart. Our work includes the exporting the generated report to user's computer so that user can see the generated report offline. Currently we focused on exporting report to PDF document.


Design

Setup (Installation)

Sahana Eden can be installed on several different operating systems:Linux,Windows,Mac. The installation of Sahana eden requires web2py framework. Sahana Eden can be easily deployed on Amazon EC2, Heroku.

To contribute to Eden foundation, fork repository from https://github.com/flavour/eden

Implementation

The base class Exporter is defined as:

function Exporter(exp)
{
    this.exporter = exp;
    this.tableExporter = null;
}

Exporter.prototype.setExporter = function(exp)
{
    this.exporter = exp;
}

Exporter.prototype.setTableExporter = function(exporter)
{
    this.tableExporter = exporter;
}

Exporter.prototype.renderTable = function()
{
    this.tableExporter.render();
}

Since we have implemented the Pdf functionality, a PdfExporter is defined for this.


function PdfExporter(exp)
{
    this.exporter = exp;
}

PdfExporter.prototype = new Exporter();

PdfExporter.prototype.getPdf = function()
{
    return this.exporter;
}

PdfExporter.prototype.export = function(imageObj, json)
{
    this.exportImage(imageObj);
    this.exportPivotTable(json);
}

PdfExporter.prototype.exportImage = function(imageObj)
{
    this.exporter.pageAdd();

    // load image from canvas into BytescoutPDF

    this.exporter.imageLoadFromUrl(imageObj);

    // place this mage at given coordinates and dimesionson on the page
    this.exporter.imagePlaceSetSize(50, 50, 0, 750, 500);
}

PdfExporter.prototype.exportPivotTable = function(json)
{
    this.exporter.pageAdd();

    if(this.tableExporter == null || this.tableExporter == undefined)
    {
        this.setTableExporter(new PdfTableRenderer(json, this.exporter));
    }

    this.renderTable();
}

Now, Table exporter is written only for table creation in Pdf. This can even be used for table creation in XLS or RSS or so. Thus, we use strategy pattern here.

Table renderer is defined as below:

function TableRenderer()
{
    this.X = 50;
    this.Y = 50;
    this.PageWidth = 750;
    this.PageHeight = 500;
    this.numcols = 0;
}

TableRenderer.prototype.constructor = function(json_data, exp)
{
    this.json = json_data;
    this.exporter = exp;
}

TableRenderer.prototype.render = function()
{
    // this method is abstract and does nothing
}

And Pdf table renderer having functionality of exporting table to Pdf, is defined as:

function PdfTableRenderer(json_data, exp)
{
    this.json = json_data;
    this.exporter = exp;
}

PdfTableRenderer.prototype = new TableRenderer();

PdfTableRenderer.prototype.render = function()
{
  // render code here
}

By setting TableRenderer in Exporter class to an instance of PdfTableRenderer, we are achieving code reuse. This can be extended for XLS by writing XLSTableRenderer class which inherits from TableRenderer and overrides the render() method.

At last, the final Pdf object which needs to be downloaded, is generated by PdfFactory. Here we have used Factory pattern to achieve the same. getPdf() method of PdfFactory hides all the implementation details from outside of the library.

PdfFactory is defined as:

function PdfFactory()
{

}

PdfFactory.getPdf = function()
{
    //... code to extract canvas image

    var pe = new PdfExporter(pdf);

    pe.export(dataURL, json_data);

    return pe.getPdf(); // gets final pdf object
}

Dependency

During implementation of this project we used external java-script library.

html2canvas.js

The purpose of this file is to having ability to take "screenshots" of webpages or parts of it, directly on the users browser. The screenshot is based on the DOM.

bytesscoutpdf.js

The purpose of this client-side Javascript library to generate PDF with text, images and graphics.It Works with mainstream desktop and mobile browsers, iPhone and iPad.

Summary

Future

Export to Excel File

Currently our work is restricted to exporting the graph and pivot table-generated interactively by user to the PDF version of it. In future newer implementation can include exporting the pivot table and graph to the excel(.xls) version. This implementation may requires significant efforts as excel documents are interactive. So a user should able to manipulate the generated excel document.(Not required in the case PDF document as they are static documents). XLS would ideally include the raw Data on 1 or more sheets, the Pivot table on another sheet & Graphs on 1 or more additional sheets. The Pivot Table & Graphs should be linked to the raw data using XLS functionality.

Subscription

A user would like to subscribe to a report to receive by email daily/weekly/monthly. The format of this report can be PDF or Excel document.

External Links

1. Git repository
2. Sahana Eden Demo
3. Bytescout
4. Html2Canvas