-
Notifications
You must be signed in to change notification settings - Fork 35
73 Selecting specific Input folder (and/or Euromod Policy Schedule) per-run via config file #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
974c191
8d82eef
0204764
bfeae9c
d31cef7
641f407
55926f2
c42085d
166e4b6
7cdf68b
66dec30
78855ae
8963b4a
3ab6723
bcfabdd
008221a
c173ef8
6043d3e
cde7ba7
5bb70b7
2fc7419
f25063c
f377ed7
c64aa5b
e8d9e5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||
| import simpaths.data.Parameters; | ||||||
| import simpaths.data.XLSXfileWriter; | ||||||
| import simpaths.model.SimPathsModel; | ||||||
| import microsim.data.db.Experiment; | ||||||
| import microsim.data.MultiKeyCoefficientMap; | ||||||
| import microsim.data.excel.ExcelAssistant; | ||||||
| import microsim.engine.MultiRun; | ||||||
|
|
@@ -73,21 +74,26 @@ public static void main(String[] args) { | |||||
| // if parseYamlConfig returns false (indicating bad filename passed), exit main | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| if (parameterArgs != null) | ||||||
| updateParameters(parameterArgs); | ||||||
|
|
||||||
|
|
||||||
| // set default values for country and start year | ||||||
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap("input" + File.separator + Parameters.DatabaseCountryYearFilename + ".xlsx", "Data", 1, 1); | ||||||
| if (lastDatabaseCountryAndYear.keySet().stream().anyMatch(key -> key.toString().equals("MultiKey[IT]"))) { | ||||||
| countryString = "Italy"; | ||||||
| } else { | ||||||
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap(Parameters.getInputDirectory() + File.separator + Parameters.DatabaseCountryYearFilename + ".xlsx", "Data", 1, 1); | ||||||
| try { | ||||||
| if (lastDatabaseCountryAndYear.keySet().stream().anyMatch(key -> key.toString().equals("MultiKey[IT]"))) { | ||||||
| countryString = "Italy"; | ||||||
| } else { | ||||||
| countryString = "United Kingdom"; | ||||||
| } | ||||||
| String valueYear = lastDatabaseCountryAndYear.getValue(country.toString()).toString(); | ||||||
| startYear = Integer.parseInt(valueYear); | ||||||
| } catch (NullPointerException e) { | ||||||
| System.out.println("No last database country and year found."); | ||||||
| countryString = "United Kingdom"; | ||||||
| startYear = 2019; | ||||||
| } | ||||||
|
|
||||||
| country = Country.getCountryFromNameString(countryString); | ||||||
| String valueYear = lastDatabaseCountryAndYear.getValue(country.toString()).toString(); | ||||||
| startYear = Integer.parseInt(valueYear); | ||||||
|
|
||||||
| if (innovationArgs!=null) | ||||||
| updateLocalParameters(innovationArgs); | ||||||
|
|
@@ -402,6 +408,20 @@ public static void updateParameters(Map<String, Object> parameter_args) { | |||||
| Object value = entry.getValue(); | ||||||
|
|
||||||
| switch (key) { | ||||||
| case "working_directory": | ||||||
| Parameters.setWorkingDirectory(value.toString()); | ||||||
| setExperimentFolders(value.toString(), true); | ||||||
| break; | ||||||
| case "input_directory": | ||||||
| Parameters.setInputDirectory(value.toString()); | ||||||
| setExperimentFolders(); | ||||||
| break; | ||||||
| case "input_directory_initial_populations": | ||||||
| Parameters.setInputDirectoryInitialPopulations(value.toString()); | ||||||
| break; | ||||||
| case "euromod_output_directory": | ||||||
| Parameters.setEuromodOutputDirectory(value.toString()); | ||||||
| break; | ||||||
| default: | ||||||
| try { | ||||||
| Field field = Parameters.class.getDeclaredField(key); | ||||||
|
|
@@ -428,6 +448,37 @@ public static void updateParameters(Map<String, Object> parameter_args) { | |||||
|
|
||||||
| } | ||||||
|
|
||||||
| public static void setExperimentFolders() { | ||||||
|
|
||||||
| try { | ||||||
| Field inputDir = Experiment.class.getDeclaredField("inputFolder"); | ||||||
| inputDir.setAccessible(true); | ||||||
| inputDir.set(Experiment.class, Parameters.getInputDirectory()); | ||||||
|
||||||
| inputDir.set(Experiment.class, Parameters.getInputDirectory()); | |
| inputDir.set(null, Parameters.getInputDirectory()); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concatenation lacks a separator before input; include File.separator (or ensure the directory string ends with one) to avoid malformed paths.
| if (persist_root) model.setPersistDatabasePath(Parameters.getInputDirectory() + "input"); | |
| if (persist_root) model.setPersistDatabasePath(ensureTrailingSeparator(Parameters.getInputDirectory()) + "input"); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,7 +84,7 @@ public static void main(String[] args) { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| //Adjust the country and year to the value read from Excel, which is updated when the database is rebuilt. Otherwise it will set the country and year to the last one used to build the database | ||||||||||||||
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap("input" + File.separator + Parameters.DatabaseCountryYearFilename + ".xlsx", "Data", 1, 1); | ||||||||||||||
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap(Parameters.getInputDirectory() + Parameters.DatabaseCountryYearFilename + ".xlsx", "Data", 1, 1); | ||||||||||||||
|
||||||||||||||
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap(Parameters.getInputDirectory() + Parameters.DatabaseCountryYearFilename + ".xlsx", "Data", 1, 1); | |
| MultiKeyCoefficientMap lastDatabaseCountryAndYear = ExcelAssistant.loadCoefficientMap( | |
| java.nio.file.Paths.get(Parameters.getInputDirectory(), Parameters.DatabaseCountryYearFilename + ".xlsx").toString(), | |
| "Data", 1, 1); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception message is confusing: it prefixes the path with File.separator and includes a stray backtick (). Refactor to show the full path correctly, e.g., "Policy Schedule file '" + fullPath + "' doesn't exist."`.
| throw new FileNotFoundException("Policy Schedule file '"+ File.separator + Parameters.getInputDirectory() + | |
| Parameters.EUROMODpolicyScheduleFilename + ".xlsx` doesn't exist. " + | |
| "Provide excel file or use `--rewrite-policy-schedule` to re-construct from available policy files."); | |
| throw new FileNotFoundException("Policy Schedule file '" + Parameters.getInputDirectory() + | |
| Parameters.EUROMODpolicyScheduleFilename + ".xlsx' doesn't exist. " + | |
| "Provide the Excel file or use `--rewrite-policy-schedule` to re-construct it from available policy files."); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing path separator before the filename; add File.separator between getInputDirectory() and the schedule filename.
| MultiKeyCoefficientMap previousEUROMODfileInfo = ExcelAssistant.loadCoefficientMap(Parameters.getInputDirectory() + Parameters.EUROMODpolicyScheduleFilename + ".xlsx", country.toString(), 1, 3); | |
| MultiKeyCoefficientMap previousEUROMODfileInfo = ExcelAssistant.loadCoefficientMap(Parameters.getInputDirectory() + File.separator + Parameters.EUROMODpolicyScheduleFilename + ".xlsx", country.toString(), 1, 3); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -63,7 +63,7 @@ public static void databaseFromCSV(Country country, int startYear, boolean isVis | |||||
| Connection conn = null; | ||||||
| try { | ||||||
| Class.forName("org.h2.Driver"); | ||||||
| conn = DriverManager.getConnection("jdbc:h2:file:./input" + File.separator + "input;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE", "sa", ""); | ||||||
| conn = DriverManager.getConnection("jdbc:h2:file:" + Parameters.getInputDirectory() + "input;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE", "sa", ""); | ||||||
|
||||||
| conn = DriverManager.getConnection("jdbc:h2:file:" + Parameters.getInputDirectory() + "input;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE", "sa", ""); | |
| conn = DriverManager.getConnection("jdbc:h2:file:" + Parameters.getInputDirectory() + File.separator + "input;TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE", "sa", ""); |
Copilot
AI
Jun 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path concatenation omits a separator before input, leading to an incorrect JDBC URL. Insert File.separator between the directory and "input".
| propertyMap.put("hibernate.connection.url", "jdbc:h2:file:" + Parameters.getInputDirectory() + "input" + ";TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE"); | |
| propertyMap.put("hibernate.connection.url", "jdbc:h2:file:" + Parameters.getInputDirectory() + File.separator + "input" + ";TRACE_LEVEL_FILE=0;TRACE_LEVEL_SYSTEM_OUT=0;AUTO_SERVER=TRUE"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ class WithLawrenceParameters { | |
| @BeforeEach | ||
| public void setupLawrenceCoefficients() { | ||
|
|
||
| Parameters.setInputDirectory("src/test/java/simpaths/testinput"); | ||
|
||
|
|
||
| Parameters.eq5dConversionParameters = "lawrence"; | ||
| Parameters.loadEQ5DParameters("UK", 8); | ||
|
|
||
|
|
@@ -70,6 +72,8 @@ class WithFranksParameters { | |
| @BeforeEach | ||
| public void setupFranksCoefficients() { | ||
|
|
||
| Parameters.setInputDirectory("src/test/java/simpaths/testinput"); | ||
|
|
||
| Parameters.eq5dConversionParameters = "franks"; | ||
| Parameters.loadEQ5DParameters("UK", 8); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing file separator when building the H2 JDBC URL; add
File.separatorbetween the configured directory andinput.