updated report count
This commit is contained in:
@@ -56,32 +56,85 @@ def generate_event_report(user_id):
|
||||
start_date, end_date = get_previous_month_date_range()
|
||||
user = User.objects.get(id=user_id)
|
||||
|
||||
# events = Event.objects.filter(
|
||||
# created_by=user, start_date__gte=start_date, start_date__lte=end_date
|
||||
# ).annotate(
|
||||
# favorites_count=Count("favorites"),
|
||||
# interested_count=Count(
|
||||
# "interaction_event",
|
||||
# filter=Q(interaction_event__status=EventInteractionType.INTERESTED),
|
||||
# ),
|
||||
# going_count=Count(
|
||||
# "interaction_event",
|
||||
# filter=Q(interaction_event__status=EventInteractionType.GOING),
|
||||
# ),
|
||||
# reviews_count=Count(
|
||||
# "reviews", filter=Q(reviews__active=True, reviews__deleted=False)
|
||||
# ),
|
||||
# views_count=Count("views"),
|
||||
# )
|
||||
# # print("events: ", events)
|
||||
|
||||
# report_data = []
|
||||
# for event in events:
|
||||
# views = EventView.objects.filter(event=event)
|
||||
# locations = defaultdict(int)
|
||||
# for view in views:
|
||||
# locations[view.location] += 1
|
||||
|
||||
# shares = (
|
||||
# EventShare.objects.filter(event=event)
|
||||
# .values("principal")
|
||||
# .annotate(share_count=Count("principal"))
|
||||
# )
|
||||
# shares_data = {
|
||||
# User.objects.get(id=share["principal"]).get_full_name(): share[
|
||||
# "share_count"
|
||||
# ]
|
||||
# for share in shares
|
||||
# }
|
||||
|
||||
# report_data.append(
|
||||
# {
|
||||
# "event_name": event.title,
|
||||
# "event_type": event.category.title,
|
||||
# "event_date": str(event.start_date),
|
||||
# "favorites_count": event.favorites_count,
|
||||
# "interested_count": event.interested_count,
|
||||
# "going_count": event.going_count,
|
||||
# "reviews_count": event.reviews_count,
|
||||
# "views_count": event.views_count,
|
||||
# "locations": dict(locations),
|
||||
# "social_media_shares": event.social_media_shares_count,
|
||||
# "shares_data": shares_data,
|
||||
# }
|
||||
# )
|
||||
# # print("report_data: ", report_data)
|
||||
# return report_data
|
||||
events = Event.objects.filter(
|
||||
created_by=user, start_date__gte=start_date, start_date__lte=end_date
|
||||
).annotate(
|
||||
favorites_count=Count("favorites"),
|
||||
interested_count=Count(
|
||||
"interaction_event",
|
||||
filter=Q(interaction_event__status=EventInteractionType.INTERESTED),
|
||||
),
|
||||
going_count=Count(
|
||||
"interaction_event",
|
||||
filter=Q(interaction_event__status=EventInteractionType.GOING),
|
||||
),
|
||||
reviews_count=Count(
|
||||
"reviews", filter=Q(reviews__active=True, reviews__deleted=False)
|
||||
),
|
||||
views_count=Count("views"),
|
||||
)
|
||||
# print("events: ", events)
|
||||
|
||||
report_data = []
|
||||
for event in events:
|
||||
# Collecting individual counts for each event
|
||||
favorites_count = event.favorites_set.count()
|
||||
interested_count = event.interaction_event.filter(
|
||||
status=EventInteractionType.INTERESTED
|
||||
).count()
|
||||
going_count = event.interaction_event.filter(
|
||||
status=EventInteractionType.GOING
|
||||
).count()
|
||||
reviews_count = event.reviews_set.filter(active=True, deleted=False).count()
|
||||
views_count = event.views_set.count()
|
||||
|
||||
# Collecting views and locations
|
||||
views = EventView.objects.filter(event=event)
|
||||
locations = defaultdict(int)
|
||||
for view in views:
|
||||
locations[view.location] += 1
|
||||
|
||||
# Collecting shares data
|
||||
shares = (
|
||||
EventShare.objects.filter(event=event)
|
||||
.values("principal")
|
||||
@@ -94,22 +147,23 @@ def generate_event_report(user_id):
|
||||
for share in shares
|
||||
}
|
||||
|
||||
# Appending event data to report
|
||||
report_data.append(
|
||||
{
|
||||
"event_name": event.title,
|
||||
"event_type": event.category.title,
|
||||
"event_date": str(event.start_date),
|
||||
"favorites_count": event.favorites_count,
|
||||
"interested_count": event.interested_count,
|
||||
"going_count": event.going_count,
|
||||
"reviews_count": event.reviews_count,
|
||||
"views_count": event.views_count,
|
||||
"favorites_count": favorites_count,
|
||||
"interested_count": interested_count,
|
||||
"going_count": going_count,
|
||||
"reviews_count": reviews_count,
|
||||
"views_count": views_count,
|
||||
"locations": dict(locations),
|
||||
"social_media_shares": event.social_media_shares_count,
|
||||
"shares_data": shares_data,
|
||||
}
|
||||
)
|
||||
# print("report_data: ", report_data)
|
||||
|
||||
return report_data
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user