-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
not working: test plugin pattern with yml
- Loading branch information
Showing
18 changed files
with
225 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.io.File; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import models.config.ConfigFile; | ||
|
||
public class FileReader { | ||
// public FileReader() { | ||
|
||
// } | ||
|
||
// public ConfigFile readConfig(String path) { | ||
// File file = new File("src/simulationModels/test.json"); | ||
|
||
// ObjectMapper mapper = new ObjectMapper(); | ||
// ConfigFile config = mapper.readValue(file, ConfigFile.class); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package functions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FunctionCollector { | ||
// XCompiler unable to compile <> with type <IFunction>, so left generic | ||
private List functions; | ||
|
||
public FunctionCollector() { | ||
init(); | ||
} | ||
|
||
public void init() { | ||
functions = new ArrayList(); | ||
} | ||
|
||
public void run() { | ||
for (IFunction function : functions) { | ||
function.run(); | ||
} | ||
} | ||
|
||
public void add(IFunction function) { | ||
functions.add(function); | ||
} | ||
|
||
public List getFunctions() { | ||
return functions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package functions; | ||
|
||
public class Growth implements IFunction { | ||
public void init() { | ||
println("init Growth"); | ||
} | ||
|
||
public void run() { | ||
println("run Growth"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package functions; | ||
|
||
public interface IFunction { | ||
void init(); | ||
void run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package functions; | ||
|
||
public class LightInterception implements IFunction { | ||
public void init() { | ||
println("init LightInterception"); | ||
} | ||
|
||
public void run() { | ||
println("run LightInterception"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,43 @@ | ||
import static light.*; | ||
import static organs.*; | ||
|
||
const float GOLDEN_ANGLE = 137.5; | ||
const float BRANCH_ANGLE = 50; | ||
const float LEAF_ANGLE = 70; | ||
const int PHYLLOCHRON = 1; | ||
|
||
protected void init() | ||
[ | ||
Axiom ==> Bud(1, PHYLLOCHRON, 1); | ||
// light source is placed | ||
// above the scene | ||
==>> ^ M(50) RU(180) MyLight; | ||
] | ||
public void run() | ||
[ | ||
Bud(r, p, o), (p > 0) ==> Bud(r, p-1, o); | ||
b:Bud(r, p, o), (r < 10 && p == 0 && o < 4) ==> if (forall(distance(b, (* Internode *)) > 0.6)) ( | ||
RV(-0.1) Internode Node | ||
[ RL(BRANCH_ANGLE) Bud(r, PHYLLOCHRON, o+1) ] | ||
[ RL(LEAF_ANGLE) Leaf(0f) ] | ||
RH(GOLDEN_ANGLE) RV(-0.1) Internode Bud(r+1, PHYLLOCHRON, o) | ||
); | ||
|
||
Bud(r, p, o), (r == 10) ==> RV(-0.1) Internode RV(-0.1) Internode Flower; | ||
] | ||
|
||
// light model instance | ||
// 100000: number of random rays | ||
// 5: recursion depth (nb. of reflections) | ||
LightModel lm = new LightModel(100000, 5); | ||
|
||
public void grow() { | ||
// apply growth rules | ||
run(); | ||
// compute light | ||
lm.compute(); | ||
// calculate the amount of light | ||
// (integrated over the whole spectrum), | ||
// absorbed by a leaf | ||
absorb(); | ||
} | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import models.*; | ||
import functions.*; | ||
|
||
static List organs = new ArrayList(); | ||
|
||
protected void init() { | ||
|
||
Leaf leaf = new Leaf(); | ||
File organConfig = new File("/var/model/src/organConfig.yml"); | ||
|
||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
JsonNode organTree = mapper.readTree(organConfig); | ||
|
||
for (JsonNode organNode : organTree) { | ||
// Create organ instances | ||
String organName = organNode.get("name"); | ||
Class organClass = Class.forName(organName); | ||
GenericOrgan organ = (GenericOrgan) organClass.getDeclaredConstructor().newInstance(); | ||
|
||
JsonNode functions = organNode.get("functions"); | ||
|
||
for (JsonNode functionName : functions) { | ||
String className = functionName.asText(); | ||
Class functionClass = Class.forName(className); | ||
IFunction function = (IFunction) functionClass.getDeclaredConstructor().newInstance(); | ||
|
||
protected void absorb() [ | ||
lf:Leaf ::> { | ||
// 2.25 - conversion factor W -> PAR | ||
// (photosynthetically active radiation [mikro mol/m^2/s]) | ||
lf[al] = lm.getAbsorbedPower3d(lf).integrate() * 2.25; | ||
//println(lf[al]); | ||
organ.getCollector().add(function); | ||
} | ||
} | ||
} | ||
] | ||
public void run() { | ||
for (GenericOrgan organ : organs) { | ||
organ.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import models.GenericOrgan; | ||
|
||
public class Fruit extends GenericOrgan { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package models; | ||
|
||
import functions.FunctionCollector; | ||
|
||
public abstract class GenericOrgan { | ||
private FunctionCollector collector; | ||
|
||
public FunctionCollector getCollector() { | ||
return collector; | ||
} | ||
|
||
public void run() { | ||
collector.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import models.GenericOrgan; | ||
|
||
public class Leaf extends GenericOrgan { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package models.config; | ||
|
||
public class BooleanField extends Field { | ||
|
||
private boolean value; | ||
|
||
public BooleanField(String name, boolean value) { | ||
super(name); | ||
this.value = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package models.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
|
||
public class ConfigFile { | ||
private Map fields; | ||
|
||
public ConfigFile() { | ||
fields = new HashMap(); | ||
} | ||
|
||
@JsonAnySetter | ||
public void addField(String name, String value) { | ||
fields.put(name, value); | ||
} | ||
|
||
public Map getFields() { | ||
return fields; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package models.config; | ||
|
||
abstract class Field { | ||
private String name; | ||
|
||
public Field(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
leaf: | ||
name: models.Leaf | ||
functions: | ||
- functions.Growth | ||
- functions.LightInterception | ||
|
||
fruit: | ||
name: models.Fruit | ||
functions: | ||
- functions.Growth |
Oops, something went wrong.