Community

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
themidiman
Community Champion

Sort order/algorithm rules?

Does anyone have a good handle on how Canvas sorts certain items in certain areas? I know there's some sort of lexicographical routine that will do things like make the number 10 come right after the number 1 in certain situations.

Here's a series of pages that have to-do dates filled in for the exact same time of 11:59pm, but they are sorting in this order in the course summary section of the syllabus:

M3-1: Evidence Based Practice: Overview and Learning Goals
M3-3: Required Reading: Types of Evidence
M3-2: Required Reading: The What & Why of EPB

What would make them sort in this order if they all have the same to-do "deadline", and better yet, how would one make them sort more intuitively by the first 4 characters in each string? M3-1:, M3-2:, M3-3:?

Thanks in advance

Labels (2)
0 Kudos
2 Replies
michael5
Community Contributor

Do they end up appearing in the order as you have written them here? Ie.:

M3-1: Evidence Based Practice: Overview and Learning Goals
M3-3: Required Reading: Types of Evidence
M3-2: Required Reading: The What & Why of EPB

That would indicate that the sorting algorithm - as you have probably guessed - doesn't take the first 4 letters of the string into account. It might be sorting by the 0th and the 1st index of the string ie. M3. But not the 3rd and the 4th ie. -1, -3 and -2.

It's also possible it doesn't sort by assignment titles at all, it could just be that it's sorting by due date/time. If these happen to be identical, the reason for the order in which they appear in the course summary is borderline arcane without direct access to the sorting algorithm. 

But if I was you, I'd test it by...

1) Changing the titles from M3-1 to 1-M3, for example. If they sort correctly after this, the sorting algorithm uses the first index of the title string (and maybe the second and the third but not the 4th, because if that was the case they'd be sorting correctly already). 

2) If that doesn't help, set the due times to 11:57, 11:58, 11:59. If that works, the sorting algorithm sorts by date/time specifically and has no method for further sorting of identical due times. This would generally cause an error but more likely the algorithm handles this exception specifically by skipping the element in question and simply placing it as the next item (and not before/after any other element that is being processed - which in turn causes them to appear in a random order). 

Hope this helps to reverse-engineer the algorithm, haha. 🙂 

maguire
Community Champion

For the syllabus, I force the order using the minutes of the hour of the due date to get the items displayed in the order that I want.

Internally in the Ruby code Canvas uses language-specific sort rules in a number of places. So depending on the user's UI language setting there can be different sort orders. Additionally, some pages (such as the gradebook) do sorts in Javascript.