rufuspollock-okfn / dataexplorer

View, visualize, clean and process data in the browser.
http://explorer.okfnlabs.org
148 stars 47 forks source link

Move to explicit getting of a dataset in scripting #126

Closed rufuspollock closed 11 years ago

rufuspollock commented 11 years ago

var dataset = loadDataset('name');

or possibly getDataset('name');

If no name provided get dataset named current.

djw commented 11 years ago

I propose two improvements to this:

1) Just now loadDataset() would be grabbing data synchronously from memory (via postMessage), but it's possible that this might end up being an asynchronous process at some point. So instead let's do:

loadDataset("name", function (dataset) {
  // do stuff
});

2) As discussed before, the scripts can't be guaranteed to be idempotent, so it makes more sense for them to run against the original data. original.csv + scripted transformations = current.csv. We're persisting the current data so that we don't have to run the script when we load a project, which is good because it means that browsers without web workers can still view projects. In other words, I think loadDataset() should default to using the original data. :-)

rufuspollock commented 11 years ago

My one concern is that async stuff can confuse the hell out of novice users. I wonder if we should be trying to insulate them from this as much as possible.

wdyt?

djw commented 11 years ago

This is a little trickier than I thought, mainly because original and current should be recline.Datasets, and we don't have proper multi-dataset support. Also, because they'll start off almost identical, we could really do with a working .clone() on recline.Dataset.

djw commented 11 years ago

@rgrp The snippet above doesn't seem too complicated, does it? It's not like we're going to expose them to deferreds. :-)

rufuspollock commented 11 years ago
var info = dataset.toJSON();
info.fields = dataset.fields.toJSON();
info.records = dataset._store.data;
var current = $.extend({}, info, true)
current.id = 'current'
var project = new Project({
  datasets: [
    current,
    info
  ] 
})
djw commented 11 years ago

This'll be neater with a proper clone() method, but see 159629d80c8d41ef559839a8bab66c5ed278d640

rufuspollock commented 11 years ago

@djw it seems you have a working version here. Let's go with this for the time being.

djw commented 11 years ago

@rgrp Ok. Still waiting on a decision sync-vs-async syntax.

rufuspollock commented 11 years ago

@djw let's go with the async syntax (I'd thought we'd agreed to this on chat last week - or, more specifically, that this was up to you :-) )

djw commented 11 years ago

How does this look, @rgrp? There's still the question of getting access to other datasets (mainly "original") — for now we can pass them both over postMessage, I think.