Branch creator: Difference between revisions
(temporary step 3 added) |
(→Answer) |
||
Line 28: | Line 28: | ||
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. | 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 | 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". | 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". | ||
Line 38: | Line 38: | ||
name:branchname|description:What was the branch name again?|type:text| | name:branchname|description:What was the branch name again?|type:text| | ||
category:Content for a new branch page|category_conditions:newpage;TRUE| | category:Content for a new branch page|category_conditions:newpage;TRUE| | ||
name:output. | name:output.ovariable|description:What again is the name of the ovariable that is the final outcome of the branch?|type:text| | ||
name: | 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:t2bdata|description:Give a data table for the input variable (under construction!)|type:table| | ||
name: | name:data.rationale|description:Give free-text rationale about what the data ovariable is and where the data comes from.|type:textbox| | ||
name: | name:formula.ovariable|description:Give a short name (no spaces!) to an ovariable with a formula.|type:text| | ||
category:Content for a new ovariable with formula|category_conditions:newformula;TRUE| | category:Content for a new ovariable with formula|category_conditions:newformula;TRUE| | ||
name:dependencies|description:What are the input (parent or upstream) ovariables for this ovariable? Format c('var1', 'var2')|type:default| | name:dependencies|description:What are the input (parent or upstream) ovariables for this ovariable? Format c('var1', 'var2')|type:default| | ||
name:formula|description:What is the formula that defines the calculations with the parents?|type:textbox| | name:formula|description:What is the formula that defines the calculations with the parents?|type:textbox| | ||
name: | name:formula.rationale|description:Give free-text rationale about what the outcome variable is and how it is calculated.|type:textbox | ||
"> | "> | ||
# This is code Op_en7457/fill on page [[Branch creator]] | |||
# Parameters: | |||
## newpage: TRUE if a new page is being created | |||
## newdata: TRUE if a new data-based (from t2b) ovariable is being created | |||
## newformula: TRUE if a new formula-based ovariable is being created | |||
## branchname: name of the branch | |||
## 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 | |||
## t2bdata: table of data to be converted in the data slot of the variable | |||
## data.rationale: textbox of description for data.ovariable | |||
## formula.ovariable: name of an ovariable based on formula and dependencies | |||
## dependencies: character vector of the names of dependencies | |||
## formula: the body of the formula (should contain the function 'return' in the end) | |||
## formula.rationale: textbox of description for formula.ovariable | |||
library(OpasnetUtils) | library(OpasnetUtils) | ||
Line 55: | Line 69: | ||
#branchname <- "Garden tower branch" | #branchname <- "Garden tower branch" | ||
#PAGEID <- "1234" | #PAGEID <- "1234" | ||
# | #formula.ovariable <- "gardentower" | ||
# | #data.ovariable <- "vegeproduction" | ||
#dependencies <- c("vegeproduction", "wasteproduction", "waterconsumption") | #dependencies <- c("vegeproduction", "wasteproduction", "waterconsumption") | ||
# | #formula.rationale <- "Garden tower composts kitchen waste and turns it into soil." | ||
# | #data.rationale <- "vegeproduction is the amount of vegetables produced in the garden tower. It is a critical benefit that reduces consumption of other products and thus footprint." | ||
#<t2b name='Tire inflation parameters' index='Parameter,Unit' obs='Result' unit='-'> | #<t2b name='Tire inflation parameters' index='Parameter,Unit' obs='Result' unit='-'> | ||
Line 72: | Line 85: | ||
if(newpage) { | if(newpage) { | ||
newpage <- paste("[[Category:Life cycle assessment]] | newpage <- paste("[[Category:Life cycle assessment]] | ||
[[Category:Handprinter]] | [[Category:Handprinter]] | ||
{{method|moderator=", | {{method|moderator=", | ||
wiki_username, | wiki_username, | ||
"}} | "}} | ||
", | ", | ||
"'''{{PAGENAME}}''' is a '''branch''' of Handprinter. This page is a test case how to manage branches. | "'''{{PAGENAME}}''' is a '''branch''' of Handprinter. This page is a test case how to manage branches. | ||
== Question == | == Question == | ||
How to estimate the life-cycle impacts of '''{{PAGENAME}}'''? | How to estimate the life-cycle impacts of '''{{PAGENAME}}'''? | ||
== Answer == | == Answer == | ||
@rcode embed=1 variables=' | @rcode embed=1 variables=' | ||
name:PAGEID|type:hidden|default:`{{PAGEID}}` | name:PAGEID|type:hidden|default:`{{PAGEID}}` | ||
'> | '> | ||
# This is code Op_enXXXX/ on page [[", | # This is code Op_enXXXX/ on page [[", | ||
branchname, | branchname, | ||
"]] | "]] | ||
library(OpasnetUtils) | library(OpasnetUtils) | ||
objects.latest(paste('Op_en', PAGEID, sep = ''), code_name = '", | objects.latest(paste('Op_en', PAGEID, sep = ''), code_name = '", | ||
output. | output.ovariable, | ||
"') | "') | ||
", | ", | ||
output. | output.ovariable, | ||
" <- EvalOutput(", | " <- EvalOutput(", | ||
output. | output.ovariable, | ||
") | ") | ||
oprint(summary(", | oprint(summary(", | ||
output. | output.ovariable, | ||
")) | ")) | ||
@/rcode> | @/rcode> | ||
== Rationale == | == Rationale == | ||
", | ", | ||
sep = "") | sep = "" | ||
) | |||
} | } | ||
if( | if(newdata) { | ||
newdata <- paste( | |||
"=== ", | |||
data.ovariable, | |||
" === | |||
", | |||
"=== ", | t2bdata, | ||
"@rcode name='", | |||
" = | data.ovariable, | ||
"' embed=1 label='Initiate ", | |||
data.ovariable, | |||
" (for developers only)' variables=' | |||
name:PAGEID|type:hidden|default:`{{PAGEID}}` | |||
'> | |||
# This is code Op_enXXXX/ on page [[add page name here]]", | |||
data.ovariable, | |||
" on page [[", | |||
branchname, | |||
"]] | |||
library(OpasnetUtils) | |||
", | |||
data.ovariable, | |||
"' | " <- Ovariable('", | ||
data.ovariable, | |||
" ( | "', | ||
ddata = paste('Op_en', PAGEID, sep = ''), | |||
' | subset = '", | ||
data.ovariable, | |||
"') | |||
" | |||
", | objects.store(", | ||
data.ovariable, | |||
" | ") | ||
cat('", | |||
" | data.ovariable, | ||
"stored.@@') | |||
", | |||
"@/rcode> | |||
" | ", | ||
data.rationale, | |||
" | |||
", | |||
sep = "" | |||
) | |||
} | |||
if(newformula) { | |||
", | newformula <- paste( | ||
"=== ", | |||
formula.ovariable, | |||
" === | |||
@rcode name='", | |||
formula.ovariable, | |||
"== | "' embed=1 label='Initiate ", | ||
formula.ovariable, | |||
" | " (for developers only)'> | ||
# This is code Op_enXXXX/ on page [[add page name here]]", | |||
formula.ovariable, | |||
" on page [[", | |||
branchname, | |||
"]] | |||
library(OpasnetUtils) | |||
", | ", | ||
formula.ovariable, | |||
" | " <- Ovariable('", | ||
formula.ovariable, | |||
"' | "', | ||
dependencies = data.frame( | |||
" | Name = c('", | ||
paste(dependencies, collapse = "', '"), | |||
"') | |||
), | |||
formula = function(...) { | |||
" | ", | ||
formula, | |||
" } | |||
) | |||
objects.store(", | |||
formula.ovariable, | |||
") | |||
cat('Objects ',", | |||
" | formula.ovariable, | ||
", ' stored.@@') | |||
@/rcode> | |||
") | |||
", | |||
formula.rationale, | |||
" | |||
" | |||
", | |||
sep = "" | |||
", | ) | ||
sep = "") | |||
} | } | ||
finale <- paste( | finale <- paste( | ||
"== See also == | "== See also == | ||
* [[Handprinter]] | * [[Handprinter]] | ||
* [[Developing branches]] | * [[Developing branches]] | ||
", | ", | ||
"== Related files == | "== Related files == | ||
", | ", | ||
sep = "") | sep = "" | ||
) | |||
text1 <- "" | text1 <- "" | ||
Line 239: | Line 259: | ||
=== Step 3. Finalize the page === | === Step 3. Finalize the page === | ||
In step 2, page content is created. | In step 2, page content is created. 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". You should find and replace them with "<rcode" and "</rcode", respectively. Then you can save your page. | |||
== See also == | == See also == |
Revision as of 11:50, 10 March 2016
Moderator:Jouni (see all) |
|
Upload data
|
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".
Step 3. Finalize the page
In step 2, page content is created. 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". You should find and replace them with "<rcode" and "</rcode", respectively. Then you can save your page.