Skip to content

Add reconstruction unit tests#128

Open
sebastianrowan wants to merge 17 commits intoUSACE:reconstruction-lifecyclefrom
sebastianrowan:building-reconstruction
Open

Add reconstruction unit tests#128
sebastianrowan wants to merge 17 commits intoUSACE:reconstruction-lifecyclefrom
sebastianrowan:building-reconstruction

Conversation

@sebastianrowan
Copy link
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
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)

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
Contributor

Choose a reason for hiding this comment

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

beautiful

if err != nil {
panic(err)
}
fmt.Printf("Damage was %3.2f. Expected: %3.2f\n", dmgout, expectedDmgs[idx])
Copy link
Contributor

Choose a reason for hiding this comment

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

perfet!

@sebastianrowan
Copy link
Contributor Author

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

@sebastianrowan
Copy link
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.


events := []hazards.ArrivalDepthandDurationEvent{d5, d1, d2, d3, d4}

addMulti := &hazards.ArrivalDepthandDurationEventMulti{Events: events} //need to use the pointer reference because methods on MultiHazardEvent require pointers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HenryGeorgist will this be a problem? The Increment() and ResetIndex() methods on the MultiHazardEvent have to use pointers to be able to modify the index value of the struct.

trying to send addMulti to Compute() without the & means it doesn't satisfy the MultiHazardEvent interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

either an instance will implement all the methods or the pointer will implement all the methods. So if you have to have a pointer on one then you have to have a pointer on all methods. An alternative: func (h ArrivalDepthAndDurationEvent) Index() ArrivalDepthAndDurationEvent where the interface would have to be Index() MultiHazard

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