Skip to content

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

Add Rawpixel to image popularity recalculation logic (#897)

Madison Swain-Bowden0728cdbe8b8e
diff --git a/docker/local_postgres/0007_openledger_audio_view.sql b/docker/local_postgres/0007_openledger_audio_view.sql
index d8d800bcf..559698258 100644
--- a/docker/local_postgres/0007_openledger_audio_view.sql
+++ b/docker/local_postgres/0007_openledger_audio_view.sql
@@ -9,7 +9,8 @@ INSERT INTO public.audio_popularity_metrics (
provider, metric, percentile
) VALUES
('wikimedia_audio', 'global_usage_count', 0.85),
- ('jamendo', 'listens', 0.85);
+ ('jamendo', 'listens', 0.85),
+ ('freesound', 'num_downloads', 0.85);
CREATE FUNCTION audio_popularity_percentile(
diff --git a/justfile b/justfile
index 05457a79c..24ccc7dd7 100644
--- a/justfile
+++ b/justfile
@@ -82,6 +82,7 @@ _deps:
docker-compose {{ DOCKER_FILES }} run \
-e AIRFLOW_VAR_INGESTION_LIMIT=1000000 \
-v {{ justfile_directory() }}/tests:/usr/local/airflow/tests/ \
+ -v {{ justfile_directory() }}/docker:/usr/local/airflow/docker/ \
-v {{ justfile_directory() }}/pytest.ini:/usr/local/airflow/pytest.ini \
--rm \
{{ SERVICE }} \
diff --git a/openverse_catalog/dags/common/popularity/sql.py b/openverse_catalog/dags/common/popularity/sql.py
index 6c181e982..a7c8d7a6e 100644
--- a/openverse_catalog/dags/common/popularity/sql.py
+++ b/openverse_catalog/dags/common/popularity/sql.py
@@ -45,6 +45,7 @@ IMAGE_POPULARITY_METRICS = {
"flickr": {"metric": "views"},
"wikimedia": {"metric": "global_usage_count"},
"stocksnap": {"metric": "downloads_raw"},
+ "rawpixel": {"metric": "download_count"},
}
AUDIO_POPULARITY_METRICS = {
diff --git a/tests/dags/common/popularity/test_sql.py b/tests/dags/common/popularity/test_sql.py
index f5b52c290..420a8bf75 100644
--- a/tests/dags/common/popularity/test_sql.py
+++ b/tests/dags/common/popularity/test_sql.py
@@ -1,5 +1,7 @@
import os
+import re
from collections import namedtuple
+from pathlib import Path
from textwrap import dedent
from typing import NamedTuple
@@ -8,6 +10,7 @@ import pytest
from common.popularity import sql
+DDL_DEFINITIONS_PATH = Path(__file__).parents[4] / "docker" / "local_postgres"
POSTGRES_CONN_ID = os.getenv("TEST_CONN_ID")
POSTGRES_TEST_URI = os.getenv("AIRFLOW_CONN_POSTGRES_OPENLEDGER_TESTING")
@@ -500,3 +503,25 @@ def test_image_view_calculates_std_pop(postgres_with_image_table, table_info):
rd["fid_d"] == 0.75,
]
)
+
+
+ "ddl_filename, metrics",
+ [
+ ("0004_openledger_image_view.sql", sql.IMAGE_POPULARITY_METRICS),
+ ("0007_openledger_audio_view.sql", sql.AUDIO_POPULARITY_METRICS),
+ ],
+)
+def test_ddl_matches_definitions(ddl_filename, metrics):
+ ddl = (DDL_DEFINITIONS_PATH / ddl_filename).read_text()
+ if not (
+ match := re.search(
+ r"INSERT INTO public.\w+_popularity_metrics.*?;",
+ ddl,
+ re.MULTILINE | re.DOTALL,
+ )
+ ):
+ raise ValueError(f"Could not find insert statement in ddl file {ddl_filename}")
+
+ for provider in metrics:
+ assert provider in match.group(0)