From a32aec84ccad12b0baa0c70c61574eb5f27ce3ec Mon Sep 17 00:00:00 2001 From: Peter Powers <pmpowers@usgs.gov> Date: Sat, 5 Feb 2022 11:47:11 -0700 Subject: [PATCH] refac disagg output flag handling; add DISAGG_DATA --- .../usgs/earthquake/nshmp/calc/DataType.java | 5 +- .../earthquake/nshmp/calc/DisaggExport.java | 8 ++-- .../earthquake/nshmp/calc/Disaggregation.java | 47 +++++-------------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java index 2561ab96..8ad506aa 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DataType.java @@ -24,6 +24,9 @@ public enum DataType { MAP, /** Data by {@link SourceType}. */ - SOURCE; + SOURCE, + + /** Disaggregation r-m-ε bin data */ + DISAGG_DATA; } diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java index c2f2ccd7..0b7bf999 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/DisaggExport.java @@ -61,18 +61,16 @@ final class DisaggExport { DisaggDataset dd, DisaggConfig dc, String id, - boolean jsonFlag, - boolean εDataFlag, - boolean summaryFlag) { + boolean εDataFlag) { this.ddTotal = ddTotal; this.dd = dd; this.dc = dc; this.id = id; - summary = summaryFlag ? createSummaryElements(ddTotal, dd, dc) : null; + summary = createSummaryElements(ddTotal, dd, dc); + sources = createJsonContributorList(ddTotal, dd, dc.contributorLimit); data = εDataFlag ? createDistanceMagnitudeData(ddTotal, dd) : null; - sources = jsonFlag ? createJsonContributorList(ddTotal, dd, dc.contributorLimit) : null; } @Override diff --git a/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java b/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java index 47a720f4..100d8081 100644 --- a/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java +++ b/src/main/java/gov/usgs/earthquake/nshmp/calc/Disaggregation.java @@ -186,33 +186,18 @@ public final class Disaggregation { } /** - * Returns an object containing all disaggregation results that is suitable - * for JSON serialization. + * Returns an object containing disaggregation results that is suitable for + * JSON serialization. * * @param imt of the disaggregation to retrieve. - */ - public Object toJson(Imt imt) { - return disaggs.get(imt).toJson(true, true, true, true); - } - - /** - * Returns an object containing custom disaggregation results that is suitable - * for JSON serialization. - * - * @param imt of the disaggregation to retrieve. - * @param summary include summary information, or not * @param gmms include results decomposed by GMM (values are scaled by GMM * logic tree weight) * @param types include results decomposed by source type - * @param epsilons include distance-magnitude-epsilon data that can be used to + * @param rmeData include distance-magnitude-epsilon data that can be used to * build a 3D stem plot */ - public Object toJson(Imt imt, - boolean summary, - boolean gmms, - boolean types, - boolean epsilons) { - return disaggs.get(imt).toJson(summary, gmms, types, epsilons); + public Object toJson(Imt imt, boolean gmms, boolean types, boolean rmeData) { + return disaggs.get(imt).toJson(gmms, types, rmeData); } /** @@ -298,7 +283,7 @@ public final class Disaggregation { public String toString() { StringBuilder sb = new StringBuilder(); sb.append(NEWLINE); - for (DisaggExport export : buildExports(false, true, true, true, true)) { + for (DisaggExport export : buildExports(true, true, false)) { sb.append(export.toString()); sb.append(NEWLINE); } @@ -310,16 +295,14 @@ public final class Disaggregation { * structured object that may be serialized directly or added to some other * object prior to serialization. */ - Object toJson(boolean summary, boolean gmmDisaggs, boolean typeDisaggs, boolean εData) { - return buildExports(true, summary, gmmDisaggs, typeDisaggs, εData); + Object toJson(boolean gmmDisaggs, boolean typeDisaggs, boolean rmεData) { + return buildExports(gmmDisaggs, typeDisaggs, rmεData); } private List<DisaggExport> buildExports( - boolean json, - boolean summary, boolean gmmDisaggs, boolean typeDisaggs, - boolean εData) { + boolean rmεData) { List<DisaggExport> exports = new ArrayList<>(); DisaggExport total = new DisaggExport( @@ -327,9 +310,7 @@ public final class Disaggregation { totalDataset, config, TOTAL_COMPONENT, - json, - εData, - summary); + rmεData); exports.add(total); if (gmmDisaggs) { for (Entry<Gmm, DisaggDataset> gmmEntry : gmmDatasets.entrySet()) { @@ -338,9 +319,7 @@ public final class Disaggregation { gmmEntry.getValue(), config, GMM_COMPONENT + gmmEntry.getKey().toString(), - json, - εData, - summary); + rmεData); exports.add(gmm); } } @@ -351,9 +330,7 @@ public final class Disaggregation { typeEntry.getValue(), config, TYPE_COMPONENT + typeEntry.getKey().toString(), - json, - εData, - summary); + rmεData); exports.add(type); } } -- GitLab