Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Refactor `analytics` (#442)

Dhruv Bhanushalic6cfbe33dc46
diff --git a/analytics/Pipfile b/analytics/Pipfile
index 58b3d9daf..6cde948de 100644
--- a/analytics/Pipfile
+++ b/analytics/Pipfile
@@ -16,6 +16,8 @@ pytest = "*"
falcon-cors = "*"
confluent-kafka = "*"
python-decouple = "*"
+spectree = "*"
+pydantic = "*"
[requires]
python_version = "3.10"
diff --git a/analytics/Pipfile.lock b/analytics/Pipfile.lock
index b0018c682..bf1b5c273 100644
--- a/analytics/Pipfile.lock
+++ b/analytics/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "5e2f893619d7cabdb0a2e0fecad2f5e282528686e05f89f83a2f991eefe3747d"
+ "sha256": "e05f553252816bf4153370b8c0dc69abd0586a94c26660e333bc81df053a2332"
},
"pipfile-spec": 6,
"requires": {
@@ -260,6 +260,47 @@
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==1.11.0"
},
+ "pydantic": {
+ "hashes": [
+ "sha256:085ca1de245782e9b46cefcf99deecc67d418737a1fd3f6a4f511344b613a5b3",
+ "sha256:086254884d10d3ba16da0588604ffdc5aab3f7f09557b998373e885c690dd398",
+ "sha256:0b6037175234850ffd094ca77bf60fb54b08b5b22bc85865331dd3bda7a02fa1",
+ "sha256:0fe476769acaa7fcddd17cadd172b156b53546ec3614a4d880e5d29ea5fbce65",
+ "sha256:1d5278bd9f0eee04a44c712982343103bba63507480bfd2fc2790fa70cd64cf4",
+ "sha256:2cc6a4cb8a118ffec2ca5fcb47afbacb4f16d0ab8b7350ddea5e8ef7bcc53a16",
+ "sha256:2ee7e3209db1e468341ef41fe263eb655f67f5c5a76c924044314e139a1103a2",
+ "sha256:3011b975c973819883842c5ab925a4e4298dffccf7782c55ec3580ed17dc464c",
+ "sha256:3c3b035103bd4e2e4a28da9da7ef2fa47b00ee4a9cf4f1a735214c1bcd05e0f6",
+ "sha256:4c68c3bc88dbda2a6805e9a142ce84782d3930f8fdd9655430d8576315ad97ce",
+ "sha256:574936363cd4b9eed8acdd6b80d0143162f2eb654d96cb3a8ee91d3e64bf4cf9",
+ "sha256:5a79330f8571faf71bf93667d3ee054609816f10a259a109a0738dac983b23c3",
+ "sha256:5e48ef4a8b8c066c4a31409d91d7ca372a774d0212da2787c0d32f8045b1e034",
+ "sha256:6c5b77947b9e85a54848343928b597b4f74fc364b70926b3c4441ff52620640c",
+ "sha256:742645059757a56ecd886faf4ed2441b9c0cd406079c2b4bee51bcc3fbcd510a",
+ "sha256:7bdfdadb5994b44bd5579cfa7c9b0e1b0e540c952d56f627eb227851cda9db77",
+ "sha256:815ddebb2792efd4bba5488bc8fde09c29e8ca3227d27cf1c6990fc830fd292b",
+ "sha256:8b5ac0f1c83d31b324e57a273da59197c83d1bb18171e512908fe5dc7278a1d6",
+ "sha256:96f240bce182ca7fe045c76bcebfa0b0534a1bf402ed05914a6f1dadff91877f",
+ "sha256:a733965f1a2b4090a5238d40d983dcd78f3ecea221c7af1497b845a9709c1721",
+ "sha256:ab624700dc145aa809e6f3ec93fb8e7d0f99d9023b713f6a953637429b437d37",
+ "sha256:b2571db88c636d862b35090ccf92bf24004393f85c8870a37f42d9f23d13e032",
+ "sha256:bbbc94d0c94dd80b3340fc4f04fd4d701f4b038ebad72c39693c794fd3bc2d9d",
+ "sha256:c0727bda6e38144d464daec31dff936a82917f431d9c39c39c60a26567eae3ed",
+ "sha256:c556695b699f648c58373b542534308922c46a1cda06ea47bc9ca45ef5b39ae6",
+ "sha256:c86229333cabaaa8c51cf971496f10318c4734cf7b641f08af0a6fbf17ca3054",
+ "sha256:c8d7da6f1c1049eefb718d43d99ad73100c958a5367d30b9321b092771e96c25",
+ "sha256:c8e9dcf1ac499679aceedac7e7ca6d8641f0193c591a2d090282aaf8e9445a46",
+ "sha256:cb23bcc093697cdea2708baae4f9ba0e972960a835af22560f6ae4e7e47d33f5",
+ "sha256:d1e4c28f30e767fd07f2ddc6f74f41f034d1dd6bc526cd59e63a82fe8bb9ef4c",
+ "sha256:d9c9bdb3af48e242838f9f6e6127de9be7063aad17b32215ccc36a09c5cf1070",
+ "sha256:dee5ef83a76ac31ab0c78c10bd7d5437bfdb6358c95b91f1ba7ff7b76f9996a1",
+ "sha256:e0896200b6a40197405af18828da49f067c2fa1f821491bc8f5bde241ef3f7d7",
+ "sha256:f5a64b64ddf4c99fe201ac2724daada8595ada0d102ab96d019c1555c2d6441d",
+ "sha256:f947352c3434e8b937e3aa8f96f47bdfe6d92779e44bb3f41e4c213ba6a32145"
+ ],
+ "index": "pypi",
+ "version": "==1.9.0"
+ },
"pyparsing": {
"hashes": [
"sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4",
@@ -286,11 +327,19 @@
},
"requests": {
"hashes": [
- "sha256:6c1246513ecd5ecd4528a0906f910e8f0f9c6b8ec72030dc9fd154dc1a6efd24",
- "sha256:b8aa58f8cf793ffd8782d3d8cb19e66ef36f7aba4353eec859e74678b01b07a7"
+ "sha256:8e5643905bf20a308e25e4c1dd379117c09000bf8a82ebccc462cfb1b34a16b5",
+ "sha256:f71a09d7feba4a6b64ffd8e9d9bc60f9bf7d7e19fd0e04362acb1cfc2e3d98df"
+ ],
+ "index": "pypi",
+ "version": "==2.27.0"
+ },
+ "spectree": {
+ "hashes": [
+ "sha256:1f4fab59b464510d2b81668375342fad820710cc4e0807507eaa4c60825e00e8",
+ "sha256:affc2e0972f2971124df56e994221e19bf5a30520f12981734895c63bbf14ca3"
],
"index": "pypi",
- "version": "==2.26.0"
+ "version": "==0.6.8"
},
"sqlalchemy": {
"hashes": [
@@ -342,6 +391,14 @@
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==0.10.2"
},
+ "typing-extensions": {
+ "hashes": [
+ "sha256:4ca091dea149f945ec56afb48dae714f21e8692ef22a395223bcd328961b6a0e",
+ "sha256:7f001e5ac290a0c0401508864c7ec868be4e701886d5b573a9528ed3973d9d3b"
+ ],
+ "markers": "python_version >= '3.6'",
+ "version": "==4.0.1"
+ },
"urllib3": {
"hashes": [
"sha256:4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece",
diff --git a/analytics/alembic.ini b/analytics/alembic.ini
index 37667d1f3..ef7440192 100644
--- a/analytics/alembic.ini
+++ b/analytics/alembic.ini
@@ -2,7 +2,7 @@
[alembic]
# path to migration scripts
-script_location = migrations
+script_location = analytics/migrations
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
diff --git a/analytics/__init__.py b/analytics/analytics/__init__.py
similarity index 100%
rename from analytics/__init__.py
rename to analytics/analytics/__init__.py
diff --git a/analytics/attribution_worker.py b/analytics/analytics/attribution_worker.py
similarity index 90%
rename from analytics/attribution_worker.py
rename to analytics/analytics/attribution_worker.py
index 7be877025..5fbec5082 100644
--- a/analytics/attribution_worker.py
+++ b/analytics/analytics/attribution_worker.py
@@ -4,12 +4,13 @@ import urllib.parse as urlparse
from urllib.parse import parse_qs
from uuid import UUID
-import settings
from confluent_kafka import Consumer
-from models import AttributionReferrerEvent
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
+from analytics import settings
+from analytics.models import AttributionReferrerEvent
+
def parse_identifier(resource):
identifier = None
@@ -63,15 +64,15 @@ def scrub_malformed(_json: str):
def is_valid(parsed_msg: dict):
"""
We are only interested in attribution image logs for images that are
- embedded in domains not owned by Creative Commons. We also want to make
- sure that we're only tracking hits on embedded content.
+ embedded in domains not owned by us. We also want to make sure that we're
+ only tracking hits on embedded content.
"""
if parsed_msg is None:
return False
try:
referer = parsed_msg["http_referer"]
resource = parsed_msg["resource"]
- valid = "creativecommons.org" not in referer and ".svg" in resource
+ valid = settings.IGNORED_REFERRER not in referer and ".svg" in resource
except KeyError:
valid = False
return valid
@@ -91,7 +92,7 @@ def listen(consumer, database):
else:
ignored += 1
else:
- log.info("No message received in {timeout}")
+ log.info(f"No message received in {timeout}")
if saved + ignored % 100 == 0:
log.info(f"Saved {saved} attribution events, ignored {ignored}")
diff --git a/analytics/backdate.py b/analytics/analytics/backdate.py
similarity index 97%
rename from analytics/backdate.py
rename to analytics/analytics/backdate.py
index e614b0df9..58e3aed9c 100644
--- a/analytics/backdate.py
+++ b/analytics/analytics/backdate.py
@@ -1,9 +1,14 @@
+"""
+A one-off script for generating analytics reports back to September 2019, when
+we first started collecting analytics data.
+"""
+
import datetime
-import settings
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
+from analytics import settings
from analytics.report_controller import (
generate_referrer_usage_report,
generate_source_usage_report,
@@ -13,12 +18,6 @@ from analytics.report_controller import (
)
-"""
-A one-off script for generating analytics reports back to September 2019, when
-we first started collecting analytics data.
-"""
-
-
engine = create_engine(settings.DATABASE_CONNECTION)
session_maker = sessionmaker(bind=engine)
session = session_maker()
diff --git a/analytics/analytics/docs/README.md b/analytics/analytics/docs/README.md
new file mode 100644
index 000000000..7b4290ad9
--- /dev/null
+++ b/analytics/analytics/docs/README.md
@@ -0,0 +1,4 @@
+# Introduction
+
+An API for registering anonymous usage data events in Openverse, which we intend
+to use to improve the quality of the search results.
diff --git a/analytics/analytics/docs/__init__.py b/analytics/analytics/docs/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/analytics/docs/redoc.html b/analytics/analytics/docs/redoc.html
similarity index 50%
rename from analytics/docs/redoc.html
rename to analytics/analytics/docs/redoc.html
index 94ffef81e..df87efeda 100644
--- a/analytics/docs/redoc.html
+++ b/analytics/analytics/docs/redoc.html
@@ -2,26 +2,21 @@
<html>
<head>
<title>Openverse Analytics</title>
- <!-- needed for adaptive design -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
-
+ <link rel="icon" type="image/svg" href="https://raw.githubusercontent.com/WordPress/openverse/master/brand/icon.svg">
<!--
ReDoc doesn't change outer page styles
-->
<style>
- body {
+ body {{
margin: 0;
padding: 0;
- }
-
- img[alt='logo'] {
- padding: 20px; /* same as other sidebar items */
- }
+ }}
</style>
</head>
<body>
- <redoc spec-url='/swagger.yaml' expand-responses="all"></redoc>
- <script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
+ <redoc spec-url='{spec_url}' expand-responses="all"></redoc>
+ <script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
-</html>
+ </html>
diff --git a/analytics/analytics/docs/schemas/__init__.py b/analytics/analytics/docs/schemas/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/analytics/analytics/docs/schemas/requests.py b/analytics/analytics/docs/schemas/requests.py
new file mode 100644
index 000000000..13bce5df4
--- /dev/null
+++ b/analytics/analytics/docs/schemas/requests.py
@@ -0,0 +1,91 @@
+from uuid import UUID
+
+from pydantic import BaseModel, Field, validator
+
+from analytics.models import DetailPageEvents
+
+
+class SearchEventSchema(BaseModel):
+ query: str = Field(description="the search query")
+ session_uuid: str = Field(
+ description="a unique identifier labeling an anonymous user's session"
+ )
+
+ @validator("session_uuid")
+ def session_uuid_must_be_v4(cls, val):
+ return UUID(val, version=4).hex
+
+ class Config:
+ schema_extra = {
+ "example": {
+ "query": "cat",
+ "session_uuid": "00000000-0000-0000-0000-000000000000",
+ }
+ }
+
+
+class SearchRatingEventSchema(BaseModel):
+ query: str = Field(description="the search query")
+ relevant: bool = Field(description="whether the search results are relevant")
+
+ class Config:
+ schema_extra = {"example": {"query": "cat", "relevant": True}}
+
+
+class ResultClickEventSchema(BaseModel):
+ query: str = Field(description="the search query")
+ session_uuid: str = Field(
+ description="a unique identifier labeling an anonymous user's session"
+ )
+ result_uuid: str = Field(
+ description="a unique identifier for the result that was clicked"
+ )
+ result_rank: int = Field(
+ description="the 0-indexed position of the result in the search results grid"
+ )
+
+ @validator("session_uuid")
+ def session_uuid_must_be_v4(cls, val):
+ return UUID(val, version=4).hex
+
+ @validator("result_uuid")
+ def result_uuid_must_be_v4(cls, val):
+ return UUID(val, version=4).hex
+
+ class Config:
+ schema_extra = {
+ "example": {
+ "query": "cat",
+ "session_uuid": "00000000-0000-0000-0000-000000000000",
+ "result_uuid": "cdbd3bf6-1745-45bb-b399-61ee149cd58a",
+ "result_rank": 0,
+ }
+ }
+
+
+class DetailEventSchema(BaseModel):
+ result_uuid: str = Field(
+ description=(
+ "the unique identifier for the detail page " "associated with the event"
+ )
+ )
+ event_type: str = Field(
+ description=(
+ f"one of {', '.join([f'`{item.name}`' for item in DetailPageEvents])}"
+ )
+ )
+
+ @validator("event_type")
+ def event_must_be_valid_enum_item(cls, val):
+ if not hasattr(DetailPageEvents, val):
+ items = ", ".join([f"`{item.name}`" for item in DetailPageEvents])
+ raise ValueError(f"Event type must be one of {items}")
+ return val
+
+ class Config:
+ schema_extra = {
+ "example": {
+ "event_type": "SHARED_SOCIAL",
+ "result_uuid": "cdbd3bf6-1745-45bb-b399-61ee149cd58a",
+ }
+ }
diff --git a/analytics/analytics/docs/schemas/responses.py b/analytics/analytics/docs/schemas/responses.py
new file mode 100644
index 000000000..d19c28a07
--- /dev/null
+++ b/analytics/analytics/docs/schemas/responses.py
@@ -0,0 +1,35 @@
+from pydantic import BaseModel, Field
+
+
+class OkSchema(BaseModel):
+ status: str = Field(
+ default="200 OK",
+ description="synonymous with the HTTP status-code of the response",
+ )
+
+
+class CreatedSchema(BaseModel):
+ status: str = Field(
+ default="201 Created",
+ description="synonymous with the HTTP status-code of the response",
+ )
+
+
+class BadRequestSchema(BaseModel):
+ class BadRequestSchemaElement(BaseModel):
+ loc: list[str] = Field(description="the fields that did not validate")
+ msg: str = Field(description="explanation for why the validation failed")
+ type: str = Field(description="the type of error encountered during validation")
+ ctx: object = Field(description="the context of the error")
+
+ __root__: list[BadRequestSchemaElement]
+
+
+class InternalServerErrorSchema(BaseModel):
+ title: str = Field(
+ default="500 Internal Server Error",
+ description="synonymous with the HTTP status-code of the response",
+ )
+ description: str = Field(
+ description="explanation for why the server experienced errors"
+ )
diff --git a/analytics/event_controller.py b/analytics/analytics/event_controller.py
similarity index 91%
rename from analytics/event_controller.py
rename to analytics/analytics/event_controller.py
index 863c84846..854e7b412 100644
--- a/analytics/event_controller.py
+++ b/analytics/analytics/event_controller.py
@@ -1,18 +1,19 @@
-from models import (
+from sqlalchemy import create_engine
+from sqlalchemy.orm import sessionmaker
+
+from analytics import settings
+from analytics.models import (
DetailPageEvent,
DetailPageEvents,
ResultClickedEvent,
SearchEvent,
SearchRatingEvent,
)
-from settings import DATABASE_CONNECTION
-from sqlalchemy import create_engine
-from sqlalchemy.orm import sessionmaker
class EventController:
def __init__(self):
- self.engine = create_engine(DATABASE_CONNECTION)
+ self.engine = create_engine(settings.DATABASE_CONNECTION)
def _persist(self, _object):
Session = sessionmaker(bind=self.engine)
diff --git a/analytics/gen_daily_report.py b/analytics/analytics/gen_daily_report.py
similarity index 96%
rename from analytics/gen_daily_report.py
rename to analytics/analytics/gen_daily_report.py
index 5ef39df61..424a26ba3 100644
--- a/analytics/gen_daily_report.py
+++ b/analytics/analytics/gen_daily_report.py
@@ -1,10 +1,10 @@
import datetime
import logging as log
-import settings
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
+from analytics import settings
from analytics.report_controller import (
generate_referrer_usage_report,
generate_source_usage_report,
diff --git a/analytics/migrations/README b/analytics/analytics/migrations/README
similarity index 100%
rename from analytics/migrations/README
rename to analytics/analytics/migrations/README
diff --git a/analytics/migrations/env.py b/analytics/analytics/migrations/env.py
similarity index 94%
rename from analytics/migrations/env.py
rename to analytics/analytics/migrations/env.py
index 87298ecae..9f12d6d7d 100644
--- a/analytics/migrations/env.py
+++ b/analytics/analytics/migrations/env.py
@@ -1,14 +1,16 @@
-
+import inspect
from logging.config import fileConfig
+from alembic import context
from sqlalchemy import engine_from_config
from sqlalchemy import pool
+from sqlalchemy.ext.declarative import declarative_base
+
+from analytics import models
+from analytics.settings import DATABASE_CONNECTION
+
+Base = declarative_base()
-from alembic import context
-import inspect
-from settings import DATABASE_CONNECTION
-import models
-from models import *
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
@@ -23,6 +25,7 @@ fileConfig(config.config_file_name)
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata
+
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
diff --git a/analytics/migrations/script.py.mako b/analytics/analytics/migrations/script.py.mako
similarity index 100%
rename from analytics/migrations/script.py.mako
rename to analytics/analytics/migrations/script.py.mako
diff --git a/analytics/migrations/versions/0cd416f5a7d2_add_attribution_events_table.py b/analytics/analytics/migrations/versions/0cd416f5a7d2_add_attribution_events_table.py
similarity index 100%
rename from analytics/migrations/versions/0cd416f5a7d2_add_attribution_events_table.py
rename to analytics/analytics/migrations/versions/0cd416f5a7d2_add_attribution_events_table.py
diff --git a/analytics/migrations/versions/54e56668b66a_regenerate_initial_migration.py b/analytics/analytics/migrations/versions/54e56668b66a_regenerate_initial_migration.py
similarity index 100%
rename from analytics/migrations/versions/54e56668b66a_regenerate_initial_migration.py
rename to analytics/analytics/migrations/versions/54e56668b66a_regenerate_initial_migration.py
diff --git a/analytics/migrations/versions/7695412f8a64_switch_to_boolean_search_rating_instead_.py b/analytics/analytics/migrations/versions/7695412f8a64_switch_to_boolean_search_rating_instead_.py
similarity index 100%
rename from analytics/migrations/versions/7695412f8a64_switch_to_boolean_search_rating_instead_.py
rename to analytics/analytics/migrations/versions/7695412f8a64_switch_to_boolean_search_rating_instead_.py
diff --git a/analytics/migrations/versions/beb6d39f2dfd_add_reporting_tables.py b/analytics/analytics/migrations/versions/beb6d39f2dfd_add_reporting_tables.py
similarity index 100%
rename from analytics/migrations/versions/beb6d39f2dfd_add_reporting_tables.py
rename to analytics/analytics/migrations/versions/beb6d39f2dfd_add_reporting_tables.py
diff --git a/analytics/analytics/models/__init__.py b/analytics/analytics/models/__init__.py
new file mode 100644
index 000000000..7754212c9
--- /dev/null
+++ b/analytics/analytics/models/__init__.py
@@ -0,0 +1,16 @@
+from analytics.models.events import (
+ AttributionReferrerEvent,
+ DetailPageEvent,
+ DetailPageEvents,
+ ResultClickedEvent,
+ SearchEvent,
+ SearchRatingEvent,
+)
+from analytics.models.orm import Image
+from analytics.models.reports import (
+ AttributionRefererReport,
+ SourceUsageReport,
+ TopResultsReport,
+ TopSearchesReport,
+ UsageReport,
+)
diff --git a/analytics/models.py b/analytics/analytics/models/events.py
similarity index 53%
rename from analytics/models.py
rename to analytics/analytics/models/events.py
index 6333ca06d..d449d1be5 100644
--- a/analytics/models.py
+++ b/analytics/analytics/models/events.py
@@ -1,6 +1,6 @@
import enum
-from sqlalchemy import Boolean, Column, DateTime, Enum, Float, Integer, String
+from sqlalchemy import Boolean, Column, DateTime, Enum, Integer, String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql import func
@@ -9,28 +9,11 @@ from sqlalchemy.sql import func
Base = declarative_base()
-class Image(Base):
- __tablename__ = "image"
- # Managed by Django ORM; partially duplicated here so we can join
- # analytics and image data together. This is excluded from migrations.
- id = Column(Integer, primary_key=True)
- identifier = Column(UUID)
- source = Column(String)
- provider = Column(String)
- title = Column(String)
-
-
class EventMixin(object):
id = Column(Integer, primary_key=True)
timestamp = Column(DateTime, server_default=func.now(), index=True)
-class ReportMixin(object):
- id = Column(Integer, primary_key=True)
- start_time = Column(DateTime, index=True)
- end_time = Column(DateTime, index=True)
-
-
class SearchEvent(Base, EventMixin):
"""
Store searches linked to a session UUID.
@@ -100,51 +83,3 @@ class AttributionReferrerEvent(Base, EventMixin):
referer_domain = Column(String, index=True)
# The path to the embedded asset on our server. ex: /static/img/cc-by.svg
resource = Column(String, index=True)
-
-
-# Reports
-
-
-class UsageReport(Base, ReportMixin):
- """Tracks statistics for the last 24 hours"""
-
- __tablename__ = "usage_reports"
- results_clicked = Column(Integer)
- attribution_buttonclicks = Column(Integer)
- survey_responses = Column(Integer)
- source_clicked = Column(Integer)
- creator_clicked = Column(Integer)
- shared_social = Column(Integer)
- sessions = Column(Integer)
- searches = Column(Integer)
- attribution_referer_hits = Column(Integer)
- avg_rating = Column(Float)
- avg_searches_per_session = Column(Float)
-
-
-class SourceUsageReport(Base, ReportMixin):
- __tablename__ = "source_report"
-
- source_id = Column(String, index=True)
- result_clicks = Column(Integer, index=True)
-
-
-class AttributionRefererReport(Base, ReportMixin):
- __tablename__ = "attribution_referer_report"
-
- domain = Column(String, index=True)
- hits = Column(Integer, index=True)
-
-
-class TopSearchesReport(Base, ReportMixin):
- __tablename__ = "top_searches"
- term = Column(String, index=True)
- hits = Column(Integer, index=True)
-
-
-class TopResultsReport(Base, ReportMixin):
- __tablename__ = "top_results"
- result_uuid = Column(UUID, index=True)
- hits = Column(Integer, index=True)
- source = Column(String, index=True)
- title = Column(String, index=True)
diff --git a/analytics/analytics/models/orm.py b/analytics/analytics/models/orm.py
new file mode 100644
index 000000000..6a629ef72
--- /dev/null
+++ b/analytics/analytics/models/orm.py
@@ -0,0 +1,31 @@
+"""
+Contains SQLAlchemy models corresponding to Django ORM models. These models are
+excluded from migrations.
+"""
+
+from sqlalchemy import Column, Integer, String
+from sqlalchemy.dialects.postgresql import UUID
+from sqlalchemy.ext.declarative import declarative_base
+
+
+Base = declarative_base()
+
+
+class MediaMixin:
+ id = Column(Integer, primary_key=True)
+ identifier = Column(UUID)
+ source = Column(String)
+ provider = Column(String)
+ title = Column(String)
+
+
+class Image(Base, MediaMixin):
+ """Managed by Django model ``Image``"""
+
+ __tablename__ = "image"
+
+
+class Audio(Base, MediaMixin):
+ """Managed by Django model ``Audio``"""
+
+ __tablename__ = "audio"
diff --git a/analytics/analytics/models/reports.py b/analytics/analytics/models/reports.py
new file mode 100644
index 000000000..ec6095840
--- /dev/null
+++ b/analytics/analytics/models/reports.py
@@ -0,0 +1,57 @@
+from sqlalchemy import Column, DateTime, Float, Integer, String
+from sqlalchemy.dialects.postgresql import UUID
+from sqlalchemy.ext.declarative import declarative_base
+
+
+Base = declarative_base()
+
+
+class ReportMixin(object):
+ id = Column(Integer, primary_key=True)
+ start_time = Column(DateTime, index=True)
+ end_time = Column(DateTime, index=True)
+
+
+class UsageReport(Base, ReportMixin):
+ """Tracks statistics for the last 24 hours"""
+
+ __tablename__ = "usage_reports"
+ results_clicked = Column(Integer)
+ attribution_buttonclicks = Column(Integer)
+ survey_responses = Column(Integer)
+ source_clicked = Column(Integer)
+ creator_clicked = Column(Integer)
+ shared_social = Column(Integer)
+ sessions = Column(Integer)
+ searches = Column(Integer)
+ attribution_referer_hits = Column(Integer)
+ avg_rating = Column(Float)
+ avg_searches_per_session = Column(Float)
+
+
+class SourceUsageReport(Base, ReportMixin):
+ __tablename__ = "source_report"
+
+ source_id = Column(String, index=True)
+ result_clicks = Column(Integer, index=True)
+
+
+class AttributionRefererReport(Base, ReportMixin):
+ __tablename__ = "attribution_referer_report"
+
+ domain = Column(String, index=True)
+ hits = Column(Integer, index=True)
+
+
+class TopSearchesReport(Base, ReportMixin):
+ __tablename__ = "top_searches"
+ term = Column(String, index=True)
+ hits = Column(Integer, index=True)
+
+
+class TopResultsReport(Base, ReportMixin):
+ __tablename__ = "top_results"
+ result_uuid = Column(UUID, index=True)
+ hits = Column(Integer, index=True)
+ source = Column(String, index=True)
+ title = Column(String, index=True)
diff --git a/analytics/report_controller.py b/analytics/analytics/report_controller.py
similarity index 100%
rename from analytics/report_controller.py
rename to analytics/analytics/report_controller.py
diff --git a/analytics/analytics/server.py b/analytics/analytics/server.py
new file mode 100644
index 000000000..970320795
--- /dev/null
+++ b/analytics/analytics/server.py
@@ -0,0 +1,207 @@
+import logging
+import sys
+from uuid import UUID
+
+import falcon
+from falcon_cors import CORS
+from spectree import Response, SpecTree
+
+from analytics import settings
+from analytics.docs.schemas.requests import (
+ DetailEventSchema,
+ ResultClickEventSchema,
+ SearchEventSchema,
+ SearchRatingEventSchema,
+)
+from analytics.docs.schemas.responses import (
+ BadRequestSchema,
+ CreatedSchema,
+ InternalServerErrorSchema,
+ OkSchema,
+)
+from analytics.event_controller import EventController
+
+
+with open("docs/redoc.html", "r") as redoc_html:
+ page_templates = {"redoc": redoc_html.read()}
+with open("docs/README.md", "r") as readme_file:
+ description = readme_file.read()
+spec = SpecTree(
+ "falcon",
+ title="Openverse Analytics",
+ version=settings.VERSION,
+ description=description,
+ page_templates=page_templates,
+ path="doc",
+ mode="strict",
+ validation_error_status=400,
+)
+
+resp = Response(
+ HTTP_201=CreatedSchema,
+ HTTP_400=BadRequestSchema,
+ HTTP_500=InternalServerErrorSchema,
+)
+
+
+class HealthResource:
+ @spec.validate(
+ resp=Response(HTTP_200=OkSchema),
+ validation_error_status=200, # never fails validation
+ tags=["health"],
+ )
+ def on_get(self, _, resp):
+ """detail"""
+ resp.media = {"status": "200 OK"}
+ resp.status = falcon.HTTP_200
+
+
+class BaseEventResource:
+ """Base class for all resource that need access to an event controller"""
+
+ @staticmethod
+ def _validate_uuid(field, uuid):
+ try:
+ return UUID(uuid, version=4).hex
+ except ValueError:
+ raise falcon.HTTPBadRequest(description=f"{field} must be a v4 UUID")
+
+ def __init__(self, event_controller: EventController, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.event_controller = event_controller
+
+
+class SearchEventResource(BaseEventResource):
+ @spec.validate(
+ json=SearchEventSchema,
+ resp=resp,
+ tags=["search_event"],
+ )
+ def on_post(self, req, resp):
+ """create
+
+ Register a search query event.
+ """
+
+ j = req.media
+ try:
+ self.event_controller.create_search(
+ query=j["query"],
+ session_uuid=j["session_uuid"],
+ )
+ resp.media = {"status": "201 Created"}
+ resp.status = falcon.HTTP_201
+ except Exception as e:
+ raise falcon.HTTPInternalServerError(description=str(e))
+
+
+class SearchRatingEventResource(BaseEventResource):
+ @spec.validate(
+ json=SearchRatingEventSchema,
+ resp=resp,
+ tags=["search_rating_event"],
+ )
+ def on_post(self, req, resp):
+ """create
+
+ Submit a user's rating of a search.
+ """
+
+ j = req.media
+ try:
+ self.event_controller.create_search_rating(
+ query=j["query"],
+ relevant=j["relevant"],
+ )
+ resp.media = {"status": "201 Created"}
+ resp.status = falcon.HTTP_201
+ except Exception as e:
+ raise falcon.HTTPInternalServerError(description=str(e))
+
+
+class ResultClickEventResource(BaseEventResource):
+ @spec.validate(
+ json=ResultClickEventSchema,
+ resp=resp,
+ tags=["result_click_event"],
+ )
+ def on_post(self, req, resp):
+ """create
+
+ Submit an event indicating which result was clicked for a given search
+ query.
+ """
+
+ j = req.media
+ try:
+ self.event_controller.create_result_click(
+ query=j["query"],
+ session_uuid=j["session_uuid"],
+ result_uuid=j["result_uuid"],
+ rank=j["result_rank"],
+ )
+ resp.media = {"status": "201 Created"}
+ resp.status = falcon.HTTP_201
+ except Exception as e:
+ raise falcon.HTTPInternalServerError(description=str(e))
+
+
+class DetailEventResource(BaseEventResource):
+ @spec.validate(
+ json=DetailEventSchema,
+ resp=resp,
+ tags=["detail_page_event"],
+ )
+ def on_post(self, req, resp):
+ """create
+
+ Record events occurring on detail pages, such as sharing an image to
+ social media or clicking through to its source.
+ """
+
+ j = req.media
+ try:
+ self.event_controller.create_detail_event(
+ event=j["event_type"],
+ result_uuid=j["result_uuid"],
+ )
+ resp.media = {"status": "201 Created"}
+ resp.status = falcon.HTTP_201
+ except Exception as e:
+ raise falcon.HTTPInternalServerError(description=str(e))
+
+
+def create_api(log=True):
+ """Create an instance of the Falcon API server."""
+
+ if log:
+ root = logging.getLogger()
+ root.setLevel(logging.DEBUG)
+ handler = logging.StreamHandler(sys.stdout)
+ handler.setLevel(logging.INFO)
+ formatter = logging.Formatter(
+ "%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s"
+ )
+ handler.setFormatter(formatter)
+ root.addHandler(handler)
+
+ cors = CORS(
+ allow_origins_list=settings.ORIGINS,
+ allow_all_methods=True,
+ allow_all_headers=True,
+ )
+ _api = falcon.App(middleware=[cors.middleware])
+
+ event_controller = EventController()
+
+ _api.add_route("/", HealthResource())
+ _api.add_route("/search_event", SearchEventResource(event_controller))
+ _api.add_route("/search_rating_event", SearchRatingEventResource(event_controller))
+ _api.add_route("/result_click_event", ResultClickEventResource(event_controller))
+ _api.add_route("/detail_page_event", DetailEventResource(event_controller))
+
+ return _api
+
+
+api = create_api()
+spec.register(api)
diff --git a/analytics/analytics/settings.py b/analytics/analytics/settings.py
new file mode 100644
index 000000000..8305bb1d6
--- /dev/null
+++ b/analytics/analytics/settings.py
@@ -0,0 +1,27 @@
+from decouple import Csv, config
+
+
+VERSION = config("VERSION", default="1.0.0")
+
+ORIGINS = config(
+ "ORIGINS",
+ cast=Csv(),
+ default=",".join(
+ [
+ "https://search.openverse.engineering",
+ "https://search-dev.openverse.engineering",
+ "https://wordpress.org",
+ ]
+ ),
+)
+
+DATABASE_CONNECTION = config(
+ "DATABASE_CONN",
+ default="postgresql+psycopg2://deploy:deploy@localhost/openledger",
+)
+
+# Attribution events stream configuration
+KAFKA_HOSTS = config("KAFKA_HOSTS", default="kafka:9092")
+KAFKA_TOPIC_NAME = config("KAFKA_TOPIC", default="attribution_events_dev")
+ATTRIBUTION_LOGFILE = config("LOGFILE", default="/var/log/attribution_worker.log")
+IGNORED_REFERRER = config("IGNORED_REFERRER", default="wordpress.org")
diff --git a/analytics/docs/swagger.yaml b/analytics/docs/swagger.yaml
deleted file mode 100644
index 3e7313f66..000000000
--- a/analytics/docs/swagger.yaml
+++ /dev/null
@@ -1,198 +0,0 @@
-swagger: "2.0"
-
-info:
- description: |
- # Introduction
-
- An API for registering anonymous usage data events in Openverse, which we
- intend to use to improve the quality of the search results.
- version: "1.0.0"
- title: "Openverse Analytics"
- termsOfService: "https://api.openverse.engineering/terms_of_service.html"
- contact:
- license:
- name: "MIT License"
- url: "https://github.com/WordPress/openverse-api/blob/HEAD/LICENSE"
- x-logo:
- url: "https://raw.githubusercontent.com/WordPress/openverse/HEAD/brand/logo.svg"
- backgroundColor: "#fafafa"
-
-host: "api.openverse.engineering"
-basePath: "/analytics"
-
-tags:
- - name: "Register events"
- description: "Send events to the analytics server."
-schemes:
- - "https"
-paths:
- /search_event:
- post:
- tags:
- - "Register events"
- summary: "Register a search query event."
- description: ""
- operationId: "addSearch"
- consumes:
- - "application/json"
- produces:
- - "application/json"
- parameters:
- - in: "body"
- name: "body"
- description: "The user's search query and unique session UUID."
- required: true
- schema:
- $ref: "#/definitions/CreateSearchEvent"
-
- responses:
- 400:
- description: "Invalid input"
- /search_rating_event:
- post:
- tags:
- - "Register events"
- summary: "Submit a user's rating of a search."
- description: ""
- operationId: "addSearchRating"
- consumes:
- - "application/json"
- produces:
- - "application/json"
- parameters:
- - in: "body"
- name: "body"
- required: true
- schema:
- $ref: "#/definitions/CreateSearchRatingEvent"
-
- responses:
- 201:
- description: "Created"
- 400:
- description: "Invalid input"
- /result_click_event:
- post:
- tags:
- - "Register events"
- summary: "Submit an event indicating which result was clicked for a given search query."
- description: ""
- operationId: "addResultClick"
- consumes:
- - "application/json"
- produces:
- - "application/json"
- parameters:
- - in: "body"
- name: "body"
- required: true
- schema:
- $ref: "#/definitions/CreateResultClickEvent"
- responses:
- 201:
- description: "Created"
- 400:
- description: "Invalid input"
- /detail_page_event:
- post:
- tags:
- - "Register events"
- summary: "Record events occurring on detail pages, such as sharing an image to social media or clicking through to its source."
- description: ""
- operationId: "addDetailPageEvent"
- consumes:
- - "application/json"
- produces:
- - "application/json"
- parameters:
- - in: "body"
- name: "body"
- required: true
- schema:
- $ref: "#/definitions/CreateDetailPageEvent"
- responses:
- 201:
- description: "Created"
- 400:
- description: "Invalid input"
-
-definitions:
- CreateSearchEvent:
- type: "object"
- required:
- - query
- - session_uuid
- properties:
- query:
- type: "string"
- session_uuid:
- type: "string"
- example: "12345678-1234-1234-1234-1234567890ab"
-
- CreateSearchRatingEvent:
- type: "object"
- required:
- - query
- - relevant
- properties:
- query:
- type: "string"
- description: "A unique identifier labeling an anonymous user's session."
- relevant:
- type: "boolean"
- example: true
-
- CreateResultClickEvent:
- type: "object"
- required:
- - query
- - session_uuid
- - result_uuid
- - result_rank
- properties:
- query:
- type: "string"
- result_rank:
- type: "integer"
- example: 2
- description: "The position of the result in the search results grid, e.g. 0 for the first result, or 22 for the 21st result."
- result_uuid:
- type: "string"
- example: "12345678-1234-1234-1234-1234567890ab"
- description: "The unique identifier for the result that was clicked."
- session_uuid:
- type: "string"
- example: "12345678-1234-1234-1234-1234567890ab"
- description: "A unique identifier labeling an anonymous user's session."
-
- CreateDetailPageEvent:
- type: "object"
- required:
- - event_type
- - result_uuid
- properties:
- event_type:
- type: "string"
- description: >
- Supported event types:
- * `ATTRIBUTION_CLICKED` - The user generated an attribution string for this result.
- * `REUSE_SURVEY` - The user took a reuse survey.
- * `SOURCE_CLICKED` - The user visited the source page of the work.
- * `CREATOR_CLICKED` - The user visited the creator of the work's page.
- * `SHARED_SOCIAL` - The user shared a link to the work on social media.
- example: "ATTRIBUTION_CLICKED"
- enum:
- - ATTRIBUTION_CLICKED
- - REUSE_SURVEY
- - SOURCE_CLICKED
- - CREATOR_CLICKED
- - SHARED_SOCIAL
- result_uuid:
- type: "string"
- example: "12345678-1234-1234-1234-1234567890ab"
- description: "The unique identifier for the detail page associated with the event."
-
-externalDocs:
- description: "Openverse API docs"
- url: "https://api.openverse.engineering"
diff --git a/analytics/gunicorn.conf.py b/analytics/gunicorn.conf.py
index c2c23703d..4bb9eece1 100644
--- a/analytics/gunicorn.conf.py
+++ b/analytics/gunicorn.conf.py
@@ -1,2 +1,7 @@
bind = ["0.0.0.0:8090"]
+capture_output = True
+chdir = "./analytics/"
+timeout = 120
+reload = True
+loglevel = "debug"
wsgi_app = "server:api"
diff --git a/analytics/server.py b/analytics/server.py
deleted file mode 100644
index a7c314ae9..000000000
--- a/analytics/server.py
+++ /dev/null
@@ -1,86 +0,0 @@
-import falcon
-from event_controller import EventController
-from falcon_cors import CORS
-
-
-event_controller = EventController()
-
-
-class SearchEventResource:
- def on_post(self, req, resp):
- j = req.media
- event_controller.create_search(query=j["query"], session_uuid=j["session_uuid"])
- resp.status = falcon.HTTP_201
-
-
-class SearchRatingEventResource:
- def on_post(self, req, resp):
- j = req.media
- try:
- event_controller.create_search_rating(
- query=j["query"], relevant=j["relevant"]
- )
- resp.status = falcon.HTTP_201
- except ValueError:
- resp.body = '{"message": "Rating must be True or False"}'
- resp.status = falcon.HTTP_400
-
-
-class ResultClickEventResource:
- def on_post(self, req, resp):
- j = req.media
- event_controller.create_result_click(
- session_uuid=j["session_uuid"],
- result_uuid=j["result_uuid"],
- query=j["query"],
- rank=j["result_rank"],
- )
- resp.status = falcon.HTTP_201
-
-
-class DetailEventResource:
- def on_post(self, req, resp):
- j = req.media
- try:
- event_controller.create_detail_event(
- event=j["event_type"], result_uuid=j["result_uuid"]
- )
- resp.status = falcon.HTTP_201
- except KeyError:
- valid_events = event_controller.list_valid_detail_events()
- resp.body = '{{"message": "Invalid event_type. Valid types: {}"}}'.format(
- valid_events
- )
- resp.status = falcon.HTTP_400
-
-
-class RedocResource:
- def on_get(self, req, resp):
- resp.status = falcon.HTTP_200
- resp.content_type = "text/html"
- with open("docs/redoc.html", "r") as f:
- resp.body = f.read()
-
-
-class OpenAPISpecResource:
- def on_get(self, req, resp):
- resp.status = falcon.HTTP_200
- resp.content_type = "text/html"
- with open("docs/swagger.yaml", "r") as f:
- resp.body = f.read()
-
-
-origins = [
- # @todo: Switch these to environment variables
- "https://search.openverse.engineering",
- "https://search-dev.openverse.engineering",
- "https://wordpress.org/openverse",
-]
-cors = CORS(allow_origins_list=origins, allow_all_methods=True, allow_all_headers=True)
-api = falcon.App(middleware=[cors.middleware])
-api.add_route("/", RedocResource())
-api.add_route("/swagger.yaml", OpenAPISpecResource())
-api.add_route("/search_event", SearchEventResource())
-api.add_route("/search_rating_event", SearchRatingEventResource())
-api.add_route("/result_click_event", ResultClickEventResource())
-api.add_route("/detail_page_event", DetailEventResource())
diff --git a/analytics/settings.py b/analytics/settings.py
deleted file mode 100644
index 3ac79ee81..000000000
--- a/analytics/settings.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from decouple import config
-
-
-DATABASE_CONNECTION = config(
- "DATABASE_CONN",
- default="postgresql+psycopg2://deploy:deploy@localhost/openledger",
-)
-
-# Attribution events stream configuration
-KAFKA_HOSTS = config("KAFKA_HOSTS", default="kafka:9092")
-KAFKA_TOPIC_NAME = config("KAFKA_TOPIC", default="attribution_events_dev")
-ATTRIBUTION_LOGFILE = config("LOGFILE", default="/var/log/attribution_worker.log")
diff --git a/analytics/tests.py b/analytics/test/all_test.py
similarity index 98%
rename from analytics/tests.py
rename to analytics/test/all_test.py
index effe01e84..e3ddff139 100644
--- a/analytics/tests.py
+++ b/analytics/test/all_test.py
@@ -11,7 +11,7 @@ import requests
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
-import analytics.settings as settings
+from analytics import settings
from analytics.attribution_worker import is_valid, parse_message
from analytics.models import AttributionReferrerEvent
from analytics.report_controller import (
@@ -87,7 +87,7 @@ def test_attribution_validation():
)
invalid_msg = mock_attribution_event(
{
- "http_referer": "https://search.creativecommons.org/photos/12345",
+ "http_referer": "https://wordpress.org/openverse/photos/12345",
"request": "GET /static/img/cc-nd_icon.svg HTTP/1.1",
}
)
diff --git a/analytics/test/run_test.sh b/analytics/test/run_test.sh
new file mode 100755
index 000000000..1b2deb5dc
--- /dev/null
+++ b/analytics/test/run_test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+red="\e[31m"
+green="\e[32m"
+endcol="\e[0m"
+
+# Specify a file as the first argument to restrict the test to that file only.
+# ```
+# $ ./test/run_test.sh test/audio_integration_test.py
+# ```
+TEST_ARG="${1:-test/}"
+
+PYTHONWARNINGS="ignore:Unverified HTTPS request" \
+PYTHONPATH=. \
+pytest -s --disable-pytest-warnings $TEST_ARG
+
+succeeded=$?
+if [[ $succeeded -eq 0 ]]; then
+ printf "${green}:-) All tests passed${endcol}\n"
+else
+ printf "${red}:'( Some tests did not pass${endcol}\n"
+fi
+exit $succeeded
diff --git a/ingestion_server/ingestion_server/api.py b/ingestion_server/ingestion_server/api.py
index 2e348bd39..58f9fc4e7 100644
--- a/ingestion_server/ingestion_server/api.py
+++ b/ingestion_server/ingestion_server/api.py
@@ -26,16 +26,22 @@ CALLBACK_URL = "callback_url"
SINCE_DATE = "since_date"
-class Health:
- def on_get(self, req, resp):
+class HealthResource:
+ @staticmethod
+ def on_get(_, resp):
resp.status = falcon.HTTP_200
resp.media = {"status": "200 OK"}
-class TaskResource:
- def __init__(self, tracker: TaskTracker):
+class BaseTaskResource:
+ """Base class for all resource that need access to a task tracker"""
+
+ def __init__(self, tracker: TaskTracker, *args, **kwargs):
+ super().__init__(*args, **kwargs)
self.tracker = tracker
+
+class TaskResource(BaseTaskResource):
@staticmethod
def _get_base_url(req):
parsed = urlparse(req.url)
@@ -119,10 +125,7 @@ class TaskResource:
resp.media = self.tracker.list_task_statuses()
-class TaskStatus:
- def __init__(self, tracker: TaskTracker):
- self.tracker = tracker
-
+class TaskStatus(BaseTaskResource):
def on_get(self, req, resp, task_id):
"""Check the status of a single task."""
task = self.tracker.id_task[task_id]
@@ -142,7 +145,8 @@ class WorkerFinishedResource:
task.
"""
- def on_post(self, req, resp):
+ @staticmethod
+ def on_post(req, _):
target_index = worker_finished(str(req.remote_addr))
if target_index:
logging.info(
@@ -162,7 +166,8 @@ class WorkerFinishedResource:
class StateResource:
- def on_delete(self, req, resp):
+ @staticmethod
+ def on_delete(_, __):
"""
Forget about the last scheduled indexing job.
"""
@@ -171,6 +176,7 @@ class StateResource:
def create_api(log=True):
"""Create an instance of the Falcon API server."""
+
if log:
root = logging.getLogger()
root.setLevel(logging.DEBUG)
@@ -183,12 +189,12 @@ def create_api(log=True):
root.addHandler(handler)
_api = falcon.App()
+
task_tracker = TaskTracker()
- task_resource = TaskResource(task_tracker)
- get_task_status = TaskStatus(task_tracker)
- _api.add_route("/", Health())
- _api.add_route("/task", task_resource)
- _api.add_route("/task/{task_id}", get_task_status)
+
+ _api.add_route("/", HealthResource())
+ _api.add_route("/task", TaskResource(task_tracker))
+ _api.add_route("/task/{task_id}", TaskStatus(task_tracker))
_api.add_route("/worker_finished", WorkerFinishedResource())
_api.add_route("/state", StateResource())
diff --git a/justfile b/justfile
index df49d2ab0..48b8fc189 100644
--- a/justfile
+++ b/justfile
@@ -190,7 +190,7 @@ _nl-install:
cd analytics && pipenv install --dev
nl-test args="":
- docker-compose exec {{ args }} analytics pytest tests.py
+ docker-compose exec {{ args }} analytics ./test/run_test.sh
##########