Skip to content

Commit

Permalink
fix: various minor ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeaturner committed Jul 17, 2024
1 parent 5f9fd32 commit 7679a63
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 35 deletions.
6 changes: 2 additions & 4 deletions components/EarlyWarningCourseMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ const EarlyWarningCourseMetrics = ({
return (
<div className="tw-flex tw-flex-row tw-justify-center">
<SmallMetricCard
title="Course Avg"
title="Average of Predicted Scores"
value={`${course_avg ?? 0}%`}
unit="By Predicted Scores"
loading={false}
/>
<SmallMetricCard
title="Course Std Dev"
title="Std. Dev. of Predicted Scores"
value={course_std_dev ?? 0}
unit="By Predicted Scores"
loading={false}
className="tw-ml-36"
/>
Expand Down
22 changes: 12 additions & 10 deletions components/EarlyWarningStudentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const Metric = ({
unit: string;
percent: boolean;
absolute?: boolean;
color?: "red" | "green";
color?: "red" | "dark-red" | "black";
}) => {
const textColorClass =
color === "red"
? "tw-text-red-500"
: color === "green"
? "tw-text-black"
: "";
: color === "dark-red"
? "tw-text-red-700"
: "tw-text-black";

return (
<div className="tw-rounded-md tw-border tw-border-slate-300 tw-border-solid tw-w-52 xl:tw-w-72 tw-p-1 xl:tw-p-2 tw-shadow-sm">
Expand Down Expand Up @@ -93,18 +93,20 @@ const EarlyWarningStudentRow: React.FC<EarlyWarningStudentRowProps> = ({
value={data.estimated_final}
unit="Predicted Final Score"
percent={true}
color={data.estimated_final > 70 ? "green" : "red"}
color={
data.estimated_final < 50
? "dark-red"
: data.estimated_final < 70
? "red"
: "black"
}
/>
<Metric
value={data.course_avg_diff}
unit={`${direction} Class Average`}
percent={true}
/>
<Metric
value={data.z_score}
unit="Z-Score"
percent={false}
/>
<Metric value={data.z_score} unit="Z-Score" percent={false} />
</div>
</Card.Body>
</Card.Body>
Expand Down
14 changes: 7 additions & 7 deletions components/InstructorDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const InstructorDashboard = ({
<GenericPageContainer>
<PageHeader
title="Instructor Dashboard"
subtitle="View analytics and data visualizations for your course. Click on a visualization to view more details."
subtitle="View analytics and data visualizations for your course."
/>
<InstructorQuickMetrics course_id={course_id} />
<VisualizationContainer
title="Performance"
title="Performance per Assignment"
description="Class average vs. selected student's scores"
tooltipDescription="Performance per assignment is the student's score on each assignment, compared to the class average."
>
Expand All @@ -45,8 +45,8 @@ const InstructorDashboard = ({
/>
</VisualizationContainer>
<VisualizationContainer
title="Student Activity Per Assignment"
description="Comparison of student activity on the selected assignment"
title="Student Activity on Assignment"
description="Submitted vs. unsubmitted questions for selected student"
>
<ActivityAccessed
getData={(student_id, assignment_id) =>
Expand All @@ -63,7 +63,7 @@ const InstructorDashboard = ({
</VisualizationContainer> */}
<VisualizationContainer
title="Time on Task"
description="Class average vs. selected student's cumulative time on task"
description="Class average vs. selected student's cumulative time on task per question"
tooltipDescription="Time on task is the student's time spent working on a question before they submit it."
>
<TimeOnTask
Expand All @@ -74,7 +74,7 @@ const InstructorDashboard = ({
</VisualizationContainer>
<VisualizationContainer
title="Time in Review"
description="Class average vs. selected student's cumulative time in review"
description="Class average vs. selected student's cumulative time in review per question"
tooltipDescription="Time in review is the student's time spent reviewing questions after they have been submitted."
>
<TimeInReview
Expand All @@ -90,7 +90,7 @@ const InstructorDashboard = ({
<NoData width={1200} height={400} />
</VisualizationContainer> */}
<VisualizationContainer
title="Submission Activity"
title="Submission Activity (All Students)"
description="Timeline of student submissions for selected assignment"
tooltipDescription="A histogram of student submissions over time for the selected assignment."
>
Expand Down
8 changes: 4 additions & 4 deletions components/InstructorQuickMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ const InstructorQuickMetrics = ({ course_id }: { course_id: string }) => {
<SmallMetricCard
title="Assignments"
value={data?.assignments}
unit="Assignments in Course"
//unit="Assignments in Course"
loading={isFetching}
/>
<SmallMetricCard
title="Total Questions"
value={data?.totalQuestions}
unit="Questions in Course"
// unit="Questions in Course"
className="tw-ml-4"
loading={isFetching}
/>
{data && data?.totalPageViews && (
<SmallMetricCard
title="Textbook Page Views"
value={data?.totalPageViews}
unit="Textbook Total Page Views"
// unit="Textbook Total Page Views"
className="tw-ml-4"
loading={isFetching}
/>
)}
<SmallMetricCard
title="Enrolled Students"
value={data?.enrolled}
unit="Active Students in Course"
// unit="Active Students in Course"
className="tw-ml-4"
loading={isFetching}
/>
Expand Down
37 changes: 35 additions & 2 deletions components/LearningCurveDescriptor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ const LearningCurveDescriptor: React.FC<LearningCurveDescriptorProps> = ({
return calculated > DEFAULT_MAX ? calculated : DEFAULT_MAX;
};

const xMax = maxAttempts();
const yMax = maxScore();

const x = d3
.scaleLinear()
.domain([0, maxAttempts()])
.domain([0, xMax])
.range([MARGIN.left, width - MARGIN.right]);

const y = d3
.scaleLinear()
.domain([0, maxScore()])
.domain([0, yMax])
.range([height - MARGIN.bottom, MARGIN.top]);

svg
Expand All @@ -97,6 +100,36 @@ const LearningCurveDescriptor: React.FC<LearningCurveDescriptorProps> = ({
.attr("transform", `translate(${MARGIN.left}, 0)`)
.call(d3.axisLeft(y));

// Calculate the regression line
const n = cleaned.length;
const sumX = cleaned.reduce((sum, d) => sum + d.num_attempts, 0);
const sumY = cleaned.reduce((sum, d) => sum + d.score, 0);
const sumXY = cleaned.reduce((sum, d) => sum + d.num_attempts * d.score, 0);
const sumXX = cleaned.reduce(
(sum, d) => sum + d.num_attempts * d.num_attempts,
0
);

const slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
const intercept = (sumY - slope * sumX) / n;

// Define the regression line data
const regressionLine = [
{ num_attempts: 0, score: intercept },
{ num_attempts: xMax, score: slope * xMax + intercept },
];

// Add the regression line to the SVG
svg
.append("line")
.datum(regressionLine)
.attr("x1", (d) => x(d[0].num_attempts))
.attr("y1", (d) => y(d[0].score))
.attr("x2", (d) => x(d[1].num_attempts))
.attr("y2", (d) => y(d[1].score))
.attr("stroke", "red")
.attr("stroke-width", 2);

setLoading(false);
}

Expand Down
8 changes: 4 additions & 4 deletions components/LearningObjectiveLevel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
} from "react-bootstrap-icons";
import LearningObjectiveQuestionsAligned from "./LearningObjectiveQuestionsAligned";

const MARGIN = DEFAULT_MARGINS;
const MARGIN = {
...DEFAULT_MARGINS,
bottom: 50,
};
const DEFAULT_HEIGHT = 150;

interface LearningObjectiveLevelProps {
Expand Down Expand Up @@ -144,9 +147,6 @@ const LearningObjectiveLevel: React.FC<LearningObjectiveLevelProps> = ({
.append("g")
.call(d3.axisBottom(x).ticks(5))
.attr("transform", `translate(0, 0)`);

// remove the text from the axis
group.append("g").call(d3.axisLeft(y)).selectAll("text").remove();
});

setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions components/SmallMetricCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from "classnames";
interface SmallMetricCardProps {
title: string;
value?: number | string;
unit: string;
unit?: string;
className?: string;
loading?: boolean;
}
Expand Down Expand Up @@ -40,7 +40,7 @@ const SmallMetricCard: React.FC<SmallMetricCardProps> = ({
: new Intl.NumberFormat().format(value)}
</p>
)}
<p className="tw-text-sm tw-mb-0 tw-text-slate-400">{unit}</p>
{unit && <p className="tw-text-sm tw-mb-0 tw-text-slate-400">{unit}</p>}
</Card>
);
};
Expand Down
30 changes: 30 additions & 0 deletions components/Visualizations/StudentActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ const StudentActivity: React.FC<StudentActivityProps> = ({
.scaleOrdinal()
.domain(subgroups)
.range(["#1f77b4", "#ff7f0e"]);

const labelScale = d3
.scaleOrdinal()
.domain(subgroups)
.range([0, 1]);

const pie = d3.pie().value((d: any) => {
return d[1];
Expand All @@ -142,6 +147,10 @@ const StudentActivity: React.FC<StudentActivityProps> = ({
) as any
);
const arcGenerator = d3.arc().innerRadius(0).outerRadius(radius);
const labelArcGenerator = d3
.arc()
.innerRadius(radius * 0.5)
.outerRadius(radius * 0.5);

svg
.selectAll("slices")
Expand All @@ -157,6 +166,27 @@ const StudentActivity: React.FC<StudentActivityProps> = ({
.style("opacity", 0.7)
.attr("transform", `translate(${width / 2}, ${height / 2})`);

// Add labels
svg
.selectAll("slices")
.data(dataReady)
.enter()
.append("text")
// @ts-ignore
.text((d) => labelScale(d.data) === 0 ? "Submitted" : unsubmitted.length > 0 ? "Not Submitted" : "") // Only show "Not Submitted" if there are unsubmitted questions
// @ts-ignore
.attr("transform", (d) => `translate(${labelArcGenerator.centroid(d)})`)
.style("text-anchor", "middle")
.style("font-size", "12px")
.style("font-weight", "semibold")
.attr("transform", (d) => {
// @ts-ignore
const pos = labelArcGenerator.centroid(d);
pos[0] = pos[0] * 2; // Change the 1.5 to another value to move the label further or closer
pos[1] = pos[1] * 1.5;
return `translate(${pos}) translate(${width / 2}, ${height / 2})`;
});

if (unsubmitted.length > 0) {
// Add "Not Submitted" to the legend
svg
Expand Down
2 changes: 1 addition & 1 deletion components/Visualizations/TimeInReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const TimeInReview: React.FC<TimeInReviewProps> = ({
.attr("text-anchor", "middle")
.style("font-size", "12px")
.style("font-weight", "semibold")
.text(`Assignment: ${getName(selectedAssignmentId)}`);
.text(`Questions in Assignment: ${getName(selectedAssignmentId)}`);

// Add one dot in the legend for each name.
svg
Expand Down
2 changes: 1 addition & 1 deletion components/Visualizations/TimeOnTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const TimeOnTask: React.FC<TimeOnTaskProps> = ({
.attr("text-anchor", "middle")
.style("font-size", "12px")
.style("font-weight", "semibold")
.text(`Assignment: ${getName(selectedAssignmentId)}`);
.text(`Questions in Assignment: ${getName(selectedAssignmentId)}`);

// Add one dot in the legend for each name.
svg
Expand Down

0 comments on commit 7679a63

Please sign in to comment.