Skip to content

Commit

Permalink
Fix collection stats and add sales stats
Browse files Browse the repository at this point in the history
  • Loading branch information
JOJ0 committed Dec 31, 2024
1 parent c87d6f4 commit 0066f5d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
6 changes: 4 additions & 2 deletions discodos/ctrl/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,10 @@ def view_stats(self):
self.collection.stats_releases_matched(),
self.collection.stats_tracks_total(),
self.collection.stats_tracks_matched(),
self.collection.stats_releases_d_collection_flag(),
self.collection.stats_releases_d_collection_online(),
self.collection.stats_collection_items_discobase(),
self.collection.stats_collection_items_discogs(),
self.collection.stats_sales_listings_discobase(),
self.collection.stats_sales_listings_discogs(),
self.collection.stats_mixtracks_total(),
self.collection.stats_mixtracks_unique(),
self.collection.stats_tracks_key_brainz(),
Expand Down
13 changes: 11 additions & 2 deletions discodos/model/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,18 @@ def stats_tracks_matched(self):
stats = self._select(sql_stats, fetchone=True)
return stats[0] if stats else 0

def stats_releases_d_collection_flag(self):
def stats_collection_items_discobase(self):
sql_stats = '''
SELECT COUNT(*) FROM release WHERE in_d_collection == 1;
SELECT COUNT(*) FROM release LEFT OUTER JOIN collection
ON discogs_id = d_coll_release_id
WHERE coll_orphaned = 0;
'''
stats = self._select(sql_stats, fetchone=True)
return stats[0] if stats else 0

def stats_sales_listings_discobase(self):
sql_stats = '''
SELECT COUNT(*) FROM sales;
'''
stats = self._select(sql_stats, fetchone=True)
return stats[0] if stats else 0
Expand Down
10 changes: 9 additions & 1 deletion discodos/model/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,22 @@ def fetch_collection_item_instances(self, release_id):

return all_instances

def stats_releases_d_collection_online(self):
def stats_collection_items_discogs(self):
count = 0
try:
count = len(self.me.collection_folders[0].releases)
except Exception as Exc:
log.error("%s (Exception)", Exc)
return count

def stats_sales_listings_discogs(self):
count = 0
try:
count = len(self.me.inventory)
except Exception as Exc:
log.error("%s (Exception)", Exc)
return count

def fetch_sales_listing_details(self, listing_id, db_keys=True, tui_view=False):
"""Fetches details like price for a Discogs marketplace listing.
Expand Down
9 changes: 6 additions & 3 deletions discodos/view/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ def tab_all_releases(self, releases_data):
def tab_stats(
self, releases_total, releases_matched,
tracks_total, tracks_matched,
releases_collection_flag, releases_collection_online,
collection_items_discobase, collection_items_discogs,
sales_listings_discobase, sales_listings_discogs,
mixtracks_total, mixtracks_unique,
tracks_key_brainz, tracks_key_manual,
tracks_bpm_brainz, tracks_bpm_manual
):
stats = [
['Releases in DiscoBASE', releases_total],
['Releases in Collection (DB flag)', releases_collection_flag],
['Releases in Collection (Discogs)', releases_collection_online],
['Collection items (DiscoBASE)', collection_items_discobase],
['Collection items (Discogs)', collection_items_discogs],
['Sales listings (DiscoBASE)', sales_listings_discobase],
['Sales listings (Discogs)', sales_listings_discogs],
['Releases matched with *Brainz', releases_matched],
['Tracks in DiscoBASE', tracks_total],
['Tracks matched with *Brainz', tracks_matched],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def test_stats_releases_d_collection_flag(self):
name = inspect.currentframe().f_code.co_name
print("\n{} - {} - BEGIN".format(self.clname, name))
self.collection = Collection(False, self.db_path)
db_return = self.collection.stats_releases_d_collection_flag()
db_return = self.collection.stats_collection_items_discobase()
self.assertEqual(db_return, 4)
print("{} - {} - END".format(self.clname, name))

Expand Down

0 comments on commit 0066f5d

Please sign in to comment.