From fa74b7e2ba6b1eb2559f5ebdf29a5de7e62774f1 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Thu, 27 Jun 2019 16:15:34 +0300 Subject: [PATCH 1/3] Fix calculation of yearly productivity --- .../src/services/studytrack.js | 21 +++++++++++++++++-- .../ProductivityTable/index.jsx | 2 +- .../StudyProgramme/ThroughputTable/index.jsx | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/services/backend/oodikone2-backend/src/services/studytrack.js b/services/backend/oodikone2-backend/src/services/studytrack.js index cadbdb2c78..bba439d8e2 100644 --- a/services/backend/oodikone2-backend/src/services/studytrack.js +++ b/services/backend/oodikone2-backend/src/services/studytrack.js @@ -1,6 +1,7 @@ const sequelize = require('sequelize') const { Op } = sequelize const moment = require('moment') +const { flatMap } = require('lodash') const { Credit, Student, Course, Provider, Studyright, StudyrightElement, ElementDetails, ThesisCourse, ThesisTypeEnums } = require('../models') @@ -215,9 +216,25 @@ const thesisProductivityForStudytrack = async code => { } const combineStatistics = (creditStats, studyrightStats, thesisStats, creditsForMajors, transferredCredits) => { - const stats = { ...creditStats } - Object.keys(stats).forEach(year => { + const allYears = [ + ...new Set( + flatMap( + [ + creditStats, + studyrightStats, + thesisStats, + creditsForMajors, + transferredCredits + ], + Object.keys + ) + ) + ] + const stats = {} + allYears.forEach(year => { const thesis = thesisStats[year] || {} + stats[year] = {} + stats[year] = creditStats[year] || { credits: 0, year } stats[year].graduated = studyrightStats[year] ? studyrightStats[year].graduated : 0 // stats[year].medianGraduationTime = studyrightStats[year] ? studyrightStats[year].medianGraduationTime : 0 stats[year].bThesis = thesis.bThesis || 0 diff --git a/services/oodikone2-frontend/src/components/StudyProgramme/ProductivityTable/index.jsx b/services/oodikone2-frontend/src/components/StudyProgramme/ProductivityTable/index.jsx index 546c0ae300..32c555b56e 100644 --- a/services/oodikone2-frontend/src/components/StudyProgramme/ProductivityTable/index.jsx +++ b/services/oodikone2-frontend/src/components/StudyProgramme/ProductivityTable/index.jsx @@ -94,7 +94,7 @@ ProductivityTable.propTypes = { lastUpdated: string, status: string, data: arrayOf(shape({ - year: number, + year: string, credits: number, mThesis: number, bThesis: number, diff --git a/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx b/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx index 01fc01ac34..fc3d16f1b3 100644 --- a/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx +++ b/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx @@ -132,7 +132,7 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro {year.credits.length} {genders.map(gender => ( - + {`${year.genders[gender] || 0} (${Math.floor((year.genders[gender] / year.credits.length) * 100) || 0}%)`} ))} @@ -145,12 +145,12 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro } {year.transferred} {renderCountries ? countries.map(country => ( - + {year.countries[country] || 0} )) : null} {Object.keys(year.creditValues).map(creditKey => ( - {year.creditValues[creditKey]} + {year.creditValues[creditKey]} ))} {thesisTypes.includes('MASTER') ? ( From 9a191e911d5fbdad7cf01161ca60a1cf777622f7 Mon Sep 17 00:00:00 2001 From: esakemp Date: Tue, 2 Jul 2019 09:46:48 +0300 Subject: [PATCH 2/3] fix semesters --- .../backend/oodikone2-backend/src/routes/semesters.js | 3 +-- .../oodikone2-backend/src/services/semesters.js | 10 ++-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/services/backend/oodikone2-backend/src/routes/semesters.js b/services/backend/oodikone2-backend/src/routes/semesters.js index 1682770ae9..c7e85ad027 100644 --- a/services/backend/oodikone2-backend/src/routes/semesters.js +++ b/services/backend/oodikone2-backend/src/routes/semesters.js @@ -2,8 +2,7 @@ const router = require('express').Router() const { getSemestersAndYears } = require('../services/semesters') router.get('/semesters/codes', async(req, res) => { - const before = new Date() - const providers = await getSemestersAndYears(before) + const providers = await getSemestersAndYears() res.json(providers) }) diff --git a/services/backend/oodikone2-backend/src/services/semesters.js b/services/backend/oodikone2-backend/src/services/semesters.js index 1fc21c9c7e..1fb06d4242 100644 --- a/services/backend/oodikone2-backend/src/services/semesters.js +++ b/services/backend/oodikone2-backend/src/services/semesters.js @@ -2,14 +2,8 @@ const sequelize = require('sequelize') const { Semester } = require('../models/index') const { Op } = sequelize -const getSemestersAndYears = async before => { - const semesters = await Semester.findAll({ - where: { - startdate: { - [Op.lt]: before - } - } - }) +const getSemestersAndYears = async () => { + const semesters = await Semester.findAll({}) const result = semesters.reduce((acc, semester) => { const { semestercode, name, yearcode, yearname } = semester const semesters = { ...acc.semesters, [semestercode]: { semestercode, name, yearcode }} From 276e426d346a5792bde479e3d6810c8f35a8a763 Mon Sep 17 00:00:00 2001 From: Tuomo Torppa Date: Tue, 2 Jul 2019 09:59:54 +0300 Subject: [PATCH 3/3] bring back countries to frontend --- .../backend/oodikone2-backend/src/services/studytrack.js | 3 +-- .../src/components/StudyProgramme/ThroughputTable/index.jsx | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/backend/oodikone2-backend/src/services/studytrack.js b/services/backend/oodikone2-backend/src/services/studytrack.js index 99906d2696..c2167f7b43 100644 --- a/services/backend/oodikone2-backend/src/services/studytrack.js +++ b/services/backend/oodikone2-backend/src/services/studytrack.js @@ -532,15 +532,14 @@ const throughputStatsForStudytrack = async (studytrack, since) => { const studentnumbers = await studentnumbersWithAllStudyrightElements([studytrack], startDate, endDate, false, false) const creditsForStudyprogramme = await productivityCreditsFromStudyprogrammeStudents(studytrack, startDate, studentnumbers) - console.log('ASDFASDFADSF') const [credits, graduated, theses, genders, countries, transferredTo, endedStudyright] = await statsForClass(studentnumbers, startDate, studytrack, endDate) - console.log(countries) //console.log(year) //console.log(transferredFrom.rows.map(r => r.get({ plain: true }))) // theres so much shit in the data that transefferFrom doesnt rly mean anything delete genders[null] delete countries[null] + delete countries[undefined] const creditValues = credits.reduce((acc, curr) => { acc.mte30 = curr >= 30 ? acc.mte30 + 1 : acc.mte30 acc.mte60 = curr >= 60 ? acc.mte60 + 1 : acc.mte60 diff --git a/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx b/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx index 8f7337ed3e..6a51dbe4f4 100644 --- a/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx +++ b/services/oodikone2-frontend/src/components/StudyProgramme/ThroughputTable/index.jsx @@ -31,9 +31,10 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro } const data = throughput && throughput.data ? throughput.data.filter(year => year.credits.length > 0) : [] const genders = data.length > 0 ? uniq(flatten(data.map(year => Object.keys(year.genders)))) : [] - const countries = data.length > 0 && throughput.totals.countries ? uniq(flatten(data.map(year => Object.keys(year.countries)))).sort() : [] + const countries = data.length > 0 && throughput.totals.countries ? + uniq(flatten(data.map(year => Object.keys(year.countries)))).sort() : [] const renderGenders = genders.length > 0 - const renderCountries = false // countries.length > 0, disabled for now + const renderCountries = countries.length > 0 let thesisTypes = [] if (thesis) { thesisTypes = thesis.map(t => t.thesisType)