Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate score: [Score Agent] Add BMI #47

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/scores/bmi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add documentation here
50 changes: 50 additions & 0 deletions src/scores/bmi/bmi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ScoreLibrary } from '../library'
import { bmi } from './bmi'
import { Score } from '../../classes'
import { ZodError } from 'zod'

const bmi_calculation = new Score(bmi)

describe('bmi', function () {
it('bmi calculation function should be available as a calculation', function () {
expect(ScoreLibrary).toHaveProperty('bmi')
})

describe('basic assumptions', function () {
const outcome = bmi_calculation.calculate({
payload: {
weight: 70,
height: 170,
},
})

it('should return a BMI result', function () {
const EXPECTED_BMI = 24.22
expect(outcome).toEqual({ bmi: EXPECTED_BMI })
})
})

describe('validations', function () {
describe('when called with an invalid payload', function () {
it('should throw an error', function () {
expect(() =>
bmi_calculation.calculate({
payload: {
weight: 'invalid',
},
}),
).toThrow(ZodError)
})
})

describe('when the response is empty', function () {
it('should throw an error', function () {
expect(() =>
bmi_calculation.calculate({
payload: {},
}),
).toThrow(ZodError)
})
})
})
})
15 changes: 15 additions & 0 deletions src/scores/bmi/bmi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { type ScoreType } from '../../types'
import { BMI_INPUTS, BMI_OUTPUT } from './definition'

Check failure on line 2 in src/scores/bmi/bmi.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find module './definition' or its corresponding type declarations.
import { sum, mean } from 'lodash'

export const bmi: ScoreType<typeof BMI_INPUTS, typeof BMI_OUTPUT> = {
name: 'Body Mass Index (BMI)',
readmeLocation: __dirname,
inputSchema: BMI_INPUTS,
outputSchema: BMI_OUTPUT,
calculate: ({ data }) => {
return {
bmi: data.weight / ((data.height / 100) ** 2),
}
}
}
15 changes: 15 additions & 0 deletions src/scores/bmi/definition/bmi_inputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from 'zod'
import type { ScoreInputSchemaType } from '../../../types'

export const BMI_INPUTS = {
weight: {
label: { en: 'Weight (kg)' },
type: z.number().nonnegative(),
unit: 'kg',

Check failure on line 8 in src/scores/bmi/definition/bmi_inputs.ts

View workflow job for this annotation

GitHub Actions / test

Type 'string' has no properties in common with type 'LabelType'.
},
height: {
label: { en: 'Height (cm)' },
type: z.number().positive(),
unit: 'cm',

Check failure on line 13 in src/scores/bmi/definition/bmi_inputs.ts

View workflow job for this annotation

GitHub Actions / test

Type 'string' has no properties in common with type 'LabelType'.
}
} satisfies ScoreInputSchemaType
10 changes: 10 additions & 0 deletions src/scores/bmi/definition/bmi_output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from 'zod'
import type { ScoreOutputSchemaType } from '../../../types'

export const BMI_OUTPUT = {
bmi: {
label: { en: 'Body Mass Index (BMI)' },
type: z.number(),
unit: 'kg/m²'

Check failure on line 8 in src/scores/bmi/definition/bmi_output.ts

View workflow job for this annotation

GitHub Actions / test

Type 'string' has no properties in common with type 'LabelType'.
}
} satisfies ScoreOutputSchemaType
1 change: 1 addition & 0 deletions src/scores/bmi/definition/bmi_subscales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder for BMI subscales if needed in the future
3 changes: 1 addition & 2 deletions src/scores/bmi/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { bmi as bmi_metric } from './metric/bmi'
export { bmi_us as bmi_imperial } from './us/bmi'
export * from './bmi'
Loading