Method to automate export?

৫৫টি ভিউ
প্রথম অপঠিত মেসেজটিতে চলে আসুন

Helen

পড়া হয়নি,
১০ মে, ২০১১, ৬:০৭:২৩ PM১০/৫/১১
প্রাপক google-refine
Hello,

I have a large spreadsheet of hundreds of patients listed in one
column with thousands of glucose readings per patient listed in the
next column. I would like to export all of the patients with their
data into individual spreadsheets. I see that I am able to use "text
facet" to separately view the patient ID's and then click "export" to
export each patient's spreadsheet. However, this can be incredibly
tedious to repeat for hundreds of patients. Is there a way to use
Google Refine to automate this exporting procedure?

Thank you so much in advance for any help you can offer!

Helen

David Huynh

পড়া হয়নি,
১১ মে, ২০১১, ১:০৫:৩১ AM১১/৫/১১
প্রাপক google...@googlegroups.com
Helen,

If I understand what you need correctly, then there is no standard mechanism for doing it, but there is a work around. Are you familiar with the Javascript console in your browser? If so, please follow these steps

1. Open to the Refine project that you want to export.

2. Make sure there is only a single text facet for the patient ID column.

3. Open up the Javascript console, and paste in this code and hit Enter (you can adjust the interval if you like):

var format = "xls";
var extension = "xls";
var interval = 2; // seconds

var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
var form = $(document.createElement("form"))
    .css("display", "none")
    .attr("method", "post")
    .attr("target", "refine-export");
$('<input />')
    .attr("name", "project")
    .attr("value", theProject.id)
    .appendTo(form);
$('<input />')
    .attr("name", "format")
    .attr("value", format)
    .appendTo(form);
var engineInput = $('<input />')
    .attr("name", "engine")
    .appendTo(form);

document.body.appendChild(form[0]);

window.open("about:blank", "refine-export");

var facet = ui.browsingEngine._facets[0].facet;
var values = $.map(facet._data.choices, function(o) { return o.v; });
var next = function() {
  if (values.length > 0) {
    var choice = values.pop();
    var engineConfig = {
      "facets":[{
        "type": "list",
        "name": facet._config.name,
        "columnName": facet._config.columnName,
        "expression": facet._config.expression,
        "omitBlank": false,
        "omitError": false,
        "selection": [{ "v": choice }],
        "selectBlank": false,
        "selectError": false,
        "invert": false
      }],
      "mode": "row-based"
    };
    form.attr("action", "/command/core/export-rows/" + name + "-" + choice.l + "." + extension)
    engineInput.attr("value", JSON.stringify(engineConfig))
    
    form[0].submit();
    
    window.setTimeout(next, interval * 1000);
  }
};
next();

This will open a new window (or tab) and use that to download the files you want. Some browser will detect this as a bad behavior (web sites that constantly try to open new windows or tabs are bad). Make sure to look for a message in your browser that says so, and force the browser to allow this behavior to continue for Refine.

Hope that helps,

David

Luling Huang

পড়া হয়নি,
৩০ নভে, ২০১৬, ২:৫৩:৪৩ PM৩০/১১/১৬
প্রাপক OpenRefine,google...@googlegroups.com
Thanks, David. The code works for me.

However, I'm wondering if I can export the separated files in csv. I've tried changing "xls" to "csv" in the first two lines. After the change, the csv files appeared one by one in a new tab. But none of them was downloaded. Is there any other part of the code that I need to change? Javascript is very new to me. It would be great if someone can point me to the right direction. Thank you in advance! 

Luling
সকলকে উত্তর দিন
লেখককে লিখে পাঠান
ফরওয়ার্ড করুন
0টি নতুন মেসেজ