Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow plugins to add field types information for flexattrs #445
Conversation
pscn
added some commits
Nov 4, 2013
sampsyo
reviewed
Nov 5, 2013
sampsyo
reviewed
Nov 5, 2013
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sampsyo
Nov 5, 2013
Member
This looks awesome; thanks for putting this together. This kind of type map is exactly right; ideally, we can reuse the same infrastructure to do formatting as well (which we can tackle later, of course).
My only suggestion for the design here is to reduce the distinction between plugin-provided (flexattr) and built-in types. Maybe field_types can be constructed to contain both sets of types to make the type-to-query mapping simpler.
|
This looks awesome; thanks for putting this together. This kind of type map is exactly right; ideally, we can reuse the same infrastructure to do formatting as well (which we can tackle later, of course). My only suggestion for the design here is to reduce the distinction between plugin-provided (flexattr) and built-in types. Maybe field_types can be constructed to contain both sets of types to make the type-to-query mapping simpler. |
pscn
added some commits
Nov 5, 2013
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pscn
Nov 5, 2013
Collaborator
I just "hacked" the BooleanQuery to work with flexattrs and added support for quering template_fields to BooleanQuery and NumericQuery.
As an example I added the template_field played to mpdstats. It just checks if last_played is greater then 0 and returns True (or False if not set). I also added played as bool to field_types.
Now you can query like this:
beet ls -f '$played $last_played $artist - $title' played:True
True 1383226085 59 Times the Pain - Let Me In
True 1383221451 59 Times the Pain - Sense of Right and Wrong
True 1383312879 ART-SCHOOL - foolish
True 1383224504 Against All Authority - No Reason
[ ... ]These are heavier changes then I initially intended, so I'm not sure if they have any unwanted side effects.
|
I just "hacked" the As an example I added the Now you can query like this: beet ls -f '$played $last_played $artist - $title' played:True
True 1383226085 59 Times the Pain - Let Me In
True 1383221451 59 Times the Pain - Sense of Right and Wrong
True 1383312879 ART-SCHOOL - foolish
True 1383224504 Against All Authority - No Reason
[ ... ]These are heavier changes then I initially intended, so I'm not sure if they have any unwanted side effects. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pscn
Nov 5, 2013
Collaborator
Another commit to complete mpdstats. Adding template_fields for all values returning defaults, if no flexattrs are set. Also adding a start_count template_field that just adds play_count and skip_count and makes it accessible through queries.
Examples for the default values:
beet ls -f '$start_count $rating $play_count $skip_count $last_played $artist - $title' start_count:0
0 0.5 0 0 0 +44 - Baby Come On
0 0.5 0 0 0 +44 - Make You Smile
[ ... ]Example for start_count:
beet ls -f '$start_count $rating $play_count $skip_count $last_played $artist - $title' skip_count:1.. start_count:1..
3 0.6609375 2 1 1383228619 The Bouncing Souls - Old School
2 0.5390625 1 1 1383222249 The Lawrence Arms - Quincentuple Your Money
1 0.3125 0 1 0 Me First and the Gimme Gimmes - Isn't She Lovely|
Another commit to complete mpdstats. Adding Examples for the default values: beet ls -f '$start_count $rating $play_count $skip_count $last_played $artist - $title' start_count:0
0 0.5 0 0 0 +44 - Baby Come On
0 0.5 0 0 0 +44 - Make You Smile
[ ... ]Example for start_count: beet ls -f '$start_count $rating $play_count $skip_count $last_played $artist - $title' skip_count:1.. start_count:1..
3 0.6609375 2 1 1383228619 The Bouncing Souls - Old School
2 0.5390625 1 1 1383222249 The Lawrence Arms - Quincentuple Your Money
1 0.3125 0 1 0 Me First and the Gimme Gimmes - Isn't She Lovely |
pscn
added some commits
Nov 5, 2013
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pscn
Nov 5, 2013
Collaborator
Finishing this up for today with adding album support.
Example:
beet ls -a -f '$play_count $skip_count $rating $albumartist - $album' play_count:1..
2 0 0.5375 59 Times the Pain - Blind Anger & Hate
1 0 0.5625 ART-SCHOOL - REQUIEM FOR INNOCENCE
1 1 0.501395089286 Various Artists - Mailorder for the Masses
[ ... ]|
Finishing this up for today with adding album support. Example: beet ls -a -f '$play_count $skip_count $rating $albumartist - $album' play_count:1..
2 0 0.5375 59 Times the Pain - Blind Anger & Hate
1 0 0.5625 ART-SCHOOL - REQUIEM FOR INNOCENCE
1 1 0.501395089286 Various Artists - Mailorder for the Masses
[ ... ] |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sampsyo
Nov 7, 2013
Member
Looking very cool; thanks for all the revisions!
One thing we should take somewhat slow here: the way you've let queries access template fields here is very interesting—it makes them into something like "computed fields", which I think is a great direction. However, I think it's important that we tackle that in a general way. Specifically, it should be possible for any type of query to access any template field. This can work in the same way that we handle flexattrs (with "slow" queries that work transparently independent of the specific query kind). That way, substring and regex queries can get the same benefits.
We can either try to get to this ideal, orthogonal feature implementation in this PR or try splitting that off into a new branch of work—finish up the field-type stuff and then move onto computed fields. Got a preference?
|
Looking very cool; thanks for all the revisions! One thing we should take somewhat slow here: the way you've let queries access template fields here is very interesting—it makes them into something like "computed fields", which I think is a great direction. However, I think it's important that we tackle that in a general way. Specifically, it should be possible for any type of query to access any template field. This can work in the same way that we handle flexattrs (with "slow" queries that work transparently independent of the specific query kind). That way, substring and regex queries can get the same benefits. We can either try to get to this ideal, orthogonal feature implementation in this PR or try splitting that off into a new branch of work—finish up the field-type stuff and then move onto computed fields. Got a preference? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pscn
Nov 7, 2013
Collaborator
If I got some time tonight I'll try to make this work for all queries. Shouldn't be too much effort.
|
If I got some time tonight I'll try to make this work for all queries. Shouldn't be too much effort. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sampsyo
Nov 7, 2013
Member
Okay, cool. My suggested tactic: add the functionality to LibModel itself (or to Album and Item if that's impossible). Then make obj[field] work for these fields. This could help simplify the template-filling code also.
|
Okay, cool. My suggested tactic: add the functionality to LibModel itself (or to Album and Item if that's impossible). Then make |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pscn
Nov 11, 2013
Collaborator
This is not forgotten. But I didn't find time to work on it. Hopefully over this week I get it done.
|
This is not forgotten. But I didn't find time to work on it. Hopefully over this week I get it done. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sampsyo
Nov 11, 2013
Member
There's no rush, of course.
|
There's no rush, of course. |
pscn commentedNov 4, 2013
As discussed in #424 here's a proposal based on @sampsyo suggestion. It allows plugins to define field types.
In the plugin
__init__method you can now define the field types like so:intandfloatwill use theNumericQuery. Every other value will fallback to theSubstringQuery. A rudimentary conflict detection is also in place which will output something like this:A few examples how this looks like in action:
Would this be doable?