Skip to content

Commit c46c03b

Browse files
authored
Implement AG spam duration sliders (#111)
1 parent a96b0f1 commit c46c03b

2 files changed

Lines changed: 98 additions & 30 deletions

File tree

src/snapshots-app/app/controllers/api/debugging/autograder_spam_controller.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def show
4343
sessions = []
4444
current_session = nil
4545

46-
backups.each do |backup|
46+
backups.each_with_index do |backup, index|
4747
backup_time = Time.zone.parse(backup.created)
4848

4949
if current_session.nil? || (backup_time - current_session[:end_time] > session_gap_limit)
@@ -53,13 +53,15 @@ def show
5353
end_time: backup_time,
5454
num_backups: 0,
5555
problems: Set.new,
56-
start_backup_id: backup.backup_id
56+
start_backup_id: backup.backup_id,
57+
start_index: index
5758
}
5859
sessions << current_session
5960
end
6061

6162
current_session[:end_time] = backup_time
6263
current_session[:num_backups] += 1
64+
current_session[:end_index] = index
6365

6466
if backup.analytics_location
6567
analytics = AnalyticsMessage.find_by(backup_id: backup.backup_id)
@@ -82,7 +84,10 @@ def show
8284
startTimestamp: s[:start_time].iso8601,
8385
endTimestamp: s[:end_time].iso8601,
8486
numBackups: s[:num_backups],
85-
problems: s[:problems].to_a.sort
87+
problems: s[:problems].to_a.sort,
88+
startIndex: s[:start_index],
89+
endIndex: s[:end_index],
90+
totalBackups: backups.count
8691
}
8792
end
8893

src/snapshots-app/client/bundles/components/submission/tabs/debugging/AutograderSpam.jsx

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
IconButton,
99
TextField,
1010
Stack,
11+
Slider,
1112
} from "@mui/material";
1213
import { DataGrid } from "@mui/x-data-grid";
1314
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
@@ -85,20 +86,79 @@ const AutograderSpam = () => {
8586
});
8687
}, [routeParams, numBackupsThreshold, timeThreshold]);
8788

89+
const getMarks = (totalBackups) => {
90+
return [
91+
{
92+
value: 0,
93+
label: "0",
94+
},
95+
{
96+
value: Math.round(totalBackups * 0.25),
97+
label: `${Math.round(totalBackups * 0.25)}`,
98+
},
99+
{
100+
value: Math.round(totalBackups * 0.5),
101+
label: `${Math.round(totalBackups * 0.5)}`,
102+
},
103+
{
104+
value: Math.round(totalBackups * 0.75),
105+
label: `${Math.round(totalBackups * 0.75)}`,
106+
},
107+
{
108+
value: totalBackups,
109+
label: `${totalBackups}`,
110+
},
111+
];
112+
};
113+
88114
const columns = [
89115
{
90-
field: "startTimestamp",
91-
headerName: "Start Timestamp",
92-
flex: 1,
93-
valueGetter: (value) => value,
94-
valueFormatter: (value) => formatTimestamp(value),
95-
},
96-
{
97-
field: "endTimestamp",
98-
headerName: "End Timestamp",
99-
flex: 1,
100-
valueGetter: (value) => value,
101-
valueFormatter: (value) => formatTimestamp(value),
116+
field: "worksession",
117+
headerName: "Worksession",
118+
flex: 2,
119+
valueGetter: (value, row) => new Date(row.startTimestamp),
120+
sortComparator: (v1, v2) => v1 - v2,
121+
// TODO fix popper being hidden by DataGrid on the far left side when hovering over the slider thumbs
122+
renderCell: (params) => {
123+
const getSliderValueText = (value) => {
124+
if (value === params.row.startIndex) {
125+
return `Backup #${value} (${formatTimestamp(params.row.startTimestamp)})`;
126+
} else {
127+
return `Backup #${value} (${formatTimestamp(params.row.endTimestamp)})`;
128+
}
129+
};
130+
131+
return (
132+
<div
133+
style={{ display: "flex", alignItems: "center", height: "100%" }}
134+
>
135+
<Slider
136+
aria-label="Worksession"
137+
value={[params.row.startIndex, params.row.endIndex]}
138+
valueLabelDisplay="auto"
139+
min={0}
140+
max={params.row.totalBackups}
141+
marks={getMarks(params.row.totalBackups)}
142+
valueLabelFormat={getSliderValueText}
143+
getAriaValueText={getSliderValueText}
144+
sx={{
145+
// Reduce the size of the circles (thumbs)
146+
"& .MuiSlider-thumb": {
147+
height: 12,
148+
width: 12,
149+
},
150+
// Adjust the track and rail thickness to match smaller thumbs
151+
"& .MuiSlider-track": {
152+
height: 4,
153+
},
154+
"& .MuiSlider-rail": {
155+
height: 4,
156+
},
157+
}}
158+
/>
159+
</div>
160+
);
161+
},
102162
},
103163
{
104164
field: "duration",
@@ -113,9 +173,9 @@ const AutograderSpam = () => {
113173
},
114174
{
115175
field: "numBackups",
116-
headerName: "Number of Backups",
176+
headerName: "# of Backups",
117177
type: "number",
118-
width: 150,
178+
width: 100,
119179
align: "right",
120180
headerAlign: "right",
121181
},
@@ -134,19 +194,21 @@ const AutograderSpam = () => {
134194
align: "center",
135195
headerAlign: "center",
136196
renderCell: (params) => (
137-
<Tooltip title="Jump to start of session in Timeline">
138-
<IconButton
139-
color="primary"
140-
size="small"
141-
onClick={() => {
142-
navigate(
143-
`/courses/${routeParams.courseId}/assignments/${routeParams.assignmentId}/students/${routeParams.studentId}/submission/timeline/${params.id}`,
144-
);
145-
}}
146-
>
147-
<OpenInNewIcon fontSize="small" />
148-
</IconButton>
149-
</Tooltip>
197+
<div style={{ display: "flex", alignItems: "center", height: "100%" }}>
198+
<Tooltip title="Jump to start of session in Timeline">
199+
<IconButton
200+
color="primary"
201+
size="small"
202+
onClick={() => {
203+
navigate(
204+
`/courses/${routeParams.courseId}/assignments/${routeParams.assignmentId}/students/${routeParams.studentId}/submission/timeline/${params.id}`,
205+
);
206+
}}
207+
>
208+
<OpenInNewIcon fontSize="small" />
209+
</IconButton>
210+
</Tooltip>
211+
</div>
150212
),
151213
},
152214
];
@@ -228,6 +290,7 @@ const AutograderSpam = () => {
228290
}}
229291
pageSizeOptions={[5, 10, 25]}
230292
disableRowSelectionOnClick
293+
rowHeight={100}
231294
/>
232295
</Paper>
233296
</Box>

0 commit comments

Comments
 (0)