Skip to content

Commit

Permalink
Merge pull request #1145 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
Warning!
  • Loading branch information
esakemp authored Jul 22, 2019
2 parents 8bac62e + 73742a1 commit 7ff9c0c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 58 deletions.
92 changes: 39 additions & 53 deletions services/backend/updater_writer/updater/database_updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,49 @@ const {
} = require('../models/index')
const { updateAttainmentDates } = require('./update_attainment_dates')

const deleteStudentStudyrights = async (studentnumber, transaction) => {
const updateAttainments = (studyAttainments, transaction) => studyAttainments.map(async ({ credit, creditTeachers, teachers, course }) => {
await Course.upsert(course, { transaction })
await Credit.upsert(credit, { transaction })
const { disciplines, providers, courseproviders } = course
disciplines && disciplines.length > 0 && await Promise.all(disciplines.map(courseDiscipline => CourseDisciplines.upsert(courseDiscipline, { transaction })))
providers.length > 0 && await Promise.all(providers.map(provider => Provider.upsert(provider, { transaction })))
courseproviders.length > 0 && await Promise.all(courseproviders.map(courseProvider => CourseProvider.upsert(courseProvider, { transaction })))
teachers && teachers.length > 0 && await Promise.all(teachers.map(teacher => Teacher.upsert(teacher, { transaction })))
creditTeachers.length > 0 && await Promise.all(creditTeachers.map(cT => CreditTeacher.upsert(cT, { transaction })))
})

const updateStudyRights = (studyRights, transaction) => studyRights.map(async ({ studyRightExtent, studyright, elementDetails, studyRightElements, transfers }) => {
await StudyrightExtent.upsert(studyRightExtent, { transaction })
// this needs to be done because Oodi just deletes deprecated studyrights from students ( big yikes )
await Studyright.destroy({
where: {
student_studentnumber: studentnumber
}
}, { transaction })
await Studyright.create(studyright, { transaction })
await Promise.all(elementDetails.map(elementdetails => ElementDetails.upsert(elementdetails, { transaction })))
// this needs to be done because Oodi just deletes deprecated studyrights from students ( big yikes )
await StudyrightElement.destroy({
where: {
studentnumber
}
}, { transaction })
}

const updateAttainments = (studyAttainments, transaction) => studyAttainments.map(async ({ credit, creditTeachers, teachers, course }) => {
await Promise.all([
Course.upsert(course, { transaction }),
Credit.upsert(credit, { transaction }),
])
const { disciplines, providers, courseproviders } = course
await Promise.all([
disciplines && disciplines.length > 0 && Promise.all(disciplines.map(courseDiscipline => CourseDisciplines.upsert(courseDiscipline, { transaction }))),
providers.length > 0 && Promise.all(providers.map(provider => Provider.upsert(provider, { transaction }))),
courseproviders.length > 0 && Promise.all(courseproviders.map(courseProvider => CourseProvider.upsert(courseProvider, { transaction }))),
teachers && teachers.length > 0 && Promise.all(teachers.map(teacher => Teacher.upsert(teacher, { transaction }))),
creditTeachers.length > 0 && Promise.all(creditTeachers.map(cT => CreditTeacher.upsert(cT, { transaction })))
])

})

const updateStudyRights = (studyRights, transaction) => studyRights.map(async ({ studyRightExtent, studyright, elementDetails, studyRightElements, transfers }) => {
await Promise.all([
StudyrightExtent.upsert(studyRightExtent, { transaction }),
Studyright.create(studyright, { transaction })
])
return Promise.all([
Promise.all(elementDetails.map(elementdetails => ElementDetails.upsert(elementdetails, { transaction }))),
Promise.all(studyRightElements.map(StudyRightElement => StudyrightElement.create(StudyRightElement, { transaction }))),
Promise.all(transfers.map(transfer => Transfers.upsert(transfer, { transaction })))
])
await Promise.all(studyRightElements.map(StudyRightElement => StudyrightElement.create(StudyRightElement, { transaction })))
await Promise.all(transfers.map(transfer => Transfers.upsert(transfer, { transaction })))
})

const updateStudent = async (student, stan) => {
const { studentInfo, studyAttainments, semesterEnrollments, studyRights } = student
const transaction = await sequelize.transaction()
try {
console.time(studentInfo.studentnumber)
await deleteStudentStudyrights(studentInfo.studentnumber, transaction) // this needs to be done because Oodi just deletes deprecated studyrights from students ( big yikes )

await Student.upsert(studentInfo, { transaction })
await Promise.all(semesterEnrollments.map(SE =>
SemesterEnrollment.upsert(SE, { transaction })))

if (studyAttainments) await Promise.all(updateAttainments(studyAttainments, transaction))
if (studyAttainments) await updateAttainments(studyAttainments, transaction)

if (studyRights) await Promise.all(updateStudyRights(studyRights, transaction))
if (studyRights) await updateStudyRights(studyRights, transaction)
console.log("old transactions")
console.timeEnd(studentInfo.studentnumber)
console.time(studentInfo.studentnumber)
Expand Down Expand Up @@ -101,26 +89,24 @@ const updateMeta = async ({
const transaction = await sequelize.transaction()

try {
await Promise.all([
Promise.all(courseTypeCodes.map(cT =>
CourseType.upsert(cT, { transaction })
)),
Promise.all(faculties.map(org =>
Organisation.upsert(org, { transaction })
)),
Promise.all(courseRealisationsTypes.map(cR =>
CourseRealisationType.upsert(cR, { transaction })
)),
Promise.all(semesters.map(s =>
Semester.upsert(s, { transaction })
)),
Promise.all(creditTypeCodes.map(cTC =>
CreditType.upsert(cTC, { transaction })
)),
Promise.all(disciplines.map(d =>
Discipline.upsert(d, { transaction })
)),
])
await Promise.all(
courseTypeCodes.map(cT => CourseType.upsert(cT, { transaction }))
)
await Promise.all(
faculties.map(org => Organisation.upsert(org, { transaction }))
)
await Promise.all(
courseRealisationsTypes.map(cR => CourseRealisationType.upsert(cR, { transaction }))
)
await Promise.all(
semesters.map(s => Semester.upsert(s, { transaction }))
)
await Promise.all(
creditTypeCodes.map(cTC => CreditType.upsert(cTC, { transaction }))
)
await Promise.all(
disciplines.map(d => Discipline.upsert(d, { transaction }))
)
await transaction.commit()
} catch (err) {
await transaction.rollback()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const updateAttainmentDates = async () => {
WHERE course.code=cr.course_code`,
{ type: sequelize.QueryTypes.UPDATE, transaction, lock: transaction.LOCK.UPDATE }
)
transaction.commit()
await transaction.commit()
} catch (e) {
transaction.rollback()
await transaction.rollback()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ class PopulationCourseStats extends Component {
.filter(g => g.status.passingGrade || g.status.improvedGrade)
.reduce(countSumReducer, 0)
}

return (
<Table.Row active={this.isActiveCourse(course)}>
<Table.Cell
Expand All @@ -315,7 +314,7 @@ class PopulationCourseStats extends Component {
<Table.Cell content={attempts} />
<Table.Cell content={failedGrades} />
{courseGradesTypes.map(g =>
<Table.Cell content={grades[g] ? grades[g].count || 0 : 0} />)
<Table.Cell content={grades[g] ? grades[g].count || 0 : 0} key={code + g} />)
}
<Table.Cell content={otherPassed} />
</Table.Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ class PopulationSearchForm extends Component {
getMinSelection = (startYear, semester) => (semester === 'FALL' ? `${startYear}-08-01` : `${startYear}-01-01`)

checkPreviousQuery = (query, previousQuery) => {
if (!previousQuery.studyRights) {
return false
}
const sameProgramme = query.studyRights.programme === previousQuery.studyRights.programme
const sameMonths = query.months === previousQuery.months
const sameStartYear = query.startYear === previousQuery.startYear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class PopulationStudents extends Component {
return workbook
}
return (
<Fragment style={{ overflowX: 'auto', maxHeight: '80vh' }}>
<Fragment>
<Grid columns="two">
<Grid.Column><StudentNameVisibilityToggle /></Grid.Column>
<Grid.Column textAlign="right">
Expand Down

0 comments on commit 7ff9c0c

Please sign in to comment.