Skip to content

Commit f464e67

Browse files
test StreamAbstract with MultiHazardProvider
1 parent 8c8f1ff commit f464e67

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

compute/simulation_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ func Test_StreamAbstract_MultiFrequency(t *testing.T) {
101101
//compute consequences.
102102
StreamAbstractMultiFrequency(hazardProviders, frequencies, nsp, w)
103103
}
104+
105+
func Test_StreamAbstract_MultiHazard(t *testing.T) {
106+
//initialize the NSI API structure provider
107+
nsp := structureprovider.InitNSISPwithOcctypeFilePath("/workspaces/go-consequences/data/lifecycle/occtypes_reconstruction.json")
108+
now := time.Now()
109+
fmt.Println(now)
110+
111+
root := "/workspaces/go-consequences/data/lifecycle/"
112+
filepath := root + "test_arrival-depth-duration_hazards.json"
113+
w, _ := resultswriters.InitSpatialResultsWriter(root+"multihazardtest_consequences.json", "results", "GeoJSON")
114+
//w := consequences.InitSummaryResultsWriterFromFile(root + "_consequences_SUMMARY.json")
115+
//create a result writer based on the name of the depth grid.
116+
//w, _ := resultswriters.InitGpkResultsWriter(root+"_consequences_nsi.gpkg", "nsi_result")
117+
defer w.Close()
118+
//initialize a hazard provider based on the depth grid.
119+
dfr, err := hazardproviders.InitADDMHP(filepath)
120+
if err != nil {
121+
panic(err)
122+
}
123+
//compute consequences.
124+
StreamAbstract(dfr, nsp, w)
125+
fmt.Println(time.Since(now))
126+
}
127+
104128
func Test_Config(t *testing.T) {
105129
config := Config{
106130
StructureProviderInfo: structureprovider.StructureProviderInfo{

hazardproviders/json_multi_hazard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (j jsonArrivalDepthDurationMultiHazardProvider) Close() {
7474
}
7575
}
7676

77-
func (j jsonArrivalDepthDurationMultiHazardProvider) Hazard(l geography.Location) (hazards.ArrivalDepthandDurationEventMulti, error) {
77+
func (j jsonArrivalDepthDurationMultiHazardProvider) Hazard(l geography.Location) (hazards.HazardEvent, error) {
7878
var hm hazards.ArrivalDepthandDurationEventMulti
7979
for i, cr := range j.depthCRs {
8080
d, err := cr.ProvideValue(l)
@@ -95,7 +95,7 @@ func (j jsonArrivalDepthDurationMultiHazardProvider) Hazard(l geography.Location
9595
h, err = j.process(hd, h)
9696
hm.Append(h.(hazards.ArrivalDepthandDurationEvent))
9797
}
98-
return hm, nil
98+
return &hm, nil
9999
}
100100

101101
func (j jsonArrivalDepthDurationMultiHazardProvider) HazardBoundary() (geography.BBox, error) {

hazardproviders/json_multi_hazard_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/USACE/go-consequences/geography"
8+
"github.com/USACE/go-consequences/hazards"
89
)
910

1011
func TestInitADDMHP(t *testing.T) {
@@ -21,7 +22,8 @@ func TestInitADDMHP(t *testing.T) {
2122
SRID: "",
2223
}
2324

24-
h, err := ADDMHP.Hazard(loc)
25+
haz, err := ADDMHP.Hazard(loc)
26+
h := haz.(hazards.ArrivalDepthandDurationEventMulti)
2527
if err != nil {
2628
panic(err)
2729
}

structures/structure.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ func (s StructureDeterministic) Compute(d hazards.HazardEvent) (consequences.Res
135135
return computeConsequences(d, s)
136136
}
137137

138-
func (s StructureDeterministic) Compute2(d hazards.MultiHazardEvent) {
139-
fmt.Println("Delete this function")
140-
}
141-
142138
// Compute implements the consequences.Receptor interface on StrucutreDeterminstic
143139
func (s StructureDeterministic) Clone() StructureDeterministic {
144140
return StructureDeterministic{
@@ -659,6 +655,20 @@ func computeConsequencesMultiHazard(event hazards.MultiHazardEvent, s StructureD
659655
subResultsHeader = append(subResultsHeader, fmt.Sprintf("%d", event.Index()))
660656
subResultsResult = append(subResultsResult, result)
661657
subResult = consequences.Result{Headers: subResultsHeader, Result: subResultsResult}
658+
ret.Result[0] = s.BaseStructure.Name
659+
ret.Result[1] = s.BaseStructure.X
660+
ret.Result[2] = s.BaseStructure.Y
661+
ret.Result[3] = s.BaseStructure.DamCat
662+
ret.Result[4] = s.OccType.Name
663+
ret.Result[5] = s.Pop2amu65
664+
ret.Result[6] = s.Pop2amo65
665+
ret.Result[7] = s.Pop2pmu65
666+
ret.Result[8] = s.Pop2pmo65
667+
ret.Result[9] = s.CBFips
668+
ret.Result[10] = sval
669+
ret.Result[11] = conval
670+
ret.Result[12] = svalcurr
671+
ret.Result[13] = convalcurr
662672
ret.Result[20] = subResult
663673

664674
if event.HasNext() {

0 commit comments

Comments
 (0)