Skip to content

Commit d5cc709

Browse files
fix(moment): remove server-side duration formatting on stats page
1 parent 4d8b813 commit d5cc709

File tree

15 files changed

+71
-60
lines changed

15 files changed

+71
-60
lines changed

app/helpers/course/statistics/aggregate_helper.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/views/course/statistics/aggregate/all_assessments.json.jbuilder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ json.assessments @assessments do |assessment|
2424
json.averageGrade grade_stats ? grade_stats[0] : 0
2525
json.stdevGrade grade_stats ? grade_stats[1] : 0
2626

27-
json.averageTimeTaken seconds_to_str(duration_stats[0])
28-
json.stdevTimeTaken seconds_to_str(duration_stats[1])
27+
json.averageTimeTaken duration_stats[0]
28+
json.stdevTimeTaken duration_stats[1]
2929

3030
json.numSubmitted @num_submitted_students_hash[assessment.id] || 0
3131
json.numAttempted @num_attempted_students_hash[assessment.id] || 0

app/views/course/statistics/aggregate/all_staff.json.jbuilder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ json.staff graded_staff do |staff|
66
json.name staff.name
77
json.numGraded staff.published_submissions.size
88
json.numStudents staff.my_students.count
9-
json.averageMarkingTime seconds_to_str(staff.average_marking_time)
10-
json.stddev seconds_to_str(staff.marking_time_stddev)
9+
json.averageMarkingTime staff.average_marking_time
10+
json.stddev staff.marking_time_stddev
1111
end

client/app/bundles/course/assessment/pages/AssessmentStatistics/LiveFeedbackHistory/LiveFeedbackMessageHistory.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'course/assessment/submission/components/GetHelpChatPage/utils';
1111
import MarkdownText from 'course/assessment/submission/components/MarkdownText';
1212
import useTranslation from 'lib/hooks/useTranslation';
13-
import moment, { SHORT_DATE_TIME_FORMAT } from 'lib/moment';
13+
import { formatShortDateTime } from 'lib/moment';
1414

1515
interface Props {
1616
messages: LiveFeedbackChatMessage[];
@@ -110,9 +110,7 @@ const LiveFeedbackMessageHistory: FC<Props> = (props) => {
110110
const message = messages[messageIndex];
111111
const isStudent = message.creatorId !== 0;
112112
const isError = message.isError;
113-
const createdAt = moment(new Date(message.createdAt)).format(
114-
SHORT_DATE_TIME_FORMAT,
115-
);
113+
const createdAt = formatShortDateTime(message.createdAt);
116114

117115
return (
118116
<div

client/app/bundles/course/assessment/submission/reducers/liveFeedbackChats/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@reduxjs/toolkit';
77
import shuffle from 'lodash-es/shuffle';
88

9-
import moment, { SHORT_TIME_FORMAT } from 'lib/moment';
9+
import moment, { formatShortTime } from 'lib/moment';
1010

1111
import {
1212
getLocalStorageValue,
@@ -138,9 +138,7 @@ export const liveFeedbackChatSlice = createSlice({
138138
new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(),
139139
)
140140
.map((message) => {
141-
const createdAt = moment(new Date(message.createdAt)).format(
142-
SHORT_TIME_FORMAT,
143-
);
141+
const createdAt = formatShortTime(new Date(message.createdAt));
144142
return {
145143
sender:
146144
message.creatorId === 0
@@ -267,7 +265,7 @@ export const liveFeedbackChatSlice = createSlice({
267265
const { answerId, message } = action.payload;
268266
const liveFeedbackChats =
269267
state.liveFeedbackChatPerAnswer.entities[answerId];
270-
const currentTime = moment(new Date()).format(SHORT_TIME_FORMAT);
268+
const currentTime = formatShortTime(new Date());
271269

272270
if (liveFeedbackChats) {
273271
const changes: Partial<LiveFeedbackChatData> = {
@@ -342,7 +340,7 @@ export const liveFeedbackChatSlice = createSlice({
342340
{
343341
sender: ChatSender.codaveri,
344342
message: overallContent,
345-
createdAt: moment(new Date()).format(SHORT_TIME_FORMAT),
343+
createdAt: formatShortTime(new Date()),
346344
isError: false,
347345
},
348346
]
@@ -384,7 +382,7 @@ export const liveFeedbackChatSlice = createSlice({
384382
const newChat: ChatShape = {
385383
sender: ChatSender.codaveri,
386384
message: errorMessage,
387-
createdAt: moment(new Date()).format(SHORT_TIME_FORMAT),
385+
createdAt: formatShortTime(new Date()),
388386
isError: true,
389387
};
390388

client/app/bundles/course/duplication/pages/Duplication/DestinationCourseSelector/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { duplicationModes } from 'course/duplication/constants';
88
import { duplicateCourse } from 'course/duplication/operations';
99
import { courseShape, sourceCourseShape } from 'course/duplication/propTypes';
1010
import { actions } from 'course/duplication/store';
11-
import moment, { SHORT_DATE_TIME_FORMAT } from 'lib/moment';
11+
import moment, { formatShortDateTime } from 'lib/moment';
1212

1313
import NewCourseForm from './NewCourseForm';
1414

@@ -85,7 +85,7 @@ class DestinationCourseSelector extends Component {
8585
date: tomorrow.date(),
8686
});
8787

88-
const timeNow = moment().format(SHORT_DATE_TIME_FORMAT);
88+
const timeNow = formatShortDateTime(new Date());
8989
const newTitleValues = { title: sourceCourse.title, timestamp: timeNow };
9090
const initialValues = {
9191
destination_instance_id: currentInstanceId,

client/app/bundles/course/lesson-plan/pages/LessonPlanShow/LessonPlanItem/Details/Chips.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Avatar, Chip } from '@mui/material';
88
import { red } from '@mui/material/colors';
99
import PropTypes from 'prop-types';
1010

11-
import moment, { SHORT_DATE_TIME_FORMAT, SHORT_TIME_FORMAT } from 'lib/moment';
11+
import moment, { formatShortDateTime, formatShortTime } from 'lib/moment';
1212

1313
const translations = defineMessages({
1414
notPublished: {
@@ -58,17 +58,13 @@ export const formatDateRange = (startAt, endAt) => {
5858

5959
const end = moment(endAt);
6060
if (!end.isValid()) {
61-
return start.format(SHORT_DATE_TIME_FORMAT);
61+
return formatShortDateTime(start);
6262
}
6363

6464
if (end.isSame(start, 'day')) {
65-
return `${start.format(SHORT_DATE_TIME_FORMAT)} - ${end.format(
66-
SHORT_TIME_FORMAT,
67-
)}`;
65+
return `${formatShortDateTime(start)} - ${formatShortTime(end)}`;
6866
}
69-
return `${start.format(SHORT_DATE_TIME_FORMAT)} - ${end.format(
70-
SHORT_DATE_TIME_FORMAT,
71-
)}`;
67+
return `${formatShortDateTime(start)} - ${formatShortDateTime(end)}`;
7268
};
7369

7470
class Chips extends Component {

client/app/bundles/course/statistics/pages/StatisticsIndex/assessments/AssessmentsStatisticsTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from 'lib/helpers/url-builders';
1818
import { getCourseId } from 'lib/helpers/url-helpers';
1919
import useTranslation from 'lib/hooks/useTranslation';
20-
import { formatMiniDateTime } from 'lib/moment';
20+
import { formatMiniDateTime, formatSecondsDuration } from 'lib/moment';
2121

2222
import AssessmentsScoreSummaryDownload from './AssessmentsScoreSummaryDownload';
2323

@@ -226,14 +226,14 @@ const AssessmentsStatisticsTable: FC<Props> = (props) => {
226226
of: 'averageTimeTaken',
227227
title: t(translations.averageTimeTaken),
228228
sortable: true,
229-
cell: (assessment) => assessment.averageTimeTaken,
229+
cell: (assessment) => formatSecondsDuration(assessment.averageTimeTaken),
230230
csvDownloadable: true,
231231
},
232232
{
233233
of: 'stdevTimeTaken',
234234
title: t(translations.stdevTimeTaken),
235235
sortable: true,
236-
cell: (assessment) => assessment.stdevTimeTaken,
236+
cell: (assessment) => formatSecondsDuration(assessment.stdevTimeTaken),
237237
csvDownloadable: true,
238238
},
239239
];

client/app/bundles/course/statistics/pages/StatisticsIndex/staff/StaffStatisticsTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { processStaff } from 'course/statistics/utils/parseStaffResponse';
77
import Table, { ColumnTemplate } from 'lib/components/table';
88
import { DEFAULT_TABLE_ROWS_PER_PAGE } from 'lib/constants/sharedConstants';
99
import useTranslation from 'lib/hooks/useTranslation';
10+
import { formatSecondsDuration } from 'lib/moment';
1011

1112
const translations = defineMessages({
1213
name: {
@@ -82,14 +83,14 @@ const StaffStatisticsTable: FC<Props> = (props) => {
8283
title: t(translations.averageMarkingTime),
8384
sortable: true,
8485
csvDownloadable: true,
85-
cell: (staff) => staff.averageMarkingTime,
86+
cell: (staff) => formatSecondsDuration(staff.averageMarkingTime),
8687
},
8788
{
8889
of: 'stddev',
8990
title: t(translations.stddev),
9091
sortable: true,
9192
csvDownloadable: true,
92-
cell: (staff) => staff.stddev,
93+
cell: (staff) => formatSecondsDuration(staff.stddev),
9394
},
9495
];
9596

client/app/bundles/course/statistics/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export interface Staff {
6363
name: string;
6464
numGraded: number;
6565
numStudents: number;
66-
averageMarkingTime: string;
67-
stddev: string;
66+
averageMarkingTime: number;
67+
stddev: number;
6868
}
6969

7070
export interface StaffStatistics {
@@ -125,8 +125,8 @@ export interface CourseAssessment {
125125
maximumGrade: number;
126126
averageGrade: number;
127127
stdevGrade: number;
128-
averageTimeTaken: string;
129-
stdevTimeTaken: string;
128+
averageTimeTaken: number;
129+
stdevTimeTaken: number;
130130
numSubmitted: number;
131131
numAttempted: number;
132132
numLate: number;

0 commit comments

Comments
 (0)