Skip to content

Commit

Permalink
Merge pull request #943 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
fix first time render of labels, disable save when label not changed
  • Loading branch information
Rochet2 authored May 27, 2019
2 parents 6909609 + 4b3e907 commit 34b0699
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
14 changes: 3 additions & 11 deletions scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,12 @@ db_oodikone_reset () {
ping_psql () {
echo "Pinging psql in container $1 with db name $2"
retry docker exec -u postgres $1 pg_isready
docker exec -u postgres oodi_db psql -c "CREATE DATABASE tkt_oodi" || echo "tkt_oodi DB already exists"
echo "Pinging psql in container $1 with db name tkt_oodi_test"
retry docker exec -u postgres $1 pg_isready
docker exec -u postgres oodi_db psql -c "CREATE DATABASE tkt_oodi_test" || echo "tkt_oodi_test DB already exists"
}

ping_psql_real () {
echo "Pinging psql in container $1 with db name $2"
docker exec -u postgres oodi_db psql -c "CREATE DATABASE tkt_oodi_real" || echo "tkt_oodi_real DB already exists"
retry docker exec -u postgres $1 pg_isready
docker exec -u postgres $1 psql -c "CREATE DATABASE $2" || echo "container $1 DB $2 already exists"
}

db_setup_full () {
echo "Restoring PostgreSQL from backup"
ping_psql_real "oodi_db" "tkt_oodi_real"
ping_psql "oodi_db" "tkt_oodi_real"
retry restore_real_psql_from_backup
# echo "Restoring MongoDB from backup"
# retry restore_mongodb_from_backup
Expand All @@ -118,6 +109,7 @@ db_setup_full () {
db_anon_setup_full () {
echo "Restoring PostgreSQL from backup"
ping_psql "oodi_db" "tkt_oodi"
ping_psql "oodi_db" "tkt_oodi_test"
retry restore_psql_from_backup
# echo "Restoring MongoDB from backup"
# retry restore_mongodb_from_backup
Expand Down
7 changes: 6 additions & 1 deletion services/backend/oodikone2-backend/src/routes/feedback.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const router = require('express').Router()
const mailservice = require('../services/mailservice')
const userService = require('../services/userService')

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

const formattedEmail = content.split('\n\n').map(line => `<p> ${line} </p>`).join('')
const feedback = mailservice.feedback(formattedEmail, req.headers.uid)
const feedback = mailservice.feedback(formattedEmail, uid, email)

if (process.env.SMTP !== undefined && content) {
await mailservice.transporter.sendMail(feedback, (error) => {
if (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const message2 = email => {
<img style="max-width: 13.5%;height: auto;" src="https://i.imgur.com/tnNDAJk.png" /> `,
})
}
const feedback = (content, user) => {
const feedback = (content, user, email) => {
return ({
to: 'Toska <[email protected]>',
subject: `New message from Oodikone feedback`,
text: `New message from user ${user}`,
html: `${content}
<p>send by user: ${user} </p>
<p>send by user: ${user}, email: ${email}</p>
<img src="cid:toskalogoustcid"/>`,
attachments: [
{
Expand Down
52 changes: 44 additions & 8 deletions services/backend/oodikone2-backend/src/services/studytrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,43 @@ const gendersFromClass = async (studentnumbers) => {
}, {})
}

const productivityStats = async (studentnumbers, startDate, studytrack) => {
const tranferredToStudyprogram = async (studentnumbers, startDate, studytrack, endDate) => {
return Studyright.findAndCountAll({
include: {
include: {
model: ElementDetails,
where: {
type: {
[Op.eq]: 20
}
}
},
model: StudyrightElement,
required: true,
where: {
code: {
[Op.eq]: studytrack
},
startdate: {
[Op.gt]: moment(startDate).add(1, 'days'), // because somehow startdates have a time that is not 00:00
[Op.lt]: new Date(endDate)
}
}
},
where: {
student_studentnumber: {
[Op.in]: studentnumbers
}
}
})
}

const productivityStats = async (studentnumbers, startDate, studytrack, endDate) => {
return Promise.all([creditsAfter(studentnumbers, startDate),
graduationsFromClass(studentnumbers, studytrack),
thesesFromClass(studentnumbers, startDate, studytrack),
gendersFromClass(studentnumbers)])
graduationsFromClass(studentnumbers, studytrack),
thesesFromClass(studentnumbers, startDate, studytrack),
gendersFromClass(studentnumbers),
tranferredToStudyprogram(studentnumbers, startDate, studytrack, endDate)])
}

const getYears = (since) => {
Expand All @@ -298,14 +330,16 @@ const throughputStatsForStudytrack = async (studytrack, since) => {
thesisM: 0,
thesisB: 0,
students: 0,
graduated: 0
graduated: 0,
transferred: 0
}
const years = getYears(since)
const arr = await Promise.all(years.map(async year => {
const startDate = `${year}-${semesterStart['FALL']}`
const endDate = `${moment(year, 'YYYY').add(1, 'years').format('YYYY')}-${semesterEnd['SPRING']}`
const studentnumbers = await studentnumbersWithAllStudyrightElements([studytrack], startDate, endDate, false, false)
const [credits, graduated, theses, genders] = await productivityStats(studentnumbers, startDate, studytrack)
const [credits, graduated, theses, genders, transferred] =
await productivityStats(studentnumbers, startDate, studytrack, endDate)
delete genders[null]
const creditValues = credits.reduce((acc, curr) => {
acc.mte30 = curr >= 30 ? acc.mte30 + 1 : acc.mte30
Expand All @@ -326,15 +360,17 @@ const throughputStatsForStudytrack = async (studytrack, since) => {
totals.thesisM = theses.MASTER ? totals.thesisM + theses.MASTER : totals.thesisM
totals.thesisB = theses.BACHELOR ? totals.thesisB + theses.BACHELOR : totals.thesisB
totals.students = totals.students + credits.length
totals.graduated = totals.graduated + graduated.length
totals.graduated = totals.graduated + graduated.length,
totals.transferred = totals.transferred + transferred.count
return {
year: `${year}-${year + 1}`,
credits: credits.map(cr => cr === null ? 0 : cr),
graduated: graduated.length,
thesisM: theses.MASTER || 0,
thesisB: theses.BACHELOR || 0,
genders,
creditValues
creditValues,
transferred: transferred.count
}
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ const MandatoryCourseTable = ({ studyProgramme, mandatoryCourses, language, dele
const labelInput = code => (
<Form>
<Form.Group>
<Form.Input defaultValue={labels[code]} onChange={e => setLabels({ ...labels, [code]: e.target.value })} />
<Form.Input defaultValue={initialLabels[code]} onChange={e => setLabels({ ...labels, [code]: e.target.value })} />
<Form.Button
disabled={initialLabels[code] === labels[code] || labels[code] == null || (initialLabels[code] == null && labels[code] === '')}
onClick={() => setMandatoryCourseLabel(studyProgramme, code, labels[code])}
>
Save label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro
<Table.HeaderCell rowSpan="2">Students</Table.HeaderCell>
}
<Table.HeaderCell rowSpan="2">Graduated</Table.HeaderCell>
<Table.HeaderCell rowSpan="2">Transferred to this program</Table.HeaderCell>
<Table.HeaderCell colSpan="5">Credits</Table.HeaderCell>
{(thesisTypes.includes('BACHELOR') ||
thesisTypes.includes('MASTER')) && (
Expand Down Expand Up @@ -105,10 +106,11 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro
<Table.Cell>{year.credits.length}</Table.Cell>
{genders.map(gender => (
<Table.Cell key={year.year + year.genders[gender]}>
{`${year.genders[gender]} (${Math.floor((year.genders[gender] / year.credits.length) * 100)}%)` || 0}
{`${year.genders[gender] || 0} (${Math.floor((year.genders[gender] / year.credits.length) * 100) || 0}%)`}
</Table.Cell>
))}
<Table.Cell>{year.graduated}</Table.Cell>
<Table.Cell>{year.transferred}</Table.Cell>
{Object.keys(year.creditValues).map(creditKey => (
<Table.Cell key={creditKey}>{year.creditValues[creditKey]}
</Table.Cell>
Expand All @@ -133,6 +135,7 @@ const ThroughputTable = ({ history, throughput, thesis, loading, error, studypro
</Table.HeaderCell>
))}
<Table.HeaderCell>{throughput.totals.graduated}</Table.HeaderCell>
<Table.HeaderCell>{throughput.totals.transferred}</Table.HeaderCell>
{Object.keys(throughput.totals.credits).map(creditKey => (
<Table.HeaderCell key={`${creditKey}total`}>{throughput.totals.credits[creditKey]}
</Table.HeaderCell>
Expand Down

0 comments on commit 34b0699

Please sign in to comment.