mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
Creating statistic container for channels.
This commit is contained in:
parent
81fb9b06c5
commit
95c37ae415
3 changed files with 65 additions and 3 deletions
|
|
@ -88,7 +88,11 @@ def get_channel(source_id: str = None, link: str = None, url: str = None, return
|
|||
raise UnknownChannel(f'No channel matches {link=} {source_id=} {url=}')
|
||||
|
||||
logger.debug(f'Found {channel=} using {source_id=} {link=} {url=}')
|
||||
return channel.dict() if return_dict else channel
|
||||
if return_dict:
|
||||
statistics = channel.get_statistics()
|
||||
channel = channel.dict()
|
||||
channel['statistics'] = statistics
|
||||
return channel
|
||||
|
||||
|
||||
def _spread_by_frequency(channels: List[Channel]):
|
||||
|
|
|
|||
|
|
@ -338,3 +338,18 @@ class Channel(ModelHelper, Base):
|
|||
link=self.link,
|
||||
)
|
||||
return d
|
||||
|
||||
def get_statistics(self):
|
||||
"""
|
||||
Get statistics about this channel.
|
||||
"""
|
||||
with get_db_curs() as curs:
|
||||
stmt = 'SELECT SUM(size), MAX(size) FROM video WHERE channel_id = %s'
|
||||
curs.execute(stmt, (self.id,))
|
||||
size, largest_video = curs.fetchone()
|
||||
statistics = dict(
|
||||
video_count=len(self.videos),
|
||||
size=size,
|
||||
largest_video=largest_video,
|
||||
)
|
||||
return statistics
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue