Skip to content

Commit

Permalink
feat(calcs): migrate to new SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
nckhell committed Jan 4, 2025
1 parent 6dbf9f1 commit 2b0551f
Show file tree
Hide file tree
Showing 270 changed files with 3,225 additions and 5,010 deletions.
221 changes: 40 additions & 181 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
"license": "ISC",
"dependencies": {
"lodash": "^4.17.21",
"mathjs": "^14.0.1",
"moment": "^2.30.1",
"ramda": "^0.30.1",
"showdown": "^2.1.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@types/cpx": "^1",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.14.186",
"@types/lodash": "^4",
"@types/node": "^18.7.23",
"@types/ramda": "^0.28.15",
"@types/showdown": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
Expand All @@ -44,6 +40,7 @@
"eslint": "^9.17.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"mockdate": "^3.0.5",
"pre-commit": "^1.2.2",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
Expand Down
22 changes: 9 additions & 13 deletions src/classes/Score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
type ScoreOutputSchemaType,
type ScoreType,
type CalculateFn,
type CategoryType,
type TerminologyType,
} from '../types'
import {
Expand All @@ -20,7 +19,7 @@ import {
tryCastToStringsArray,
tryCastToNumbersArray,
} from '../lib/castFunctions'
import _ from 'lodash'
import { mapValues, sample, random, sampleSize, pickBy } from 'lodash'
import { simulateDateInput, simulateStringInput } from '../lib/simulation'
import { parseToApiResultFormat } from '../lib/parseToApiResultFormat'

Expand Down Expand Up @@ -207,7 +206,7 @@ export class Score<
return input_value
}

return _.mapValues(data, castInputToExactType)
return mapValues(data, castInputToExactType)
}

/**
Expand All @@ -221,7 +220,7 @@ export class Score<
z.infer<OutputSchema[keyof OutputSchema]['type']> | null
>
} {
const simulatedInput = _.mapValues(
const simulatedInput = mapValues(
this.inputSchemaAsObject.shape,
zodType => {
const getZodType = () => {
Expand All @@ -247,31 +246,28 @@ export class Score<
}

if (inputType instanceof z.ZodBoolean) {
return _.sample([true, false])
return sample([true, false])
}

if (inputType instanceof z.ZodNumber) {
const min = inputType.minValue
const max = inputType.maxValue

return _.random(min ?? 0, max ?? 100, false)
return random(min ?? 0, max ?? 100, false)
}

if (inputType instanceof z.ZodUnion) {
const optionValues = inputType.options.map(option => option.value)
return _.sample(optionValues)
return sample(optionValues)
}

if (inputType instanceof z.ZodArray) {
const itemType = inputType.element

if (itemType instanceof z.ZodUnion) {
const optionValues = itemType.options.map(option => option.value)
const randomNumberBetweenOneAndMax = _.random(
1,
optionValues.length,
)
return _.sampleSize(optionValues, randomNumberBetweenOneAndMax)
const randomNumberBetweenOneAndMax = random(1, optionValues.length)
return sampleSize(optionValues, randomNumberBetweenOneAndMax)
}
}

Expand All @@ -280,7 +276,7 @@ export class Score<
)

return {
simulatedInput: _.pickBy(simulatedInput, value => value !== undefined),
simulatedInput: pickBy(simulatedInput, value => value !== undefined),
results: this.calculate({ payload: simulatedInput }),
}
}
Expand Down
Loading

0 comments on commit 2b0551f

Please sign in to comment.