Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include file path in 'sort by random' key to increase diversity #3278

Open
5 tasks done
claremacrae opened this issue Jan 19, 2025 · 0 comments
Open
5 tasks done

Include file path in 'sort by random' key to increase diversity #3278

claremacrae opened this issue Jan 19, 2025 · 0 comments
Labels
scope: sorting Changes to the sorting capabilities type: enhancement New feature or request

Comments

@claremacrae
Copy link
Collaborator

⚠️ Check request is valid.

  • My request is about the Tasks plugin for Obsidian.
  • I am only requesting a single feature in the Tasks plugin. Multiple changes should be split into individual requests, with links between them.
  • I believe my requested feature will be generally applicable to other Tasks plugin users, not just me: it is not uniquely tied to my personal workflow.

⚠️ Please check that this feature request hasn't been suggested before.

🔖 Feature description

I have noticed that sort by random can generate tasks with the same description on any given day.

Example query:

sort by random
limit 10

For me today is giving:

Image

I want results to be more random, so I get more variety of options in any given day.

✔️ Solution

The relevant code is line 45 here:

public sortKey(task: Task): number {
// Credit:
// - @qelo https://github.com/obsidian-tasks-group/obsidian-tasks/discussions/330#discussioncomment-8902878
// - Based on TinySimpleHash in https://stackoverflow.com/a/52171480/104370
const tinySimpleHash = (s: string): number => {
let i = 0; // Index for iterating over the string
let h = 9; // Initial hash value
while (i < s.length) {
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
}
return h ^ (h >>> 9);
};
const currentDate = window.moment().format('Y-MM-DD');
return tinySimpleHash(currentDate + ' ' + task.description);
}

I think it would be worth including the file path in the key, not just the description, for greater diversity of results.

❓ Alternatives

No response

📝 Additional Context

No response

@claremacrae claremacrae added type: enhancement New feature or request scope: sorting Changes to the sorting capabilities labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: sorting Changes to the sorting capabilities type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant