Ag Spreadsheet Import
Created: 2011-09-21 18:09:09
Last updated: 2011-09-21 18:09:06
Based on Spreadsheet Import Example by David WithersSusan
Example using the SpreadsheetImport service to import data from an Excel spreadsheet.
The workflow imports the file spreadsheet file WaterUse.xlsx and generates a graph from the date.
The source data is from http://data.gov.uk/
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (1)
Descriptions (1)
Based on Spreadsheet Import Example by David WithersSusan
Example using the SpreadsheetImport service to import data from an Excel spreadsheet.
The workflow imports the file spreadsheet file WaterUse.xlsx and generates a graph from the date.
The source data is from http://data.gov.uk/ |
Dependencies (0)
Processors (5)
Name |
Type |
Description |
SpreadsheetImport |
spreadsheet |
Modified columns and rows for spreadsheet import service:
Columns B to F and Rows 5 to 54.
Row 5 is key as it pulls the header info to be used later in the legend on the graph.
Added new ports to reflect the header:
Nitrogen, Phosphate, Potash, Total and Year. |
GenerateGraphURL |
beanshell |
Modified the script to more appropriately "scale" the output and the units:
sb.append(",2|1,0,25");
sb.append("&chds=0,25000");
sb.append("&chxl=2:|1000%20nutrient%20tons"); ScriptStringBuilder sb = new StringBuilder();
sb.append("http://chart.apis.google.com/chart?");
sb.append("cht=bvg");
sb.append("&chs=1000x300");
sb.append("&ch=");
sb.append("&chxt=x,y,y");
sb.append("&chbh=3,1,3");
sb.append("&chxr=0,");
sb.append(Float.parseFloat(years.get(0)).intValue());
sb.append(",");
sb.append(Float.parseFloat(years.get(years.size() - 1)).intValue());
sb.append(",2|1,0,25");
sb.append("&chds=0,25000");
sb.append("&chxl=2:|1000%20nutrient%20tons");
sb.append("&chxp=2,50");
sb.append("&chco=FF0000,00FF00,0000FF");
sb.append("&chdl=");
for (int i = 0; i < headers.size(); i++) {
sb.append(headers.get(i).replace(" ", "%20"));
if (i+1 < data.size()) {
sb.append("|");
}
}
if (title != void) {
sb.append("&chtt=");
sb.append(type);
}
if (data != void) {
sb.append("&chd=t:");
for (int i = 0; i < data.size(); i++) {
List data1 = (List) data.get(i);
for (int j = 0; j < data1.size(); j++) {
Float value = Float.parseFloat(data1.get(j));
sb.append(value.intValue());
if (j+1 < data1.size()) {
sb.append(",");
}
}
if (i+1 < data.size()) {
sb.append("|");
}
}
}
graphURL = sb.toString(); |
Get_Image_From_URL |
localworker |
gets the image using the URL from the GenerateGraphURL service. ScriptURL inputURL = null;
if (base != void) {
inputURL = new URL(new URL(base), url);
} else {
inputURL = new URL(url);
}
byte[] contents;
if (inputURL.openConnection().getContentLength() == -1) {
// Content size unknown, must read first...
byte[] buffer = new byte[1024];
int bytesRead = 0;
int totalBytesRead = 0;
InputStream is = inputURL.openStream();
while (bytesRead != -1) {
totalBytesRead += bytesRead;
bytesRead = is.read(buffer, 0, 1024);
}
contents = new byte[totalBytesRead];
} else {
contents = new byte[inputURL.openConnection().getContentLength()];
}
int bytesRead = 0;
int totalBytesRead = 0;
InputStream is = inputURL.openStream();
while (bytesRead != -1) {
bytesRead = is.read(contents, totalBytesRead, contents.length - totalBytesRead);
totalBytesRead += bytesRead;
if (contents.length==totalBytesRead) break;
}
image = contents;
|
Beanshell |
beanshell |
Adds headers and data for to be added to GenerateGraphURL service:
year
Nitrogen
Phosphate
Potash
total
All of depth 1 as they are lists.
Modified the script to reflect these new headers and the data to be imported. Scriptdata = new ArrayList();
headers = new ArrayList();
headers.add(year.remove(0));
headers.add(Nitrogen.remove(0));
headers.add(Phosphate.remove(0));
headers.add(Potash.remove(0));
headers.add(total.remove(0));
data.add(year);
data.add(Nitrogen);
data.add(Phosphate);
data.add(Potash);
data.add(total);
year.remove(0);
years = year; |
url_value |
stringconstant |
URL for spreadsheet to be imported:
http://www.myexperiment.org/files/568/download/FertilizerUse.xls Valuehttp://www.myexperiment.org/files/568/download/FertilizerUse.xls |
Beanshells (2)
Name |
Description |
Inputs |
Outputs |
GenerateGraphURL |
Modified the script to more appropriately "scale" the output and the units:
sb.append(",2|1,0,25");
sb.append("&chds=0,25000");
sb.append("&chxl=2:|1000%20nutrient%20tons"); |
title
data
headers
years
|
graphURL
|
Beanshell |
Adds headers and data for to be added to GenerateGraphURL service:
year
Nitrogen
Phosphate
Potash
total
All of depth 1 as they are lists.
Modified the script to reflect these new headers and the data to be imported. |
year
Nitrogen
Phosphate
Potash
total
|
data
headers
years
|
Datalinks (11)
Source |
Sink |
url_value:value |
SpreadsheetImport:fileurl |
Beanshell:data |
GenerateGraphURL:data |
Beanshell:headers |
GenerateGraphURL:headers |
Beanshell:years |
GenerateGraphURL:years |
GenerateGraphURL:graphURL |
Get_Image_From_URL:url |
SpreadsheetImport:Nitrogen |
Beanshell:Nitrogen |
SpreadsheetImport:Phosphate |
Beanshell:Phosphate |
SpreadsheetImport:Potash |
Beanshell:Potash |
SpreadsheetImport:total |
Beanshell:total |
SpreadsheetImport:year |
Beanshell:year |
Get_Image_From_URL:image |
graph |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1
(of 1)
Credits (2)
(People/Groups)
Attributions (0)
(Workflows/Files)
None
Shared with Groups (1)
Featured In Packs (0)
None
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment