2022-07-23 01:44:03 +02:00
|
|
|
defmodule Claper.Stats do
|
|
|
|
|
@moduledoc """
|
|
|
|
|
The Stats context.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import Ecto.Query, warn: false
|
|
|
|
|
alias Claper.Repo
|
|
|
|
|
|
|
|
|
|
def distinct_poster_count(event_id) do
|
|
|
|
|
from(posts in Claper.Posts.Post,
|
|
|
|
|
where: posts.event_id == ^event_id,
|
|
|
|
|
select: count(posts.user_id, :distinct) + count(posts.attendee_identifier, :distinct)
|
|
|
|
|
)
|
|
|
|
|
|> Repo.one()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def total_vote_count(presentation_file_id) do
|
|
|
|
|
from(p in Claper.Polls.Poll,
|
2024-04-06 11:48:47 +02:00
|
|
|
join: pv in Claper.Polls.PollVote,
|
|
|
|
|
on: pv.poll_id == p.id,
|
2022-07-23 01:44:03 +02:00
|
|
|
where: p.presentation_file_id == ^presentation_file_id,
|
2024-04-06 11:48:47 +02:00
|
|
|
group_by: p.presentation_file_id,
|
|
|
|
|
select:
|
|
|
|
|
count(
|
|
|
|
|
fragment("DISTINCT COALESCE(?, CAST(? AS varchar))", pv.attendee_identifier, pv.user_id)
|
|
|
|
|
)
|
2022-07-23 01:44:03 +02:00
|
|
|
)
|
|
|
|
|
|> Repo.all()
|
|
|
|
|
end
|
|
|
|
|
end
|