أبحث عن شارات جيدة تتعلق بالتصويت

لديّ بعض الأفكار للشارات، لكنني غير متأكد من كيفية كتابة الاستعلامات (لا أعرف هيكل الجدول جيدًا بما يكفي). الأرقام مجرد نقاط انطلاق. سأقوم بتوسيعها لإضافة شارات إضافية.

  1. حصل شخص ما على 10 أصوات في موضوع واحد كتبه
  2. حصل شخص ما على 20 صوتًا إجمالاً عبر جميع المواضيع التي كتبها
  3. صوت شخص ما 20 مرة

هل لدى أي شخص شارات مشابهة يريد مشاركتها؟ إذا لم يكن الأمر كذلك، هل يرغب أي شخص في المحاولة في كتابة الاستعلامات؟

The second query in this topic might do the trick: Badge ideas for Topic Voting. The query grants the badge to users who have cast a single vote, but there is a suggestion at the bottom of the query for how to require more votes to grant the badge.

Thanks @simon. I actually read over that post already but the query didn’t return the results I was expecting. It was the Limit 1 at the end messing me up. After removing that it works perfect for the “Someone voted x times”.

Any idea how to see how many votes a person got on a topic they wrote? Or how many likes they got total?

قد تجد بعض استعلامات Data Explorer التي يمكنك تعديلها لإنشاء استعلامات للشارات. اطلع على استعلامات Data Explorer للتصويت على المواضيع والمواضيع الأخرى sql-query و sql-triggered-badge.

Aren’t these rather similar to badges that already exist in Discourse?

That got me quite a ways towards my target:

select    
    t.user_id,
    ucf.value,
    count(*)
from
    topics t
    join user_custom_fields ucf on t.id = cast(ucf.value as int)
where ucf.name = 'votes'
group by ucf.value, t.user_id
order by t.user_id, count(*) desc

That returns:

The two things I’m trying to get are total votes someone got and the topic that has the most votes for each person. You can see mmontecalvo has 2 topics showing. I’m fairly certain I need to use row_number() to get just the highest post but I don’t know how.

@codinghorror These may be similar to a default badge but none of the defaults are built off topics getting votes.

I think I got it! This will give the topic with the most votes per person that has at least 5 votes on it:

WITH query as (
select    
    t.user_id,
    ucf.value,
    count(*) as num,
    t.created_at,
    row_number() OVER (PARTITION BY t.user_id order by count(*) desc) as rank
from
    topics t
    join user_custom_fields ucf on t.id = cast(ucf.value as int)
where ucf.name = 'votes'
group by ucf.value, t.user_id, t.created_at
having count(*) >= 5
order by t.user_id)
select user_id, value as topic_id, created_at granted_at 
from query where rank = 1

I ended up going with this instead so we could give a badge for each topic someone puts in that gets at least X votes in the correct category:

WITH query as (
select    
    t.user_id,
    ucf.value,
    count(*) as num,
    t.created_at
from
    topics t
    join user_custom_fields ucf on t.id = cast(ucf.value as int)
where ucf.name = 'votes' and category_id = (
  SELECT id FROM categories WHERE name ilike 'UI Experience Requests'
)
group by ucf.value, t.user_id, t.created_at
having count(*) >= 5
order by t.user_id)
select user_id, value as topic_id, created_at granted_at 
from query