Skip to content

Commit 41dfc39

Browse files
Merge pull request #130 from sebastianrowan/building-reconstruction
comment out tests referencing untracked files in data
2 parents 9f5bc7e + 4112f6e commit 41dfc39

5 files changed

Lines changed: 165 additions & 149 deletions

File tree

compute/simulation_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,28 @@ func Test_StreamAbstract_MultiFrequency(t *testing.T) {
102102
StreamAbstractMultiFrequency(hazardProviders, frequencies, nsp, w)
103103
}
104104

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-
}
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.gpkg", "results", "GPKG")
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+
// }
127127

128128
func Test_Config(t *testing.T) {
129129
config := Config{
Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,58 @@
11
package hazardproviders
22

3-
import (
4-
"testing"
5-
"time"
6-
7-
"github.com/USACE/go-consequences/geography"
8-
"github.com/USACE/go-consequences/hazards"
9-
)
10-
11-
func TestInitCSV(t *testing.T) {
12-
file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.csv"
13-
14-
expectedDepths := []float64{1.0, 1.0, 1.0, 2.0, 2.0}
15-
expectedDurations := []float64{0.0, 5.0, 0.0, 0.0, 0.0}
16-
et1 := time.Date(1984, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
17-
et2 := time.Date(1984, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
18-
et3 := time.Date(1984, time.Month(1), 21, 0, 0, 0, 0, time.UTC)
19-
et4 := time.Date(1985, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
20-
et5 := time.Date(1985, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
21-
expectedArrivals := []time.Time{et1, et2, et3, et4, et5}
22-
23-
b := geography.BBox{
24-
// xMin, yMin, xMax, yMax
25-
Bbox: []float64{-71.1, 43, -71, 43.1},
26-
}
27-
ADDMHP, err := InitCSV(file, b)
28-
if err != nil {
29-
panic(err)
30-
}
31-
defer ADDMHP.Close()
32-
33-
loc := geography.Location{
34-
X: -71.05,
35-
Y: 43.05,
36-
SRID: "",
37-
}
38-
39-
haz, err := ADDMHP.Hazard(loc)
40-
h := haz.(*hazards.ArrivalDepthandDurationEventMulti)
41-
if err != nil {
42-
panic(err)
43-
}
44-
45-
for {
46-
edepth := expectedDepths[h.Index()]
47-
edur := expectedDurations[h.Index()]
48-
earr := expectedArrivals[h.Index()]
49-
50-
if h.Depth() != edepth {
51-
t.Errorf("Event at index %d had Depth = %v. Expected: %3.2f", h.Index(), h.Depth(), edepth)
52-
}
53-
if h.Duration() != edur {
54-
t.Errorf("Event at index %d had Duration = %v. Expected: %3.2f", h.Index(), h.Duration(), edur)
55-
}
56-
if h.Depth() != edepth {
57-
t.Errorf("Event at index %d had ArrivalTime = %v. Expected: %v", h.Index(), h.ArrivalTime(), earr)
58-
}
59-
60-
if h.HasNext() {
61-
h.Increment()
62-
} else {
63-
break
64-
}
65-
}
66-
}
3+
// func TestInitCSV(t *testing.T) {
4+
// file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.csv"
5+
6+
// expectedDepths := []float64{1.0, 1.0, 1.0, 2.0, 2.0}
7+
// expectedDurations := []float64{0.0, 5.0, 0.0, 0.0, 0.0}
8+
// et1 := time.Date(1984, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
9+
// et2 := time.Date(1984, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
10+
// et3 := time.Date(1984, time.Month(1), 21, 0, 0, 0, 0, time.UTC)
11+
// et4 := time.Date(1985, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
12+
// et5 := time.Date(1985, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
13+
// expectedArrivals := []time.Time{et1, et2, et3, et4, et5}
14+
15+
// b := geography.BBox{
16+
// // xMin, yMin, xMax, yMax
17+
// Bbox: []float64{-71.1, 43, -71, 43.1},
18+
// }
19+
// ADDMHP, err := InitCSV(file, b)
20+
// if err != nil {
21+
// panic(err)
22+
// }
23+
// defer ADDMHP.Close()
24+
25+
// loc := geography.Location{
26+
// X: -71.05,
27+
// Y: 43.05,
28+
// SRID: "",
29+
// }
30+
31+
// haz, err := ADDMHP.Hazard(loc)
32+
// h := haz.(*hazards.ArrivalDepthandDurationEventMulti)
33+
// if err != nil {
34+
// panic(err)
35+
// }
36+
37+
// for {
38+
// edepth := expectedDepths[h.Index()]
39+
// edur := expectedDurations[h.Index()]
40+
// earr := expectedArrivals[h.Index()]
41+
42+
// if h.Depth() != edepth {
43+
// t.Errorf("Event at index %d had Depth = %v. Expected: %3.2f", h.Index(), h.Depth(), edepth)
44+
// }
45+
// if h.Duration() != edur {
46+
// t.Errorf("Event at index %d had Duration = %v. Expected: %3.2f", h.Index(), h.Duration(), edur)
47+
// }
48+
// if h.Depth() != edepth {
49+
// t.Errorf("Event at index %d had ArrivalTime = %v. Expected: %v", h.Index(), h.ArrivalTime(), earr)
50+
// }
51+
52+
// if h.HasNext() {
53+
// h.Increment()
54+
// } else {
55+
// break
56+
// }
57+
// }
58+
// }
Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,54 @@
11
package hazardproviders
22

3-
import (
4-
"testing"
5-
"time"
6-
7-
"github.com/USACE/go-consequences/geography"
8-
"github.com/USACE/go-consequences/hazards"
9-
)
10-
11-
func TestInitADDMHP(t *testing.T) {
12-
file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.json"
13-
14-
expectedDepths := []float64{1.0, 1.0, 1.0, 2.0, 2.0}
15-
expectedDurations := []float64{0.0, 5.0, 0.0, 0.0, 0.0}
16-
et1 := time.Date(1984, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
17-
et2 := time.Date(1984, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
18-
et3 := time.Date(1984, time.Month(1), 21, 0, 0, 0, 0, time.UTC)
19-
et4 := time.Date(1985, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
20-
et5 := time.Date(1985, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
21-
expectedArrivals := []time.Time{et1, et2, et3, et4, et5}
22-
23-
ADDMHP, err := InitADDMHP(file)
24-
if err != nil {
25-
panic(err)
26-
}
27-
defer ADDMHP.Close()
28-
29-
loc := geography.Location{
30-
X: -71.481,
31-
Y: 43.001,
32-
SRID: "",
33-
}
34-
35-
haz, err := ADDMHP.Hazard(loc)
36-
h := haz.(*hazards.ArrivalDepthandDurationEventMulti)
37-
if err != nil {
38-
panic(err)
39-
}
40-
41-
for {
42-
edepth := expectedDepths[h.Index()]
43-
edur := expectedDurations[h.Index()]
44-
earr := expectedArrivals[h.Index()]
45-
46-
if h.Depth() != edepth {
47-
t.Errorf("Event at index %d had Depth = %v. Expected: %3.2f", h.Index(), h.Depth(), edepth)
48-
}
49-
if h.Duration() != edur {
50-
t.Errorf("Event at index %d had Duration = %v. Expected: %3.2f", h.Index(), h.Duration(), edur)
51-
}
52-
if h.Depth() != edepth {
53-
t.Errorf("Event at index %d had ArrivalTime = %v. Expected: %v", h.Index(), h.ArrivalTime(), earr)
54-
}
55-
56-
if h.HasNext() {
57-
h.Increment()
58-
} else {
59-
break
60-
}
61-
}
62-
}
3+
// func TestInitADDMHP(t *testing.T) {
4+
// file := "/workspaces/go-consequences/data/lifecycle/test_arrival-depth-duration_hazards.json"
5+
6+
// expectedDepths := []float64{1.0, 1.0, 1.0, 2.0, 2.0}
7+
// expectedDurations := []float64{0.0, 5.0, 0.0, 0.0, 0.0}
8+
// et1 := time.Date(1984, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
9+
// et2 := time.Date(1984, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
10+
// et3 := time.Date(1984, time.Month(1), 21, 0, 0, 0, 0, time.UTC)
11+
// et4 := time.Date(1985, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
12+
// et5 := time.Date(1985, time.Month(1), 11, 0, 0, 0, 0, time.UTC)
13+
// expectedArrivals := []time.Time{et1, et2, et3, et4, et5}
14+
15+
// ADDMHP, err := InitADDMHP(file)
16+
// if err != nil {
17+
// panic(err)
18+
// }
19+
// defer ADDMHP.Close()
20+
21+
// loc := geography.Location{
22+
// X: -71.481,
23+
// Y: 43.001,
24+
// SRID: "",
25+
// }
26+
27+
// haz, err := ADDMHP.Hazard(loc)
28+
// h := haz.(*hazards.ArrivalDepthandDurationEventMulti)
29+
// if err != nil {
30+
// panic(err)
31+
// }
32+
33+
// for {
34+
// edepth := expectedDepths[h.Index()]
35+
// edur := expectedDurations[h.Index()]
36+
// earr := expectedArrivals[h.Index()]
37+
38+
// if h.Depth() != edepth {
39+
// t.Errorf("Event at index %d had Depth = %v. Expected: %3.2f", h.Index(), h.Depth(), edepth)
40+
// }
41+
// if h.Duration() != edur {
42+
// t.Errorf("Event at index %d had Duration = %v. Expected: %3.2f", h.Index(), h.Duration(), edur)
43+
// }
44+
// if h.Depth() != edepth {
45+
// t.Errorf("Event at index %d had ArrivalTime = %v. Expected: %v", h.Index(), h.ArrivalTime(), earr)
46+
// }
47+
48+
// if h.HasNext() {
49+
// h.Increment()
50+
// } else {
51+
// break
52+
// }
53+
// }
54+
// }

notes.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,41 @@
5757
- structureAmountToDamage = CalculateCurrentStructureValue(year) * structureModifier
5858
- ==> like go-consequences `sval * sdampercent`
5959

60+
## 3. Write results to file
61+
62+
- Assumption: we don't want to write several hundred columns to store results for every HazardEvent in a MultiHazardEvent
63+
- Depending on the number of hazards and variables tracked, it may not be possible: "The default setting for SQLITE_MAX_COLUMN is 2000" (https://sqlite.org/limits.html)
64+
65+
### Proposal 1: dedicate 1 column in the `consequences.Result` to results for specific hazard events
66+
- Result.Header[i] = "hazard results"
67+
- subResult = consequences.Result{}
68+
- Result.Results[i] = subResult
69+
- for event in events:
70+
1. create a new result with the fields we want to report for each event
71+
2. subResult.Header = append(subResult.Header, fmt.Sprintf("%d", event.Index())
72+
3. subResult.Results = append(subResult.Results, consequences.Result{Header: subHeader, Results: event_results}
73+
74+
Pros:
75+
1. This works and we can utilize the Fetch() method on the nested results to get results for specific events
76+
77+
Cons:
78+
1. the string headers for the results of individual events are repeated each time wasting space
79+
2. cannot save the results to gpkg unless the entire result column is converted to a string which removes our ability to parse as structs.
80+
- instead of just casting as a string, should I be using the MarshalJSON method?
81+
82+
83+
### Proposal 2: Use consequences.Results{IsTable: true}
84+
-
85+
6086

6187

6288
## General Brainstorming
6389

6490
- In `compute-configuration.go` the `Computable` struct includes a `ComputeLifeloss` bool. We could add another bool for `ComputeReconstruction` that would enable that calculation without making it a default.
6591

92+
# TODO today
93+
94+
1. [x] json_multi_hazard_test.go - replace printline with asserts that check expected values
95+
2. [x] flood_test.go - when checking if event has given parameters, also assert that the values are as expected
96+
3. [x] make a csv hazard provider that simply provides a constant arrival, depth, and duration for all locations.
6697

structures/structures_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func TestComputeConsequencesWithReconstruction(t *testing.T) {
223223

224224
//test depth values
225225
var d = hazards.ArrivalDepthandDurationEvent{}
226-
d.SetDuration(2.5)
226+
d.SetDuration(3)
227227
at := time.Date(1984, time.Month(1), 22, 0, 0, 0, 0, time.UTC)
228228
d.SetArrivalTime(at)
229229
depths := []float64{0.0, 0.5, 1.0, 1.0001, 2.25, 2.5, 2.75, 3.99, 4, 5}
@@ -240,10 +240,11 @@ func TestComputeConsequencesWithReconstruction(t *testing.T) {
240240
panic(err)
241241
}
242242
got := out.(float64)
243+
expect := math.Ceil(expectedResults[idx] + d.Duration())
243244
fmt.Printf("Reconstruction time was %3.2f days.\n", got)
244-
diff := (expectedResults[idx] + d.Duration()) - got //180.0/100=1.8
245+
diff := expect - got //180.0/100=1.8
245246
if math.Abs(diff) > .0000000000001 {
246-
t.Errorf("Compute(%f) = %f; expected %f", depths[idx], got, expectedResults[idx]*1.8+d.Duration())
247+
t.Errorf("Compute(%f) = %f; expected %f", depths[idx], got, expect)
247248
}
248249

249250
}

0 commit comments

Comments
 (0)