Skip to content

Conversation

@ndias
Copy link
Contributor

@ndias ndias commented Nov 24, 2023

Show publishing statistics for subscriptions, original from Brand Huntsman <http://qzx.com/mail/ , add column for last feed update and last episode update dates.
Ticket with this requests
#978

Show publishing statistics for subscriptions, original from Brand Huntsman <http://qzx.com/mail/ add date for last feed update and last episode update
@ndias ndias changed the title Create subscription_stats.py subscription_stats.py Extension Nov 24, 2023
@anewuser
Copy link

I get this error when I try to use your version of this script:

[gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
  File "C:\gpodder\data\lib\python3.11\site-packages\gpodder\gtkui\main.py", line 404, in <lambda>
    return lambda action, param: callback()
                                 ^^^^^^^^^^
  File "C:\gpodder\data\share\gpodder\extensions\subscription_stats.py", line 134, in open_dialog
    last_feed = datetime.strptime(channel_last, '%a, %d %b %Y %H:%M:%S %Z').strftime('%Y/%m/%d')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/home/appveyor/_gpodder_build_root/mingw32/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
  File "C:/msys64/home/appveyor/_gpodder_build_root/mingw32/lib/python3.11/_strptime.py", line 349, in _strptime
ValueError: time data 'Tue, 27 Jun 2023 23:14:29 GMT' does not match format '%a, %d %b %Y %H:%M:%S %Z'

I've been listening to the full archives of some podcasts, so I haven't done a full check for updates in ages. If this issue happens because gPodder has changed its timestamp format, you don't need to stress over it.

Copy link
Contributor

@tpikonen tpikonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, except for the few nitpicks.

@ndias
Copy link
Contributor Author

ndias commented Nov 27, 2023

It seems this is due to different ways python versions are treat the different locales!
I'm changing the extension.

I get this error when I try to use your version of this script:

[gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
  File "C:\gpodder\data\lib\python3.11\site-packages\gpodder\gtkui\main.py", line 404, in <lambda>
    return lambda action, param: callback()
                                 ^^^^^^^^^^
  File "C:\gpodder\data\share\gpodder\extensions\subscription_stats.py", line 134, in open_dialog
    last_feed = datetime.strptime(channel_last, '%a, %d %b %Y %H:%M:%S %Z').strftime('%Y/%m/%d')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:/msys64/home/appveyor/_gpodder_build_root/mingw32/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
  File "C:/msys64/home/appveyor/_gpodder_build_root/mingw32/lib/python3.11/_strptime.py", line 349, in _strptime
ValueError: time data 'Tue, 27 Jun 2023 23:14:29 GMT' does not match format '%a, %d %b %Y %H:%M:%S %Z'

I've been listening to the full archives of some podcasts, so I haven't done a full check for updates in ages. If this issue happens because gPodder has changed its timestamp format, you don't need to stress over it.

A new version with changes from comments
@ndias
Copy link
Contributor Author

ndias commented Nov 27, 2023

@anewuser please try the new version 0.2

@anewuser
Copy link

It's working now, but can you please make the columns sortable and resizable?

@auouymous
Copy link
Member

Since you want to finish this for me, here is what kept me from releasing it, other than adding the 'last episode' column.

'%s subscriptions (%d paused)' should be %d not %s.

The 25 count should be clamped to episode.limit in the label, it doesn't matter for the database query. That way users with a low limit don't think it is some how averaging episodes they don't have.

Should it have a documentation link to a page in https://github.com/gpodder/gpodder.github.io/tree/master/docs/extensions?

@ndias
Copy link
Contributor Author

ndias commented Nov 29, 2023

Since you want to finish this for me, here is what kept me from releasing it, other than adding the 'last episode' column.
'%s subscriptions (%d paused)' should be %d not %s.

Done.

The 25 count should be clamped to episode.limit in the label, it doesn't matter for the database query. That way users with a low limit don't think it is some how averaging episodes they don't have.

Sorry, can you explain better this?

Should it have a documentation link to a page in https://github.com/gpodder/gpodder.github.io/tree/master/docs/extensions?

Done.

@ndias
Copy link
Contributor Author

ndias commented Nov 29, 2023

@anewuser > It's working now, but can you please make the columns sortable and resizable?

Done, you can test the new version

@tpikonen
Copy link
Contributor

The Days column is now sorted as string, which does not work as it should with strings which are numbers (the sorting is ok on start though). One solution would be to set a custom sort function with .set_sort_func().

@tpikonen
Copy link
Contributor

It would be nice to be able to use the statistics dialog in also in narrow screens (i.e. phones). Here's a suggestion on how to make it shrinkable and almost borderless. Since the podcast name is set to ellipsize at the end of the string, the pause indicator is moved to the beginning and shortened to a symbol. The close button and labels are now without margins, so they should be padded separately.

diff --git a/share/gpodder/extensions/subscription_stats.py b/share/gpodder/extensions/subscription_stats.py
index b1d52e31..66ab927e 100644
--- a/share/gpodder/extensions/subscription_stats.py
+++ b/share/gpodder/extensions/subscription_stats.py
@@ -44,9 +44,9 @@ class gPodderExtension:
         store = Gtk.ListStore(str, str, str)
         for average, name, last, paused in channels:
             store.append([
                 ('%.1f' % round(average, 1)) if average > 0 else '?',
-                name if not paused else (_('%s (paused)') % name), last,
+                ('‖ ' if paused else '') + name, last,
             ])
 
         tree = Gtk.TreeView(model=store)
         scrolled.add(tree)
@@ -62,12 +62,14 @@ class gPodderExtension:
 
         channelcell = Gtk.CellRendererText()
         channelcell.set_property('xalign', 0)
         channelcell.set_property('alignment', Pango.Alignment.LEFT)
+        channelcell.set_property('ellipsize', Pango.EllipsizeMode.END)
         channelcolumn = Gtk.TreeViewColumn(_('Podcast'))
         channelcolumn.set_sort_column_id(1)
         channelcolumn.pack_start(channelcell, True)
         channelcolumn.add_attribute(channelcell, 'text', 1)
+        channelcolumn.set_expand(True)
         tree.append_column(channelcolumn)
 
         lastcell = Gtk.CellRendererText()
         lastcell.set_property('xalign', 0)
@@ -149,15 +151,16 @@ class gPodderExtension:
         dlg.set_size_request(400, 400)
         dlg.set_resizable(True)
 
         box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
-        box.set_border_width(10)
+        box.set_border_width(0)
 
         label = Gtk.Label(_('%d subscriptions (%d paused)') % (len(channels), nr_paused))
         box.add(label)
 
         notebook = Gtk.Notebook()
         notebook.set_vexpand(True)
+        notebook.set_scrollable(True)
         self.add_page(notebook, _('daily'), daily)
         self.add_page(notebook, _('weekly'), weekly)
         self.add_page(notebook, _('monthly'), monthly)
         self.add_page(notebook, _('yearly'), yearly)

@auouymous
Copy link
Member

The 25 count should be clamped to episode.limit in the label, it doesn't matter for the database query. That way users with a low limit don't think it is some how averaging episodes they don't have.

Sorry, can you explain better this?

-label = Gtk.Label(_('Average days between the last 25 episodes.'))
+label = Gtk.Label(_('Average days between the last %d episodes.') % (episode.limit if episode.limit < 25 else 25))

Something like that.

The sort of the date now works, and other changes suggested by @tpikonen and @auouymous
@ndias
Copy link
Contributor Author

ndias commented Dec 6, 2023

The Days column is now sorted as string, which does not work as it should with strings which are numbers (the sorting is ok on start though). One solution would be to set a custom sort function with .set_sort_func().

Done, I think the sort now works, I use another column with the epoc date and the sort is made with that column

@ndias
Copy link
Contributor Author

ndias commented Dec 6, 2023

The 25 count should be clamped to episode.limit in the label, it doesn't matter for the database query. That way users with a low limit don't think it is some how averaging episodes they don't have.

Sorry, can you explain better this?

-label = Gtk.Label(_('Average days between the last 25 episodes.'))
+label = Gtk.Label(_('Average days between the last %d episodes.') % (episode.limit if episode.limit < 25 else 25))

Something like that.

Ok, thanks add this change

@ndias
Copy link
Contributor Author

ndias commented Dec 6, 2023

It would be nice to be able to use the statistics dialog in also in narrow screens (i.e. phones). Here's a suggestion on how to make it shrinkable and almost borderless. Since the podcast name is set to ellipsize at the end of the string, the pause indicator is moved to the beginning and shortened to a symbol. The close button and labels are now without margins, so they should be padded separately.

Add this changes, thanks

Cosmetic changes to pass lint and test workflow
@anewuser
Copy link

anewuser commented Dec 6, 2023

[gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
  File "C:\gpodder\data\lib\python3.11\site-packages\gpodder\gtkui\main.py", line 404, in <lambda>
    return lambda action, param: callback()
                                 ^^^^^^^^^^
  File "C:\gpodder\data\share\gpodder\extensions\subscription_stats.py", line 174, in open_dialog
    label = Gtk.Label(_('Average days between the last %d episodes.') % (episode.limit if episode.limit < 25 else 25))
                                                                                          ^^^^^^^
NameError: name 'episode' is not defined

episode.limit was not defined, changed to the right variable
@ndias
Copy link
Contributor Author

ndias commented Dec 7, 2023

[gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
  File "C:\gpodder\data\lib\python3.11\site-packages\gpodder\gtkui\main.py", line 404, in <lambda>
    return lambda action, param: callback()
                                 ^^^^^^^^^^
  File "C:\gpodder\data\share\gpodder\extensions\subscription_stats.py", line 174, in open_dialog
    label = Gtk.Label(_('Average days between the last %d episodes.') % (episode.limit if episode.limit < 25 else 25))
                                                                                          ^^^^^^^
NameError: name 'episode' is not defined
[gpodder.log] ERROR: Uncaught exception: Traceback (most recent call last):
  File "C:\gpodder\data\lib\python3.11\site-packages\gpodder\gtkui\main.py", line 404, in <lambda>
    return lambda action, param: callback()
                                 ^^^^^^^^^^
  File "C:\gpodder\data\share\gpodder\extensions\subscription_stats.py", line 174, in open_dialog
    label = Gtk.Label(_('Average days between the last %d episodes.') % (episode.limit if episode.limit < 25 else 25))
                                                                                          ^^^^^^^
NameError: name 'episode' is not defined

Sorry, the problem is solved.

Addressing suggestions
@ndias ndias requested a review from tpikonen January 15, 2024 16:50
Variable without whitespace
Copy link
Contributor

@tpikonen tpikonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting back to this. The dialog layout and functionality look mostly OK (except for the date column width) and the functionality is fine.

@ndias ndias requested a review from tpikonen February 1, 2024 16:11
Copy link
Contributor

@tpikonen tpikonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I still found some things to tweak, but it's almost there.

more updates and change the Updated and Channel column
@auouymous
Copy link
Member

I'm not sure how to fix the horizontal scrollbar issue, but it should be okay to merge it as is. Everyone agreed on changing to ❚❚ so that could be done. And the Channel column name should be changed to Podcast until we discuss renaming it through out the project. The use of 'channel' in the source is fine.

Rename of Channel to Podcast and change the pause icon
@ndias
Copy link
Contributor Author

ndias commented Mar 20, 2024

I'm not sure how to fix the horizontal scrollbar issue, but it should be okay to merge it as is. Everyone agreed on changing to ❚❚ so that could be done. And the Channel column name should be changed to Podcast until we discuss renaming it through out the project. The use of 'channel' in the source is fine.

Ok, I upload a new version with the requested changes.

@auouymous auouymous merged commit ccb4cba into gpodder:master Mar 20, 2024
@auouymous
Copy link
Member

@ndias Thank you for finishing this for me!

@tpikonen Thank you for reviewing it.

@ushuc
Copy link

ushuc commented Dec 21, 2024

I have enabled this extension in gPodder settings to test this new functionality out, but I don't know where these stats are shown or how to use this new feature. Can you help me on this one? Thx in advance.

@auouymous
Copy link
Member

Open the Extras menu.

@ushuc
Copy link

ushuc commented Dec 21, 2024

I was blind, thanx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants