Skip to content

Commit

Permalink
Implement num questions per topic
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontromero committed Feb 16, 2024
1 parent 3573624 commit 4a58ec1
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
72 changes: 72 additions & 0 deletions client/src/components/metrics/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function Graph() {
const [numQuestionsPerDayLastWeek, setNumQuestionsPerDayLastWeek] = useState([]);
const [numQuestionsPerDay, setNumQuestionsPerDay] = useState([]);
const [numQuestionsOverall, setNumQuestionsOverall] = useState([]);
const [numQuestionsPerTopic, setNumQuestionsPerTopic] = useState([]);

useEffect(() => {
MetricsService.getNumStudentsPerDayLastWeek().then((res) => {
Expand All @@ -36,6 +37,11 @@ export default function Graph() {
MetricsService.getNumStudentsOverall().then((res) => {
setNumQuestionsOverall(res.data.numStudentsOverall);
});

MetricsService.getNumQuestionsPerTopic().then((res) => {
console.log(res.data.numQuestionsPerTopic);
setNumQuestionsPerTopic(res.data.numQuestionsPerTopic);
});
}, []);

const dateFormatter = (day) => {
Expand Down Expand Up @@ -247,6 +253,72 @@ export default function Graph() {
}}
/>
</div>

<Typography variant="h5" sx={{mt: 4, ml: 10}} fontWeight='bold'>
Number of Questions per Topic
</Typography>

<div style={{height: '40vh', width: 'auto', position: 'relative'}}>
<Bar
datasetIdKey='numQuestionsPerTopic'
options={{
layout: {
padding: {
top: 40,
right: 100,
bottom: 40,
left: 50,
},
},
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false,
},
},
scales: {
x: {
ticks: {
font: {
size: 16,
},
},
grid: {
color: theme.palette.divider,
},
},
y: {
title: {
display: true,
text: 'Number of Questions',
font: {
size: 16,
},
},
ticks: {
autoSkip: true,
},
grid: {
color: theme.palette.divider,
},
},
},
}}
data={{
labels: numQuestionsPerTopic.map((topic) => topic.name),
datasets: [
{
label: 'Number of Questions',
data: numQuestionsPerTopic.map((topic) => topic.count),
backgroundColor: theme.palette.primary.main,
borderColor: theme.palette.primary.main,
borderWidth: 3,
},
],
}}
/>
</div>
</div>
);
}
4 changes: 4 additions & 0 deletions client/src/services/MetricsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class MetricsDataService {
getNumStudentsOverall() {
return http.get('/metrics/numStudentsOverall');
}

getNumQuestionsPerTopic() {
return http.get('/metrics/numQuestionsPerTopic');
}
}

export default new MetricsDataService();
61 changes: 61 additions & 0 deletions server/controllers/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,67 @@ exports.get_num_students_overall = (req, res) => {
});
}

exports.get_num_questions_per_topic = (req, res) => {
if (!req.user || !req.user.isTA) {
respond_error(req, res, "You don't have permissions to perform this operation", 403);
return;
}

let assignmentsSet = {};

assignmentsSet[-1] = {
name: "Other",
start_date: new Date("1/1/2000"),
end_date: new Date("1/1/3000")
}

models.assignment_semester.findAll({
where: {
sem_id: settings.get_admin_settings().currSem,
},
order: [['start_date', 'ASC']],
include: models.assignment
}).then((assignments) => {

for (const assignmentSem of assignments) {
let assignment = assignmentSem.assignment;
assignmentsSet[assignment.assignment_id] = {
name: assignment.name,
start_date: assignmentSem.start_date,
end_date: assignmentSem.end_date
};
}

return models.question.findAll({
attributes: [
'assignment',
[Sequelize.fn('count', Sequelize.col('question_id')), 'count']
],
where: {
sem_id: settings.get_admin_settings().currSem,
help_time: {
[Sequelize.Op.ne]: null
},
},
group: [[Sequelize.col('assignment')]],
})
}).then((data) => {
for (const row of data) {
let assnCount = row.dataValues;
assignmentsSet[assnCount.assignment].count = assnCount.count;
}

let result = [];

for (const [id, assn] of Object.entries(assignmentsSet)) {
result.push(assn)
}
result.sort((a, b) => a.start_date - b.start_date)

respond(req, res, "Got number of questions per topic", { numQuestionsPerTopic: result }, 200);
});
}

exports.get_ranked_students = (req, res) => {
if (!req.user || !req.user.isTA || !req.user.isAdmin) {
respond_error(req, res, "You don't have permission to perform this operation", 403);
Expand Down
1 change: 1 addition & 0 deletions server/routes/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ router.get('/totalAvgWaitTime', metrics.get_total_avg_wait_time);
router.get('/numStudentsPerDayLastWeek', metrics.get_num_students_per_day_last_week);
router.get('/numStudentsPerDay', metrics.get_num_students_per_day);
router.get('/numStudentsOverall', metrics.get_num_students_overall);
router.get('/numQuestionsPerTopic', metrics.get_num_questions_per_topic);
router.get('/rankedStudents', metrics.get_ranked_students);
router.get('/rankedTAs', metrics.get_ranked_tas);
module.exports = router;

0 comments on commit 4a58ec1

Please sign in to comment.