Skip to content

Commit

Permalink
Merge pull request #1053 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
fixes and betterments
  • Loading branch information
Rochet2 authored Jun 26, 2019
2 parents 9102a90 + 15517a7 commit aa0a5f2
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const getPassRateCumSeriesFromStats = (stats) => {
],
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')
]
Expand Down Expand Up @@ -73,7 +72,6 @@ const getPassRateStudSeriesFromStats = (stats) => {
],
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'),
Expand All @@ -95,8 +93,8 @@ const PassRate = ({ primary, comparison, viewMode, isRelative = false }) => {

const maxPassRateVal = isRelative ? 1 : getMaxValueOfSeries(passGraphSerie.absolute)
const graphOptionsFn = isCumulativeMode ? passRateCumGraphOptions : passRateStudGraphOptions
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')
const primaryGraphOptions = comparison ? graphOptionsFn(statYears, maxPassRateVal, 'Primary pass rate chart', isRelative) : graphOptionsFn(statYears, maxPassRateVal, 'Pass rate chart', isRelative)
const comparisonGraphOptions = graphOptionsFn(statYears, maxPassRateVal, 'Comparison pass rate chart', isRelative)

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ResultTabs extends Component {
comparison={comparison}
primary={primary}
viewMode={viewMode}
isRelative={isRelative}
isRelative={isRelative && comparison}
/>)
},
{
Expand All @@ -51,7 +51,7 @@ class ResultTabs extends Component {
comparison={comparison}
primary={primary}
viewMode={viewMode}
isRelative={isRelative}
isRelative={isRelative && comparison}
/>)
}
]
Expand Down Expand Up @@ -125,6 +125,7 @@ class ResultTabs extends Component {
<label className="toggleLabel">Absolute</label>
<Radio
toggle
checked={this.state.isRelative}
onChange={() => this.setState({ isRelative: !this.state.isRelative })}
/>
<label className="toggleLabel">Relative</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { tagFilter } from '../../populationFilters'
const TagFilter = ({ setPopulationFilterAction, removePopulationFilterAction, filter, samples }) => {
const [options, setOptions] = useState([])
const [selectedTag, setSelectedTag] = useState()
const [selectedComp, setSelectedComp] = useState()

const createOptions = () => {
const tags = samples.map(s => s.tags.map(t => ({ tagname: t.tag.tagname, tag_id: t.tag.tag_id })))
Expand All @@ -26,13 +27,16 @@ const TagFilter = ({ setPopulationFilterAction, removePopulationFilterAction, fi
}, [])

const handleFilter = () => {
setPopulationFilterAction(tagFilter({ tag: selectedTag }))
setPopulationFilterAction(tagFilter({ tag: selectedTag, comp: selectedComp }))
}

const handleCompChange = (e, { value }) => {
setSelectedComp(value)
}

const handleChange = (e, { value }) => {
// any better solutions?
const selection = options.filter(tag => tag.value === value)
setSelectedTag(selection[0])
const selection = options.find(tag => tag.value === value)
setSelectedTag(selection)
}
const clearFilter = () => {
removePopulationFilterAction(filter.id)
Expand All @@ -47,7 +51,17 @@ const TagFilter = ({ setPopulationFilterAction, removePopulationFilterAction, fi
/>
<Form.Group inline>
<Form.Field>
<label>Select students that have tag </label>
<label>Select students that </label>
</Form.Field>
<Form.Field>
<Dropdown
placeholder="select"
options={[{ key: 1, text: 'have', value: true }, { key: 2, text: 'don\'t have', value: false }]}
onChange={handleCompChange}
/>
</Form.Field>
<Form.Field>
<label>a tag </label>
</Form.Field>
<Form.Field>
<Dropdown
Expand All @@ -69,7 +83,7 @@ const TagFilter = ({ setPopulationFilterAction, removePopulationFilterAction, fi
}
return (
<Segment>
Students that have a tag {filter.params.text}
Students that {filter.params.comp ? 'have' : 'don\'t have'} a tag {filter.params.text}
<span style={{ float: 'right' }}>
<Icon name="remove" onClick={clearFilter} />
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class PopulationStudents extends Component {
<div style={{ overflowX: 'hidden' }}><div style={{ width: 0 }}>{e.label}</div></div>
),
parent: true,
headerProps: { colSpan: labelToMandatoryCourses[e.label].length, title: e.label }
headerProps: { colSpan: labelToMandatoryCourses[e.label].length, title: e.label, ordernumber: e.orderNumber }
}))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,24 @@ class SortableTable extends Component {
const { collapsed } = this.state
const defaultColumnCount = showNames ? 6 : 3
if (collapsed) {
const collapsedKeys = collapsed.map(c => c.key)
return collapsedKeys.reduce((acc, curr) => {
const previousCols = columns.filter(c => c.key < curr)
const collapsedOrderNumbers = collapsed.map(c => c.headerProps.ordernumber)
return collapsedOrderNumbers.reduce((acc, curr) => {
const previousCols = columns.filter(c => c.headerProps && c.headerProps.ordernumber < curr)
const sumOfPreviousColSpans = previousCols.reduce((a, b) => a + b.headerProps.colSpan, 0)
return [
...acc,
sumOfPreviousColSpans + columns.find(c => c.key === curr).headerProps.colSpan + defaultColumnCount]
sumOfPreviousColSpans + columns.find(c => c.headerProps && c.headerProps.ordernumber === curr).headerProps.colSpan + defaultColumnCount]
}, [])
}
return []
}
const { tableProps, getRowProps, columns, getRowKey, collapsingHeaders } = this.props
const { selected, direction, collapsed } = this.state
const columnsWithCollapsedHeaders = collapsingHeaders ? [...columns.filter(c => (c.headerProps && (!collapsed.map(cell => cell.headerProps.title).includes(c.headerProps.title) && !c.collapsed))), ...this.state.collapsed].sort((a, b) => a.key - b.key) : columns
const columnsWithCollapsedHeaders = collapsingHeaders ? [...columns.filter(c => (
c.headerProps && (!collapsed.map(cell => cell.headerProps.title).includes(c.headerProps.title) && !c.collapsed))),
...this.state.collapsed].sort((a, b) => a.headerProps.ordernumber - b.headerProps.ordernumber)
:
columns

const sortDirection = name => (selected === name ? direction : null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const TagStudent = ({

useEffect(() => {
setTags(tags)
const tagIds = studentstags.map(t => ({ id: t.id, tag_id: t.tag.tag_id }))
setStudentsTagIds(tagIds)
const initialStudentsTagIds = studentstags.map(t => ({ id: t.id, tag_id: t.tag.tag_id }))
const tagIds = studentstags.map(t => t.tag.tag_id)
const initialTagOptions = tags.filter(tag => !tagIds.includes(tag.tag_id)).map(tag => ({
key: tag.tag_id,
text: tag.tagname,
value: tag.tag_id
}))
setStudentsTagIds(initialStudentsTagIds)
setTagOptions(initialTagOptions)
}, [])

Expand Down
8 changes: 4 additions & 4 deletions services/oodikone2-frontend/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ export const API_DATE_FORMAT = 'YYYY.MM.DD'

export const TOKEN_NAME = window.location.pathname.includes('staging') ? 'staging_token' : window.location.pathname.includes('/testing') ? 'testing_token' : 'token' //eslint-disable-line

export const passRateCumGraphOptions = (categories, max, title) => ({
export const passRateCumGraphOptions = (categories, max, title, skipFirstColor) => ({
chart: {
type: 'column'
},
colors: [chartblue, green, red],
colors: skipFirstColor ? [green, red] : [chartblue, green, red],

title: {
text: title
Expand All @@ -119,11 +119,11 @@ export const passRateCumGraphOptions = (categories, max, title) => ({
}
})

export const passRateStudGraphOptions = (categories, max, title) => ({
export const passRateStudGraphOptions = (categories, max, title, skipFirstColor) => ({
chart: {
type: 'column'
},
colors: [chartblue, chartlgreen, chartdarkg, chartlred, chartdarkred],
colors: skipFirstColor ? [chartlgreen, chartdarkg, chartlred, chartdarkred] : [chartblue, chartlgreen, chartdarkg, chartlred, chartdarkred],

title: {
text: title
Expand Down
8 changes: 6 additions & 2 deletions services/oodikone2-frontend/src/populationFilters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,20 @@ export const gradeMeanFilter = (params) => {

export const tagFilter = (params) => {
const { text, value } = params.tag
const { comp } = params
return ({
id: uuidv4(),
type: 'TagFilter',
params: {
text,
value
comp
},
filter: (student) => {
const studentTagIds = student.tags.map(t => t.tag.tag_id)
return studentTagIds.includes(value)
if (comp) {
return studentTagIds.includes(value)
}
return !studentTagIds.includes(value)
}
})
}
Expand Down

This file was deleted.

Loading

0 comments on commit aa0a5f2

Please sign in to comment.