Skip to content

Commit

Permalink
Multiply sanctions risk by 1.5 if the form of collaboration is research
Browse files Browse the repository at this point in the history
  • Loading branch information
erikao1998 committed Jan 4, 2024
1 parent afae07b commit 3d6ac69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/client/components/ResultPage/TotalRisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const TotalRisk = ({
{
id: 'country',
text: t('risks:countryRiskLevel'),
riskLevel: countryRisk(country),
riskLevel: countryRisk({ country, resultData }),
},
{
id: 'university',
Expand Down
18 changes: 14 additions & 4 deletions src/client/util/risks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { CountryData } from '@frontend/types'

export const countryRisk = (country: CountryData | undefined) => {
import { CountryData, FormValues } from '@frontend/types'

export const countryRisk = ({
country,
resultData,
}: {
country: CountryData | undefined
resultData: FormValues
}) => {
if (!country) return null

const { code, universities, safetyLevel, ...riskValues } = country
Expand All @@ -13,11 +19,15 @@ export const countryRisk = (country: CountryData | undefined) => {
['Poistu välittömästi maasta', 3],
]

const sanctionsRisk = country.sanctions ? 2 : 1
const sanctionsMultiplier =
sanctionsRisk === 2 && resultData['11'].research ? 1.5 : 1

const safetyLevelRisk =
safetyLevels.find((level) => level[0] === safetyLevel)?.[1] || null

const filteredRiskValues = Object.values(riskValues)
.concat(safetyLevelRisk as number)
.concat(safetyLevelRisk as number, sanctionsRisk * sanctionsMultiplier)
.filter((value) => value != null && typeof value === 'number')

const totalCountryRiskLevel = Math.round(
Expand Down

0 comments on commit 3d6ac69

Please sign in to comment.