Sum of certain Column Values?

Tags: #<Tag:0x00007f00c27929c0> #<Tag:0x00007f00c27928d0>

For whatever reason this code:

    elif column == 'tracknumber':
        return self.metadata['totaltracks']

As you see the 7 in the “Unclustered Files” line is the sum of the tracks in that cluster, as is the 17, while it’s also showing the %tracknumber% for that line item, it’s serving dual purpose by co-incidence, since you’d see the album name on the Cluster folder title, and how many tracks are contained within the folder at that moment…

Screen Shot 2019-12-12 at 9.03.48 AM

What I’d like to be able to do is use that behavior to have it actually add up the Size Column so that you can see how much data that Album is going to use on the disk. :slight_smile:

    elif column == '~filesize':
        filesize = self.metadata.filesize
        sizestr = "%s (%s)" % (bytes2human.decimal(size), bytes2human.binary(size))
        if not filesize:
            return sizestr

…and figure out where to apply formatting so the Track Size shows the bytes2human value as well.

Icing on that cake will be NatSort on those values instead of sorting as strings.

If youn want to display some kind of aggregated data from the child elements on a parent you have to implement it on the parent’s column method. For the file size of albums and clusters something like this should work (completely untested code):

elif column == '~filesize':
    totalsize = sum(f.metadata.filesize for f in self.iterfiles())
    return "%s (%s)" % (bytes2human.decimal(totalsize), bytes2human.binary(totalsize))

As you have already seen I have started to add configurable columns to the Picard development version. For now this intentionally is limited to a rather small number of typically requested, uncontroversial and easy to implement columns. But the idea is definitely to extend this. If filesize gets added something like the above certainly will be added to the default column implementations.


:slight_smile: Ya… I gotcha…

What do you think I blew here? … Something in Top Tags settings I have missed. I guess it’s time for Compare Diff in the Options code… (As he laughs I’m sure… ) I’m actually learning quite a bit with all this.

I see… I see… (Says the blind man … to his deaf son…)

I’m getting zero sum values from the above iteration of metadata.filesize. If I refer to it that way in metadatabox I get 0 as well. But ..getall("~filesize") works for the individual row data and in metadatabox.

            # tag_diff.add("~filesize",  # amd
            #              str(orig_metadata.filesize), str(new_metadata.filesize), False)
            tag_diff.add("~filesize",  # amd
                         orig_metadata.getall("~filesize"), new_metadata.getall("~filesize"), False)

I’ve poked around a bit looking at how format_time works as an example… but I’m not making a connection to how the sum of ~length is being calculated.

Other than there is a def format_time where as bytes2human appears to be defining it right there in the column instead of importing it.

I can’t really tell you since this is using your custom code for setting the metadata.filesize. That attribute is not normally set. Are you sure the metadata.filesize is actually set there? Or should it rather use metadata["~filesize"] instead, e.g.:

    totalsize = sum(int(f.metadata["~filesize"]) for f in self.iterfiles())
except ValueError:
    totalsize = 0
1 Like

That does it :slight_smile:

… Square brackets and double quotes.
/me makes a note of that. :slight_smile:Screen Shot 2020-01-27 at 01.37.24

def _add_path_to_metadata(self, metadata):
    metadata['~dirname'] = os.path.dirname(self.filename)
    filename, extension = os.path.splitext(os.path.basename(self.filename))
    metadata['~filename'] = filename
    metadata['~extension'] = extension.lower()[1:]
    metadata['~filesize'] = os.path.getsize(self.filename) # amd
1 Like