Skip to content

Commit

Permalink
Merge pull request #965 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
Feedback form fixes, transferred credist to teacher page, logging
  • Loading branch information
sasumaki authored Jun 3, 2019
2 parents 46c82cb + fa26194 commit 2e3866f
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 60 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/Studyprogramme_overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Studyprogramme overview', () => {
cy.contains("2018-2019").siblings().contains('9')
cy.contains("2017-2018").siblings().contains('12').siblings().contains('7').siblings().contains('2')
cy.get('table').eq(1).contains('2018').siblings().contains('443')
cy.get('table').eq(1).contains('2017').siblings().contains('383')
cy.get('table').eq(1).contains('2017').siblings().contains('381')
})

it('can search for mandatory courses', () => {
Expand Down
2 changes: 1 addition & 1 deletion services/backend/oodikone2-backend/src/routes/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const userService = require('../services/userService')

router.post('/email', async (req, res) => {
const { content } = req.body
const {uid} = req.headers
const { uid } = req.headers
const { email } = await userService.byUsername(uid)

const formattedEmail = content.split('\n\n').map(line => `<p> ${line} </p>`).join('')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const message2 = email => {
const feedback = (content, user, email) => {
return ({
to: 'Toska <[email protected]>',
replyTo: email,
subject: `New message from Oodikone feedback`,
text: `New message from user ${user}`,
html: `${content}
Expand Down
7 changes: 4 additions & 3 deletions services/backend/oodikone2-backend/src/services/studytrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const getCreditsForProvider = (provider, since) => Credit.findAll({
},
where: {
credittypecode: {
[Op.ne]: 10
[Op.notIn]: [10, 9]
},
attainment_date: {
[Op.gte]: since
Expand All @@ -66,8 +66,8 @@ const productivityStatsForProvider = async (providercode, since) => {

const formatGraduatedStudyright = ({ studyrightid, enddate, studystartdate }) => {
const year = enddate && enddate.getFullYear()
const inTargetTime = moment(enddate).diff(moment(studystartdate), 'months') <= FIVE_YEARS_IN_MONTHS
return { studyrightid, year, inTargetTime }
const timeToGraduation = moment(enddate).diff(moment(studystartdate), 'days')
return { studyrightid, year, timeToGraduation }
}

const findGraduated = (studytrack, since) => Studyright.findAll({
Expand Down Expand Up @@ -153,6 +153,7 @@ const thesisProductivityForStudytrack = async code => {

const combineStatistics = (creditStats, studyrightStats, thesisStats) => {
const stats = { ...creditStats }
console.log(studyrightStats)
Object.keys(stats).forEach(year => {
const thesis = thesisStats[year] || {}
stats[year].graduated = studyrightStats[year] || 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test('findGraduated finds graduated studyright', async () => {

test('findGraduated formats graduated studyrights correctly', async () => {
const studyrights = await findGraduated(studytrack, '2001-01-01')
expect(studyrights).toContainEqual({ studyrightid: '10', year: 2016, inTargetTime: false })
expect(studyrights).toContainEqual({ studyrightid: '10', year: 2016, timeToGraduation: NaN })
})

test('findGraduated does not return studyrights that are not graduated', async () => {
Expand Down
36 changes: 20 additions & 16 deletions services/backend/oodikone2-backend/src/services/teachers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,29 @@ const findTeacherCredits = teacherid => Teacher.findByPk(teacherid, {
const parseCreditInfo = credit => ({
studentnumber: credit.student_studentnumber,
credits: credit.credits,
transferred: credit.credittypecode === 9,
grade: credit.grade,
passed: Credit.passed(credit) || Credit.improved(credit),
failed: Credit.failed(credit),
course: credit.course,
semester: credit.semester
})

const markCredit = (stats, passed, failed, credits) => {
const markCredit = (stats, passed, failed, credits, transferred) => {
if (!stats) {
stats = {
passed: 0,
failed: 0,
credits: 0
credits: 0,
transferred: 0
}
}
if (passed) {
return {
...stats,
credits: stats.credits + credits,
passed: stats.passed + 1
credits: transferred ? stats.credits : stats.credits + credits,
passed: stats.passed + 1,
transferred: transferred ? stats.transferred + credits : stats.transferred
}
} else if (failed) {
return {
Expand All @@ -102,50 +105,50 @@ const markCredit = (stats, passed, failed, credits) => {
}

const parseAndMarkCredit = (stats, key, credit) => {
const { passed, failed, credits } = parseCreditInfo(credit)
const { passed, failed, credits, transferred } = parseCreditInfo(credit)
return {
...stats,
[key]: markCredit(stats[key], passed, failed, credits)
[key]: markCredit(stats[key], passed, failed, credits, transferred)
}
}

const markCreditForSemester = (semesters, credit) => {
const { passed, failed, credits, semester } = parseCreditInfo(credit)
const { passed, failed, credits, semester, transferred } = parseCreditInfo(credit)
const { semestercode, name } = semester
const { stats, ...rest } = semesters[semestercode] || { id: semestercode, name }
return {
...semesters,
[semestercode]: {
...rest,
stats: markCredit(stats, passed, failed, credits)
stats: markCredit(stats, passed, failed, credits, transferred)
}
}
}

const markCreditForYear = (years, credit) => {
const { passed, failed, credits, semester } = parseCreditInfo(credit)
const { passed, failed, credits, semester, transferred } = parseCreditInfo(credit)
const { yearcode, yearname } = semester
const { stats, ...rest } = years[yearcode] || { id: yearcode, name: yearname }
return {
...years,
[yearcode]: {
...rest,
stats: markCredit(stats, passed, failed, credits)
stats: markCredit(stats, passed, failed, credits, transferred)
}
}
}

const markCreditForCourse = (courses, credit) => {
const { passed, failed, credits, course, semester } = parseCreditInfo(credit)
const { passed, failed, credits, course, semester, transferred } = parseCreditInfo(credit)
const { code, name } = course
const { semestercode } = semester
const { stats, semesters = {}, ...rest } = courses[code] || { id: code, name }
return {
...courses,
[code]: {
...rest,
semesters: parseAndMarkCredit(semesters, semestercode, credit),
stats: markCredit(stats, passed, failed, credits)
semesters: parseAndMarkCredit(semesters, semestercode, credit, transferred),
stats: markCredit(stats, passed, failed, credits, transferred)
}
}
}
Expand Down Expand Up @@ -242,14 +245,15 @@ const isRegularCourse = credit => !credit.isStudyModule

const calculateCreditStatistics = credits => credits.reduce((stats, credit) => {
if (isRegularCourse(credit)) {
const { passed, failed, credits } = parseCreditInfo(credit)
return markCredit(stats, passed, failed, credits)
const { passed, failed, credits, transferred } = parseCreditInfo(credit)
return markCredit(stats, passed, failed, credits, transferred)
}
return stats
}, {
passed: 0,
failed: 0,
credits: 0
credits: 0,
transferred: 0
})

const yearlyStatistics = async (providers, semestercodeStart, semestercodeEnd) => {
Expand Down
18 changes: 10 additions & 8 deletions services/backend/oodikone2-backend/src/services/topteachers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ const creditsWithTeachersForYear = yearcode => Credit.findAll({
]
})

const updatedStats = (statistics, teacher, passed, failed, credits) => {
const updatedStats = (statistics, teacher, passed, failed, credits, transferred) => {
const { id, name } = teacher
const stats = statistics[id] || { id, name, passed: 0, failed: 0, credits: 0 }
const stats = statistics[id] || { id, name, passed: 0, failed: 0, credits: 0, transferred: 0 }
if (passed) {
return {
...stats,
passed: stats.passed + 1,
credits: stats.credits + credits
credits: transferred ? stats.credits : stats.credits + credits,
transferred: transferred ? stats.transferred + credits : stats.transferred
}
} else if (failed) {
return {
Expand Down Expand Up @@ -102,19 +103,20 @@ const findTopTeachers = async (yearcode) => {
credits
.filter(isRegularCourse)
.map(credit => {
const { credits, course } = credit
const { credits, course, credittypecode } = credit
const teachers = credit.teachers.map(({ id, name }) => ({ id, name }))
const passed = Credit.passed(credit) || Credit.improved(credit)
const failed = Credit.failed(credit)
const transferred = credittypecode === 9
const isOpenUni = course.code[0] === 'A'
return { passed, failed, credits, teachers, isOpenUni }
return { passed, failed, credits, teachers, isOpenUni, transferred }
})
.forEach(credit => {
const { passed, failed, credits, teachers, isOpenUni } = credit
const { passed, failed, credits, teachers, isOpenUni, transferred } = credit
teachers.forEach(teacher => {
all[teacher.id] = updatedStats(all, teacher, passed, failed, credits)
all[teacher.id] = updatedStats(all, teacher, passed, failed, credits, transferred)
if (isOpenUni) {
openuni[teacher.id] = updatedStats(openuni, teacher, passed, failed, credits)
openuni[teacher.id] = updatedStats(openuni, teacher, passed, failed, credits, transferred)
}
})
})
Expand Down
1 change: 0 additions & 1 deletion services/oodikone2-frontend/src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export const byCodeDesc = (a, b) => b.code.localeCompare(a.code)
export const studyRightRegex = new RegExp(/.*master|bachelor|doctor|licentiate|specialist.*/)

export const studyrightTypes = { degree: '10', programme: '20', speciality: '30' } // speciality???
/* This should be done in backend */

export const getStudentTotalCredits = student => student.courses
.filter(c => c.passed && !c.isStudyModuleCredit).reduce((a, b) => a + b.credits, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ const PopulationCreditGainTable = (props) => {
if (a.maxCredits === 0) {
return [`${a.maxCredits}`, a.amount, <Progress style={{ margin: '0px' }} percent={stats.length === 0 ? 0 : Math.round((a.amount / stats.length) * 100)} progress />]
} else if (a.maxCredits) {
return [`${a.minCredits} <= credits < ${a.maxCredits}`, a.amount, <Progress style={{ margin: '0px' }} percent={stats.length === 0 ? 0 : Math.round((a.amount / stats.length) * 100)} progress />]
return [`${a.minCredits} credits < ${a.maxCredits}`, a.amount, <Progress style={{ margin: '0px' }} percent={stats.length === 0 ? 0 : Math.round((a.amount / stats.length) * 100)} progress />]
}
return [`${a.minCredits} <= credits`, a.amount, <Progress style={{ margin: '0px' }} percent={stats.length === 0 ? 0 : Math.round((a.amount / stats.length) * 100)} progress />]
return [`${a.minCredits} credits`, a.amount, <Progress style={{ margin: '0px' }} percent={stats.length === 0 ? 0 : Math.round((a.amount / stats.length) * 100)} progress />]
})

const headers = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ const mapStateToProps = (state) => {
name: teacher.name,
credits: teacher.stats.credits,
passed: teacher.stats.passed,
failed: teacher.stats.failed
failed: teacher.stats.failed,
transferred: teacher.stats.transferred
}))
return {
providers: providerOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class TeacherStatisticsTable extends Component {
onClick={this.handleSort('credits')}
sorted={sortDirection('credits')}
/>
<Table.HeaderCell
content="Credits transferred"
onClick={this.handleSort('transferred')}
sorted={sortDirection('transferred')}
/>
<Table.HeaderCell
content="Passed"
onClick={this.handleSort('passrate')}
Expand All @@ -69,11 +74,12 @@ class TeacherStatisticsTable extends Component {
</Table.Row>
</Table.Header>
<Table.Body>
{ this.sortStatistics(statistics).map(({ id, name, credits, passrate }) => (
{ this.sortStatistics(statistics).map(({ id, name, credits, passrate, transferred }) => (
<Table.Row key={id}>
<Table.Cell content={id} width={1} onClick={this.props.onClickFn} /> {/* eslint-disable-line*/}
<Table.Cell content={name} textAlign="left" />
<Table.Cell content={credits} width={2} />
<Table.Cell content={transferred} width={2} />
<Table.Cell content={`${parseFloat(passrate).toFixed(2)} %`} width={2} />
</Table.Row>
))}
Expand All @@ -87,6 +93,7 @@ TeacherStatisticsTable.propTypes = {
statistics: arrayOf(shape({
id: any,
name: string,
transferred: number,
credits: any,
failed: number,
passed: number
Expand Down
35 changes: 26 additions & 9 deletions services/updater_api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/updater_api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"axios": "^0.19.0",
"dotenv": "^7.0.0",
"lodash": "^4.17.11",
"moment": "^2.24.0",
Expand Down
35 changes: 26 additions & 9 deletions services/updater_scheduler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e3866f

Please sign in to comment.