Skip to content

Commit

Permalink
fix: P-value calculation off by one. Added interpolation.
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Apr 8, 2024
1 parent 91e15ce commit 70cc978
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@master

- name: "Create report"
run: docker-compose build api && docker-compose run -u 0 api python tests/optimizer_test.py
run: docker-compose build api && docker-compose run -u 0 api python src/tests/optimizer_test.py

- name: Archive results
uses: actions/upload-artifact@v2
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ services:
web:
build:
context: ./web
target: prod
# target: development
target: development
restart: unless-stopped
stdin_open: true
volumes:
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react": "^18.2.0",
"react-bootstrap": "^2.9.1",
"react-dom": "^18.2.0",
"react-oauth2-code-pkce": "^1.15.2",
"react-oauth2-code-pkce": "^1.17.2",
"react-router-dom": "^6.20.1",
"react-scripts": "^5.0.1",
"react-toastify": "^9.1.3",
Expand Down
33 changes: 24 additions & 9 deletions web/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,42 @@ export function findGraphData(sizeFractions: number[], bridges: Bridge): GraphDa
sizeFractions.forEach((fraction, sizeIndex) => {
let temp: GraphData = { size: fraction }
Object.entries(bridges).forEach(([name, cumulative]) => {
temp[name] = cumulative[sizeIndex + 1]
temp[name] = cumulative[sizeIndex]
})
newGraphData.push(temp)
})
return newGraphData
}

function linearInterpolation(yMin: number, yMax: number, xMin: number, xMax: number, targetY: number): number {
const increase = (yMax - yMin) / (xMax - xMin)
return Number((increase * (targetY - xMin) + yMin).toFixed(1))
}

export function findDValue(graphData: GraphData[], goalYValue: number, bridgeName: string): number {
//A D value is defined as a bridge graph's x-value at a specific y value
//example: D90 (goalYValue = 90) is the bridge graph's x-value at at y = 90
// A D value is defined as a bridge graph's x-value at a specific y value
// Example: D90 (goalYValue = 90) is the bridge graph's x-value at y = 90

let bridgeYValues: number[] = []
graphData.map(graph => bridgeYValues.push(graph[bridgeName]))

// find the bridge's y-value that is closest to the goal y-value
var closestToGoalYvalue = bridgeYValues.reduce(function (prev: number, curr: number) {
return Math.abs(curr - goalYValue) < Math.abs(prev - goalYValue) ? curr : prev
let indexOfClosestHigherYValue = 0
bridgeYValues.some((accumulativePercentage, index) => {
if (accumulativePercentage > goalYValue) {
indexOfClosestHigherYValue = index
return true
}
return false
})
if (!indexOfClosestHigherYValue) throw new Error('Failed to find D-value of bridge')

let indexOfClosestYValue = bridgeYValues.indexOf(closestToGoalYvalue)
let DValue = graphData[indexOfClosestYValue].size //size contains the bridge's x-value

return DValue
// interpolate the values to get an approx value for the exact D requested
return linearInterpolation(
graphData[indexOfClosestHigherYValue - 1].size,
graphData[indexOfClosestHigherYValue].size,
bridgeYValues[indexOfClosestHigherYValue - 1],
bridgeYValues[indexOfClosestHigherYValue],
goalYValue
)
}

0 comments on commit 70cc978

Please sign in to comment.