-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1588 from CaliOpen/frontend/pi-score
[frontend] replace pi illustration by a pi score
- Loading branch information
Showing
26 changed files
with
837 additions
and
880 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/frontend/web_application/src/modules/pi/components/PiScore/PI-score.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
src/frontend/web_application/src/modules/pi/components/PiScore/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useLingui } from '@lingui/react'; | ||
import * as React from 'react'; | ||
import { PI } from 'src/modules/pi/types'; | ||
import { computeScoreLetter } from '../../services/pi'; | ||
import svgSrc from './PI-score.svg'; | ||
|
||
const colors = 'E0D699,C1EDFE,AFD9EF,9CC7DC,7198A7'; | ||
|
||
interface Props extends React.HTMLAttributes<HTMLEmbedElement> { | ||
average: number; | ||
title?: string; | ||
} | ||
|
||
export default function PiScore({ title, average, ...props }: Props) { | ||
const { i18n } = useLingui(); | ||
|
||
const score = computeScoreLetter(average); | ||
|
||
return ( | ||
<embed | ||
src={`${svgSrc}?score=${score}&colors=${colors}`} | ||
title={ | ||
title || | ||
i18n._( | ||
'pi-score.default-title', | ||
{ score }, | ||
{ message: 'This is scored as {score}.' } | ||
) | ||
} | ||
{...props} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as MultidimensionalPi } from './components/MultidimensionalPi'; | ||
export { default as BackgroundImage } from './components/BackgroundImage'; | ||
export { default as PiScore } from './components/PiScore'; | ||
export * from './services/pi'; |
40 changes: 0 additions & 40 deletions
40
src/frontend/web_application/src/modules/pi/services/pi/index.spec.js
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/frontend/web_application/src/modules/pi/services/pi/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
computeScoreLetter, | ||
getAngles, | ||
getAveragePI, | ||
getAveragePIMessage, | ||
PI_PROPERTIES, | ||
} from '.'; | ||
|
||
describe('MultidimensionalPi > services > pi', () => { | ||
describe('getAngles', () => { | ||
it('gives 360 / 3 or n props', () => { | ||
expect(getAngles()).toEqual(360 / PI_PROPERTIES.length); | ||
}); | ||
}); | ||
describe('getAveragePI', () => { | ||
it('gives a basic average value', () => { | ||
expect( | ||
getAveragePI( | ||
{ | ||
comportment: 5, | ||
technic: 10, | ||
context: 15, | ||
version: 1, | ||
}, | ||
PI_PROPERTIES | ||
) | ||
).toEqual((5 + 10 + 15) / 3); | ||
}); | ||
}); | ||
|
||
describe('getAveragePIMessage', () => { | ||
it('gives a basic average PIMessage value ', () => { | ||
expect( | ||
getAveragePIMessage({ | ||
message: { | ||
pi_message: { | ||
content: 5, | ||
transport: 10, | ||
social: 15, | ||
rab: 20, | ||
version: 1, | ||
}, | ||
}, | ||
}) | ||
).toEqual((5 + 10 + 15) / 3); | ||
}); | ||
}); | ||
|
||
describe('computeScoreLetter', () => { | ||
it('calc', () => { | ||
expect(computeScoreLetter(100)).toEqual('A'); | ||
expect(computeScoreLetter(90)).toEqual('A'); | ||
expect(computeScoreLetter(81)).toEqual('A'); | ||
expect(computeScoreLetter(80)).toEqual('B'); | ||
expect(computeScoreLetter(66)).toEqual('B'); | ||
expect(computeScoreLetter(61)).toEqual('B'); | ||
expect(computeScoreLetter(60)).toEqual('C'); | ||
expect(computeScoreLetter(50)).toEqual('C'); | ||
expect(computeScoreLetter(41)).toEqual('C'); | ||
expect(computeScoreLetter(40)).toEqual('D'); | ||
expect(computeScoreLetter(33)).toEqual('D'); | ||
expect(computeScoreLetter(30)).toEqual('D'); | ||
expect(computeScoreLetter(21)).toEqual('D'); | ||
expect(computeScoreLetter(20)).toEqual('E'); | ||
expect(computeScoreLetter(10)).toEqual('E'); | ||
expect(computeScoreLetter(0)).toEqual('E'); | ||
}); | ||
|
||
it('calc above min/max', () => { | ||
expect(computeScoreLetter(150)).toEqual('A'); | ||
expect(computeScoreLetter(-100)).toEqual('E'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.