Branch creator: Difference between revisions

From Opasnet
Jump to navigation Jump to search
Line 41: Line 41:
name:data.ovariable|description:Give a short name (no spaces!) for an ovariable with data|type:text|
name:data.ovariable|description:Give a short name (no spaces!) for an ovariable with data|type:text|
category:Content for a new ovariable with data|category_conditions:newdata;TRUE|
category:Content for a new ovariable with data|category_conditions:newdata;TRUE|
name:t2bdata|description:Give a data table for the input variable (under construction!)|type:table|
name:unit|description:What is(are) the unit(s) of the data?|type:text|default:-|
name:t2bdata|description:Give a data table for the input variable.|type:table|
name:data.rationale|description:Give free-text rationale about what the data ovariable is and where the data comes from.|type:textbox|
name:data.rationale|description:Give free-text rationale about what the data ovariable is and where the data comes from.|type:textbox|
name:formula.ovariable|description:Give a short name (no spaces!) to an ovariable with a formula.|type:text|
name:formula.ovariable|description:Give a short name (no spaces!) to an ovariable with a formula.|type:text|
Line 57: Line 58:
## output.ovariable: name of the ovariable that calculates the final output of this branch. The name is used in the Answer code.
## output.ovariable: name of the ovariable that calculates the final output of this branch. The name is used in the Answer code.
## data.ovariable: name of an ovariable that takes data as input
## data.ovariable: name of an ovariable that takes data as input
## unit: unit(s) of the data
## t2bdata: table of data to be converted in the data slot of the variable
## t2bdata: table of data to be converted in the data slot of the variable
## data.rationale: textbox of description for data.ovariable
## data.rationale: textbox of description for data.ovariable
Line 65: Line 67:


library(OpasnetUtils)
library(OpasnetUtils)
t2bdata <- ""
 
#wiki_username <- "Jouni"
#wiki_username <- "Jouni"
#branchname <- "Garden tower branch"
#branchname <- "Garden tower branch"
Line 132: Line 134:


if(newdata) {
if(newdata) {
newdata <- paste(
# Take the data out of the input
dat <- as.matrix(t2bdata[-1 , ])
dat <- apply(dat, 1, paste, collapse = "|")
dat <- paste(dat, "
",
sep = "")
 
# Find parameter values for t2b tag.
cols <- as.matrix(t2bdata)[1 , ]
 
# Find column(s) with results: has name Result, has semicolons, or is the last one.
rescols <- tolower(cols) %in% "result"
if(!any(rescols)) {
rescols <- grepl(":", cols)
}
if(!any(rescols)) {
rescols <- 1:length(cols) == length(cols)
}
 
# Indices are to the left from rescols, descriptions are to the right.
firstres <- min(grep(TRUE, rescols))
if(firstres > 1) indices <- cols[1:(firstres-1)] else indices <- character()
lastres <- max(grep(TRUE, rescols))
if(lastres < length(cols)) desc <- cols[(lastres+1):length(cols)] else desc <- character()
 
resnames <- strsplit(cols[rescols], split = ":")
 
# If only one rescol
## If first is Splittable
### If first is Result then no index, last is obs else add first as index, last is locations
## If nonsplittable then no index, last is obs
# If more than one rescol, then first is always splittable
## Add first as index, last is locations
if("result" == tolower(resnames[[1]][1]) | length(resnames[[1]]) == 1) {
res <- paste(c("obs='", resnames[[1]][length(resnames[[1]])], "'"), collapse = "")
} else {
indices <- c(indices, resnames[[1]][1])
resnames <- sapply(resnames, FUN = function(x) {return(x[length(x)])})
res <- paste(c(" locations='", paste(resnames, collapse = ","), "'"), collapse = "")
}
if(length(indices) > 0) {
indices <- paste(c("index='", paste(indices, collapse = ","), "'"), collapse = "")
}
if(length(desc) > 0) {
desc <- paste(c("desc='", paste(desc, collapse = ","), "'"), collapse = "")
}
out <- paste(c(
"¤t2b",
indices,
res,
desc,
paste(c("unit='", unit, "'"), collapse = ""),
">"),
collapse = " "
)
out <- c(out, "
",
dat, "¤/t2b>
")
 
newdata <- paste(c(
"=== ",
"=== ",
data.ovariable,
data.ovariable,
Line 138: Line 200:


",
",
t2bdata,
out,
"¤rcode name='",
"¤rcode name='",
data.ovariable,
data.ovariable,
Line 175: Line 237:
data.rationale,
data.rationale,
"
"
",
"),
sep = ""
collapse = ""
)
)
}
}

Revision as of 08:38, 12 March 2016



Question

How to create a branch for handprinter?

Answer

Step 1: Create a page for branch

If the branch that you are working with already has a page, open the page for editing and go to step 2.


Open two copies of this page to your browser. Give a name to your branch and click to create a new page for it. On the other page, continue from step 2.

<createbox> break=yes width=50 buttonlabel=Create branch align=left </createbox>

Step 2: Fill in data about your branch

In step 2, you can create a new branch page or add more ovariables to an existing page. Fill in the form below, click to create content for the page, and copy-paste that onto the page you created in step 1.

Each branch is a model that consists of sub-models called ovariables. If you don´t know what they are, you should first read pages Ovariable and Modelling in Opasnet.

If you need more ovariables for your branch model, you can simply rerun this code. Just remember to copy-paste the previous content first, as it will be replaced by the new ovariables. Each ovariable has its own sub-heading under the heading "Rationale".

Do you want to create content for a new branch page?:

Do you want to create content for a new ovariable with data?:

Do you want to create content for a new ovariable with a formula?:

Content for a new branch page

What was the branch name again?:

What again is the name of the ovariable that is the final outcome of the branch?:

Content for a new ovariable with data

Give a short name (no spaces!) for an ovariable with data:

What is(are) the unit(s) of the data?:

Give a data table for the input variable.:

Cancel

Give free-text rationale about what the data ovariable is and where the data comes from.:

Content for a new ovariable with formula

Give a short name (no spaces!) to an ovariable with a formula.:

What are the input (parent or upstream) ovariables for this ovariable? Format c('var1', 'var2'):

What is the formula that defines the calculations with the parents?:

Give free-text rationale about what the outcome variable is and how it is calculated.:

+ Show code

Step 3. Finalize the page

In step 2, page content is compiled. You can rerun the step 2 code as many times as you need to define all the ovariables. Remember to copy-paste the outputs each time to the branch page.

In the end, you have to adjust the page content, because there is a tiny error that has not yet been fixed. In the text produced, there is an extra space in tags "< rcode" and "< /rcode" and sign "< -". You should find and replace them with "<rcode", "</rcode", and "<-", respectively. Then you can save your page.

See also

Related files