1st – Locating the highest occurence
In order for the individual numbers to be grouped properly you’ll need to FLATTEN
any list of numbers. So maybe the following would give the wanted output:
```dataview
TABLE length(rows) as count
FROM "Github imports"
FLATTEN number(split(string(requires), ",")) as aRequire
GROUP BY aRequire
SORT aRequire DESC
```
3rd – Visualizing the subset
Some alternate approaches to this case:
- Just use the query, which has the serious drawback of no graph view. Not a good alternative, I reckon
- Have the query in a commented section, copy it into the clipboard, and apply a template which execute the clipboard as a dataview query
- Automate the process in the previous step
I’m working on the third step, but the middle step is easier to implement. For that to work, create a template (e.g. queryClipboard
) in your template folder with the following content:
<%*
const dv = app.plugins.plugins.dataview.api
const query = await tp.system.clipboard()
console.log(query)
if ( query == "" )
window.alert("Copy the query (starting with " +
"LIST|TASK|TABLE|CALENDAR) into the clipboard. " +
"Before inserting the template.")
const result = await dv.queryMarkdown(query, tp.config.target_file.path);
if ( result.successful ) {
tR += result.value
} else {
tR += "~~~~\n" + result.error + "\n~~~~"
}
%>
You can now optionally create a hotkey for this template by doing:
- Go to _Settings > Templater > Template Hotkeys>, and hit the Add new hotkey for template button, and search up your newly created template
- Press the plus icon, and the hotkey dialog opens up
- Hit the plus icon in the new dialog next to the “Templater: Insert …/queryClipboard.md” command, and press the hotkey combination you want for triggering this template
Now given a query like the one below:
```dataview
LIST LIMIT 5
```
Select just the lines between the code block fences, aka LIST LIMIT 5
, and copy it to the clipboard using Cmd + C (or Ctrl + C on windows). Position your cursor a few lines down, and hit the designated hotkey, and it’ll insert the result of the query there.
A better setup using this template
To make it even easier to rerun your query I would place the original query in a comment block, so say that you’ve got something like the following:
<!-- The query is usually commented out, since we've persisted the
result below
```dataview
... the query of your choice ...
```
-->
- previous
- result
- list
You would of course replace the ... your query ...
part with your query, and this is contained within a comment block, so that it doesn’t “duplicate” the output, but this allows for two things. One it’s accessible for selection and copying into the clipboard (and subsequently ready for use by the template). And secondly, if you just remove the <!--
part, you can see the dynamic result of the query (with a little extra garbage before and after).
The process to rerun your query would now be:
- Make sure the query is commented out
- Select the inner part of the query, that is don’t include the code fence of the triple backticks, and copy that to the clipboard
- Select the previous output, and delete or replace that with a space or something like that
- Hit the designated hotkey for the
queryClipboard
template (or select it from the insert templater menu), and see your output be refreshed - Enjoy the graph view of the current output
WIP - Fully automated persisting of a query
When I get around to it, I’ll make one template to change the syntax around an existing query, so that it’ll end up look something like:
<!-- query-abc begin --
LIST LIMIT 5
<!-- query-abc end-query -->
- previous
- result
- set
<!-- query-abc end-result -->
This markup would then be able to be parsed by another template which will pick up the query between the first two markers, and replace the contents between the last two markers with the result of the executed query.
I’ve got the second part nearly done already, but I need to test and fine tune it a little more before presenting it in #share-showcase . (And I’m a little undecided on whether I should require the query section to be selected before the template is inserted, or if I should apply the template to the entire file )
But this, as said already, is a work in progress, so one day in the future it’ll hopefully come in a post near you!