Name |
Type |
Description |
Concatenate_two_strings |
localworker |
Scriptoutput = string1 + string2; |
String_constant |
stringconstant |
Valuepop_ |
Rshell |
rshell |
Script#the source datafile with all the population and disability count details
datafile <- read.csv(datafile)
#rename the pop_'year' column
names(datafile)[names(datafile)==year]<-"population"
#only keep the rows in the required district
datafile <- subset(datafile, datafile$zonename == district )
#intercept slopes from the regression calculations
datafile$a <- ifelse(datafile$sex==2,alpha_female, alpha_male)
datafile$b <- ifelse(datafile$sex==2,beta_female, beta_male)
#logit llti schedules based on the 2001 census data
datafile$logit_LLTI <- 0.5*log(datafile$llti_2001/(1-datafile$llti_2001))
datafile$logit_mod<-datafile$a+(datafile$b*datafile$logit_LLTI)
#mobility rates based on the regression
datafile$modelled <- (exp(2*datafile$logit_mod))/(1+exp(2*datafile$logit_mod))
#sort the data
datafile <- datafile[with(datafile, order(sex, zonecode, age)), ]
#pop for the year, district and disability based on the model
datafile$pop<-datafile$population*datafile$modelled
datafile <- datafile[with(datafile, order(zonecode)), ]
library(doBy)
#sum the calculated population
disab_tot_rel <- summaryBy(pop~zonecode,data=datafile, FUN=c(sum),full.dimension=TRUE)
datafile$disab_tot_rel <- disab_tot_rel$pop.sum
#sum the total population
pop_tot <- summaryBy(population~zonecode,data=datafile, FUN=c(sum),full.dimension=TRUE)
datafile$pop_tot <- pop_tot$population.sum
#remove any duplicate rows
datafile <- datafile[!duplicated(datafile[c("zonecode")]),]
result_data <- subset(datafile, select = c(zonecode,zonename,disab_tot_rel,pop_tot))
result_data$prev <- (result_data$disab_tot_rel/result_data$pop_tot)*100
pct_out <- result_data$prev
disab_tot_out <- result_data$disab_tot_rel
pop_tot_out <- result_data$pop_tot R Serverlocalhost:6311 |
Beanshell |
beanshell |
Scriptswitch (disability_type) {
case "mobility": alpha_male = -0.35111117;
alpha_female = -0.2969268;
beta_male = 1.080914;
beta_female = 1.093486;
break;
case "sight": alpha_male = -1.461451;
alpha_female = -1.290565;
beta_male = 0.8534907;
beta_female = 0.8893959;
break;
case "hearing": alpha_male = -0.8751972;
alpha_female = -1.070253;
beta_male = 0.9570509;
beta_female = 0.9561629;
break;
case "disability": alpha_male = -0.1361027;
alpha_female = -0.1242042;
beta_male = 1.019565;
beta_female = 1.016297;
break;
case "pcare": alpha_male = -0.8308756;
alpha_female = -0.8240076;
beta_male = 0.7947015;
beta_female = 0.8196615;
break;
} |
Split_string_into_string_list_by_regular_expression |
localworker |
ScriptList split = new ArrayList();
if (!string.equals("")) {
String regexString = ",";
if (regex != void) {
regexString = regex;
}
String[] result = string.split(regexString);
for (int i = 0; i < result.length; i++) {
split.add(result[i]);
}
}
|
split_by_line |
stringconstant |
Value\n |
methodbox_url |
stringconstant |
Valuehttps://methodbox.org |
data_download_url |
stringconstant |
Valuedata_extracts/402-census-and-hse-mix/download?type=CSV |
Get_Web_Page_from_URL_2 |
localworker |
ScriptURL inputURL = null;
if (base != void) {
inputURL = new URL(new URL(base), url);
}
else {
inputURL = new URL(url);
}
URLConnection con = inputURL.openConnection();
InputStream in = con.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
Reader inReader = new BufferedReader(isr);
StringBuffer buf = new StringBuffer();
int ch;
while ((ch = inReader.read()) > -1) {
buf.append((char)ch);
}
inReader.close();
contents = buf.toString();
//String NEWLINE = System.getProperty("line.separator");
//
//URL inputURL = null;
//if (base != void) {
// inputURL = new URL(new URL(base), url);
//} else {
// inputURL = new URL(url);
//}
//StringBuffer result = new StringBuffer();
//BufferedReader reader = new BufferedReader(new InputStreamReader(inputURL.openStream()));
//String line = null;
//while ((line = reader.readLine()) != null) {
// result.append(line);
// result.append(NEWLINE);
//}
//
//contents = result.toString();
|
unzip_file |
beanshell |
Scriptimport *;
File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".csv");
BufferedOutputStream dest = null;
FileOutputStream unzippedDatafile = null;
FileInputStream fis = new FileInputStream(zipped_datafile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while((entry = zis.getNextEntry()) != null) {
if (entry.getName().endsWith(".csv")) {
int count;
data = new byte[2048];
// write the files to the disk
FileOutputStream unzippedDatafile = new FileOutputStream(tempFile);
dest = new BufferedOutputStream(unzippedDatafile, 2048);
while ((count = zis.read(data, 0, 2048)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
}
zis.close(); |
Write_Text_File |
localworker |
ScripttempFile = File.createTempFile(UUID.randomUUID().toString(), ".zip");
BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
out.write(filecontents);
out.close();
outputFile = tempFile.getAbsolutePath();
|
Comments (1)
Log in to make a comment
At the moment the workflow only runs on mac osx and unix due to an issue with reading files on windows. I hope to sort that in the future.
There is an example of using this workflow integrated into a web service using taverna server at http://sae.methodbox.org