Skip to content

Commit

Permalink
Merge pull request #1064 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
fast fixes
  • Loading branch information
esakemp authored Jul 2, 2019
2 parents 0ad2966 + 276e426 commit 673cffa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
3 changes: 1 addition & 2 deletions services/backend/oodikone2-backend/src/routes/semesters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
10 changes: 2 additions & 8 deletions services/backend/oodikone2-backend/src/services/semesters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
24 changes: 20 additions & 4 deletions services/backend/oodikone2-backend/src/services/studytrack.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -515,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ ProductivityTable.propTypes = {
lastUpdated: string,
status: string,
data: arrayOf(shape({
year: number,
year: string,
credits: number,
mThesis: number,
bThesis: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -132,7 +133,7 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro
</Table.Cell>
<Table.Cell>{year.credits.length}</Table.Cell>
{genders.map(gender => (
<Table.Cell key={year.year + year.genders[gender]}>
<Table.Cell key={`${year.year} gender:${gender}`}>
{`${year.genders[gender] || 0} (${Math.floor((year.genders[gender] / year.credits.length) * 100) || 0}%)`}
</Table.Cell>
))}
Expand All @@ -145,12 +146,12 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro
}
<Table.Cell>{year.transferred}</Table.Cell>
{renderCountries ? countries.map(country => (
<Table.Cell key={year.year + country}>
<Table.Cell key={`${year.year} country:${country}`}>
{year.countries[country] || 0}
</Table.Cell>
)) : null}
{Object.keys(year.creditValues).map(creditKey => (
<Table.Cell key={creditKey}>{year.creditValues[creditKey]}
<Table.Cell key={`${year.year} credit:${creditKey}`}>{year.creditValues[creditKey]}
</Table.Cell>
))}
{thesisTypes.includes('MASTER') ? (
Expand Down

0 comments on commit 673cffa

Please sign in to comment.