INTERACT FORUM

Please login or register.

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

Author Topic: Expression help for new field  (Read 427 times)

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Expression help for new field
« on: March 09, 2024, 01:28:14 pm »

I do expressions at a first grade level so I'm trying to make a new calculated field.

I want to tally plays on songs that are in more than one place, but by the same artist.  For instance a song may be on the original album, but also on other compilation or greatest hits albums. 

As an example, I want a "Total Plays" field that will add the "Plays" fields on all tracks that fit this duplication and put the sum in the "Total Plays" field.  So "Long Train Running" by The Doobie Brothers is on their original album, their Best of album, and a 70's collection album.  I want the total plays from all three added up to equal the total times the same song has been played in this field. 

Help appreciated.

This would give me an exact "most listened to" listing of the song.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2407
Re: Expression help for new field
« Reply #1 on: March 09, 2024, 04:29:42 pm »

Hi Dawg,
The expression is simple, but can be VERY slow depending on your library size. You can try it on a calculated field, but I think it's best to use ZStats to run this expression once per day to update the Total Count daily (overnight), instead of trying to use it in realtime.

This expression should work for a calculated field:
Code: [Select]
listmath(fieldquery(name;artist,[name];[artist],number plays, 0, 1),2)
With ZStats you would run this instead (on the zstats.ini file):
Code: [Select]
setfield(Total Plays, listmath(fieldquery(director,[director],number plays, 0, 1),2))
Logged

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Re: Expression help for new field
« Reply #2 on: March 10, 2024, 08:47:42 am »

Thanks Zybex, but this gave me some wonky numbers.

In the attached screen shot you can see that the numbers in Total Played don't equal the sum of the Plays for a track.

I think it's giving me the total number of plays by the artist, not the track.  Except the track Bluebird is it's own thing in the screenshot.  In the screenshot you can see that all the Buffalo Springfield Total Played is 137 (except Bluebird).

The Buggles, Video Killed The Radio Star seems to be correct, however.  Any ideas?

Appreciate your help

Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2407
Re: Expression help for new field
« Reply #3 on: March 10, 2024, 09:18:06 am »

Hmm, indeed, looks like FieldQuery() does an OR search instead of AND - so it's adding counts from all files of Artist PLUS from all matching names.

You'll need to create an auxiliary calculated field for this then. Create a field called e.g. [Artist-Title] with expression "[Artist] - [Name]". Then use this for Total Plays:
Code: [Select]
listmath(fieldquery(Artist-Title,[Artist-Title],number plays, 0, 1),2)
Logged

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Re: Expression help for new field
« Reply #4 on: March 10, 2024, 08:19:49 pm »

That did it.

Appreciate your time so much. 

As an aside, the calculation was instantaneous in Media Center but it does seem to slow other entries down.  Will try to use Z-Stats when I get a chance.

One other thing, if I use the Artist field separated by semi-colon (;), the numbers are wonky.  If I change the semi-colon to the ampersand (&) or "with" it corrects.

Again, thanks.
Logged

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Re: Expression help for new field
« Reply #5 on: April 11, 2024, 02:27:03 pm »

@Zybex

Running ZStats and have a couple of questions.

It seems to run fine but the Top Plays playlist tabulations aren't correct (though my total plays add-on is more or less working except if 2 (or more) songs have the same number of plays it only counts it as one). 

I have tracks that haven't been played since 2019 in the 2024 playlist,
The All-time playlist has tracks only played 3 times in my history.
Last 6 months has 2 tracks that haven't been played since 2017.
Last 24h has tracks not played since 2021.

It seems some tracks show up erroneously in more than 1 playlist in these examples.

I thought it may work itself out as I run it, but it doesn't.  I even tried deleting some of the tracks that seem to bridge the playlists from the specific playlists where they were obviously incorrect.

It's not the end of the world, but thought you might want to know.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2407
Re: Expression help for new field
« Reply #6 on: April 11, 2024, 03:25:41 pm »

Hi Dawg,
ZStats uses the data in [Play History]. How is that being populated?
Can you paste a couple of examples of the wrong stats and their corresponding [Play History] content?
Logged

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Re: Expression help for new field
« Reply #7 on: April 12, 2024, 08:48:21 am »

Checking the "Play History" field, every single file is empty. 

"Play Stats" I notice has numbers separated by semi colons and commas which I don't believe was populated before ZStats.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2407
Re: Expression help for new field
« Reply #8 on: April 12, 2024, 09:07:02 am »

You need to follow the instructions to have MC actually record your plays in the [Play History] field. Without that ZStats can't create valid playlists. Right now it's just creating bad lists due to a feature called Pre-History, which tries to infer past plays - this also doesn't work well without some valid [play history] data.
Logged

Dawgincontrol

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 664
  • We have met the enemy and he is us.
Re: Expression help for new field
« Reply #9 on: April 12, 2024, 12:26:52 pm »

Will do
Logged
Pages: [1]   Go Up