Skip to content

Commit

Permalink
Add slack activity to release report.
Browse files Browse the repository at this point in the history
- fixes #1367
  • Loading branch information
brianjp93 committed Nov 22, 2024
1 parent 2503ee6 commit d3330bf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
46 changes: 46 additions & 0 deletions libraries/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.conf import settings

from core.models import RenderedContent, SiteSettings
from slack.models import SlackActivityBucket
from versions.models import Version
from .models import Commit, CommitAuthor, Issue, Library, LibraryVersion
from libraries.constants import SUB_LIBRARIES
Expand Down Expand Up @@ -608,6 +609,50 @@ def apply_colors(self):
graph.apply_colors()
return graph

def _get_slack_stats(self, prior_version, version):
"""Returns all slack related stats."""
start = prior_version.release_date
end = version.release_date - timedelta(days=1)
# count of all messages in the date range
total = SlackActivityBucket.objects.filter(
day__range=[start, end],
).aggregate(
total=Sum("count")
)["total"]
# message counts per user in the date range
per_user = (
SlackActivityBucket.objects.filter(
day__range=[start, end],
)
.values("user__id")
.annotate(
email=F("user__email"),
name=F("user__real_name"),
image_48=F("user__image_48"),
total=Sum("count"),
)
.values(
"email",
"name",
"image_48",
"total",
)
.order_by("-total")
)
distinct_users = SlackActivityBucket.objects.order_by("user_id").distinct(
"user_id"
)
new_user_count = (
distinct_users.filter(day__lte=end).count()
- distinct_users.filter(day__lt=start).count()
)
return {
"users": per_user[:10],
"user_count": per_user.count(),
"total": total,
"new_user_count": new_user_count,
}

def get_stats(self):
version = self.cleaned_data["version"]

Expand Down Expand Up @@ -743,4 +788,5 @@ def get_stats(self):
"removed_library_count": removed_library_count,
"downloads": downloads,
"contribution_box_graph": self._get_git_graph_data(prior_version, version),
"slack": self._get_slack_stats(prior_version, version),
}
38 changes: 38 additions & 0 deletions templates/admin/release_report_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,44 @@ <h1 class="mx-auto">Mailing List Word Cloud</h1>
</div>
</div>
{% endif %}
<div class="pdf-page flex items-center justify-items-center {{ bg_color }}">
<div class="flex flex-col mx-auto">
<h1 class="mx-auto">Slack Activity</h1>
<div class="mx-auto mb-4">
There {{ slack.total|pluralize:"was,were" }}
{% if slack.total %}
{{ slack.total|intcomma }}
{% else %}
no
{% endif %}
slack message{{ slack.total|pluralize }} in version&nbsp;{{ version.display_name }}
</div>
<div class="mx-auto mb-4">
There
{{ slack.user_count|pluralize:"was,were" }}
{{ slack.user_count }}
{{ slack.user_count|pluralize:"person,people" }}
conversing leading up to this release. ({{ slack.new_user_count }} New)
</div>
<div class="flex gap-x-2 mx-auto">
<div>
<div class="grid grid-cols-5 gap-2">
{% for item in slack.users %}
<div class="flex flex-col gap-y-2 w-20 items-center">
{% base_avatar image_url=item.image_48 name=item.name href=None %}
<div class="w-full flex flex-col">
<div class="text-[0.6rem] overflow-ellipsis overflow-hidden whitespace-nowrap w-full text-center">
{{ item.name }}
</div>
<div class="text-[0.6rem] mx-auto">({{ item.total }})</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
<div class="pdf-page flex items-center justify-items-center {{ bg_color }}">
<div class="flex flex-col h-full mx-auto">
<h1 class="mx-auto">Library Index</h1>
Expand Down

0 comments on commit d3330bf

Please sign in to comment.