Skip to content

Commit

Permalink
Merge pull request #1899 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
Implement new admin sparkline area chart proto, bug fixing, sis migrations
  • Loading branch information
woltsu authored Feb 26, 2020
2 parents 195c053 + fbe91a6 commit b131189
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import moment from 'moment'
import { getPopulationStatistics, clearPopulations } from '../../redux/populations'
import { getPopulationCourses } from '../../redux/populationCourses'
import { getPopulationSelectedStudentCourses, clearSelected } from '../../redux/populationSelectedStudentCourses'
import { getPopulationFilters, setPopulationFilter, clearPopulationFilters } from '../../redux/populationFilters'
import { getPopulationFilters, setPopulationFilter, resetPopulationFilters } from '../../redux/populationFilters'
import { getMandatoryCourses } from '../../redux/populationMandatoryCourses'
import { getSemesters } from '../../redux/semesters'
import { transferTo } from '../../populationFilters'
Expand Down Expand Up @@ -109,7 +109,7 @@ const PopulationSearchForm = props => {
setState({ isLoading: true })
props.setLoading()
props.clearSelected()
props.clearPopulationFilters()
props.resetPopulationFilters()
fetchPopulationPromises.current = cancelablePromise(
Promise.all([
props.getPopulationStatistics({ ...formattedQueryParams, uuid, onProgress }),
Expand Down Expand Up @@ -164,7 +164,7 @@ const PopulationSearchForm = props => {
setDidMount(true)
return () => {
if (fetchPopulationPromises.current) fetchPopulationPromises.current.cancel()
props.clearPopulationFilters()
props.resetPopulationFilters()
}
}, [location.search])

Expand Down Expand Up @@ -634,7 +634,7 @@ PopulationSearchForm.propTypes = {
getMandatoryCourses: func.isRequired,
getPopulationFilters: func.isRequired,
setPopulationFilter: func.isRequired,
clearPopulationFilters: func.isRequired,
resetPopulationFilters: func.isRequired,
queries: shape({}).isRequired,
studyProgrammes: shape({}), //eslint-disable-line
degrees: arrayOf(dropdownType), //eslint-disable-line
Expand Down Expand Up @@ -676,7 +676,7 @@ export default withRouter(
getPopulationFilters,
getMandatoryCourses,
setPopulationFilter,
clearPopulationFilters,
resetPopulationFilters,
getDegreesAndProgrammes,
setLoading,
getSemesters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ SearchResult.defaultProps = {
courses: []
}

const mapStateToProps = state => ({ courses: getCourseSearchResults(state).courses })

const mapStateToProps = state => {
const { thesisCourses } = state
const { data } = thesisCourses || null
const thesisCourseCodes = data.map(c => c.courseCode)
const searchResults = getCourseSearchResults(state).courses
const filteredResults = searchResults.filter(c => !thesisCourseCodes.includes(c.code))
return {
courses: filteredResults
}
}
export default connect(mapStateToProps)(SearchResult)
11 changes: 11 additions & 0 deletions services/oodikone2-frontend/src/redux/populationFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export const clearPopulationFilters = () => ({
type: 'CLEAR_POPULATION_FILTERS'
})

export const resetPopulationFilters = () => ({
type: 'RESET_POPULATION_FILTERS'
})

export const setPopulationFilter = filter => ({
type: 'ADD_POPULATION_FILTER',
filter
Expand Down Expand Up @@ -107,6 +111,13 @@ const reducer = (state = initial, action) => {
filters: [],
refreshNeeded: true
}

case 'RESET_POPULATION_FILTERS':
return {
...state,
filters: []
}

case 'ALTER_POPULATION_COURSE_FILTER': {
const toAlter = state.filters.find(f => f.id === action.id)
const { course } = toAlter.params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ const reducer = (state = defaultState, action) => {
query: action.query
}
case 'CLEAR_SELECTED':
return {
state: defaultState
}
return defaultState
default:
return state
}
Expand Down
2 changes: 1 addition & 1 deletion services/sis-updater-scheduler/src/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const scheduleStudents = async () => {
table: 'persons',
whereNotNull: 'student_number',
pluck: 'id',
limit: isDev ? 10000 : null
limit: isDev ? 100 : null
})

await redisSet(REDIS_TOTAL_STUDENTS_KEY, totalStudents)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { STRING } = require('sequelize')

module.exports = {
up: async queryInterface => {
await queryInterface.removeConstraint('credit', 'credit_course_code_fkey')
await queryInterface.addColumn('credit', 'course_id', {
type: STRING,
references: {
model: 'course',
key: 'id'
}
})
await queryInterface.addIndex('course', ['code'])
},
down: async () => {}
}
12 changes: 7 additions & 5 deletions services/sis-updater-worker/src/db/models/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Course.init(
name: {
type: JSONB
},
latestInstanceDate: {
latest_instance_date: {
type: DATE
},
isStudyModule: {
is_study_module: {
type: BOOLEAN
},
coursetypecode: {
Expand All @@ -30,21 +30,23 @@ Course.init(
enddate: {
type: DATE
},
maxAttainmentDate: {
max_attainment_date: {
type: DATE
},
minAttainmentDate: {
min_attainment_date: {
type: DATE
},
createdAt: {
field: 'created_at',
type: DATE
},
updatedAt: {
field: 'updated_at',
type: DATE
}
},
{
underscored: true,
underscored: false,
sequelize: dbConnections.sequelize,
modelName: 'course',
tableName: 'course'
Expand Down
3 changes: 3 additions & 0 deletions services/sis-updater-worker/src/db/models/credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Credit.init(
type: DATE
},
course_code: {
type: STRING
},
course_id: {
type: STRING,
references: {
model: 'course',
Expand Down
4 changes: 2 additions & 2 deletions services/sis-updater-worker/src/db/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Credit.improved = credit => credit.credittypecode === CREDIT_TYPE_CODES.IMPROVED
Credit.belongsTo(Student, { foreignKey: 'student_studentnumber', targetKey: 'studentnumber' })
Student.hasMany(Credit, { foreignKey: 'student_studentnumber', sourceKey: 'studentnumber' })

Credit.belongsTo(Course, { foreignKey: 'course_code' })
Course.hasMany(Credit, { foreignKey: 'course_code' })
Credit.belongsTo(Course, { foreignKey: 'course_id' })
Course.hasMany(Credit, { foreignKey: 'course_id' })

Credit.belongsTo(CreditType, { foreignKey: 'credittypecode', targetKey: 'credittypecode' })
Credit.belongsToMany(Teacher, { through: CreditTeacher, foreignKey: 'credit_id' })
Expand Down
6 changes: 5 additions & 1 deletion services/sis-updater-worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const msgParser = f => async msg => {
} catch (e) {
console.log('Updating failed', e)
} finally {
msg.ack()
try {
msg.ack()
} catch (e) {
console.log('Failed acking message...')
}
}
}

Expand Down
44 changes: 35 additions & 9 deletions services/sis-updater-worker/src/updater/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { Op } = require('sequelize')
const { groupBy, flatten, flattenDeep, sortBy, mapValues, uniqBy } = require('lodash')
const {
Organization,
Expand Down Expand Up @@ -43,11 +44,11 @@ const initDaysToSemesters = async () => {
}, {})
}

const getCreditTypeCodeFromAttainment = attainment => {
const getCreditTypeCodeFromAttainment = (attainment, passed) => {
const { primary, state } = attainment
if (!passed || state === 'FAILED') return 10
if (!primary) return 7
if (state === 'ATTAINED') return 4
if (state === 'FAILED') return 10
return 9
}

Expand Down Expand Up @@ -171,9 +172,9 @@ const updateCourses = async (courseIdToAttainments, groupIdToCourse) => {
name,
code,
coursetypecode,
minAttainmentDate: min_attainment_date,
maxAttainmentDate: max_attainment_date,
latestInstanceDate: max_attainment_date,
min_attainment_date,
max_attainment_date,
latest_instance_date: max_attainment_date,
startdate,
enddate,
isStudyModule: false
Expand Down Expand Up @@ -516,9 +517,14 @@ const updateAttainments = async attainments => {
const {
localId,
numericCorrespondence,
passed,
abbreviation: { fi }
} = curr
if (!res[localId]) res[localId] = numericCorrespondence || fi
if (!res[localId])
res[localId] = {
value: numericCorrespondence || fi,
passed
}
return res
}, {})
return res
Expand All @@ -534,6 +540,19 @@ const updateAttainments = async attainments => {
return res
}, {})

const courseGroupIdToCourseCode = (
await Course.findAll({
where: {
id: {
[Op.in]: Object.values(courseUnitIdToCourseGroupId)
}
}
})
).reduce((res, curr) => {
res[curr.id] = curr.code
return res
})

const organisations = await selectFromSnapshotsByIds(
'organisations',
flatten(attainments.map(a => a.organisations.map(o => o.organisationId)))
Expand Down Expand Up @@ -567,14 +586,21 @@ const updateAttainments = async attainments => {

return {
id: a.id,
grade: gradeScaleIdToGradeIdsToGrades[grade_scale_id][grade_id],
grade: gradeScaleIdToGradeIdsToGrades[grade_scale_id][grade_id].value,
student_studentnumber: personIdToStudentNumber[a.person_id],
credits: a.credits,
createdate: a.registration_date,
credittypecode: getCreditTypeCodeFromAttainment(a),
credittypecode: getCreditTypeCodeFromAttainment(
a,
gradeScaleIdToGradeIdsToGrades[grade_scale_id][grade_id].passed
),
attainment_date: a.attainment_date,
course_code:
course_id:
a.type === 'CourseUnitAttainment' ? courseUnitIdToCourseGroupId[a.course_unit_id] : a.module_group_id,
course_code:
a.type === 'CourseUnitAttainment'
? courseGroupIdToCourseCode[courseUnitIdToCourseGroupId[a.course_unit_id]]
: courseGroupIdToCourseCode[a.module_group_id],
semestercode: targetSemester.semestercode,
semester_composite: targetSemester.composite,
isStudyModule: a.type === 'ModuleAttainment',
Expand Down

0 comments on commit b131189

Please sign in to comment.