Skip to content

Commit

Permalink
Merge pull request #1089 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
Bug when clearing comparison group in course statistic when "All" selected
  • Loading branch information
sasumaki authored Jul 9, 2019
2 parents d28dcfa + b4f4717 commit 55c97c7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 deletions.
1 change: 0 additions & 1 deletion services/backend/oodikone2-backend/src/services/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ const yearlyStatsOf = async (code, year, separate, language) => {
if (yearInst) {
for (let year = start; year < end; year++) {
stats = oneYearStats(yearInst, year, separate, allInstancesUntilYear)
console.logs(stats)
if (stats.length > 0) {
resultStats.push(...stats)
resultProgrammes = getProgrammesFromStats(stats)
Expand Down
71 changes: 40 additions & 31 deletions services/backend/oodikone2-backend/src/services/populations.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formatStudentForPopulationStatistics = ({
firstnames, lastname, studentnumber, dateofuniversityenrollment, creditcount,
matriculationexamination, credits, abbreviatedname, email, studyrights,
semester_enrollments, transfers, updatedAt, createdAt, gender_code,
gender_fi, gender_sv, gender_en, tag_students
gender_fi, gender_sv, gender_en, tags
}, startDate, endDate) => {

const toCourse = ({ grade, attainment_date, credits, course, credittypecode, isStudyModule }) => {
Expand Down Expand Up @@ -101,7 +101,7 @@ const formatStudentForPopulationStatistics = ({
email,
semesterenrollments,
updatedAt: updatedAt || createdAt,
tags: tag_students || [],
tags: tags || [],
studyrightStart: startDate,
starting: moment(started).isBetween(startDate, endDate, null, '[]')
}
Expand Down Expand Up @@ -223,27 +223,36 @@ const getStudentsIncludeCoursesBetween = async (studentnumbers, startDate, endDa
}
},
})
if (tag) {
const studentTags = await TagStudent.findAll({
attributes: ['id', 'studentnumber'],
include: [
{
model: Tag,
attributes: ['tag_id', 'tagname'],
}
],
})

const studentNumberToTags = studentTags.reduce((acc, t) => {
acc[t.studentnumber] = acc[t.studentnumber] || []
acc[t.studentnumber].push(t)
return acc
}, {})
const studentTags = await TagStudent.findAll({
attributes: ['id', 'studentnumber'],
include: [
{
model: Tag,
attributes: ['tag_id', 'tagname'],
}
],
where: {
studentnumber: {
[Op.in]: studentnumbers
}
}
})
const studentNumberToTags = studentTags.reduce((acc, t) => {
acc[t.studentnumber] = acc[t.studentnumber] || []
acc[t.studentnumber].push(t)
return acc
}, {})

students.forEach(student => {
student.tags = studentNumberToTags[student.studentnumber]
})

if (tag) {
const studentsWithSearchedTag = {}
students.forEach(student => {
student.tag_students = studentNumberToTags[student.studentnumber]
if (student.tag_students.some(t => t.tag.tag_id === tag)) {
student.tags = studentNumberToTags[student.studentnumber]
if (student.tags && student.tags.some(t => t.tag.tag_id === tag)) {
studentsWithSearchedTag[student.studentnumber] = true
}
})
Expand Down Expand Up @@ -384,18 +393,18 @@ const formatStudentsForApi = async (students, startDate, endDate, { studyRights
stats.students.push(formatStudentForPopulationStatistics(student, startDate, endDate))
return stats
}, {
students: [],
extents: {},
semesters: {},
transfers: {
targets: {},
sources: {}
},
studyrights: {
degrees: [],
programmes: []
}
})
students: [],
extents: {},
semesters: {},
transfers: {
targets: {},
sources: {}
},
studyrights: {
degrees: [],
programmes: []
}
})

const transferredStudyright = (s) => {
const studyright = s.studyrights.find(s => s.studyrightElements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ test.only('new api populations can be fetched', async t => {
.expect('Content-Type', /application\/json/)

const stats = res.body
console.log(stats)
t.is(stats.length, 6)

})
Expand Down
2 changes: 1 addition & 1 deletion services/backend/updater_writer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stan.on('connect', function () {

const sub = stan.subscribe('UpdateWrite', 'updater.workers', opts)
const attSub = stan.subscribe('UpdateAttainmentDates', opts)
const prioSub = stan.subscribe('PriorityWrite', 'updater.workers', opts)
const prioSub = stan.subscribe('PriorityWrite', 'updater.workers.prio', opts)

sub.on('message', async (msg) => {
const data = JSON.parse(msg.getData())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SingleCourseStats extends Component {
const { primary: p, comparison: c } = this.state
const { programmes } = this.props.stats
const primary = !programmes[p] ? ALL.value : p
const comparison = !programmes[c] ? undefined : c
const comparison = (!programmes[c] && c !== ALL.value) ? undefined : c
return { primary, comparison }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class PopulationSearchForm extends Component {
this.props.setPopulationFilter(transferTo(false))
}
this.setState({ isLoading: false })
// not a good solution FIX
this.setState({ selectedTag: '' })
})
}

Expand Down
4 changes: 2 additions & 2 deletions services/updater_api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const handleMessage = async (priority) => async (msg) => { // :d
stan.on('connect', async () => {

const sub = stan.subscribe('UpdateApi', 'updater.workers', opts)
const prioSub = stan.subscribe('PriorityApi', 'updater.workers', opts)
const prioSub = stan.subscribe('PriorityApi', 'updater.workers.prio', opts)

sub.on('message', await handleMessage(false))
prioSub.on('message', await handleMessage(true))
})

0 comments on commit 55c97c7

Please sign in to comment.