| 1 | = Badges = |
| 2 | |
| 3 | '''Badges''' are symbols of accomplishment by volunteers or teams - |
| 4 | for example, how much computing they're contributed. |
| 5 | Badges are shown as icons on project web sites. |
| 6 | In the future, they may also be shown in client GUIs and statistics sites. |
| 7 | |
| 8 | BOINC provides a general mechanism for defining and assigning badges. |
| 9 | You can create badges for whatever accomplishments you want - |
| 10 | average credit, total credit, length of participation, |
| 11 | number of message-board posts, etc. |
| 12 | |
| 13 | The data associated with a badge includes: |
| 14 | * A name (used to identify the badge internally; not shown to users) |
| 15 | * The URL of an image file. |
| 16 | The image will be sized on display (currently 48 pixels high). |
| 17 | Make it somewhat larger than this, e.g. 300x300 pixels. |
| 18 | For flexibility, use a PNG with transparent background. |
| 19 | * A title - a short phrase that explains the accomplishment |
| 20 | for which the badge is granted. |
| 21 | |
| 22 | Badges are granted (or removed) by a PHP script that you would typically |
| 23 | run as a periodic task from your config.xml file. |
| 24 | |
| 25 | == The default badges == |
| 26 | |
| 27 | By default (for new projects) there are badges |
| 28 | for the top 1%, 5%, and 25% of recent average credit (RAC). |
| 29 | They are represented by gold, silver, and bronze medal images, respectively, |
| 30 | and are assigned to both users and teams. |
| 31 | |
| 32 | == Writing a badge-assignment script == |
| 33 | |
| 34 | The script that assigns the default badges is here: |
| 35 | http://boinc.berkeley.edu/gitweb/?p=boinc-v2.git;a=blob;f=html/ops/badge_assign.php |
| 36 | |
| 37 | You can use this script as a template for writing your own. |
| 38 | |
| 39 | The script uses the following utility functions, defined in '''html/inc/util_ops.inc''': |
| 40 | {{{ |
| 41 | get_badge($name, $title, $image_url) |
| 42 | }}} |
| 43 | Return a PHP object representing the badge with the given name, title, and image file URL. |
| 44 | Badge descriptions are stored in the MySQL database; |
| 45 | this function creates a DB record if it's not already there. |
| 46 | |
| 47 | {{{ |
| 48 | assign_badge($is_user, $item, $badge) |
| 49 | }}} |
| 50 | Assign the given badge to the given user or team; |
| 51 | '''item''' is either a user ID or a team ID. |
| 52 | |
| 53 | {{{ |
| 54 | unassign_badges($is_user, $item, $badges, $k) |
| 55 | }}} |
| 56 | Remove badges from a given user or team. |
| 57 | '''$badges''' is a vector of badges to remove. |
| 58 | Remove all except the '''$kth''' one; |
| 59 | if '''$k''' is negative, remove them all. |
| 60 | |
| 61 | Using these utility functions, the script works as follows: |
| 62 | |
| 63 | * Use '''get_badge()''' to get the gold, silver, and bronze badge objects. |
| 64 | * '''get_percentiles()''': compute the top 1, 5, and 25 percentile values of RAC. |
| 65 | * '''assign_badges()''': loop over the set of all items (users or teams). |
| 66 | This is done 1000 items at a time to limit memory usage. |
| 67 | * For each item, compare its RAC with the RAC percentiles, |
| 68 | and determine which badge to assign (if any). |
| 69 | Assign that badge, and unassign the others. |
| 70 | |
| 71 | These steps are performed first for users, then for teams. |
| 72 | |