Forem Creators and Builders 🌱

9comindia
9comindia

Posted on

How are the credits calculated and badges awarded?

Is there any admin guide that explains how the credits and badges are being awarded to the users?

Or can anyone here give a quick high level overview?

Thanks.

Top comments (7)

Collapse
 
reyesvicente profile image
Vicente Antonio G. Reyes

Hey there! I'm one of the mods on DEV. Here are the controllers and views of the badges and credits.

github.com/forem/forem/blob/main/a...

github.com/forem/forem/tree/main/a...

github.com/forem/forem/blob/main/a...

github.com/forem/forem/tree/main/a...

Hope it helps!

Collapse
 
9comindia profile image
9comindia

Thanks for the reply @reyesvicente .

If I wish to stop the badges functionality (at least on the front end, so that the users don't get to know anything about badges)

And regarding credits, users (the post writer) need to get 1 credit for each post engagement i.e hearts, comments, saves.

Is there a configuration to get this done, or could any minor tweaks to the code can help?

Thanks.

Collapse
 
ellativity profile image
Ella (she/her/elle)

In order for your Forem to award badges, you need to set them up. If you don't set up any badges, you won't have any awarded.

I'll create a post later on explaining a bit more about badges, but for the time being you can review the Forem Admin documentation about them. Hope this helps!

Collapse
 
michaeltharrington profile image
Michael Tharrington

Heyo! This is a great question.

Not too long I got some assistance from my teammate @djuber with answering the question How do the author of the week badges work?... I'm gonna just drop his explanation here. πŸ™‚

The logic is basically:

  • for each tag with a badge
  • excluding users who already have this badge (can't win twice)
  • for articles with a high enough score (100+) and this tag
  • published less than a week ago (plus half a day to forgive time zones)
  • find highest scored article and award author

This is explained in the code around Badges::AwardTag and there's also this code that denotes badges are awarded each Thursday.

I honestly don't fully know the logic around how credits are awarded. I do know that users can purchase credits and use these credits to post listings. I'll try and dig in a little more here and see the different ways that these are awarded.

Collapse
 
michaeltharrington profile image
Michael Tharrington

Sorry, but I now realize your other question is How are credits calculated? Do you mean to ask how they are awarded? I.e. I know that credits are occasionally awarded with badges, so I imagine you'd like to know how many credits are awarded with a badge and if there's any other way to be rewarded credits right?

Collapse
 
djuber profile image
Daniel Uber • Edited

Since badge credit awards I think are credit transfers (from a organization sponsoring the badge, to the badge earner), credits are introduced into the system either through purchase or admin creation.

One way that credits can be create is within the admin/users controller (there is a Credits section, with an add/remove credits form). This basically creates credits in the system (for free) and awards them to a user's account.

There is also the credits controller which allows purchasing (via Stripe/credit card) credit blocks - for example dev.to/credits has a "Purchase additional credits" button. I expect this only works if you add an api key for stripe in the general settings under "Monetization" (local testing of purchase gave an error that I needed to set a stripe api key, and pointed to stripe's documentation to do this).

monetization settings

The price of credits is set under the same settings page for credits.
credits settings

Credits are useful for adding listings (the /credits/purchase page suggests "as well as upcoming products and services" but I don't know what that includes). The listings page does give prices for each category when you start to create one, the categories and their prices in credits are managed from admin (/admin/apps/listings/categories or - admin -> apps -> listings -> listing categories to navigate). I'm not aware of any other way to spend credits besides purchasing a listing or awarding them to another user.

You asked in a comment about this situation:

And regarding credits, users (the post writer) need to get 1 credit for each post engagement i.e hearts, comments, saves.

I don't know whether this is possible right now. It may be achievable with some configuration of badges, but if you're also intent on removing badges from the system, it's probably more customization than we currently offer.

If you were looking to modify the credit system to trigger updates based on reactions and article postings, you might look at the way Article.score is tracked, and add credit handling there - most of this is funneled through Articles::ScoreCalcWorker which calls Article#update_score, if you added "and award user credits based on the difference between the old score and the new score" to either the worker or the model method you might be able to achieve what you're asking. I don't think that's something planned for Forem generally, so it would be a custom patch you'd need to maintain.

Collapse
 
ildi profile image
Ildi

Thank you for this very helpful explenation!