Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved analytics config into the database and added it to the admin interface #551

Merged
merged 10 commits into from
Jun 29, 2017
9 changes: 6 additions & 3 deletions api/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
BibliographicCoverageProvider,
CoverageFailure,
)
from core.analytics import Analytics

from authenticator import Authenticator
from circulation import (
Expand Down Expand Up @@ -232,7 +233,7 @@ def update_licensepools_for_identifiers(self, identifiers):
licenses_reserved=0,
patrons_in_hold_queue=0,
)
availability.apply(pool, ReplacementPolicy.from_license_source())
availability.apply(pool, ReplacementPolicy.from_license_source(self._db))


class Axis360CirculationMonitor(CollectionMonitor):
Expand Down Expand Up @@ -281,9 +282,10 @@ def run_once(self, start, cutoff):
self._db.commit()

def process_book(self, bibliographic, availability):


analytics = Analytics(self._db)
license_pool, new_license_pool = availability.license_pool(
self._db, self.collection
self._db, self.collection, analytics
)
edition, new_edition = bibliographic.edition(self._db)
license_pool.edition = edition
Expand All @@ -292,6 +294,7 @@ def process_book(self, bibliographic, availability):
subjects=True,
contributions=True,
formats=True,
analytics=analytics,
)
availability.apply(self._db, self.collection, replace=policy)
if new_edition:
Expand Down
7 changes: 5 additions & 2 deletions api/oneclick.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def update_licensepool_for_identifier(self, isbn, availability):
subjects=True,
contributions=True,
formats=True,
analytics=Analytics(self._db),
)

# licenses_available can be 0 or 999, depending on whether the book is
Expand Down Expand Up @@ -787,6 +788,7 @@ def __init__(self, collection, batch_size=None, api_class=OneClickAPI,
collection=self.collection, api_class=self.api,
)
)
self.analytics = Analytics(self._db)

def process_availability(self, media_type='ebook'):
# get list of all titles, with availability info
Expand All @@ -800,8 +802,9 @@ def process_availability(self, media_type='ebook'):
license_pool, is_new, is_changed = self.api.update_licensepool_for_identifier(isbn, available)
# Log a circulation event for this work.
if is_new:
Analytics.collect_event(
self._db, license_pool, CirculationEvent.DISTRIBUTOR_AVAILABILITY_NOTIFY, license_pool.last_checked)
for library in self.collection.libraries:
self.analytics.collect_event(
library, license_pool, CirculationEvent.DISTRIBUTOR_TITLE_ADD, license_pool.last_checked)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All these places that were calling Analytics.collect_event are missing test coverage.

Also, for some reason this one was using the wrong event type. I think AVAILABILITY_NOTIFY is when a patron has something on hold and it becomes available for checkout. I'm not completely sure what's going on here, but TITLE_ADD is usually the event type for a new license pool.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this should be TITLE_ADD. Sounds like someone was thinking the "availability" meant availability in general.


item_count += 1
if item_count % self.batch_size == 0:
Expand Down
6 changes: 4 additions & 2 deletions api/overdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ def __init__(self, _db, collection, api_class=OverdriveAPI):
self.maximum_consecutive_unchanged_books = (
self.MAXIMUM_CONSECUTIVE_UNCHANGED_BOOKS
)
self.analytics = Analytics(_db)

def recently_changed_ids(self, start, cutoff):
return self.api.recently_changed_ids(start, cutoff)
Expand All @@ -863,8 +864,9 @@ def run_once(self, start, cutoff):
license_pool, is_new, is_changed = self.api.update_licensepool(book)
# Log a circulation event for this work.
if is_new:
Analytics.collect_event(
_db, license_pool, CirculationEvent.DISTRIBUTOR_TITLE_ADD, license_pool.last_checked)
for library in self.collection.libraries:
self.analytics.collect_event(
library, license_pool, CirculationEvent.DISTRIBUTOR_TITLE_ADD, license_pool.last_checked)

_db.commit()

Expand Down
2 changes: 1 addition & 1 deletion core