Achievement Module
- Source:
Methods
(static) _awardAchievement(orm, editorId, tier) → {object}
Awards a Title
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
editorId |
int
|
The editor the title will be assigned to |
tier |
object
|
Achievement Tier the Title (if it exists) belongs to |
Returns:
- Type:
-
object
- {tier.titleName: unlock} where unlock comes from
awardUnlock or false if the title is not in the tier
(static) _awardUnlock(orm, editorId, achievementName) → {object}
Awards an Achievement
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
editorId |
int
|
The editor the achievement will be awarded to |
achievementName |
string
|
Name of achievement in database |
Returns:
- Type:
-
object
- {achievementName: unlock} where unlock is JSON returned
from awardUnlock
(inner) _awardTitle(awardList) → {object}
In testTiers a tier is mapped to a list of achievements/titles this
converts it to an object keyed by achievementName where it is easier
to find a specific achievement.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
awardList |
object
|
List of List of achievement unlocks |
Returns:
- Type:
-
object
- Object keyed by achievement name with values
unlock json
Example
awardListToAwardObject([[{'Achievement I': unlockI}]])
//returns {'Achievement I': unlockI}
(inner) _processHotOffThePress(orm, editorId) → {int}
Returns number of distinct entities viewed by an editor
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
editorId |
int
|
Editor to get views for |
Returns:
- Type:
-
int
- Number of views user has
(inner) _processMarathoner(achievementUnlock) → {list}
Converts achievementTier object to a list of achievementUnlock id's,
this will be used to notify the user which achievement they unlocked
- Source:
Parameters:
Name | Type | Description |
---|---|---|
achievementUnlock |
object
|
A track of achievements containing unlock JSON for each |
Returns:
- Type:
-
list
- A list of achievementUnlock id's
(inner) _processPageVisit(orm, userId, revisionId) → {object}
Run each time an edit occurs on the site, will test for each achievement
type
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
userId |
int
|
Id of the user to query |
revisionId |
int
|
Id of latest revision |
Returns:
- Type:
-
object
- Output of each achievement test as well as an alert
containing id's for each unlocked achievement in .alert
(inner) _processSprinter(orm, editorId, days) → {int}
Gets number of consecutive days from today the editor created revisions upto a specified
time limit
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
editorId |
int
|
Editor to query on |
days |
int
|
Number of days before today to collect edits from |
Returns:
- Type:
-
int
- Number of consecutive days edits were performed on
(inner) _testTiers(revisionType, revisionString, editor) → {int}
Returns number of revisions of a certain type created by a specified
editor
- Source:
Parameters:
Name | Type | Description |
---|---|---|
revisionType |
function
|
Constructor for the revisionType |
revisionString |
string
|
Snake case string of revisionType |
editor |
int
|
Editor id being queried |
Returns:
- Type:
-
int
- Number of revisions of type (type)
(inner) awardUnlock(UnlockType, awardAttribs) → {object}
Awards an Unlock type with awardAttribs if not already awarded
- Source:
Parameters:
Name | Type | Description |
---|---|---|
UnlockType |
function
|
Either TitleUnlock or AchievementUnlock |
awardAttribs |
object
|
Values that are supplied to Unlock constructor |
Returns:
- Type:
-
object
- 'already unlocked' or JSON of new unlock
(inner) getEditionDateDifference(orm, revisionId) → {int}
Gets days since edition release date, positive implies released in future
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
revisionId |
int
|
Revision to get release date of |
Returns:
- Type:
-
int
- Days since edition was released
(inner) testTiers(orm, signal, editorId, tiers) → {object}
Takes a list of achievement 'tiers' and awards the related achievement and
title if the signal is greater than or equal to the threshold
- Source:
Parameters:
Name | Type | Description |
---|---|---|
orm |
object
|
the BookBrainz ORM, initialized during app setup |
signal |
int
|
Value tier threshold will be compared against |
editorId |
int
|
Editor to award achievements/titles to |
tiers |
object
|
Object with threshold and relatedachievement/title names |
Returns:
- Type:
-
object
- Returns a track of achievements keyed by achievement
name/title containing their respective unlockJSON each tier
Example
testTiers(10, 1, [{
threshold: 10, name: 'achievement I', titleName: 'achievement'
}])
//returns {'achievement I': achievementJSON}