Query per creare alcuni gruppi in base all'attività

In tal caso, penso che qualcosa di simile potrebbe fornire la ricerca manuale:

-- [params]
-- int :likes_received
-- int :posts_read


WITH user_activity AS (

    SELECT 
        p.user_id, 
        COUNT(p.id) as posts_count
    FROM posts p
    LEFT JOIN topics t ON t.id = p.topic_id
    WHERE p.created_at::date >= CURRENT_DATE - INTERVAL '1 YEAR'
        AND t.deleted_at IS NULL
        AND p.deleted_at IS NULL
        AND t.archetype = 'regular'
    GROUP BY 1
)

SELECT 
    us.user_id,
    us.likes_received,
    us.posts_read_count,
    ua.posts_count
FROM user_stats us
  JOIN user_activity ua ON UA.user_id = us.user_id
WHERE us.likes_received >= :likes_received
  AND us.posts_read_count >= :posts_read
  AND ua.posts_count >= 10
ORDER BY 2 DESC, 3 DESC, 4 DESC

E modificandolo/semplificandolo solo per i nomi utente fornirebbe un elenco che potresti copiare e incollare nella casella “Aggiungi Utenti” nella pagina dei gruppi se esportassi i risultati come csv (e lo aprissi in qualcosa come notepad, per esempio):

-- [params]
-- int :likes_received
-- int :posts_read


WITH user_activity AS (

    SELECT 
        p.user_id, 
        COUNT(p.id) as posts_count
    FROM posts p
    LEFT JOIN topics t ON t.id = p.topic_id
    WHERE p.created_at::date >= CURRENT_DATE - INTERVAL '1 YEAR'
        AND t.deleted_at IS NULL
        AND p.deleted_at IS NULL
        AND t.archetype = 'regular'
    GROUP BY 1
)

SELECT 
    u.username
FROM user_stats us
  JOIN user_activity ua ON UA.user_id = us.user_id
  JOIN users u ON u.id = us.user_id
WHERE us.likes_received >= :likes_received
  AND us.posts_read_count >= :posts_read
  AND ua.posts_count >= 10
ORDER BY 1

Anche questo è possibile. :partying_face: Avresti bisogno di un badge (e una query per badge) per ogni gruppo, e un’accompagnatoria automazione utilizzando lo script “User Group Membership through Badge”. Potresti anche automatizzare i badge piuttosto che assegnarli manualmente abilitando i Badge Personalizzati Attivati (Enable Badge SQL e Creating triggered custom badge queries)

Ci sono molte parti in movimento, quindi potresti voler mantenere le cose semplici in questa fase.

2 Mi Piace