Skip to content

Commit

Permalink
delete import and old functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-solo committed Oct 3, 2023
1 parent e7b7e44 commit 333531e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 188 deletions.
1 change: 0 additions & 1 deletion utils/api/futureHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { RequestSchema as schema } from './definitions/schemas'
import {
buildQuery,
getAgeArray,
getAgeArray2,
OasEligibility,
AlwsEligibility,
} from './helpers/utils'
Expand Down
187 changes: 0 additions & 187 deletions utils/api/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,193 +78,6 @@ export function getAgeArray(residencyData) {
return result
}

export function getAgeArray3(residencyData) {
let [userAge, partnerAge] = [
residencyData.client.age,
residencyData.partner.age,
]
let [userRes, partnerRes] = [
residencyData.client.res,
residencyData.partner.res,
]

const resLimit = 10
const result = []

// Early return if any element is missing
if ([userAge, partnerAge, userRes, partnerRes].some((el) => isNaN(el)))
return []

// Helper function to check ALW eligibility
function isEligibleForALW(age, residency, partnerOASEligibility) {
return (
age >= 60 && age < 65 && residency >= resLimit && partnerOASEligibility
)
}

// Helper function to check OAS eligibility
function isEligibleForOAS(age, residency) {
return age >= 65 && residency >= resLimit
}

// Tracking initial eligibility
let userPrevEligibility = [
isEligibleForALW(
userAge,
userRes,
isEligibleForOAS(partnerAge, partnerRes)
),
isEligibleForOAS(userAge, userRes),
]

let partnerPrevEligibility = [
isEligibleForALW(
partnerAge,
partnerRes,
isEligibleForOAS(userAge, userRes)
),
isEligibleForOAS(partnerAge, partnerRes),
]

// Iterate until both are eligible for OAS
while (
!(
isEligibleForOAS(userAge, userRes) &&
isEligibleForOAS(partnerAge, partnerRes)
)
) {
// Increase age and residency for both user and partner
userAge++
userRes++
partnerAge++
partnerRes++

// Check current eligibility
const userCurrEligibility = [
isEligibleForALW(
userAge,
userRes,
isEligibleForOAS(partnerAge, partnerRes)
),
isEligibleForOAS(userAge, userRes),
]

const partnerCurrEligibility = [
isEligibleForALW(
partnerAge,
partnerRes,
isEligibleForOAS(userAge, userRes)
),
isEligibleForOAS(partnerAge, partnerRes),
]

// If eligibility changed for either person, add to result
if (
userCurrEligibility.join() !== userPrevEligibility.join() ||
partnerCurrEligibility.join() !== partnerPrevEligibility.join()
) {
result.push([userAge, partnerAge])
}

// Update previous eligibility
userPrevEligibility = userCurrEligibility
partnerPrevEligibility = partnerCurrEligibility
}

return result
}

export function getAgeArray2(ages: number[]) {
// {66.42: 40, 60.92: 10} == [70.5, 65]
// uALW: null
// uOAS: null
// pALW: null
// pOAS: 4.08

// {68.75: 12, 59.25: 40} == [69.5,60], [74.5,65]
// uALW: null // uALW: null
// uOAS: null // uOAS: null
// pALW: 0.75 // pALW: null
// pOAS: 5.75 // pOAS: 5

// {70: 15, 64: 8} -> (72:17, 66:10) == [72,66]
// {70: 15, 66: 8} -> (72:17, 68:10) == [72,68]
// {70.5: 15, 64.5: 8} -> [72.5, 66.5]
// 60: 9, 65: 10 -> 61: 10, 66: 11 -> 65: 14, 70: 15 == [61, 66], [65, 70]

// uALW: 1 // uALW: null (if already ALW eligible return null) // uALW: null
// uOAS: 5 // uOAS: 4 // uOAS: null
// pALW: null // pALW: null // pALW: null
// pOAS: null // pOAS: null // pOAS: null

// 45: 1, 62: 20 -> (48: 4, 65: 23), (60: 16, 77: 35), (65: 21, 82:42) == [48, 65], [60, 77], [65, 82]

// how to determine next milestone
// if under 65
// increase age and res by 1

// noone eligible -> client will eligible first -> then a year later partner will be eligible -> EVERYONE ELIGIBLE FOR OAS, DONE
// {68: 5, 69: 4} -> (73: 10, 74: 9) -> (74: 11, 75: 10) => [73, 74], [74, 75]

// 53, 59 -> (60,66), (65,71)
// 53:2, 59:1 -> (54:3, 60:2), (59: 8, 65: 7), (60: 9, 66:8) -> (61:10, 67:9) -> (62:11, 68:10) -> (65:14, 71:13) == [62, 68], [65,71]
const [userAge, partnerAge] = ages
const ageDiff = Math.abs(userAge - partnerAge)

const result = []

// while both res are below 10
// add 1 to everything

if (ageDiff > 5 && ages.some((age) => age < 60)) {
while (!ages.some((age) => age === 60)) {
// should be "until some age is not over 60"
let [userAge, partnerAge] = ages
if (userAge > partnerAge && userAge < 65) {
// make this 65 user oas eligibility age
let diff = 65 - userAge // client oas eligibility age - user age
userAge += diff
partnerAge += diff
} else if (userAge < partnerAge) {
let diff = 60 - userAge // user ALW eli age instead of 60
userAge += diff
partnerAge += diff
} else {
let diff = 60 - partnerAge // partner ALW age instead of 60
userAge += diff
partnerAge += diff
}
ages = [userAge, partnerAge]
result.push(ages)
}
}

while (!ages.every((age) => age >= 65)) {
// while both are not eligible
let [userAge, partnerAge] = ages
if (userAge >= 65 || partnerAge >= 65) {
if (userAge < partnerAge) {
let diff = 65 - userAge // partner OAS eligibility age instead of 65
userAge += diff
partnerAge += diff
} else {
let diff = 65 - partnerAge
userAge += diff
partnerAge += diff
}
} else {
const maxAge = Math.max(userAge, partnerAge)
const diff = 65 - maxAge
userAge += diff
partnerAge += diff
}
ages = [userAge, partnerAge]
result.push(ages)
}

return result
}

export function buildQuery(
query,
ageSet,
Expand Down

0 comments on commit 333531e

Please sign in to comment.