INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Issue with Item Count Expression  (Read 1274 times)

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Issue with Item Count Expression
« on: December 07, 2022, 03:19:28 pm »

Trying to display the number of songs and albums (per artist) for my music files.

Created a new view and it does display appropriately but the number of songs (using itemcount) is wrong in many instances.  Using groupcount for albums is consistently correct.

Example - The 3 Doors Down has a total of 25 songs but is showing 62.  See example showing count on the left at 62 and also at the bottom of the screen showing the correct number of 25

Basically any artist that has more than one song in almost all examples has the wrong number displayed.

I even created an expression field to just display the number of songs and it comes up with the same number even though it wrong.

thanks
Matt


Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2592
Re: Issue with Item Count Expression
« Reply #1 on: December 07, 2022, 03:47:41 pm »

Itemcount() takes the field name without brackets. Try just ItemCount(artist). wrong, it does need brackets
Logged

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Re: Issue with Item Count Expression
« Reply #2 on: December 07, 2022, 06:26:18 pm »

I tried that and no luck.  I now get a new number and all of the artist have the same number of songs. See attached file

I followed this thread and that's where I got the syntax from.
https://yabb.jriver.com/interact/index.php?topic=122370.0

I thought that it might include other .jpg files etc.  that have the artist field defined, but when I went through directory by directory checking on total files (not just music files )defined there still was no correlation.

Not sure what's happening here.  Is there a potential issue with the itemcount expression?  Do other use it successfully?

Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #3 on: December 07, 2022, 06:38:40 pm »

I had a similar issue with the item count expression - that is, it returned the same incorrect number for every artist (in my case, I had created an expression column for the number of albums for each artist in a detailed list view). I never could figure it out and eventually gave up and deleted the expression, so I can't resurrect exactly what the expression syntax was anymore.

In any event, I am very interested to hear from master expressionist zybex. I would be shocked if he is unable to guide us to a solution.
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #4 on: December 07, 2022, 07:11:45 pm »

I resurrected that expression column to clarify my prior post.  The column expression is: [Artist] (itemcount(album) albums)

As you can see in the 1st pic, it shows 33647 albums for every single artist. This matches exactly the total number of all files in my MC library (see 2nd pic).  When I replace itemcount with groupcount in the above expression, the number of albums changes to 327 for every artist - I have no idea where that number is coming from.

Hopefully one of the expression masters will come to the rescue and point out my obvious error.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2592
Re: Issue with Item Count Expression
« Reply #5 on: December 08, 2022, 04:35:53 am »

In any event, I am very interested to hear from master expressionist zybex.



OK, what you're probably looking for is:
[Artist] <font color="#8080FF">/(GroupCount() songs in GroupCount(album) albums/)

The boring stuff:

So actually ItemCount() takes an expression as an argument, and returns the number of files for which that expression has the same value. So ItemCount(some random text) will return the total file count in your library because the expression "some random text" evaluates to the same string in ALL of them. Same for ItemCount(artist), because "artist" here is just a string. Hence we need to use ItemCount(/[artist/]) to evaluate the "[artist]" expression on all files and count those that share the same value with the current file. HOWEVER, ItemCount() actually searches the entire library regardless of whatever filters you have on the view, so it will count any images or other files that share the same [artist]. To avoid that you can tweak the expression inside ItemCount() to something like ItemCount(/[artist]/-/[Media Sub Type/]), which will only count files sharing the same Artist and Media Subtype. So that's one solution.

GroupCount() is actually a much better choice here because it's designed for these grouping scenarios - it will only count files that are part of the current group/filter/tree, not the entire collection. Just using GroupCount() with no argument returns the total number of files of the current group (file count under each tree node). Adding a field name as an argument returns the total number of different values for that field *in the current group*. So that takes us to the solution above. Unlike ItemCount() which takes an expression, GroupCount needs the actual field name without brackets because it needs to know which field to compare, not which expression to evaluate.

Bonus expression pr0n:
[Artist, 1] <font color="#8080FF">/(replace(replace(.GroupCount() songs,.1 songs,1 song),.,) in replace(replace(.GroupCount(album) albums,.1 albums,1 album),.,)/)
Logged

mvandyke

  • World Citizen
  • ***
  • Posts: 159
Re: Issue with Item Count Expression
« Reply #6 on: December 08, 2022, 01:44:02 pm »

That worked - Thanks again Zybex you truly are the master of the expression language.

The second option worked best for me!

Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #7 on: December 13, 2022, 11:13:45 am »

First things first, thank you so much Zybex for taking the time to answer these questions - you truly are one of the most helpful users on the forum.

Unfortunately, neither of the expressions work for me.  Both expressions yield the exact same result as shown in the 1st picture below (same album/track count for every artist).  For the record, the current actual values are ~ 1000 artists, 2249 albums, and 26,750 files/songs. 

I spent some time tweaking around the edges with some slightly different approaches, but nothing worked.  Interestingly though, when I use the expression below that Marko created (found on an old thread) for thumbnail text, I get exactly what I want (as shown in the 2nd pic):
Code: [Select]
<b><font size="130">[Artist Sort]<//font><//b> if(isequal(groupcount(album),1,5),/(groupcount(album) Albums/),/(groupcount(album) Album/))
I figured if I used the above expression for the TREE and expression column, it would solve the problem, but no luck there either.  I did not make additional pictures for this post to show it, but for the TREE, it again shows every artist has only one album. For a detail list, it also shows the same number of albums for every artist, but instead of 339 for every artist that I got using your expression(s), it shows 32.   Also interesting though, is if I use your expressions as thumbnail text they also work perfectly. It just won't work in the TREE list, or in a LIST list.

I am completely flummoxed.  If you have any ideas or guidance, I would greatly appreciate it!
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2592
Re: Issue with Item Count Expression
« Reply #8 on: December 13, 2022, 11:23:05 am »

You're doing something else entirely from what mvandyke is doing. That looks like a Details view with some custom columns? The solution for that has to be different, but without knowing how you're defining that tree and view, I can't help much.
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #9 on: December 13, 2022, 11:57:26 am »

You're doing something else entirely from what mvandyke is doing. That looks like a Details view with some custom columns? The solution for that has to be different, but without knowing how you're defining that tree and view, I can't help much.

Well yes and no. Yes, I want to create an expression column, and I thought if I could get the TREE to populate correctly (per what mvandyke wanted), I could then leverage that to modify my custom column expression.  That said, I did mess up on the TREE. I put the expression in the Expression to Group by box instead of the Expression to Display box. After putting the expression in the correct location, the TREE now displays as expected.
 
So now I would like to create a custom column expression where each listed Artist shows the corresponding album count.  The album count could be shown in the same column, or in a dedicated column... either/both would be great. Unfortunately, no amount of my tweaking has yielded an expression that works - I always end up with the exact same number of albums for every artist (as shown in prior screenshots).
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #10 on: December 13, 2022, 12:16:21 pm »

Screenshots to supplement prior post.   Pic1: TREE custom view/expression.  Pic2: column custom expression
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2592
Re: Issue with Item Count Expression
« Reply #11 on: December 13, 2022, 03:13:10 pm »

The expression column requires GroupCountQuery:

[Artist] <font color="#4040FF" size="75">/(ItemCount(/[artist/]) songs in GroupCountQuery(artist, album) albums/)

Dealing with singular/plural (using replace() to avoid using itemcount/groupcountquery more than once since they're slow functions):

[Artist] <font color="#4040FF" size="75">/(replace(replace(.ItemCount(/[artist/]) songs,.1 songs,1 song),.,) in replace(replace(.GroupCountQuery(artist, album) albums,.1 albums,1 album),.,)/)
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #12 on: December 13, 2022, 07:12:16 pm »

As expected, the expression master comes through.  Thanks very much zybex.

I was wondering what that "replace(replace" expression was all about, so thank you for the explanation. And indeed, using an expression column is pretty slow, even when using your optimized "replace" version.  Displaying the number of albums/songs in the tree is instantaneous for whatever reason, but clicking/scrolling items in the content list area has a very noticeable lag.  So much so, it has dissuaded me from using an expression column at all. But thank you for all your help regardless… I learned something new for sure.  That said, I think many of us (e.g., me) do not care to spend hours trying to come up with complex expressions :(.   

Is it just me, or does anybody else think that album count (and album rating for that matter) should be default MC tags? Album count/rating are built into other media players by default... Why not MC? This is just a no-brainer IMO - seems like everybody would want that data automatically calculated by the program instead of having to create a complex expression to show it.
Logged

DJLegba

  • Citizen of the Universe
  • *****
  • Posts: 995
Re: Issue with Item Count Expression
« Reply #13 on: December 13, 2022, 07:29:33 pm »

Is it just me, or does anybody else think that album count (and album rating for that matter) should be default MC tags? Album count/rating are built into other media players by default... Why not MC? This is just a no-brainer IMO - seems like everybo
dy would want that data automatically calculated by the program instead of having to create a complex expression to show it.

I never use the rating feature and have to remove Rating from every view that I like. Number of plays would be a better indicator. When I build a smartlist I use lastplayed to prevent the list from pulling up stuff I have listened to recently. Why turn your collection into a personal Top 40?
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #14 on: December 13, 2022, 08:02:16 pm »

Number of plays would be a better indicator.
Better indicator of what? Your degree of like of a particular song?  I don't see how number of plays is "better" than a straight up rating, but to each his own. And as you indicated, you can simply "turn-off" showing ratings anywhere in MC that you desire.  My personal approach is a smart list that shuffle plays all songs in my library rated 6 and up (I use a 10-star system), which also automatically removes any song with number of plays > zero.  Every time I launch that smart list (via a dedicated radio button) it only populates songs that have not yet been played (i.e, the playlist gets shorter and shorter with each use). When that smart list can no longer find songs with zero plays, I reset the number of plays of my entire library back to zero. I like my approach very much and it works for me.

Regardless, what I am referring to is an album rating anyway, not a track/song rating. I have seen this requested on various threads over the years.  I'm looking to add something that people could use/turn on at their discretion - nothing that would be forced upon anyone. The album rating was also not my primary point.  IMO, MC should automatically know, manage and be able to easily display the number of albums per artist - MC calculating the album rating would be a bonus.  Again… it is something that already exists in other media players, so why not MC?

If this is something you have no interest in, that's okay. I am still reasonably confident most people would like to have album count/rating managed by MC without having to learn how to create a complex expression to show this data.
Logged

markf2748

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 816
Re: Issue with Item Count Expression
« Reply #15 on: December 14, 2022, 01:57:40 am »

Is it just me, or does anybody else think that album count (and album rating for that matter) should be default MC tags? Album count/rating are built into other media players by default... Why not MC? This is just a no-brainer IMO - seems like everybody would want that data automatically calculated by the program instead of having to create a complex expression to show it.
+1 for a new album artist relational field, which might be called [album total (album artist)] or [album count (album artist)], if MC can manage this internally without much overhead.
Or... is there an efficient expression for the user to define a custom field that would avoid the overhead of a query function call?
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2592
Re: Issue with Item Count Expression
« Reply #16 on: December 14, 2022, 03:08:31 am »

You could use ZStats to precalculate those fields for all files, and just re-run it on a schedule (or after each import) to update the counts.
¯\_(ツ)_/¯
Logged

HPBEME

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1094
  • Goodnight and Good Luck
Re: Issue with Item Count Expression
« Reply #17 on: December 14, 2022, 11:55:12 am »

Here is how another media program does this by default. No expression required - just minimal effort selecting tags I wanted displayed (via a dialog box).  The 2nd pic is after drilling down artist Acoustic Alchemy to show all their albums - note the album rating (none are rated as this is not primary music player... yet).
Logged
Pages: [1]   Go Up