Has anyone got examples of numerically ordering local db’s?
I am trying to create a leaderboard from local db entries. One column in the local db is ‘time’ I want to order all the entries so smallest time first and longest last, so it can then be displayed in a DVL.
Has anyone done this? Seems simple but struggling to get it done
There are no blocks at the moment that do the ordering/sorting for you, but I can help provide the logic to get this working.
You would need two data tables, one that will be connected to the DVL and one that won’t. I will call the table connected to the DVL the “DVL table” and the one that isn’t just “table”. When you want to sort, empty the table. Then you can loop through the table to find the smallest ‘time’ and then add it to the table. Repeat until everything is added in.
Then you remove everything from your DVL table, loop through the table, and add row by row from the table to your DVL table.
assuming your column time is a number, and assuming you have less than 1000 rows in the table, go over this column and build a list where each entry is computed from (value of time from the current row ) * 1000 + row_number so you may end with a list like [42423001, 54545002, 92442003, …85345026, 13748027] - simply sort this list and it’s now in time order. As you process this list, get the remainder of each entry after dividing by 1000 - that is the row number you want to obtain in order to populate your list.
(this is not tested)
This is slightly different than what I would do but this method works too. There are a few minor changes you will have to make.
You would have to make is to a “while app variable timelist is not empty list” after deleting all rows. Then after after the loop and before the end of the while loop, set i to 1 again.
Create another variable(let’s call it j) that will be set at 1. In “in list app variable timelist get i”, instead ‘i’, use ‘j’. Then where you have “in list app variable timelist remove i”, change ‘i’ to ‘j’, and increment j by 1.
@brianl do you know why when the blocks above are run, the whole db is not added to the DVL? After one button press it seems to add the first 5 entries rather than run through the whole db.
In the block where you have “count with i from 1 to length of”, it should be “list of values” of your db rather than the variable “app variables timelist”