From d784221fdaed4ab5c36c69329302c50ce3f5c91d Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Tue, 17 Jul 2012 14:43:28 -0400 Subject: [PATCH 01/20] graphing add_new_button --- bamboo-client/client/bamboo.html | 49 +++++++++++---------------- bamboo-client/client/client.coffee | 54 ++++++++++-------------------- 2 files changed, 37 insertions(+), 66 deletions(-) diff --git a/bamboo-client/client/bamboo.html b/bamboo-client/client/bamboo.html index 5a5afb6..a30cf41 100644 --- a/bamboo-client/client/bamboo.html +++ b/bamboo-client/client/bamboo.html @@ -17,19 +17,15 @@ @@ -73,6 +69,7 @@

Preparing your dataset, just a split second..

- - - diff --git a/bamboo-client/client/client.coffee b/bamboo-client/client/client.coffee index 2219938..34476e5 100644 --- a/bamboo-client/client/client.coffee +++ b/bamboo-client/client/client.coffee @@ -76,9 +76,9 @@ if root.Meteor.is_client Session.get('fields').length < 6 or Session.get('show_all') #####################Control-Panel################## - root.Template.control_panel.show = -> - #if there is currentDatasetURL in session-> show - Session.get('currentDatasetURL') and Session.get('fields') and not Session.get('graph') + root.Template.control_panel.active = -> + #Session.get('currentDatasetURL') and Session.get('fields') and not Session.get('graph') + true # have to write this code to make chosen recognized in jquery root.Template.control_panel.chosen= -> Meteor.defer(-> @@ -102,6 +102,9 @@ if root.Meteor.is_client root.Template.control_panel.num_graph= -> 20 + root.Template.control_panel.waiting=-> + Session.get('waiting') + root.Template.control_panel.events= "click .btn": -> group = $('#group-by').val() view_field = $('#view').val() @@ -109,26 +112,17 @@ if root.Meteor.is_client Meteor.call("summarize_by_group",[url,group]) Session.set('currentGroup', group) Session.set('currentView', view_field) - Session.set('graph', false) - - ##################WAITING_GRAPH###################### - root.Template.waiting_graph.exist =-> - exist = Session.get('graph') - - root.Template.waiting_graph.titles =-> - Session.get("titles") - - #####################GRAPH#######################333 - root.Template.graph.show=-> - url = Session.get('currentDatasetURL') - group = Session.get('currentGroup') - view = Session.get('currentView') - url and view + Session.set('waiting', true) + + frag = Meteor.ui.render( -> + return Template.graph({ + field: view_field + group: group + }) + ) + $(".graph_area")[0].appendChild(frag) - root.Template.graph.field =-> - div = Session.get('currentView') - - root.Template.graph.charting =-> + root.Template.control_panel.charting =-> #todo: move summarize_by_group here? #todo: use async to serize sum & charting fieldInterval = setInterval(-> @@ -136,17 +130,11 @@ if root.Meteor.is_client summary = Summaries.findOne( {groupKey : Session.get('currentGroup')} ) if summary Meteor.call('field_charting') - Session.set('graph', true) + Session.set('waiting', false) clearInterval(fieldInterval) ,1000) "" - ##########ADDNEW GRAPH##################################### - root.Template.add_new_graph.show =-> - Session.get('graph') - - root.Template.add_new_graph.events = "click #addGraphBtn":-> - Session.set('add_new_graph_flag', true) ############# UI LIB ############################# @@ -188,14 +176,8 @@ Meteor.methods( boxplot(dataElement,div,min,max) - clear_graphs: -> - graph_divs = $('.gg_graph') - for item in graph_divs - $(item).empty() - field_charting: -> - Meteor.call('clear_graphs') url = Session.get("currentDatasetURL") group = Session.get("currentGroup") ? "" #some fallback field = Session.get("currentView") @@ -205,7 +187,7 @@ Meteor.methods( groupKey: group name: field .fetch() - div = "#" + field+"_graph" + div = "#" + field+"_"+group+"_graph" max_arr = item_list.map (item)-> if item.name in groupable maxing(item.data) From 7388aaed4c3c4471c4e4fbffc7ba9bebdee9e1c4 Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Tue, 17 Jul 2012 16:26:09 -0400 Subject: [PATCH 02/20] add graph button --- bamboo-client/client/bamboo.html | 4 +-- bamboo-client/client/client.coffee | 46 ++++++++++++++++-------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/bamboo-client/client/bamboo.html b/bamboo-client/client/bamboo.html index a30cf41..f29b899 100644 --- a/bamboo-client/client/bamboo.html +++ b/bamboo-client/client/bamboo.html @@ -68,8 +68,6 @@

Preparing your dataset, just a split second..

diff --git a/bamboo-client/client/client.coffee b/bamboo-client/client/client.coffee index 9a8dbb2..c116f11 100644 --- a/bamboo-client/client/client.coffee +++ b/bamboo-client/client/client.coffee @@ -2,12 +2,6 @@ root = global ? window bambooUrl = "/" observationsUrl = bambooUrl + "datasets" -constants = - #defaultURL : 'http://formhub.org/education/forms/schooling_status_format_18Nov11/data.csv' - defaultURL : 'https://www.dropbox.com/s/0m8smn04oti92gr/sample_dataset_school_survey.csv?dl=1' - #defaultURL : 'http://localhost:8000/education/forms/schooling_status_format_18Nov11/data.csv' - #defaultURL : 'http://formhub.org/mberg/forms/good_eats/data.csv' - ############ UI LOGIC ############################ if root.Meteor.is_client @@ -107,14 +101,31 @@ if root.Meteor.is_client "click #chartBtn": -> group = $('#group-by').val() view_field = $('#view').val() + + #check whether graph exists already + if Session.get(view_field + '_' + group) + alert "Graph already exists" + return + url = Session.get('currentDatasetURL') Meteor.call("summarize_by_group",[url,group]) Session.set('currentGroup', group) Session.set('currentView', view_field) Session.set('waiting', true) + Session.set(view_field + '_' + group, true) + #TODO: if the count = 1 when drawing box plot + title = "" + if view_field in Session.get('groupable_fields') + title = "Bar Chart of " + else + title = "Box Plot of " + title = title + view_field + if group != "" + title = title + " group by " + group frag = Meteor.ui.render( -> return Template.graph({ + title: title field: view_field group: group }) @@ -138,7 +149,7 @@ if root.Meteor.is_client clearInterval(fieldInterval) ,1000) "" - + #########GRAPH############################### ############# UI LIB ############################# @@ -174,6 +185,7 @@ Meteor.methods( make_single_chart: (obj) -> [div, dataElement, min, max] =obj #chart based on groupable property + console.log div if dataElement.name in Session.get("groupable_fields") barchart(dataElement,div,min,max) else @@ -191,19 +203,23 @@ Meteor.methods( groupKey: group name: field .fetch() - div = "#" + field+"_"+group+"_graph" + + div = $("#" + field+"_"+group+"_graph").get(0) + console.log "before max / min" max_arr = item_list.map (item)-> if item.name in groupable maxing(item.data) else item.data.max max = _.max(max_arr) + console.log max min_arr = item_list.map (item)-> if item.name in groupable mining(item.data) else item.data.min min = _.min(min_arr) + console.log min for item in item_list Meteor.call("make_single_chart", [div, item, min, max]) diff --git a/bamboo-client/client/d3chart.coffee b/bamboo-client/client/d3chart.coffee index ad0ca1e..915a34c 100644 --- a/bamboo-client/client/d3chart.coffee +++ b/bamboo-client/client/d3chart.coffee @@ -134,6 +134,9 @@ barchart= (dataElement, div, min, max)-> ) .attr('width',(d)-> w = (width-x_padding) / data.length - bar_padding + if ( w > 30 ) + w = 30 + w ) .attr('height',(d)-> height - y_padding - y_scale d.value @@ -225,21 +228,17 @@ barchart= (dataElement, div, min, max)-> .call(y_axis) boxplot= (dataElement, div, min, max)-> - console.log "enter" + console.log "box plot a a a enter" name = dataElement.name data = dataElement.data if data.count is 1 + console.log "data.count is one" display_name = dataElement.groupVal display_value = dataElement.data.min dataElement.data = {} dataElement.data[display_name]=display_value return barchart(dataElement, div, min, max) - if dataElement.groupKey is "" - str = "" + dataElement.name - else - str = "" + dataElement.name + " grouped by " + dataElement.groupKey - Session.set("titles", "Box Plot of " + str) y_padding = 20 x_padding = 20 @@ -249,6 +248,7 @@ boxplot= (dataElement, div, min, max)-> width = 200 height = width*1.5 + console.log div svg = d3.select(div) .append('svg:svg') .attr('width', width) diff --git a/bamboo-client/startup.coffee b/bamboo-client/startup.coffee index 1514d29..9253b48 100644 --- a/bamboo-client/startup.coffee +++ b/bamboo-client/startup.coffee @@ -1,6 +1,7 @@ root = global ? window constants = - defaultURL : 'https://www.dropbox.com/s/0m8smn04oti92gr/sample_dataset_school_survey.csv?dl=1' + #defaultURL : 'https://www.dropbox.com/s/0m8smn04oti92gr/sample_dataset_school_survey.csv?dl=1' + defaultURL : 'https://dl.dropbox.com/s/5mu9x13upanqpgy/file.csv?dl=1' Meteor.startup -> if root.Meteor.is_client From 664dad93c4c6685e4ef2e4d42e650b838d4e1af7 Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Thu, 19 Jul 2012 15:15:29 -0400 Subject: [PATCH 04/20] deletion button --- bamboo-client/public/deletion.svg | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 bamboo-client/public/deletion.svg diff --git a/bamboo-client/public/deletion.svg b/bamboo-client/public/deletion.svg new file mode 100755 index 0000000..d65f836 --- /dev/null +++ b/bamboo-client/public/deletion.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file From 77747eaa71aa0c7eb5fdbc42d2d765555898faba Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Thu, 19 Jul 2012 17:55:51 -0400 Subject: [PATCH 05/20] deletion button --- bamboo-client/client/client.coffee | 8 +++++++- bamboo-client/startup.coffee | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bamboo-client/client/client.coffee b/bamboo-client/client/client.coffee index c116f11..ed21ef0 100644 --- a/bamboo-client/client/client.coffee +++ b/bamboo-client/client/client.coffee @@ -150,7 +150,13 @@ if root.Meteor.is_client ,1000) "" #########GRAPH############################### - + root.Template.graph.events = "click .deletionBtn": -> + field = this.field + group = this.group + divstr = '#'+field+'_'+group+'_block' + Session.set(field+'_'+group, false) + $(divstr).remove() + ############# UI LIB ############################# diff --git a/bamboo-client/startup.coffee b/bamboo-client/startup.coffee index 9253b48..c5aafb7 100644 --- a/bamboo-client/startup.coffee +++ b/bamboo-client/startup.coffee @@ -1,7 +1,7 @@ root = global ? window constants = - #defaultURL : 'https://www.dropbox.com/s/0m8smn04oti92gr/sample_dataset_school_survey.csv?dl=1' - defaultURL : 'https://dl.dropbox.com/s/5mu9x13upanqpgy/file.csv?dl=1' + defaultURL : 'https://www.dropbox.com/s/0m8smn04oti92gr/sample_dataset_school_survey.csv?dl=1' + #defaultURL : 'https://dl.dropbox.com/s/5mu9x13upanqpgy/file.csv?dl=1' Meteor.startup -> if root.Meteor.is_client From e2ff12356392eba3fd83952abd3f036c30ffeffc Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Fri, 20 Jul 2012 13:34:00 -0400 Subject: [PATCH 06/20] fixes #35 --- bamboo-client/client/client.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bamboo-client/client/client.coffee b/bamboo-client/client/client.coffee index ed21ef0..a8f7b6b 100644 --- a/bamboo-client/client/client.coffee +++ b/bamboo-client/client/client.coffee @@ -13,6 +13,10 @@ if root.Meteor.is_client ###################URL-Entry########################### root.Template.url_entry.events = "click .btn": -> + if Session.get('currentDatasetURL') + keys = Session.keys + for item of keys + Session.set(item, false) url = $('#dataSourceURL').val() Session.set('currentDatasetURL', url) #Meteor.call('chosen') From 355d1e7c2b98f4a4c39c29731cacb9514d1999ad Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Mon, 23 Jul 2012 10:38:12 -0400 Subject: [PATCH 07/20] better error handling on the server side --- bamboo-client/.meteor/packages | 2 +- bamboo-client/server/server.coffee | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bamboo-client/.meteor/packages b/bamboo-client/.meteor/packages index 8584175..c5fe81f 100644 --- a/bamboo-client/.meteor/packages +++ b/bamboo-client/.meteor/packages @@ -3,9 +3,9 @@ # 'meteor add' and 'meteor remove' will edit this file for you, # but you can also edit it by hand. -autopublish coffeescript underscore jquery backbone bootstrap +autopublish diff --git a/bamboo-client/server/server.coffee b/bamboo-client/server/server.coffee index 74b87d2..1eb666e 100644 --- a/bamboo-client/server/server.coffee +++ b/bamboo-client/server/server.coffee @@ -25,12 +25,25 @@ Meteor.methods( form: {url: url} request post_options, (e, b, response) -> Fiber(-> - unless Datasets.findOne({url: url}) - Datasets.insert - bambooID: JSON.parse(response).id - url: url - cached_at: Date.now() - Meteor.call('insert_schema', url) + if b.statusCode is 200 + r = JSON.parse(response) + if r.error is undefined + unless Datasets.findOne({url: url}) + Datasets.insert + bambooID: r.id + url: url + cached_at: Date.now() + Meteor.call('insert_schema', url) + else + console.log "error message: " + r.error + Meteor.publish "message", -> + Message + message:"error message: " + r.error + else + console.log "bad status" + b.statusCode + Meteor.publish "message", -> + Message + message:"bad status: " + b.status +"\nYou have ill formated csv file" ).run() insert_schema: (datasetURL) -> From 08b715ef6d6a14410b2817b2934c9dc9f583b29b Mon Sep 17 00:00:00 2001 From: Myf Ma Date: Tue, 24 Jul 2012 11:23:20 -0400 Subject: [PATCH 08/20] publish firest batch --- bamboo-client/client/bamboo.html | 7 +++++++ bamboo-client/client/client.coffee | 5 ++++- bamboo-client/models.coffee | 1 + bamboo-client/server/server.coffee | 23 +++++++++-------------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/bamboo-client/client/bamboo.html b/bamboo-client/client/bamboo.html index 815ef8f..6052750 100644 --- a/bamboo-client/client/bamboo.html +++ b/bamboo-client/client/bamboo.html @@ -13,6 +13,10 @@
+ +