Skip to content

Commit 0066f5d

Browse files
committed
Fix collection stats and add sales stats
1 parent c87d6f4 commit 0066f5d

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

discodos/ctrl/collection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,10 @@ def view_stats(self):
10181018
self.collection.stats_releases_matched(),
10191019
self.collection.stats_tracks_total(),
10201020
self.collection.stats_tracks_matched(),
1021-
self.collection.stats_releases_d_collection_flag(),
1022-
self.collection.stats_releases_d_collection_online(),
1021+
self.collection.stats_collection_items_discobase(),
1022+
self.collection.stats_collection_items_discogs(),
1023+
self.collection.stats_sales_listings_discobase(),
1024+
self.collection.stats_sales_listings_discogs(),
10231025
self.collection.stats_mixtracks_total(),
10241026
self.collection.stats_mixtracks_unique(),
10251027
self.collection.stats_tracks_key_brainz(),

discodos/model/collection.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,18 @@ def stats_tracks_matched(self):
567567
stats = self._select(sql_stats, fetchone=True)
568568
return stats[0] if stats else 0
569569

570-
def stats_releases_d_collection_flag(self):
570+
def stats_collection_items_discobase(self):
571571
sql_stats = '''
572-
SELECT COUNT(*) FROM release WHERE in_d_collection == 1;
572+
SELECT COUNT(*) FROM release LEFT OUTER JOIN collection
573+
ON discogs_id = d_coll_release_id
574+
WHERE coll_orphaned = 0;
575+
'''
576+
stats = self._select(sql_stats, fetchone=True)
577+
return stats[0] if stats else 0
578+
579+
def stats_sales_listings_discobase(self):
580+
sql_stats = '''
581+
SELECT COUNT(*) FROM sales;
573582
'''
574583
stats = self._select(sql_stats, fetchone=True)
575584
return stats[0] if stats else 0

discodos/model/discogs.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,22 @@ def fetch_collection_item_instances(self, release_id):
208208

209209
return all_instances
210210

211-
def stats_releases_d_collection_online(self):
211+
def stats_collection_items_discogs(self):
212212
count = 0
213213
try:
214214
count = len(self.me.collection_folders[0].releases)
215215
except Exception as Exc:
216216
log.error("%s (Exception)", Exc)
217217
return count
218218

219+
def stats_sales_listings_discogs(self):
220+
count = 0
221+
try:
222+
count = len(self.me.inventory)
223+
except Exception as Exc:
224+
log.error("%s (Exception)", Exc)
225+
return count
226+
219227
def fetch_sales_listing_details(self, listing_id, db_keys=True, tui_view=False):
220228
"""Fetches details like price for a Discogs marketplace listing.
221229

discodos/view/collection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,18 @@ def tab_all_releases(self, releases_data):
129129
def tab_stats(
130130
self, releases_total, releases_matched,
131131
tracks_total, tracks_matched,
132-
releases_collection_flag, releases_collection_online,
132+
collection_items_discobase, collection_items_discogs,
133+
sales_listings_discobase, sales_listings_discogs,
133134
mixtracks_total, mixtracks_unique,
134135
tracks_key_brainz, tracks_key_manual,
135136
tracks_bpm_brainz, tracks_bpm_manual
136137
):
137138
stats = [
138139
['Releases in DiscoBASE', releases_total],
139-
['Releases in Collection (DB flag)', releases_collection_flag],
140-
['Releases in Collection (Discogs)', releases_collection_online],
140+
['Collection items (DiscoBASE)', collection_items_discobase],
141+
['Collection items (Discogs)', collection_items_discogs],
142+
['Sales listings (DiscoBASE)', sales_listings_discobase],
143+
['Sales listings (Discogs)', sales_listings_discogs],
141144
['Releases matched with *Brainz', releases_matched],
142145
['Tracks in DiscoBASE', tracks_total],
143146
['Tracks matched with *Brainz', tracks_matched],

tests/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def test_stats_releases_d_collection_flag(self):
382382
name = inspect.currentframe().f_code.co_name
383383
print("\n{} - {} - BEGIN".format(self.clname, name))
384384
self.collection = Collection(False, self.db_path)
385-
db_return = self.collection.stats_releases_d_collection_flag()
385+
db_return = self.collection.stats_collection_items_discobase()
386386
self.assertEqual(db_return, 4)
387387
print("{} - {} - END".format(self.clname, name))
388388

0 commit comments

Comments
 (0)