Skip to content

Commit

Permalink
Merge pull request #1047 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
minthify before meeting
  • Loading branch information
sasumaki authored Jun 26, 2019
2 parents dc0b02f + da32b25 commit 9102a90
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -1,93 +1,133 @@
/* eslint-disable quotes */
import React from 'react'
import { Grid } from 'semantic-ui-react'
import { bool } from 'prop-types'
import { gradeGraphOptions } from '../../../../constants'
import {
viewModeNames,
graphSeriesTypes,
getDataObject,
getMaxValueOfSeries,
dataSeriesType,
viewModeType,
getGradeSpread,
getThesisGradeSpread,
isThesisSeries
isThesisSeries,
absoluteToRelative
} from './util'
import StackedBarChart from '../../../StackedBarChart'

const getGradeSeries = (series, seriesType) => {
const { name, multiplier } = seriesType
const getGradeSeries = (series) => {
const isGradeSeries = !isThesisSeries(series)
const newSeries = isGradeSeries
? getGradeSpread(series, multiplier)
: getThesisGradeSpread(series, multiplier)

const newSeries = isGradeSeries ?
getGradeSpread(series)
: getThesisGradeSpread(series)
const sumAll = Object.values(newSeries)[0].map((_, idx) => Object.values(newSeries).map(serie => serie[idx]).reduce((a, b) => a + b, 0))
return isGradeSeries
? [
getDataObject(`${name} 0`, newSeries[0], 'a'),
getDataObject(`${name} 1`, newSeries[1], 'b'),
getDataObject(`${name} 2`, newSeries[2], 'c'),
getDataObject(`${name} 3`, newSeries[3], 'd'),
getDataObject(`${name} 4`, newSeries[4], 'e'),
getDataObject(`${name} 5`, newSeries[5], 'f'),
getDataObject(`${name} Hyv.`, newSeries['Hyv.'], 'g')
]
: [
getDataObject(`${name} I`, newSeries.I, 'a'),
getDataObject(`${name} A`, newSeries.A, 'b'),
getDataObject(`${name} NSLA`, newSeries.NSLA, 'c'),
getDataObject(`${name} LUB`, newSeries.LUB, 'd'),
getDataObject(`${name} CL`, newSeries.CL, 'e'),
getDataObject(`${name} MCLA`, newSeries.MCLA, 'f'),
getDataObject(`${name} ECLA`, newSeries.ECLA, 'g'),
getDataObject(`${name} L`, newSeries.L, 'h')
]
? {
absolute: [
getDataObject('0', newSeries[0], 'a'),
getDataObject('1', newSeries[1], 'b'),
getDataObject('2', newSeries[2], 'c'),
getDataObject('3', newSeries[3], 'd'),
getDataObject('4', newSeries[4], 'e'),
getDataObject('5', newSeries[5], 'f'),
getDataObject('Hyv.', newSeries['Hyv.'], 'g')
],
relative: [
getDataObject('0', newSeries[0].map(absoluteToRelative(sumAll)), 'a'),
getDataObject('1', newSeries[1].map(absoluteToRelative(sumAll)), 'b'),
getDataObject('2', newSeries[2].map(absoluteToRelative(sumAll)), 'c'),
getDataObject('3', newSeries[3].map(absoluteToRelative(sumAll)), 'd'),
getDataObject('4', newSeries[4].map(absoluteToRelative(sumAll)), 'e'),
getDataObject('5', newSeries[5].map(absoluteToRelative(sumAll)), 'f'),
getDataObject('Hyv.', newSeries['Hyv.'].map(absoluteToRelative(sumAll)), 'g')
]
}
: {
absolute: [
getDataObject(' I', newSeries.I, 'a'),
getDataObject('A', newSeries.A, 'b'),
getDataObject('NSLA', newSeries.NSLA, 'c'),
getDataObject('LUB', newSeries.LUB, 'd'),
getDataObject('CL', newSeries.CL, 'e'),
getDataObject('MCLA', newSeries.MCLA, 'f'),
getDataObject('ECLA', newSeries.ECLA, 'g'),
getDataObject('L', newSeries.L, 'h')
],
relative: [
getDataObject(' I', newSeries.I.map(absoluteToRelative(sumAll)), 'a'),
getDataObject('A', newSeries.A.map(absoluteToRelative(sumAll)), 'b'),
getDataObject('NSLA', newSeries.NSLA.map(absoluteToRelative(sumAll)), 'c'),
getDataObject('LUB', newSeries.LUB.map(absoluteToRelative(sumAll)), 'd'),
getDataObject('CL', newSeries.CL.map(absoluteToRelative(sumAll)), 'e'),
getDataObject('MCLA', newSeries.MCLA.map(absoluteToRelative(sumAll)), 'f'),
getDataObject('ECLA', newSeries.ECLA.map(absoluteToRelative(sumAll)), 'g'),
getDataObject('L', newSeries.L.map(absoluteToRelative(sumAll)), 'h')
]
}
}

const getGradeCumSeriesFromStats = (stats, seriesType) => {
const getGradeCumSeriesFromStats = (stats) => {
const series = stats.flatMap(s => s.cumulative.grades)
return getGradeSeries(series, seriesType)
return getGradeSeries(series)
}

const getGradeStudSeriesFromStats = (stats, seriesType) => {
const getGradeStudSeriesFromStats = (stats) => {
const series = stats.flatMap(s => s.students.grades)
return getGradeSeries(series, seriesType)
return getGradeSeries(series)
}

const Distribution = ({ primary, comparison, viewMode }) => {
const Distribution = ({ primary, comparison, viewMode, isRelative }) => {
const isCumulativeMode = viewMode === viewModeNames.CUMULATIVE
const primaryStats = primary.stats
const statYears = primaryStats.map(year => year.name)
const comparisonStats = comparison ? comparison.stats : []

const gradeGraphSerieFn = isCumulativeMode ? getGradeCumSeriesFromStats : getGradeStudSeriesFromStats

const gradeGraphSerie = [
...gradeGraphSerieFn(primaryStats, graphSeriesTypes.PRIMARY),
...gradeGraphSerieFn(comparisonStats, graphSeriesTypes.COMPARISON)
]
const gradeGraphSerie = gradeGraphSerieFn(primaryStats)
const comparisonGraphSerie = gradeGraphSerieFn(comparisonStats)

const maxGradeValue = getMaxValueOfSeries(gradeGraphSerie)
const maxGradeValue = isRelative ? 1 : getMaxValueOfSeries(gradeGraphSerie.absolute)

const distributionOptions = gradeGraphOptions(statYears, maxGradeValue)
const primaryDistributionOptions = comparison ? gradeGraphOptions(statYears, maxGradeValue, 'Primary Grades') : gradeGraphOptions(statYears, maxGradeValue, 'Grades')
const comparisonDistributionOptions = gradeGraphOptions(statYears, maxGradeValue, 'Comparison Grades')

return (
<Grid.Column>
<StackedBarChart
options={distributionOptions}
series={gradeGraphSerie}
/>
</Grid.Column>
<>
<Grid.Row>
<Grid.Column>
<StackedBarChart
options={primaryDistributionOptions}
series={isRelative ? gradeGraphSerie.relative : gradeGraphSerie.absolute}
/>
</Grid.Column>
</Grid.Row>
{comparison &&
<Grid.Row>
<Grid.Column>
<StackedBarChart
options={comparisonDistributionOptions}
series={isRelative ? comparisonGraphSerie.relative : comparisonGraphSerie.absolute}
/>
</Grid.Column>
</Grid.Row>
}

</>
)
}

Distribution.propTypes = {
primary: dataSeriesType.isRequired,
comparison: dataSeriesType,
viewMode: viewModeType.isRequired
viewMode: viewModeType.isRequired,
isRelative: bool
}

Distribution.defaultProps = {
comparison: undefined
comparison: undefined,
isRelative: false
}

export default Distribution
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
/* eslint-disable quotes */
import React from 'react'
import { Grid } from 'semantic-ui-react'
import { bool } from 'prop-types'
import StackedBarChart from '../../../StackedBarChart'
import { passRateCumGraphOptions, passRateStudGraphOptions } from '../../../../constants'
import {
viewModeNames,
graphSeriesTypes,
getDataObject,
getMaxValueOfSeries,
dataSeriesType,
viewModeType
viewModeType,
absoluteToRelative
} from './util'

const getPassRateCumSeriesFromStats = (stats, seriesType) => {
const { name, multiplier } = seriesType
const getPassRateCumSeriesFromStats = (stats) => {
const all = []
const passed = []
const failed = []

stats.forEach((year) => {
const { passed: p, failed: f } = year.cumulative.categories
all.push((p * multiplier) + (f * multiplier))
passed.push(p * multiplier)
failed.push(f * multiplier)
all.push(p + f)
passed.push(p)
failed.push(f)
})

return [
getDataObject(`${name} all`, all, 'a'),
getDataObject(`${name} passed`, passed, 'b'),
getDataObject(`${name} failed`, failed, 'c')
]
return {
absolute: [
getDataObject(`all`, all, 'a'),
getDataObject(`passed`, passed, 'b'),
getDataObject(`failed`, failed, 'c')
],
relative: [
// eslint-disable-next-line no-unused-vars
getDataObject(`all`, all.map(_ => 1), 'a'),
getDataObject(`passed`, passed.map(absoluteToRelative(all)), 'b'),
getDataObject(`failed`, failed.map(absoluteToRelative(all)), 'c')
]
}
}

const getPassRateStudSeriesFromStats = (stats, seriesType) => {
const { name, multiplier } = seriesType

const getPassRateStudSeriesFromStats = (stats) => {
const all = []
const failedFirst = []
const failedRetry = []
Expand All @@ -48,57 +56,83 @@ const getPassRateStudSeriesFromStats = (stats, seriesType) => {
passedRetry: pr
} = year.students.categories

all.push((ff * multiplier) + (fr * multiplier) + (pf * multiplier) + (pr * multiplier))
failedFirst.push(ff * multiplier)
failedRetry.push(fr * multiplier)
passedFirst.push(pf * multiplier)
passedRetry.push(pr * multiplier)
all.push((ff || 0) + (fr || 0) + (pf || 0) + (pr || 0))
failedFirst.push(ff || 0)
failedRetry.push(fr || 0)
passedFirst.push(pf || 0)
passedRetry.push(pr || 0)
})

return [
getDataObject(`${name} all`, all, 'a'),
getDataObject(`${name} passed on first try`, passedFirst, 'b'),
getDataObject(`${name} passed after retry`, passedRetry, 'b'),
getDataObject(`${name} failed on first try`, failedFirst, 'c'),
getDataObject(`${name} failed after retry`, failedRetry, 'c')
]
return {
absolute: [
getDataObject(`all`, all, 'a'),
getDataObject(` passed on first try`, passedFirst, 'b'),
getDataObject(`passed after retry`, passedRetry, 'b'),
getDataObject(`failed on first try`, failedFirst, 'c'),
getDataObject(`failed after retry`, failedRetry, 'c')
],
relative: [
// eslint-disable-next-line no-unused-vars
getDataObject(`all`, all.map(_ => 1), 'a'),
getDataObject(` passed on first try`, passedFirst.map(absoluteToRelative(all)), 'b'),
getDataObject(`passed after retry`, passedRetry.map(absoluteToRelative(all)), 'b'),
getDataObject(`failed on first try`, failedFirst.map(absoluteToRelative(all)), 'c'),
getDataObject(`failed after retry`, failedRetry.map(absoluteToRelative(all)), 'c')
]
}
}

const PassRate = ({ primary, comparison, viewMode }) => {
const PassRate = ({ primary, comparison, viewMode, isRelative = false }) => {
const isCumulativeMode = viewMode === viewModeNames.CUMULATIVE

const primaryStats = primary.stats
const statYears = primaryStats.map(year => year.name)
const comparisonStats = comparison ? comparison.stats : []
const passGraphSerieFn = isCumulativeMode ? getPassRateCumSeriesFromStats : getPassRateStudSeriesFromStats

const passGraphSerie = [
...passGraphSerieFn(primaryStats, graphSeriesTypes.PRIMARY),
...passGraphSerieFn(comparisonStats, graphSeriesTypes.COMPARISON)
]
const passGraphSerie = passGraphSerieFn(primaryStats)
const comparisonGraphSerie = passGraphSerieFn(comparisonStats)

const maxPassRateVal = getMaxValueOfSeries(passGraphSerie)
const maxPassRateVal = isRelative ? 1 : getMaxValueOfSeries(passGraphSerie.absolute)
const graphOptionsFn = isCumulativeMode ? passRateCumGraphOptions : passRateStudGraphOptions
const graphOptions = graphOptionsFn(statYears, maxPassRateVal)
const primaryGraphOptions = comparison ? graphOptionsFn(statYears, maxPassRateVal, 'Primary pass rate chart') : graphOptionsFn(statYears, maxPassRateVal, 'Pass rate chart')
const comparisonGraphOptions = graphOptionsFn(statYears, maxPassRateVal, 'Comparison pass rate chart')

return (
<Grid.Column>
<StackedBarChart
options={graphOptions}
series={passGraphSerie}
/>
</Grid.Column>
<>
<Grid.Row>
<Grid.Column>
<StackedBarChart
options={primaryGraphOptions}
series={isRelative ? passGraphSerie.relative : passGraphSerie.absolute}
/>
</Grid.Column>
</Grid.Row>
{
comparison &&
<Grid.Row>
<Grid.Column>
<StackedBarChart
options={comparisonGraphOptions}
series={isRelative ? comparisonGraphSerie.relative : comparisonGraphSerie.absolute}
/>
</Grid.Column>
</Grid.Row>
}
</>
)
}

PassRate.propTypes = {
primary: dataSeriesType.isRequired,
comparison: dataSeriesType,
viewMode: viewModeType.isRequired
viewMode: viewModeType.isRequired,
isRelative: bool
}

PassRate.defaultProps = {
comparison: undefined
comparison: undefined,
isRelative: false
}

export default PassRate
Loading

0 comments on commit 9102a90

Please sign in to comment.