Skip to content
Snippets Groups Projects
Commit 02b0ba9e authored by Powers, Peter M.'s avatar Powers, Peter M.
Browse files

tree-id to tree-info handlers

parent e9117fce
No related branches found
No related tags found
1 merge request!194Updates for tree-info.json change
......@@ -35,7 +35,7 @@ class ModelFiles {
static final String ZONE_SOURCES = "zone-sources";
static final String SOURCE_TREE = "source-tree.json";
static final String TREE_INFO = "tree-id.json";
static final String TREE_INFO = "tree-info.json";
static final String CALC_CONFIG = CalcConfig.FILE_NAME;
static final String MODEL_INFO = "model-info.json";
static final String MAP_REGION = "map-region.geojson";
......
......@@ -101,8 +101,8 @@ abstract class ModelLoader {
*/
public static void main(String[] args) {
Path testModel = Paths.get("../nshm-conus-2018");
// Path testModel = Paths.get("../nshm-hawaii");
// Path testModel = Paths.get("../nshm-conus-2018");
Path testModel = Paths.get("../nshm-hawaii");
HazardModel model = ModelLoader.load(testModel);
System.out.println();
System.out.println(model);
......
package gov.usgs.earthquake.nshmp.model;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toList;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
......@@ -22,7 +25,8 @@ public class Models {
.create();
public static void main(String[] args) {
HazardModel model = ModelLoader.load(Path.of("../nshm-conus"));
HazardModel model = ModelLoader.load(Path.of("../nshm-conus-2018"));
// HazardModel model = ModelLoader.load(Path.of("../nshm-hawaii"));
List<?> trees = trees(model);
String out = GSON.toJson(trees);
System.out.println(out);
......@@ -35,26 +39,47 @@ public class Models {
*/
public static List<?> trees(HazardModel model) {
return model.trees().asMap().entrySet().stream()
.map(Models::toTreeGroup)
.map(Models::toSettingGroup)
.collect(toList());
}
private static TreeGroup toTreeGroup(Entry<TectonicSetting, Collection<SourceTree>> entry) {
return new TreeGroup(
private static SettingGroup toSettingGroup(Entry<TectonicSetting, Collection<SourceTree>> entry) {
return new SettingGroup(
entry.getKey(),
entry.getValue().stream()
.map(Tree::new)
.collect(toList()));
toSourceGroup(entry.getValue()));
}
static final class TreeGroup {
private static List<SourceGroup> toSourceGroup(Collection<SourceTree> trees) {
return trees.stream()
.collect(groupingBy(
SourceTree::type,
mapping(
Tree::new,
Collectors.toList())))
.entrySet().stream()
.map(e -> new SourceGroup(e.getKey(), e.getValue()))
.collect(toList());
}
static final class SettingGroup {
final TectonicSetting setting;
final List<Tree> trees;
final List<SourceGroup> data;
TreeGroup(TectonicSetting setting, List<Tree> trees) {
SettingGroup(TectonicSetting setting, List<SourceGroup> data) {
this.setting = setting;
this.trees = trees;
this.data = data;
}
}
static final class SourceGroup {
final SourceType type;
final List<Tree> data;
SourceGroup(SourceType type, List<Tree> data) {
this.type = type;
this.data = data;
}
}
......@@ -62,12 +87,10 @@ public class Models {
final int id;
final String name;
final SourceType type;
Tree(SourceTree tree) {
this.id = tree.id();
this.name = tree.name();
this.type = tree.type();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment