# Album rating as a flexible attribute in .5 increments?

**URL:** <https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687>\
**Category:** Help\
**Created:** [February 6, 2021, 10:34pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687 "2021-02-06T22:34:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pandatroubles](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandatroubles](https://discourse.beets.io/u/pandatroubles)\
**Post date:** [February 6, 2021, 10:34pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/1 "2021-02-06T22:34:23Z")

</div>

Hello!

I would like to rate the albums I listen to in 2021, and I figured I could use a flexible attribute field for this and the [types plugin](https://beets.readthedocs.io/en/stable/plugins/types.html) to set said field to `int`. I want to rate albums from 1 to 5 in .5 increments, so a rating like 0.5, 3.5, etc. Is this possible somehow?

If I try setting a 1.5 rating using `beet modify -a album:album albumrating=1.5` beets tells me:

```auto
Album
  albumrating: 0
Really modify, move and write tags? (Yes/no/select) 

```

Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [February 7, 2021, 2:19am UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/2 "2021-02-07T02:19:23Z")

</div>

Hi! If you want to use non-integer values like 1.5, you’ll probably want to use a type other than `int`. Maybe try `float`?

---

<div class="post-metadata">

**Author:** ![pandatroubles](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandatroubles](https://discourse.beets.io/u/pandatroubles)\
**Post date:** [February 7, 2021, 10:53am UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/3 "2021-02-07T10:53:47Z")

</div>

> [@adrian](#):
>
> Maybe try `float` ?

I probably should have googled basic programming 101. Sorry for the trouble, and I appreciate your answer, it worked perfectly. 🙂

However, I’m running into an issue with [template functions](https://beets.readthedocs.io/en/latest/reference/pathformat.html#template-functions) now.

If I try `beet ls -a -f '$albumartist - (%if{$original_year,$original_year,$year}) - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{albumrating, ($albumrating),}' year:2021` then beets will return the album rating for the albums that has the field defined. For albums without the rating, `$albumrating` is returned.

Example:

```auto
Artist1 - (2021) - Albumname1 (2.0)
Artist2 - (2021) - Albumname2 ($albumrating)

```

Is there a solution for this as well?  
Thank you again!

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [February 7, 2021, 5:53pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/4 "2021-02-07T17:53:22Z")

</div>

That’s odd. So is `%ifdef` not working at all for that field? It might be worth doing some experimentation with `beet ls -f` to determine how it’s behaving for that and other fields—and whether it’s affected by the type you set for it.

---

<div class="post-metadata">

**Author:** ![pandatroubles](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandatroubles](https://discourse.beets.io/u/pandatroubles)\
**Post date:** [February 7, 2021, 8:20pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/5 "2021-02-07T20:20:07Z")

</div>

No, `%ifdef` doesn’t seem to work on `int` or `float` flexattr fields as far as I can tell. If I disable the `types` plugin then `%ifdef` works again. I’m not quite sure how I should troubleshoot further unfortunately.

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [February 8, 2021, 12:30pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/6 "2021-02-08T12:30:12Z")

</div>

Looks like a straight-up bug to me—reading over the implementation of `%ifdef`, I can see now how it would be confused about types with a default value. That is, `int` or `float` fields will produce a `'0'` string for unset values through the formatter, which gets interpreted as non-missing. We clearly need better logic for this. Would you mind opening an issue on GitHub?

---

<div class="post-metadata">

**Author:** ![pandatroubles](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@pandatroubles](https://discourse.beets.io/u/pandatroubles)\
**Post date:** [February 8, 2021, 10:09pm UTC](https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/7 "2021-02-08T22:09:14Z")

</div>

> [@adrian](#):
>
> Would you mind opening an issue on GitHub?

> <https://github.com/beetbox/beets/issues/3852>
>
> \### Problem
> If I try \`beet ls -a -f '$albumartist - (%if{$original\_year,$origin…al\_year,$year}) - $album%ifdef{albumdisambig, (%title{$albumdisambig}),}%ifdef{albumrating, ($albumrating),}' year:2021\` then beets will return the album rating for the albums that has the field defined. For albums without the rating, \`$albumrating\` is returned.
> 
> Example:
> \`\`\`
> Artist1 - (2021) - Albumname1 (2.0)
> Artist2 - (2021) - Albumname2 ($albumrating)
> \`\`\`
> 
> Further information on the forum:
> https://discourse.beets.io/t/album-rating-as-a-flexible-attribute-in-5-increments/1687/3
> 
> Comment from adrian:
> \_reading over the implementation of %ifdef, I can see now how it would be confused about types with a default value. That is, int or float fields will produce a '0' string for unset values through the formatter, which gets interpreted as non-missing. We clearly need better logic for this.\_
> 
> \### Setup
> 
> \* OS: Arch Linux
> \* beets version 1.5.0
> \* Python version 3.9.1
> \* plugins: edit, extrafiles, fetchart, importadded, importfeeds, info, inline, lastimport, mbcollection, mbsync, mpdstats, mpdupdate, originquery, scrub, smartplaylist, types, zero

Done!
