Skip to content

Add reconstruction unit tests#128

Merged
HenryGeorgist merged 19 commits intoUSACE:reconstruction-lifecyclefrom
sebastianrowan:building-reconstruction
Mar 2, 2026
Merged

Add reconstruction unit tests#128
HenryGeorgist merged 19 commits intoUSACE:reconstruction-lifecyclefrom
sebastianrowan:building-reconstruction

Conversation

@sebastianrowan
Copy link
Copy Markdown
Contributor

@sebastianrowan sebastianrowan commented Jan 29, 2026

This PR adds two functions to the structures module.

  1. computeConsequencesWithReconstruction() calculates the number of days to complete construction on a damaged structure and includes this in the result

    • reconstruction time is treated as a component damage function for a given occtype with percent damage as the xvalue and days to completion as yvalue
    • unit test = TestComputeConsequencesWithReconstruction()
  2. computeConsequencesMulti() calculates the number of days and final date to complete reconstruction for an array of hazard events.

    • unit test = TestComputeConsequencesMulti()

Copy link
Copy Markdown
Contributor

@HenryGeorgist HenryGeorgist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was great. im asking you to remove files from the commit history that are not directly needed for the tests. i think that there are about 12 files currently included in this, we probably need only about 3 or 4 files total for this to be complete. lets make sure we only are changing those (to minimize our chances for accidentally checking in something we dont want to change)

Comment thread compute/compute-configuration.go
Comment thread compute/simulation.go
Comment thread compute/simulation_test.go
Comment thread consequences/interfaces.go
Comment thread crops/crop.go
Comment thread structures/structure.go Outdated
Comment thread structures/structure.go Outdated
Comment thread structures/structures_test.go Outdated
t2 := time.Date(1984, time.Month(1), 11, 0, 0, 0, 0, time.UTC) // reconstruction from event 1 should be 50% complete at this time
d2.SetArrivalTime(t2)

events := []hazards.HazardEvent{d1, d2}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful

Comment thread structures/structures_test.go
Comment thread .gitattributes Outdated
@sebastianrowan
Copy link
Copy Markdown
Contributor Author

@HenryGeorgist I think I have removed all the edits to files that aren't involved in this PR.

@sebastianrowan
Copy link
Copy Markdown
Contributor Author

@HenryGeorgist this implementation now keeps track of structure/content values and the overall damage level throughout the series of events. When a new event arrives, we first calculate how much of the total damage (not just from the previous event) has been repaired since the last event ended. Then we calculate loss by applying the damage function to the adjusted structure value. Finally we calculate reconstruction time and completion date based on the total current damage state not just the loss from the current event.

Comment thread structures/structures_test.go
Copy link
Copy Markdown
Contributor

@HenryGeorgist HenryGeorgist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great

panic(err)
}
//compute consequences.
StreamAbstract(dfr, nsp, w)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ismt it cool that we get such robustly different behavior out of streamabstract when we leverage the abstractions!

Comment thread hazardproviders/json_multi_hazard.go Outdated
process HazardFunction
}

type ADDProperties struct { // will try to not use this
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my first response was why not just use a csv... but json is fine it really doesnt matter. You could also just randomly generate this information or hard code in the list of events for this level of testing we are currenly working on.

"github.com/USACE/go-consequences/hazards"
)

type jsonArrivalDepthDurationMultiHazardProvider struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using cogs at this point is overkill

Comment thread hazardproviders/json_multi_hazard.go
Comment thread hazardproviders/json_multi_hazard_test.go Outdated
Comment thread hazards/flood.go
Comment thread hazards/flood_test.go
Comment thread hazards/interfaces.go
@HenryGeorgist HenryGeorgist merged commit 81dbe95 into USACE:reconstruction-lifecycle Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants