Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Jan 25, 2018
1 parent 842d816 commit 3d242fc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 44 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ task cleanOutput {
mainClassName = 'App'

run {
// ex. gradle run -PappArgs="['arg1', 'args2']"
// args are called "arams" because they are called with -P,
// ex. gradle run -Params="['arg1', 'args2']"
// see https://stackoverflow.com/questions/27604283/gradle-task-pass-arguments-to-java-application
if (project.hasProperty("appArgs")) {
args Eval.me(appArgs)
if (project.hasProperty("arams")) {
args Eval.me(arams)
}
}
2 changes: 1 addition & 1 deletion run_synthea
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ else
# Trailing comma ok, don't need to remove it
done

./gradlew run -PappArgs="[$SYNTHEA_ARGS]"
./gradlew run -Params="[$SYNTHEA_ARGS]"
fi

2 changes: 1 addition & 1 deletion run_synthea.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ IF "%~1" == "" (
@rem Trailing comma ok, don't need to remove it
)

gradlew.bat run -PappArgs="[!syntheaArgs!]"
gradlew.bat run -Params="[!syntheaArgs!]"
)
33 changes: 17 additions & 16 deletions src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@
* This Java source file was generated by the Gradle 'init' task.
*/
public class App {

/**
* Display usage info - what are the command line args, examples, etc.
*/
public static void usage() {
System.out.println("Usage: run_synthea [-s seed] [-p populationSize] [state [city]]");
System.out.println("Examples:");
System.out.println("run_synthea Massachusetts");
System.out.println("run_synthea Alaska Juneau");
System.out.println("run_synthea -s 12345");
System.out.println("run_synthea -p 1000)");
System.out.println("run_synthea -s 987 Washington Seattle");
System.out.println("run_synthea -s 21 -p 100 Utah \"Salt Lake City\"");
}

/**
* Run Synthea generation.
* @param args None. See documentation on configuration.
* @throws Exception On errors.
*/
public static void main(String[] args) throws Exception {

// Usage: synthea [-s seed] [-p populationSize] [stateName [cityName]]
// examples:
// synthea Massachusetts
// synthea Alaska Juneau
// synthea -s 12345
// synthea -p 1000

Generator.GeneratorOptions options = new Generator.GeneratorOptions();

if (args != null && args.length > 0) {
Expand All @@ -47,17 +54,11 @@ public static void main(String[] args) throws Exception {
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Usage: synthea [-s seed] [-p populationSize] [stateName [cityName]]");
System.out.println("Examples:");
System.out.println("synthea Massachusetts");
System.out.println("synthea Alaska Juneau");
System.out.println("synthea -s 12345");
System.out.println("synthea -p 1000)");
usage();
System.exit(1); // invalid args so exit early
}
}

System.out.println("Running with options:\n" + options);

Generator generator = new Generator(options);
generator.run();

Expand Down
26 changes: 11 additions & 15 deletions src/main/java/org/mitre/synthea/engine/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ public static class GeneratorOptions {
public long seed = System.currentTimeMillis();
public String city;
public String state;

@Override
public String toString() {
String location;
if (state == null) {
location = DEFAULT_STATE;
} else if (city == null) {
location = state;
} else {
location = city + ", " + state;
}
return String.format("Population: %d\nSeed: %d\nLocation: %s\n",
population, seed, location);
}
}

public Generator() throws IOException {
Expand Down Expand Up @@ -140,8 +126,18 @@ private void init(int population, long seed, String state, String city) throws I
// initialize hospitals
Hospital.loadHospitals();
Module.getModules(); // ensure modules load early
CommunityHealthWorker.initalize(location); // ensure CHWs are set early
CommunityHealthWorker.initalize(this.location, this.random); // ensure CHWs are set early
Costs.loadCostData();

String locationName;
if (city == null) {
locationName = state;
} else {
locationName = city + ", " + state;
}
System.out.println("Running with options:");
System.out.println(String.format("Population: %d\nSeed: %d\nLocation: %s\n",
this.numberOfPeople, this.seed, locationName));
}

public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public class CommunityHealthWorker extends Provider {
public static Map<String, List<CommunityHealthWorker>> workers;


public static void initalize(Location location) {
workers = generateWorkers(location);
public static void initalize(Location location, Random random) {
workers = generateWorkers(location, random);
}

private CommunityHealthWorker(String deploymentType, Location location) {
private CommunityHealthWorker(String deploymentType, Location location, Random random) {
// don't allow anyone else to instantiate this

attributes.put(CommunityHealthWorker.ALCOHOL_SCREENING,
Expand Down Expand Up @@ -99,7 +99,7 @@ private CommunityHealthWorker(String deploymentType, Location location) {
attributes.put(CommunityHealthWorker.VITAMIN_D_INJURY_SCREENING,
Boolean.parseBoolean(Config.get("chw.vitamin_d_injury_screening")));

String city = location.randomCityName(new Random());
String city = location.randomCityName(random);
attributes.put(CITY, city);

attributes.put(DEPLOYMENT, deploymentType);
Expand All @@ -111,14 +111,14 @@ private CommunityHealthWorker(String deploymentType, Location location) {
"CHW providing " + deploymentType + " services in " + attributes.get(CITY));
}

private static Map<String, List<CommunityHealthWorker>> generateWorkers(Location location) {
private static Map<String, List<CommunityHealthWorker>> generateWorkers(Location location, Random random) {
Map<String, List<CommunityHealthWorker>> workers =
new HashMap<String, List<CommunityHealthWorker>>();
int numWorkers = budget / cost;
int numWorkersGenerated = 0;
CommunityHealthWorker worker;
for (int i = 0; i < Math.round(numWorkers * community); i++) {
worker = new CommunityHealthWorker(DEPLOYMENT_COMMUNITY, location);
worker = new CommunityHealthWorker(DEPLOYMENT_COMMUNITY, location, random);
String city = (String) worker.attributes.get(CITY);
if (!workers.containsKey(city)) {
workers.put(city, new ArrayList<CommunityHealthWorker>());
Expand All @@ -127,7 +127,7 @@ private static Map<String, List<CommunityHealthWorker>> generateWorkers(Location
numWorkersGenerated++;
}
for (int i = 0; i < Math.round(numWorkers * emergency); i++) {
worker = new CommunityHealthWorker(DEPLOYMENT_EMERGENCY, location);
worker = new CommunityHealthWorker(DEPLOYMENT_EMERGENCY, location, random);
String city = (String) worker.attributes.get(CITY);
if (!workers.containsKey(city)) {
workers.put(city, new ArrayList<CommunityHealthWorker>());
Expand All @@ -136,7 +136,7 @@ private static Map<String, List<CommunityHealthWorker>> generateWorkers(Location
numWorkersGenerated++;
}
for (int i = numWorkersGenerated; i < numWorkers; i++) {
worker = new CommunityHealthWorker(DEPLOYMENT_POSTDISCHARGE, location);
worker = new CommunityHealthWorker(DEPLOYMENT_POSTDISCHARGE, location, random);
String city = (String) worker.attributes.get(CITY);
if (!workers.containsKey(city)) {
workers.put(city, new ArrayList<CommunityHealthWorker>());
Expand Down

0 comments on commit 3d242fc

Please sign in to comment.