From 9496f21834f317293b83ba06e64c991e3384f756 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 9 Sep 2024 22:56:45 +0000 Subject: [PATCH] fix #217 and add heatmap --- auctions/management/commands/info.py | 5 +++-- auctions/templates/base_page_view.html | 9 +++++++++ auctions/templates/user_map.html | 21 ++++++++++++++++++++- auctions/views.py | 9 +++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/auctions/management/commands/info.py b/auctions/management/commands/info.py index 70638e6..67daee9 100644 --- a/auctions/management/commands/info.py +++ b/auctions/management/commands/info.py @@ -1,6 +1,6 @@ from django.core.management.base import BaseCommand -from auctions.models import find_image +from auctions.models import UserData def compare_model_instances(instance1, instance2): @@ -29,7 +29,8 @@ def compare_model_instances(instance1, instance2): class Command(BaseCommand): help = "Just a scratchpad to do things" - print(find_image("blue shrimp", None)) + d = UserData.objects.get(user__username="ira") + print(d.unsubscribe_link) # def handle(self, *args, **options): # campaigns = AuctionCampaign.objects.all() # for campaign in campaigns: diff --git a/auctions/templates/base_page_view.html b/auctions/templates/base_page_view.html index e300514..49f8c92 100644 --- a/auctions/templates/base_page_view.html +++ b/auctions/templates/base_page_view.html @@ -3,13 +3,22 @@ @@ -51,6 +51,24 @@ } })(marker, i)); } + // Heat map + var map = new google.maps.Map(document.getElementById("map_visualization"), { + zoom: 5, + center: { lat: 39.095963, lng: -83.662005 }, + }); + + var heatmapData = [ + {% for view in pageviews %} + new google.maps.LatLng({{ view.latitude}}, {{ view.longitude}}), + {% endfor %} + ]; + + var heatmap = new google.maps.visualization.HeatmapLayer({ + data: heatmapData, + radius: 20, + }); + + heatmap.setMap(map); } {% endblock %} @@ -58,6 +76,7 @@

User map

+
{% if not has_user_location %} {{ location_message }} diff --git a/auctions/views.py b/auctions/views.py index 1c80d1c..4de7cd7 100755 --- a/auctions/views.py +++ b/auctions/views.py @@ -1162,6 +1162,7 @@ def pageview(request): user_agent = user_agent[:200] referrer = clean_referrer(data.get("referrer", None)[:600]) source = data.get("src", None) + uid = data.get("uid", None) # mark auction campaign results if applicable present ip = "" x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR") @@ -1169,6 +1170,11 @@ def pageview(request): ip = x_forwarded_for.split(",")[0] else: ip = request.META.get("REMOTE_ADDR") + if uid: # and not request.user.is_authenticated: + userdata = UserData.objects.filter(unsubscribe_link=uid).first() + if userdata: + userdata.last_activity = timezone.now() + userdata.save() if source: campaign = AuctionCampaign.objects.filter(uuid=source).first() if campaign and campaign.result == "NONE": @@ -5176,6 +5182,7 @@ def get_context_data(self, **kwargs): filter1 = data["filter"] except: filter1 = None + view_qs = PageView.objects.exclude(latitude=0) qs = User.objects.filter(userdata__latitude__isnull=False, is_active=True).annotate( lots_sold=Count("lot"), lots_bought=Count("winner") ) @@ -5189,8 +5196,10 @@ def get_context_data(self, **kwargs): # users by top volume_percentile qs = qs.filter(userdata__volume_percentile__lte=filter1) elif view == "recent" and filter1: + view_qs = view_qs.filter(date_start__gte=timezone.now() - timedelta(hours=int(filter1))) qs = qs.filter(userdata__last_activity__gte=timezone.now() - timedelta(hours=int(filter1))) context["users"] = qs + context["pageviews"] = view_qs return context