Skip to content

Commit

Permalink
refactor(Stats): extra Proof type stats. new Location type stats
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Oct 18, 2024
1 parent edea8eb commit dc8d893
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
6 changes: 6 additions & 0 deletions open_prices/locations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@


class LocationQuerySet(models.QuerySet):
def has_type_osm(self):
return self.filter(type=location_constants.TYPE_OSM)

def has_type_online(self):
return self.filter(type=location_constants.TYPE_ONLINE)

def has_prices(self):
return self.filter(price_count__gt=0)

Expand Down
13 changes: 11 additions & 2 deletions open_prices/locations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"osm_type": "NODE",
"osm_name": "Monoprix",
}
LOCATION_ONLINE_DECATHLON = {
"type": location_constants.TYPE_ONLINE,
"website_url": "https://www.decathlon.fr/",
}


class LocationModelSaveTest(TestCase):
Expand Down Expand Up @@ -121,15 +125,20 @@ def test_location_online_validation(self):
class LocationQuerySetTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.location_without_price = LocationFactory()
cls.location_with_price = LocationFactory()
cls.location_with_price = LocationFactory(**LOCATION_OSM_NODE_652825274)
cls.location_without_price = LocationFactory(**LOCATION_ONLINE_DECATHLON)
PriceFactory(
location_osm_id=cls.location_with_price.osm_id,
location_osm_type=cls.location_with_price.osm_type,
price=1.0,
)

def test_has_type_osm(self):
self.assertEqual(Location.objects.count(), 2)
self.assertEqual(Location.objects.has_type_osm().count(), 1)

def test_has_prices(self):
self.assertEqual(Location.objects.count(), 2)
self.assertEqual(Location.objects.has_prices().count(), 1)

def test_with_stats(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 5.1 on 2024-10-18 08:11

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("stats", "0002_add_proof_type_counts"),
]

operations = [
migrations.AddField(
model_name="totalstats",
name="location_type_online_count",
field=models.PositiveIntegerField(default=0),
),
migrations.AddField(
model_name="totalstats",
name="location_type_osm_count",
field=models.PositiveIntegerField(default=0),
),
migrations.AddField(
model_name="totalstats",
name="proof_type_gdpr_request_count",
field=models.PositiveIntegerField(default=0),
),
migrations.AddField(
model_name="totalstats",
name="proof_type_shop_import_count",
field=models.PositiveIntegerField(default=0),
),
]
13 changes: 12 additions & 1 deletion open_prices/stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ class TotalStats(SingletonModel):
"price_type_category_tag_count",
]
PRODUCT_COUNT_FIELDS = ["product_count", "product_with_price_count"]
LOCATION_COUNT_FIELDS = ["location_count", "location_with_price_count"]
LOCATION_COUNT_FIELDS = [
"location_count",
"location_with_price_count",
"location_type_osm_count",
"location_type_online_count",
]
PROOF_COUNT_FIELDS = [
"proof_count",
"proof_with_price_count",
"proof_type_price_tag_count",
"proof_type_receipt_count",
"proof_type_gdpr_request_count",
"proof_type_shop_import_count",
]
USER_COUNT_FIELDS = ["user_count", "user_with_price_count"]
COUNT_FIELDS = (
Expand All @@ -33,10 +40,14 @@ class TotalStats(SingletonModel):
product_with_price_count = models.PositiveIntegerField(default=0)
location_count = models.PositiveIntegerField(default=0)
location_with_price_count = models.PositiveIntegerField(default=0)
location_type_osm_count = models.PositiveIntegerField(default=0)
location_type_online_count = models.PositiveIntegerField(default=0)
proof_count = models.PositiveIntegerField(default=0)
proof_with_price_count = models.PositiveIntegerField(default=0)
proof_type_price_tag_count = models.PositiveIntegerField(default=0)
proof_type_receipt_count = models.PositiveIntegerField(default=0)
proof_type_gdpr_request_count = models.PositiveIntegerField(default=0)
proof_type_shop_import_count = models.PositiveIntegerField(default=0)
user_count = models.PositiveIntegerField(default=0)
user_with_price_count = models.PositiveIntegerField(default=0)

Expand Down

0 comments on commit dc8d893

Please sign in to comment.