From 3284c4b252824516ba3cb4abef80b1f98b907cae Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Fri, 11 Mar 2022 16:23:52 +0000 Subject: [PATCH 01/15] Update seirs-config.yaml Update config to use namespace_name in external block --- src/main/resources/seirs-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/seirs-config.yaml b/src/main/resources/seirs-config.yaml index f898970..47a16a1 100644 --- a/src/main/resources/seirs-config.yaml +++ b/src/main/resources/seirs-config.yaml @@ -10,7 +10,7 @@ register: website: https://ror.org/04p491231 - external_object: SEIRS_model/parameters - namespace: PSU + namespace_name: PSU root: https://raw.githubusercontent.com/ path: FAIRDataPipeline/rSimpleModel/main/inst/extdata/static_params_SEIRS.csv title: Static parameters of the model From f824e879702dc5797a3ebbede20c2e6fca1f5785 Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Fri, 11 Mar 2022 19:57:34 +0000 Subject: [PATCH 02/15] Update seirs-config.yaml --- src/main/resources/seirs-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/seirs-config.yaml b/src/main/resources/seirs-config.yaml index 47a16a1..4d61c0e 100644 --- a/src/main/resources/seirs-config.yaml +++ b/src/main/resources/seirs-config.yaml @@ -1,5 +1,5 @@ run_metadata: - default_input_namespace: bram + default_input_namespace: testing description: SEIRS Model java script: | gradle run --args "${{CONFIG_DIR}}" From 8df369b8b12b38b62b7d95263a4f4909a33e41a9 Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Sat, 9 Apr 2022 10:47:53 +0100 Subject: [PATCH 03/15] Update build.gradle Update to latest version of API --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0cef5e1..2cc72f6 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ repositories { } dependencies { - implementation 'org.fairdatapipeline:api:1.0.0-beta' + implementation 'org.fairdatapipeline:api:1.0.0-rc1' implementation 'com.opencsv:opencsv:5.5.2' implementation('org.slf4j:slf4j-simple:1.7.25') } From 5026d595945fa6b6b75ed83541fba5eebf3a490b Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Fri, 8 Apr 2022 18:30:44 +0100 Subject: [PATCH 04/15] give it a package name --- .../fairdatapipeline/javasimplemodel/JavaSimpleModel.java} | 4 +++- .../fairdatapipeline/javasimplemodel}/PrepareParams.java | 2 ++ .../{ => org/fairdatapipeline/javasimplemodel}/SEIRS.java | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) rename src/main/java/{main.java => org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java} (95%) rename src/main/java/{ => org/fairdatapipeline/javasimplemodel}/PrepareParams.java (95%) rename src/main/java/{ => org/fairdatapipeline/javasimplemodel}/SEIRS.java (99%) diff --git a/src/main/java/main.java b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java similarity index 95% rename from src/main/java/main.java rename to src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java index a7252ae..45eb1ee 100644 --- a/src/main/java/main.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java @@ -1,7 +1,9 @@ +package org.fairdatapipeline.javasimplemodel; + import java.io.File; import java.nio.file.Path; -public class main { +public class JavaSimpleModel { public static void main(String[] args) { //System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); if(System.getenv("FDP_LOCAL_TOKEN") == null) { diff --git a/src/main/java/PrepareParams.java b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java similarity index 95% rename from src/main/java/PrepareParams.java rename to src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java index 6b6ea79..201618e 100644 --- a/src/main/java/PrepareParams.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java @@ -1,3 +1,5 @@ +package org.fairdatapipeline.javasimplemodel; + import org.fairdatapipeline.api.*; import java.nio.file.Path; diff --git a/src/main/java/SEIRS.java b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java similarity index 99% rename from src/main/java/SEIRS.java rename to src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java index a76f74f..68fd296 100644 --- a/src/main/java/SEIRS.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java @@ -1,3 +1,5 @@ +package org.fairdatapipeline.javasimplemodel; + import com.opencsv.exceptions.CsvValidationException; import org.fairdatapipeline.api.*; import org.fairdatapipeline.file.CleanableFileChannel; From a881aeccaa25ddd2bfbf584bd7380aeba2bfe65c Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Fri, 8 Apr 2022 20:05:38 +0100 Subject: [PATCH 05/15] update dependencies --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 2cc72f6..d0b70d9 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ repositories { dependencies { implementation 'org.fairdatapipeline:api:1.0.0-rc1' - implementation 'com.opencsv:opencsv:5.5.2' - implementation('org.slf4j:slf4j-simple:1.7.25') + implementation 'com.opencsv:opencsv:5.6' + implementation('org.slf4j:slf4j-simple:1.7.36') } From 644d87d70598da726c6a430813c2c4a38e5b6930 Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Fri, 8 Apr 2022 20:06:02 +0100 Subject: [PATCH 06/15] some code improvements --- .../javasimplemodel/JavaSimpleModel.java | 12 ++-- .../javasimplemodel/PrepareParams.java | 2 - .../javasimplemodel/SEIRS.java | 68 +++++++++---------- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java index 45eb1ee..6c54efc 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java @@ -3,10 +3,12 @@ import java.io.File; import java.nio.file.Path; + public class JavaSimpleModel { + private static final String ENV_VAR_NAME = "FDP_LOCAL_TOKEN"; + public static void main(String[] args) { - //System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); - if(System.getenv("FDP_LOCAL_TOKEN") == null) { + if(System.getenv(ENV_VAR_NAME) == null) { System.err.println("The fair CLI needs to set the environment variable FDP_LOCAL_TOKEN to the authorization token for the local registry"); System.exit(2); } @@ -27,13 +29,13 @@ public static void main(String[] args) { Path scriptFile = Path.of(confDir).resolve("script.sh"); if(args.length == 1) { SEIRS s = new SEIRS(); - s.runFromExternal(configFile, scriptFile, System.getenv("FDP_LOCAL_TOKEN")); + s.runFromExternal(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); }else if(args[0].equals("--prepare")) { PrepareParams pp = new PrepareParams(); - pp.run(configFile, scriptFile, System.getenv("FDP_LOCAL_TOKEN")); + pp.run(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); }else if(args[0].equals("--seirsFromPrepared")) { SEIRS s = new SEIRS(); - s.runFromPrepared(configFile, scriptFile, System.getenv("FDP_LOCAL_TOKEN")); + s.runFromPrepared(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); }else { System.err.println("Usage: gradle run --args=\"[{--seirsFromPrepared,--prepare}] configDir\""); System.exit(1); diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java index 201618e..32219a1 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java @@ -6,8 +6,6 @@ public class PrepareParams { - public void PrepareParams() {} - public void run(Path configPath, Path scriptPath, String regtoken) { try (Coderun cr = new Coderun(configPath, scriptPath, regtoken)){ Data_product_write dp = cr.get_dp_for_write("SEIRS_model/preparedParams"); diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java index 68fd296..587676a 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java @@ -4,7 +4,6 @@ import org.fairdatapipeline.api.*; import org.fairdatapipeline.file.CleanableFileChannel; -import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -14,6 +13,8 @@ import java.util.HashMap; import java.util.Map; import com.opencsv.CSVReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /****************************************************************************** * SEIRS ODE model in Java @@ -24,12 +25,13 @@ ******************************************************************************/ class SEIRS { - - - public void SEIRS(){ - - } - + private static final Logger logger = LoggerFactory.getLogger(SEIRS.class); + private static final String INV_G = "inv_gamma"; + private static final String INV_S = "inv_sigma"; + private static final String INV_O = "inv_omega"; + private static final String INV_M = "inv_mu"; + private static final String ALPHA = "alpha"; + private static final String BETA = "beta"; public void runFromExternal(Path configPath, Path scriptPath, String regToken) { try(Coderun cr = new Coderun(configPath, scriptPath, regToken)) { @@ -38,26 +40,24 @@ public void runFromExternal(Path configPath, Path scriptPath, String regToken) { try { Path filepath = dp.getComponent().readLink(); FileReader fr = new FileReader(filepath.toString()); - CSVReader r = new CSVReader(fr); - String[] line; - int i = 0; - r.readNext(); // ignore header - while ((line = r.readNext()) != null) { - params.put(line[0], Double.parseDouble(line[1])); - i += 1; + try(CSVReader r = new CSVReader(fr)) { + String[] line; + r.readNext(); // ignore header + while ((line = r.readNext()) != null) { + params.put(line[0], Double.parseDouble(line[1])); + } } }catch(FileNotFoundException e){ - System.out.println("FileNotFoundException: can't find the file: " + e); - e.printStackTrace(); + logger.error("FileNotFoundException: can't find the file.", e); System.exit(1); }catch(IOException e) { - System.out.println("error reading parameter CSV: " + e); + logger.error("error reading parameter CSV.", e); System.exit(1); }catch(CsvValidationException e){ - System.out.println("bad CSV: " + e); + logger.error("bad CSV.", e); System.exit(1); }catch(Exception e) { - System.out.print("Exception reading parameters: " + e); + logger.error("Exception reading parameters: ", e); System.exit(1); } @@ -71,7 +71,7 @@ public void runFromExternal(Path configPath, Path scriptPath, String regToken) { CleanableFileChannel f = dpw.getComponent().writeFileChannel(); do_SEIRS(params, f); }catch(IOException e) { - System.err.println("failed to write output to file: " + e); + logger.error("failed to write output to file: ", e); } } @@ -86,19 +86,19 @@ public void runFromPrepared(Path configPath, Path scriptPath, String regToken) { params.put("E", (Double) dp.getComponent("E").readEstimate()); params.put("I", (Double) dp.getComponent("I").readEstimate()); params.put("R", (Double) dp.getComponent("R").readEstimate()); - params.put("inv_gamma", (Double) dp.getComponent("inv_gamma").readEstimate()); - params.put("inv_sigma", (Double) dp.getComponent("inv_sigma").readEstimate()); - params.put("inv_omega", (Double) dp.getComponent("inv_omega").readEstimate()); - params.put("inv_mu", (Double) dp.getComponent("inv_mu").readEstimate()); - params.put("beta", (Double) dp.getComponent("beta").readEstimate()); - params.put("alpha", (Double) dp.getComponent("alpha").readEstimate()); + params.put(INV_G, (Double) dp.getComponent(INV_G).readEstimate()); + params.put(INV_S, (Double) dp.getComponent(INV_S).readEstimate()); + params.put(INV_O, (Double) dp.getComponent(INV_O).readEstimate()); + params.put(INV_M, (Double) dp.getComponent(INV_M).readEstimate()); + params.put(BETA, (Double) dp.getComponent(BETA).readEstimate()); + params.put(ALPHA, (Double) dp.getComponent(ALPHA).readEstimate()); Data_product_write dpw = cr.get_dp_for_write("SEIRS_model/results/fromPreparedParams"); try { CleanableFileChannel f = dpw.getComponent().writeFileChannel(); do_SEIRS(params, f); }catch(IOException e) { - System.err.println("failed to write output to file: " + e); + logger.error("failed to write output to file.", e); } } @@ -106,7 +106,7 @@ public void runFromPrepared(Path configPath, Path scriptPath, String regToken) { void do_SEIRS(Map params, CleanableFileChannel f) throws IOException { - double N = 1.0; + double N; int total_time = 5 * 365; // 5 years int step_per_day_int = 2; @@ -133,12 +133,12 @@ void do_SEIRS(Map params, CleanableFileChannel f) throws IOExcep time[0] = 0; - double inv_gamma = params.get("inv_gamma"); - double inv_sigma = params.get("inv_sigma"); - double inv_omega = params.get("inv_omega"); - double inv_mu = params.get("inv_mu"); - double beta = params.get("beta"); - double alpha= params.get("alpha"); + double inv_gamma = params.get(INV_G); + double inv_sigma = params.get(INV_S); + double inv_omega = params.get(INV_O); + double inv_mu = params.get(INV_M); + double beta = params.get(BETA); + double alpha= params.get(ALPHA); double gamma_d = 1 / inv_gamma; From 73005b40cdaf77e0f6eeb341f085d5b6cabb0944 Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Mon, 18 Apr 2022 15:21:56 +0100 Subject: [PATCH 07/15] spotless 6.4.2 added to gradle; and applied --- build.gradle | 6 + .../javasimplemodel/JavaSimpleModel.java | 72 +++-- .../javasimplemodel/PrepareParams.java | 32 +- .../javasimplemodel/SEIRS.java | 305 +++++++++--------- 4 files changed, 210 insertions(+), 205 deletions(-) diff --git a/build.gradle b/build.gradle index d0b70d9..50ef0ce 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'application' + id "com.diffplug.spotless" version "6.4.2" } group 'org.example' @@ -19,3 +20,8 @@ dependencies { implementation('org.slf4j:slf4j-simple:1.7.36') } +spotless { + java { + googleJavaFormat() + } +} \ No newline at end of file diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java index 6c54efc..16b7e71 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/JavaSimpleModel.java @@ -3,42 +3,44 @@ import java.io.File; import java.nio.file.Path; - public class JavaSimpleModel { - private static final String ENV_VAR_NAME = "FDP_LOCAL_TOKEN"; + private static final String ENV_VAR_NAME = "FDP_LOCAL_TOKEN"; - public static void main(String[] args) { - if(System.getenv(ENV_VAR_NAME) == null) { - System.err.println("The fair CLI needs to set the environment variable FDP_LOCAL_TOKEN to the authorization token for the local registry"); - System.exit(2); - } - String confDir = ""; - if(args.length == 1) { - confDir = args[0]; - }else if(args.length == 2) { - confDir = args[1]; - }else{ - System.err.println("Usage: gradle run --args=\"[{--seirsFromPrepared,--prepare}] configDir\""); - System.exit(1); - } - if(!new File(confDir).isDirectory()) { - System.err.println("Config dir " + confDir + " doesn't seem to exist."); - System.exit(1); - } - Path configFile = Path.of(confDir).resolve("config.yaml"); - Path scriptFile = Path.of(confDir).resolve("script.sh"); - if(args.length == 1) { - SEIRS s = new SEIRS(); - s.runFromExternal(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); - }else if(args[0].equals("--prepare")) { - PrepareParams pp = new PrepareParams(); - pp.run(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); - }else if(args[0].equals("--seirsFromPrepared")) { - SEIRS s = new SEIRS(); - s.runFromPrepared(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); - }else { - System.err.println("Usage: gradle run --args=\"[{--seirsFromPrepared,--prepare}] configDir\""); - System.exit(1); - } + public static void main(String[] args) { + if (System.getenv(ENV_VAR_NAME) == null) { + System.err.println( + "The fair CLI needs to set the environment variable FDP_LOCAL_TOKEN to the authorization token for the local registry"); + System.exit(2); + } + String confDir = ""; + if (args.length == 1) { + confDir = args[0]; + } else if (args.length == 2) { + confDir = args[1]; + } else { + System.err.println( + "Usage: gradle run --args=\"[{--seirsFromPrepared,--prepare}] configDir\""); + System.exit(1); + } + if (!new File(confDir).isDirectory()) { + System.err.println("Config dir " + confDir + " doesn't seem to exist."); + System.exit(1); + } + Path configFile = Path.of(confDir).resolve("config.yaml"); + Path scriptFile = Path.of(confDir).resolve("script.sh"); + if (args.length == 1) { + SEIRS s = new SEIRS(); + s.runFromExternal(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); + } else if (args[0].equals("--prepare")) { + PrepareParams pp = new PrepareParams(); + pp.run(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); + } else if (args[0].equals("--seirsFromPrepared")) { + SEIRS s = new SEIRS(); + s.runFromPrepared(configFile, scriptFile, System.getenv(ENV_VAR_NAME)); + } else { + System.err.println( + "Usage: gradle run --args=\"[{--seirsFromPrepared,--prepare}] configDir\""); + System.exit(1); } + } } diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java index 32219a1..deabd58 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/PrepareParams.java @@ -1,24 +1,22 @@ package org.fairdatapipeline.javasimplemodel; -import org.fairdatapipeline.api.*; - import java.nio.file.Path; - +import org.fairdatapipeline.api.*; public class PrepareParams { - public void run(Path configPath, Path scriptPath, String regtoken) { - try (Coderun cr = new Coderun(configPath, scriptPath, regtoken)){ - Data_product_write dp = cr.get_dp_for_write("SEIRS_model/preparedParams"); - dp.getComponent("S").writeEstimate(0.999); - dp.getComponent("E").writeEstimate(0.001); - dp.getComponent("I").writeEstimate(0.0); - dp.getComponent("R").writeEstimate(0.0); - dp.getComponent("inv_gamma").writeEstimate(14.0); - dp.getComponent("inv_sigma").writeEstimate(7.0); - dp.getComponent("inv_omega").writeEstimate(1.0); - dp.getComponent("inv_mu").writeEstimate(76.0); - dp.getComponent("beta").writeEstimate(0.21); - dp.getComponent("alpha").writeEstimate(0.0); - } + public void run(Path configPath, Path scriptPath, String regtoken) { + try (Coderun cr = new Coderun(configPath, scriptPath, regtoken)) { + Data_product_write dp = cr.get_dp_for_write("SEIRS_model/preparedParams"); + dp.getComponent("S").writeEstimate(0.999); + dp.getComponent("E").writeEstimate(0.001); + dp.getComponent("I").writeEstimate(0.0); + dp.getComponent("R").writeEstimate(0.0); + dp.getComponent("inv_gamma").writeEstimate(14.0); + dp.getComponent("inv_sigma").writeEstimate(7.0); + dp.getComponent("inv_omega").writeEstimate(1.0); + dp.getComponent("inv_mu").writeEstimate(76.0); + dp.getComponent("beta").writeEstimate(0.21); + dp.getComponent("alpha").writeEstimate(0.0); } + } } diff --git a/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java index 587676a..fa37c66 100644 --- a/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java +++ b/src/main/java/org/fairdatapipeline/javasimplemodel/SEIRS.java @@ -1,9 +1,7 @@ package org.fairdatapipeline.javasimplemodel; +import com.opencsv.CSVReader; import com.opencsv.exceptions.CsvValidationException; -import org.fairdatapipeline.api.*; -import org.fairdatapipeline.file.CleanableFileChannel; - import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -12,165 +10,166 @@ import java.nio.file.Path; import java.util.HashMap; import java.util.Map; -import com.opencsv.CSVReader; +import org.fairdatapipeline.api.*; +import org.fairdatapipeline.file.CleanableFileChannel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/****************************************************************************** - * SEIRS ODE model in Java - * Author: Sibylle Mohr - * Compilation: javac SEIRS.java - * Execution: java SEIRS - * SEIRS model with Euler integration - ******************************************************************************/ - +/** + * **************************************************************************** SEIRS ODE model in + * Java Author: Sibylle Mohr Compilation: javac SEIRS.java Execution: java SEIRS SEIRS model with + * Euler integration **************************************************************************** + */ class SEIRS { - private static final Logger logger = LoggerFactory.getLogger(SEIRS.class); - private static final String INV_G = "inv_gamma"; - private static final String INV_S = "inv_sigma"; - private static final String INV_O = "inv_omega"; - private static final String INV_M = "inv_mu"; - private static final String ALPHA = "alpha"; - private static final String BETA = "beta"; - - public void runFromExternal(Path configPath, Path scriptPath, String regToken) { - try(Coderun cr = new Coderun(configPath, scriptPath, regToken)) { - Map params = new HashMap<>(); - Data_product_read dp = cr.get_dp_for_read("SEIRS_model/parameters"); - try { - Path filepath = dp.getComponent().readLink(); - FileReader fr = new FileReader(filepath.toString()); - try(CSVReader r = new CSVReader(fr)) { - String[] line; - r.readNext(); // ignore header - while ((line = r.readNext()) != null) { - params.put(line[0], Double.parseDouble(line[1])); - } - } - }catch(FileNotFoundException e){ - logger.error("FileNotFoundException: can't find the file.", e); - System.exit(1); - }catch(IOException e) { - logger.error("error reading parameter CSV.", e); - System.exit(1); - }catch(CsvValidationException e){ - logger.error("bad CSV.", e); - System.exit(1); - }catch(Exception e) { - logger.error("Exception reading parameters: ", e); - System.exit(1); - } - - // set initial state: - params.put("S", 0.999); - params.put("E", 0.001); - params.put("I", 0.0); - params.put("R", 0.0); - Data_product_write dpw = cr.get_dp_for_write("SEIRS_model/results/model_output"); - try { - CleanableFileChannel f = dpw.getComponent().writeFileChannel(); - do_SEIRS(params, f); - }catch(IOException e) { - logger.error("failed to write output to file: ", e); - } - + private static final Logger logger = LoggerFactory.getLogger(SEIRS.class); + private static final String INV_G = "inv_gamma"; + private static final String INV_S = "inv_sigma"; + private static final String INV_O = "inv_omega"; + private static final String INV_M = "inv_mu"; + private static final String ALPHA = "alpha"; + private static final String BETA = "beta"; + + public void runFromExternal(Path configPath, Path scriptPath, String regToken) { + try (Coderun cr = new Coderun(configPath, scriptPath, regToken)) { + Map params = new HashMap<>(); + Data_product_read dp = cr.get_dp_for_read("SEIRS_model/parameters"); + try { + Path filepath = dp.getComponent().readLink(); + FileReader fr = new FileReader(filepath.toString()); + try (CSVReader r = new CSVReader(fr)) { + String[] line; + r.readNext(); // ignore header + while ((line = r.readNext()) != null) { + params.put(line[0], Double.parseDouble(line[1])); + } } + } catch (FileNotFoundException e) { + logger.error("FileNotFoundException: can't find the file.", e); + System.exit(1); + } catch (IOException e) { + logger.error("error reading parameter CSV.", e); + System.exit(1); + } catch (CsvValidationException e) { + logger.error("bad CSV.", e); + System.exit(1); + } catch (Exception e) { + logger.error("Exception reading parameters: ", e); + System.exit(1); + } + + // set initial state: + params.put("S", 0.999); + params.put("E", 0.001); + params.put("I", 0.0); + params.put("R", 0.0); + Data_product_write dpw = cr.get_dp_for_write("SEIRS_model/results/model_output"); + try { + CleanableFileChannel f = dpw.getComponent().writeFileChannel(); + do_SEIRS(params, f); + } catch (IOException e) { + logger.error("failed to write output to file: ", e); + } } + } + + public void runFromPrepared(Path configPath, Path scriptPath, String regToken) { + try (Coderun cr = new Coderun(configPath, scriptPath, regToken)) { + Map params = new HashMap<>(); + Data_product_read dp = cr.get_dp_for_read("SEIRS_model/preparedParams"); + params.put("S", (Double) dp.getComponent("S").readEstimate()); + params.put("E", (Double) dp.getComponent("E").readEstimate()); + params.put("I", (Double) dp.getComponent("I").readEstimate()); + params.put("R", (Double) dp.getComponent("R").readEstimate()); + params.put(INV_G, (Double) dp.getComponent(INV_G).readEstimate()); + params.put(INV_S, (Double) dp.getComponent(INV_S).readEstimate()); + params.put(INV_O, (Double) dp.getComponent(INV_O).readEstimate()); + params.put(INV_M, (Double) dp.getComponent(INV_M).readEstimate()); + params.put(BETA, (Double) dp.getComponent(BETA).readEstimate()); + params.put(ALPHA, (Double) dp.getComponent(ALPHA).readEstimate()); + + Data_product_write dpw = cr.get_dp_for_write("SEIRS_model/results/fromPreparedParams"); + try { + CleanableFileChannel f = dpw.getComponent().writeFileChannel(); + do_SEIRS(params, f); + } catch (IOException e) { + logger.error("failed to write output to file.", e); + } + } + } + void do_SEIRS(Map params, CleanableFileChannel f) throws IOException { - public void runFromPrepared(Path configPath, Path scriptPath, String regToken) { - try(Coderun cr = new Coderun(configPath, scriptPath, regToken)) { - Map params = new HashMap<>(); - Data_product_read dp = cr.get_dp_for_read("SEIRS_model/preparedParams"); - params.put("S", (Double) dp.getComponent("S").readEstimate()); - params.put("E", (Double) dp.getComponent("E").readEstimate()); - params.put("I", (Double) dp.getComponent("I").readEstimate()); - params.put("R", (Double) dp.getComponent("R").readEstimate()); - params.put(INV_G, (Double) dp.getComponent(INV_G).readEstimate()); - params.put(INV_S, (Double) dp.getComponent(INV_S).readEstimate()); - params.put(INV_O, (Double) dp.getComponent(INV_O).readEstimate()); - params.put(INV_M, (Double) dp.getComponent(INV_M).readEstimate()); - params.put(BETA, (Double) dp.getComponent(BETA).readEstimate()); - params.put(ALPHA, (Double) dp.getComponent(ALPHA).readEstimate()); - - Data_product_write dpw = cr.get_dp_for_write("SEIRS_model/results/fromPreparedParams"); - try { - CleanableFileChannel f = dpw.getComponent().writeFileChannel(); - do_SEIRS(params, f); - }catch(IOException e) { - logger.error("failed to write output to file.", e); - } + double N; + int total_time = 5 * 365; // 5 years - } - } + int step_per_day_int = 2; - void do_SEIRS(Map params, CleanableFileChannel f) throws IOException { - - double N; - int total_time = 5 * 365; // 5 years - - int step_per_day_int = 2; - - double step_per_day = step_per_day_int; - - double dt = 1 / step_per_day; - - - int time_steps = total_time * step_per_day_int; - - double[] S = new double[time_steps+1]; - double[] E = new double[time_steps+1]; - double[] I = new double[time_steps+1]; - double[] R = new double[time_steps+1]; - - double[] time = new double[time_steps+1]; - - - S[0] = params.get("S"); - E[0] = params.get("E"); - I[0] = params.get("I"); - R[0] = params.get("R"); - - time[0] = 0; - - double inv_gamma = params.get(INV_G); - double inv_sigma = params.get(INV_S); - double inv_omega = params.get(INV_O); - double inv_mu = params.get(INV_M); - double beta = params.get(BETA); - double alpha= params.get(ALPHA); - - - double gamma_d = 1 / inv_gamma; - double omega_d = 1 / (inv_omega * 365); - double mu_d = 1 / (inv_mu * 365); - double sigma_d = 1 / inv_sigma; - - String line; - - line = "time,S,E,I,R\n"; - f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); - line = (0) + "," + S[0] + "," + E[0] + "," + I[0] + "," + R[0] + "\n"; - f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); - - for (int i = 0; i < time_steps; i++) { - N = S[i] + E[i] + I[i] + R[i]; - double dSdt = mu_d*N - (beta*S[i]*I[i])/N + omega_d*R[i] - mu_d*S[i]; - double dEdt = -sigma_d*E[i] + (beta*S[i]*I[i])/N - mu_d*E[i]; - double dIdt = -gamma_d*I[i] + sigma_d*E[i] - (mu_d+alpha)*I[i]; - double dRdt = -omega_d*R[i] + gamma_d*I[i] - mu_d*R[i]; - - /* integrate using Euler */ - time[i+1] = time[i] + dt; - - S[i+1] = S[i] + dSdt * dt; - E[i+1] = E[i] + dEdt * dt; - I[i+1] = I[i] + dIdt * dt; - R[i+1] = R[i] + dRdt * dt; - - line = (time[i+1] / 365) + "," + S[i+1] + "," + E[i+1] + "," + I[i+1] + "," + R[i+1] + "\n"; - f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); - } - + double step_per_day = step_per_day_int; + + double dt = 1 / step_per_day; + + int time_steps = total_time * step_per_day_int; + + double[] S = new double[time_steps + 1]; + double[] E = new double[time_steps + 1]; + double[] I = new double[time_steps + 1]; + double[] R = new double[time_steps + 1]; + + double[] time = new double[time_steps + 1]; + + S[0] = params.get("S"); + E[0] = params.get("E"); + I[0] = params.get("I"); + R[0] = params.get("R"); + + time[0] = 0; + + double inv_gamma = params.get(INV_G); + double inv_sigma = params.get(INV_S); + double inv_omega = params.get(INV_O); + double inv_mu = params.get(INV_M); + double beta = params.get(BETA); + double alpha = params.get(ALPHA); + + double gamma_d = 1 / inv_gamma; + double omega_d = 1 / (inv_omega * 365); + double mu_d = 1 / (inv_mu * 365); + double sigma_d = 1 / inv_sigma; + + String line; + + line = "time,S,E,I,R\n"; + f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); + line = (0) + "," + S[0] + "," + E[0] + "," + I[0] + "," + R[0] + "\n"; + f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); + + for (int i = 0; i < time_steps; i++) { + N = S[i] + E[i] + I[i] + R[i]; + double dSdt = mu_d * N - (beta * S[i] * I[i]) / N + omega_d * R[i] - mu_d * S[i]; + double dEdt = -sigma_d * E[i] + (beta * S[i] * I[i]) / N - mu_d * E[i]; + double dIdt = -gamma_d * I[i] + sigma_d * E[i] - (mu_d + alpha) * I[i]; + double dRdt = -omega_d * R[i] + gamma_d * I[i] - mu_d * R[i]; + + /* integrate using Euler */ + time[i + 1] = time[i] + dt; + + S[i + 1] = S[i] + dSdt * dt; + E[i + 1] = E[i] + dEdt * dt; + I[i + 1] = I[i] + dIdt * dt; + R[i + 1] = R[i] + dRdt * dt; + + line = + (time[i + 1] / 365) + + "," + + S[i + 1] + + "," + + E[i + 1] + + "," + + I[i + 1] + + "," + + R[i + 1] + + "\n"; + f.write(ByteBuffer.wrap(line.getBytes(StandardCharsets.UTF_8))); } + } } From cb0161a1c5a47722ff99df889280d2e361b75e7c Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Mon, 18 Apr 2022 15:48:17 +0100 Subject: [PATCH 08/15] set main class --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 50ef0ce..f773380 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ group 'org.example' version '1.0-SNAPSHOT' application { - mainClass = 'main' + mainClass = 'org.fairdatapipeline.javasimplemodel.JavaSimpleModel' } repositories { From ddfaa4a4e8aae9cfc042e29a657a2ad153653320 Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:16:30 +0100 Subject: [PATCH 09/15] Update gradle-build.yml --- .github/workflows/gradle-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index 350b2fa..be5698d 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -5,6 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: jobs: build: From cd465ea124449ed704231326035b6d8a48f046b9 Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:16:50 +0100 Subject: [PATCH 10/15] Update runWithFairCli.yml --- .github/workflows/runWithFairCli.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/runWithFairCli.yml b/.github/workflows/runWithFairCli.yml index 47db3d4..463e976 100644 --- a/.github/workflows/runWithFairCli.yml +++ b/.github/workflows/runWithFairCli.yml @@ -5,6 +5,7 @@ on: branches: [ master ] pull_request: branches: [ master ] + workflow_dispatch: jobs: build: From c708e192b895ce59454f0f06729903aa3a6dd079 Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Wed, 14 Jun 2023 14:19:18 +0000 Subject: [PATCH 11/15] update fairdatapipeline version; also update opencsv version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index f773380..6e4e47a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,8 @@ repositories { } dependencies { - implementation 'org.fairdatapipeline:api:1.0.0-rc1' - implementation 'com.opencsv:opencsv:5.6' + implementation 'org.fairdatapipeline:api:1.0.0-rc3' + implementation 'com.opencsv:opencsv:5.7.1' implementation('org.slf4j:slf4j-simple:1.7.36') } From fd073da4fc8b3c926344d82af45383c890629000 Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Wed, 14 Jun 2023 14:57:44 +0000 Subject: [PATCH 12/15] workflow yml ; use actions @v3 --- .github/workflows/gradle-build.yml | 4 ++-- .github/workflows/runWithFairCli.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml index be5698d..e30810a 100644 --- a/.github/workflows/gradle-build.yml +++ b/.github/workflows/gradle-build.yml @@ -16,9 +16,9 @@ jobs: packages: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '11' distribution: 'adopt' diff --git a/.github/workflows/runWithFairCli.yml b/.github/workflows/runWithFairCli.yml index 463e976..edd0948 100644 --- a/.github/workflows/runWithFairCli.yml +++ b/.github/workflows/runWithFairCli.yml @@ -16,9 +16,9 @@ jobs: packages: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '11' distribution: 'adopt' @@ -30,7 +30,7 @@ jobs: - name: Install local registry run: | /bin/bash -c "$(curl -fsSL https://data.scrc.uk/static/localregistry.sh)" - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v3 with: python-version: '3.x' - name: install fair-cli from pip From 0f64ff61d59b523e0a7def64ab3dcefbecb95ff3 Mon Sep 17 00:00:00 2001 From: Ryan J Field <57794045+RyanJField@users.noreply.github.com> Date: Thu, 15 Jun 2023 09:24:55 +0100 Subject: [PATCH 13/15] Update runWithFairCli.yml Fix CI --- .github/workflows/runWithFairCli.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/runWithFairCli.yml b/.github/workflows/runWithFairCli.yml index edd0948..cfa7298 100644 --- a/.github/workflows/runWithFairCli.yml +++ b/.github/workflows/runWithFairCli.yml @@ -37,7 +37,7 @@ jobs: run: pip install fair-cli - name: run javaSimpleModel with fair cli run: | - fair init --ci - fair pull src/main/resources/seirs-config.yaml - fair run src/main/resources/seirs-config.yaml + fair init --ci --local + fair pull --local src/main/resources/seirs-config.yaml + fair run --local src/main/resources/seirs-config.yaml From af41861e1ab6b8d2e14a95b966ae842727c3b1f1 Mon Sep 17 00:00:00 2001 From: Richard Reeve Date: Wed, 12 Jul 2023 14:39:27 +0100 Subject: [PATCH 14/15] Don't use --ci --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index e71ae72..394b286 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,7 @@ At this point you can configure `fair` to run in this repo. Either run: fair init ``` -And fill in your own details, or simply run: - -```sh -fair init --ci -``` - -In this case the CLI will initialise the repo with dummy values that are used for continuous integration testing. +And fill in your own details. Finally you can run the example! From e3a23ecc956eddb6a455670cb08661c8d10ba7ac Mon Sep 17 00:00:00 2001 From: Bram Boskamp Date: Wed, 7 Feb 2024 10:34:09 +0000 Subject: [PATCH 15/15] fromprep yaml needed a file_type --- src/main/resources/fromprep.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/fromprep.yaml b/src/main/resources/fromprep.yaml index be97265..27bf1d5 100644 --- a/src/main/resources/fromprep.yaml +++ b/src/main/resources/fromprep.yaml @@ -12,5 +12,6 @@ read: write: - data_product: SEIRS_model/results/fromPreparedParams + file_type: csv use: version: 0.0.1