From 4dc62507f891fda7acb05a4cafef656c1694b135 Mon Sep 17 00:00:00 2001 From: esakemp Date: Thu, 4 Jul 2019 10:00:00 +0300 Subject: [PATCH 1/2] fix unmatching numbers maybe --- .../src/services/course_yearly_stats_counter.js | 7 ++++++- .../backend/oodikone2-backend/src/services/courses.js | 11 +++++------ .../CourseStatistics/SingleCourseStats/index.jsx | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/services/backend/oodikone2-backend/src/services/course_yearly_stats_counter.js b/services/backend/oodikone2-backend/src/services/course_yearly_stats_counter.js index b99fb7e47a..bf2eb13fd3 100644 --- a/services/backend/oodikone2-backend/src/services/course_yearly_stats_counter.js +++ b/services/backend/oodikone2-backend/src/services/course_yearly_stats_counter.js @@ -8,6 +8,7 @@ const CATEGORY = { class CourseYearlyStatsCounter { constructor() { + this.all = [] this.groups = {} this.programmes = {} this.history = { @@ -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) { diff --git a/services/backend/oodikone2-backend/src/services/courses.js b/services/backend/oodikone2-backend/src/services/courses.js index 8f6104dafe..677de10149 100644 --- a/services/backend/oodikone2-backend/src/services/courses.js +++ b/services/backend/oodikone2-backend/src/services/courses.js @@ -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 }, {}) @@ -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] } }) @@ -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 } diff --git a/services/oodikone2-frontend/src/components/CourseStatistics/SingleCourseStats/index.jsx b/services/oodikone2-frontend/src/components/CourseStatistics/SingleCourseStats/index.jsx index 866430c676..27444f456d 100644 --- a/services/oodikone2-frontend/src/components/CourseStatistics/SingleCourseStats/index.jsx +++ b/services/oodikone2-frontend/src/components/CourseStatistics/SingleCourseStats/index.jsx @@ -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 }) => ({ From 560c82907a92bf3124189c9782302f3ef62c0233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A4kinen=20Sasu=20S?= Date: Thu, 4 Jul 2019 12:17:02 +0300 Subject: [PATCH 2/2] revert scheduler to old life --- .../updater_writer/database/dump_database.js | 4 +- services/updater_scheduler/index.js | 89 ++++++++++--------- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/services/backend/updater_writer/database/dump_database.js b/services/backend/updater_writer/database/dump_database.js index 30eb0e1ca1..5778a9a427 100644 --- a/services/backend/updater_writer/database/dump_database.js +++ b/services/backend/updater_writer/database/dump_database.js @@ -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 () => { @@ -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') } }) } diff --git a/services/updater_scheduler/index.js b/services/updater_scheduler/index.js index a5ea6a3cc6..7cce2984f5 100644 --- a/services/updater_scheduler/index.js +++ b/services/updater_scheduler/index.js @@ -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() @@ -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')