From 94fb1064a0d89cb760c144fea4fa34873561a5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Odini?= Date: Sun, 2 Mar 2025 16:52:02 +0100 Subject: [PATCH] feat(Stats): new price_location_country_count field (#740) --- open_prices/api/locations/tests.py | 1 + open_prices/api/prices/tests.py | 1 + open_prices/api/proofs/tests.py | 1 + open_prices/locations/tests.py | 1 + open_prices/proofs/tests.py | 1 + ...4_totalstats_price_location_country_count.py | 17 +++++++++++++++++ open_prices/stats/models.py | 8 ++++++++ open_prices/stats/tests.py | 3 +++ 8 files changed, 33 insertions(+) create mode 100644 open_prices/stats/migrations/0014_totalstats_price_location_country_count.py diff --git a/open_prices/api/locations/tests.py b/open_prices/api/locations/tests.py index aa625819..01cef7b8 100644 --- a/open_prices/api/locations/tests.py +++ b/open_prices/api/locations/tests.py @@ -10,6 +10,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", "osm_lat": "45.1805534", "osm_lon": "5.7153387", "price_count": 15, diff --git a/open_prices/api/prices/tests.py b/open_prices/api/prices/tests.py index 88284bba..5dbe2c85 100644 --- a/open_prices/api/prices/tests.py +++ b/open_prices/api/prices/tests.py @@ -37,6 +37,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", "osm_lat": "45.1805534", "osm_lon": "5.7153387", } diff --git a/open_prices/api/proofs/tests.py b/open_prices/api/proofs/tests.py index da16e6a8..14424694 100644 --- a/open_prices/api/proofs/tests.py +++ b/open_prices/api/proofs/tests.py @@ -24,6 +24,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", "osm_lat": "45.1805534", "osm_lon": "5.7153387", } diff --git a/open_prices/locations/tests.py b/open_prices/locations/tests.py index 99ac9c3f..a886004e 100644 --- a/open_prices/locations/tests.py +++ b/open_prices/locations/tests.py @@ -17,6 +17,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", } LOCATION_ONLINE_DECATHLON = { "type": location_constants.TYPE_ONLINE, diff --git a/open_prices/proofs/tests.py b/open_prices/proofs/tests.py index 2178b66f..d21530b9 100644 --- a/open_prices/proofs/tests.py +++ b/open_prices/proofs/tests.py @@ -41,6 +41,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", } LOCATION_OSM_NODE_6509705997 = { "type": location_constants.TYPE_OSM, diff --git a/open_prices/stats/migrations/0014_totalstats_price_location_country_count.py b/open_prices/stats/migrations/0014_totalstats_price_location_country_count.py new file mode 100644 index 00000000..43a4bc63 --- /dev/null +++ b/open_prices/stats/migrations/0014_totalstats_price_location_country_count.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1.4 on 2025-03-02 15:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("stats", "0013_totalstats_price_year_count"), + ] + + operations = [ + migrations.AddField( + model_name="totalstats", + name="price_location_country_count", + field=models.PositiveIntegerField(default=0), + ), + ] diff --git a/open_prices/stats/models.py b/open_prices/stats/models.py index d2515bb3..14552e01 100644 --- a/open_prices/stats/models.py +++ b/open_prices/stats/models.py @@ -13,6 +13,7 @@ class TotalStats(SingletonModel): "price_with_discount_count", "price_currency_count", "price_year_count", + "price_location_country_count", "price_type_group_community_count", "price_type_group_consumption_count", "price_source_web_count", @@ -74,6 +75,7 @@ class TotalStats(SingletonModel): price_with_discount_count = models.PositiveIntegerField(default=0) price_currency_count = models.PositiveIntegerField(default=0) price_year_count = models.PositiveIntegerField(default=0) + price_location_country_count = models.PositiveIntegerField(default=0) price_type_group_community_count = models.PositiveIntegerField(default=0) price_type_group_consumption_count = models.PositiveIntegerField(default=0) price_source_web_count = models.PositiveIntegerField(default=0) @@ -143,6 +145,12 @@ def update_price_stats(self): .distinct() .count() ) + self.price_location_country_count = ( + Price.objects.select_related("location") + .values_list("location__osm_address_country", flat=True) + .distinct() + .count() + ) self.price_type_group_community_count = ( Price.objects.has_type_group_community().count() ) diff --git a/open_prices/stats/tests.py b/open_prices/stats/tests.py index b2a3860c..d0272c8c 100644 --- a/open_prices/stats/tests.py +++ b/open_prices/stats/tests.py @@ -17,6 +17,7 @@ "osm_id": 652825274, "osm_type": location_constants.OSM_TYPE_NODE, "osm_name": "Monoprix", + "osm_address_country": "France", "osm_lat": "45.1805534", "osm_lon": "5.7153387", "price_count": 15, @@ -112,6 +113,7 @@ def test_update_price_stats(self): self.assertEqual(self.total_stats.price_with_discount_count, 0) self.assertEqual(self.total_stats.price_currency_count, 0) self.assertEqual(self.total_stats.price_year_count, 0) + self.assertEqual(self.total_stats.price_location_country_count, 0) self.assertEqual(self.total_stats.price_type_group_community_count, 0) self.assertEqual(self.total_stats.price_type_group_consumption_count, 0) self.assertEqual(self.total_stats.price_source_web_count, 0) @@ -126,6 +128,7 @@ def test_update_price_stats(self): self.assertEqual(self.total_stats.price_with_discount_count, 0) self.assertEqual(self.total_stats.price_currency_count, 1) self.assertEqual(self.total_stats.price_year_count, 3) # None included + self.assertEqual(self.total_stats.price_location_country_count, 1) self.assertEqual(self.total_stats.price_type_group_community_count, 1) self.assertEqual(self.total_stats.price_type_group_consumption_count, 1) self.assertEqual(self.total_stats.price_source_web_count, 1)