Skip to content

Commit

Permalink
feat(Stats): new price_location_country_count field (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Mar 2, 2025
1 parent 16e0e59 commit 94fb106
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions open_prices/api/locations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions open_prices/api/prices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
1 change: 1 addition & 0 deletions open_prices/api/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
1 change: 1 addition & 0 deletions open_prices/locations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions open_prices/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
8 changes: 8 additions & 0 deletions open_prices/stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
)
Expand Down
3 changes: 3 additions & 0 deletions open_prices/stats/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 94fb106

Please sign in to comment.