Skip to content

Commit

Permalink
Merge pull request #1074 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
Esakkkkempppa
  • Loading branch information
esakemp authored Jul 4, 2019
2 parents 05de857 + 560c829 commit c7711db
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CATEGORY = {
class CourseYearlyStatsCounter {

constructor() {
this.all = []
this.groups = {}
this.programmes = {}
this.history = {
Expand Down Expand Up @@ -48,7 +49,11 @@ class CourseYearlyStatsCounter {
this.initProgramme(code, name)
}
const prog = this.programmes[code]
prog.students.push(studentnumber)

if (!prog.students.includes(studentnumber) && !this.all.includes(studentnumber)) {
this.all.push(studentnumber)
prog.students.push(studentnumber)
}
}

markStudyProgrammes(studentnumber, programmes) {
Expand Down
11 changes: 5 additions & 6 deletions services/backend/oodikone2-backend/src/services/courses.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ const getMainCodeToDuplicates = async () => {
)[0]
acc[main.code] = {
maincourse: { code: main.code, name: main.name },
duplicates: courses.map( c => ({ code: c.code, name: c.name }))
duplicates: courses.map(c => ({ code: c.code, name: c.name }))
}
return acc
}, {})
Expand Down Expand Up @@ -549,18 +549,18 @@ const setDuplicateCode = async (code1, code2) => {
if (course1 && course2) {
const all = await getDuplicatesToIdMap()
// make sure both dont have a group
if ([all[code1], all[code2]].filter(e=>e).length <= 1) {
if ([all[code1], all[code2]].filter(e => e).length <= 1) {
let groupid = all[code1] || all[code2]
if (!groupid) {
// neither has a group, make one
groupid = Math.max(0, ...Object.values(all).filter(e=>e))
groupid = groupid && !isNaN(groupid) ? groupid+1 : 1
groupid = Math.max(0, ...Object.values(all).filter(e => e))
groupid = groupid && !isNaN(groupid) ? groupid + 1 : 1
}
await CourseDuplicates.bulkCreate([
{ groupid, coursecode: code1 },
{ groupid, coursecode: code2 }
],
{ ignoreDuplicates: true })
{ ignoreDuplicates: true })
} else {
// both have a group, must merge groups
await CourseDuplicates.update({ groupid: all[code1] }, { where: { groupid: all[code2] } })
Expand Down Expand Up @@ -642,7 +642,6 @@ const yearlyStatsOfNew = async (coursecode, separate, startyearcode, endyearcode
const courseYearlyStats = async (coursecodes, separate, startyearcode, endyearcode) => {
const stats = await Promise.all(coursecodes
.map(code => yearlyStatsOfNew(code, separate, startyearcode, endyearcode || startyearcode)))

return stats
}

Expand Down
4 changes: 1 addition & 3 deletions services/backend/updater_writer/database/dump_database.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const spawn = require('child_process').spawn
const fs = require('fs')
const { sync } = require('./force_sync_database')
const { DB_SCHEMA } = require('../conf-backend')

const dumpDatabase = async () => {
Expand All @@ -19,8 +18,7 @@ const dumpDatabase = async () => {
if (code !== 0) {
throw new Error('pg_dump: Bad exit code (' + code + ')');
} else {
console.log('database dump created, force syncing database')
await sync()
console.log('database dump created')
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ SingleCourseStats.propTypes = {

const mapStateToProps = (state) => {
const { semesters = [], years = [] } = state.semesters.data

return {
programmes: selectors.getAllStudyProgrammes(state),
years: Object.values(years).map(({ yearcode, yearname }) => ({
Expand Down
89 changes: 45 additions & 44 deletions services/updater_scheduler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,34 @@ const updateTask = async (task, status, type) => {
}

stan.on('connect', async () => {
// cron.schedule('0 0 1 * *', async () => {
// // Update ALL students and meta every month
// scheduleAllStudentsAndMeta()
// }, { timezone })
cron.schedule('0 0 1 * *', async () => {
// Update ALL students and meta every month
scheduleAllStudentsAndMeta()
}, { timezone })

cron.schedule('20 4 1 1,3,8,10 *', async () => {
// At 04:20 on day-of-month 1 in January, March, August, and October.”
updateStudentNumberList()
})

cron.schedule('0 * * * *'), async () => {
const allStudentTasks = await Schedule.find({ type: 'student' })
if (allStudentTasks && allStudentTasks.every(task => task.status === 'DONE')) {

stan.publish('DumpDatabase', null, (err, guid) => {
if (err) {
console.log('publish failed', 'DumpDatabase')
} else {
console.log('published', 'DumpDatabase')
}
})
}
}
// cron.schedule('0 23 * * *', async () => {
// // Update ACTIVE students every night
// scheduleActiveStudents()
// }, { timezone })
// cron.schedule('0 * * * *'), async () => {
// const allStudentTasks = await Schedule.find({ type: 'student' })
// if (allStudentTasks && allStudentTasks.every(task => task.status === 'DONE')) {

// stan.publish('DumpDatabase', null, (err, guid) => {
// if (err) {
// console.log('publish failed', 'DumpDatabase')
// } else {
// console.log('published', 'DumpDatabase')
// }
// })
// }
// }

cron.schedule('0 23 * * *', async () => {
// Update ACTIVE students every night
scheduleActiveStudents()
}, { timezone })

cron.schedule('*/5 * * * *', async () => {
const oldestTasks = await getOldestTasks()
Expand All @@ -67,29 +68,29 @@ stan.on('connect', async () => {
scheduledCount = 0
}, { timezone })

// cron.schedule('0 7 * * *', async () => {
// stan.publish('RefreshOverview', null, (err, guid) => {
// if (err) {
// console.log('publish failed', 'RefreshOverview')
// } else {
// console.log('published', 'RefreshOverview')
// }
// })
// stan.publish('RefreshStudyrightAssociations', null, (err, guid) => {
// if (err) {
// console.log('publish failed', 'RefreshStudyrightAssociations')
// } else {
// console.log('published', 'RefreshStudyrightAssociations')
// }
// })
// stan.publish('updateAttainmentDates', null, (err, guid) => {
// if (err) {
// console.log('publish failed', 'UpdateAttainmentDates')
// } else {
// console.log('published', 'UpdateAttainmentDates')
// }
// })
// }, { timezone })
cron.schedule('0 7 * * *', async () => {
stan.publish('RefreshOverview', null, (err, guid) => {
if (err) {
console.log('publish failed', 'RefreshOverview')
} else {
console.log('published', 'RefreshOverview')
}
})
stan.publish('RefreshStudyrightAssociations', null, (err, guid) => {
if (err) {
console.log('publish failed', 'RefreshStudyrightAssociations')
} else {
console.log('published', 'RefreshStudyrightAssociations')
}
})
stan.publish('updateAttainmentDates', null, (err, guid) => {
if (err) {
console.log('publish failed', 'UpdateAttainmentDates')
} else {
console.log('published', 'UpdateAttainmentDates')
}
})
}, { timezone })

const scheduleSub = stan.subscribe('ScheduleAll')

Expand Down

0 comments on commit c7711db

Please sign in to comment.