What is the format for the Average Time display in Quiz Summary?

Jump to solution
anniezk
Community Member

I found this information about the Total Activity in the How do I use the People page:
"Total activity time is displayed in hours:minutes:seconds. If a user has not yet reached an hour of activity, total activity time is displayed as minutes:seconds."

However, the attached screenshot of a Quiz summary with Average Time shows 18:55:64. There can't be more than 60 seconds (or minutes), so do you have another idea? To be clear, I know this number isn't of much use because in this untimed quiz a few students took many hours to complete it. Still, I'd love to know what that number means. Does someone like @James  have a suggestion?

Labels (2)
0 Likes
1 Solution
James
Community Champion

@anniezk 

I don't like TLDR, but the short version is you should ignore any seconds that are displayed. The number is unreliable as in do not trust it even if it is less than 60. You may want to file a bug report

Here's the reason.

I looked into this and finally found a quiz from Fall 2020 when this happened. Canvas displays the average time as 99:26:66.

I looked at what Canvas is saying vs what it is displaying. When it makes the request to get the statistics, the response has a quiz_statistics[0].submission_statistics object that contains the duration_average. This is 718014.8 for my quiz. That is in seconds.

Divide by the number of seconds in an hour (3600) to get the number of hours. 718014.8 / 3600 = 199.44855555555 hours.

The first thing that I notice is that Canvas is only displaying the last two digits of the hours. Instead of 199, it's showing 99.

Is the fact that it's more than 99 hours significant? Let's keep exploring.

Subtract the 199 hours to get the decimal part and multiply that by 60 to get the number of minutes. 60 * 0.44855555555 = 26.913333333 minutes. That agrees with the 26 minutes.

Now subtract the 26 minutes to get the decimal part and multiply that by 60 to get the number of seconds. 60 * 0.913333333 = 54.8 seconds, which would be 55 seconds if rounded.

That doesn't explain the extra 11 seconds, though.

After a bunch of looking, I found that there is a secondsToTime function in the seconds_to_time.js file. It inputs the seconds and returns a formatted time string. It has the faulty implementation.

If the number of seconds is greater than 3600 (more than one hour), then the number of hours is the floor(seconds/3600). floor is a round down function, so 718014.8/3600=199.448555, which has a floor of 199.

The minutes are the floor of (seconds - hours*3600)/60. This returns the 26 minutes.

The number of seconds is the remainder when the original number of seconds is divided by 60. This is 54.8 (or 54.800000000046566 because of decimal to binary conversion issues).

Those are all generated properly. The next line of code is

return [hh, mm, ss].map(pad).join(':')

That concatenates them together with colons using the pad function. The pad function returns the last two characters of the input with a '00' in front of it. The idea is that 9 become '009' and then you take the last two characters to get '09'. It forces all of the time portions to have exactly two characters.

  • 199 hours turns into '00199', which becomes '99'.
  • 26 minutes turns into '0026' becomes '26'
  • 54.8 is really 54.800000000046566 and turns into '0054.800000000046566' before becoming '66'.
 

It comes down to Canvas not rounding the number of seconds before trying to display it. If, for instance, it had been able to exactly represent 54.8, then it would have prepended two 0's and then taken the last two digits. That would be '0054.8' which would be '.8' so it would say '99:26:.8' for the answer. That said, it seems to calculate the value twice. I debugged the code, changed it to 54.8 and got '99:26:.8' as the value, but then when I let it continue and finish, it returned to '99:26:66'. Still wrong, but at least there's no .8 seconds when it should have been 54.

By the way, the number of seconds is unreliable for the same reason when it's just minutes and seconds as well. The code to find the number of seconds is still seconds % 60 (the remainder when dividing by 60).

What Canvas should do is to take the floor when they do the division by 60 to get the number of seconds. That would force it to be an integer and you wouldn't have to worry about the extra digits at the end.

The other alternative is to take the floor of the seconds at the very beginning and make 718014.8 just be 718014. Then everything works properly. Perhaps they did this at one time, but it is definitely broken now. This approach isn't as good because there may be some other place that they call secondsToTime() where the value isn't rounded.

In the end, the fact that it was more than 99 hours is not the reason for the number of seconds being more than 59, so that was a false lead. However, the time is inaccurately displayed for sighted users. For those using screen readers, it shows up as "199 hours and 26 minutes" and doesn't try to give the number of seconds.

View solution in original post