<commit_before># leaderboard

Leaderboards backed by [Redis](http://redis.io) in CoffeeScript.

Builds off ideas proposed in http://blog.agoragames.com/2011/01/01/creating-high-score-tables-leaderboards-using-redis/.

## Installation

`npm install ???`

TBD: Figure out what to do here since there's already a leaderboard library on npmjs.org :(

Make sure your redis server is running! Redis configuration is outside the scope of this README, but
check out the [Redis documentation](http://redis.io/documentation).

## Usage

### Creating a leaderboard

Create a new leaderboard or attach to an existing leaderboard named 'highscores':

```javascript
highscores = new Leaderboard('highscores')
```

### Ranking members in the leaderboard


### Retrieving members from the leaderboard


### Conditionally rank a member in the leaderboard


## Performance Metrics

You can view [performance metrics](https://github.com/agoragames/leaderboard#performance-metrics) for the 
leaderboard library at the original Ruby library's page.

## Ports<commit_msg>Basic overview of functionality in README<commit_after># leaderboard

Leaderboards backed by [Redis](http://redis.io) in CoffeeScript.

Builds off ideas proposed in http://blog.agoragames.com/2011/01/01/creating-high-score-tables-leaderboards-using-redis/.

## Installation

`npm install ???`

TBD: Figure out what to do here since there's already a leaderboard library on npmjs.org :(

Make sure your redis server is running! Redis configuration is outside the scope of this README, but
check out the [Redis documentation](http://redis.io/documentation).

## Usage

All methods take a callback as the final argument. The callback is non-optional for methods that return data.

### Creating a leaderboard

Create a new leaderboard or attach to an existing leaderboard named 'highscores':

```javascript
highscores = new Leaderboard('highscores')
```

### Ranking members in the leaderboard

Add members to your leaderboard using `rankMember`:

```javascript
for index in [1..50]
  highscores.rankMember("member_#{index}", index, "Optional member data for member #{index}", (reply) -> )
```

You can call `rankMember` with the same member and the leaderboard will be updated automatically.

Get some information about your leaderboard:

```javascript
highscores.totalMembers((numMembers) -> ...)

highscores.totalPages(Leaderboard.DEFAULT_PAGE_SIZE, (totalPages) -> ...)
```

Get some information about a specific member(s) in the leaderboard:

```javascript
highscores.scoreFor('member_5', (memberScore) -> ...)

highscores.rankFor('member_5', (memberRank) -> ...)
```

### Retrieving members from the leaderboard

Get page 1 in the leaderboard:

```javascript
highscores.leaders(1, {'with_member_data': false}, (leaders) -> ...)
```

Get an "Around Me" leaderboard page for a given member, which pulls members above and below the given member:

```javascript
highscores.aroundMe('member_25', {'with_member_data': false}, (leaders) -> ...)
```

Get rank and score for an arbitrary list of members (e.g. friends) from the leaderboard:

```javascript
highscores.rankedInList(['member_5', 'member_17', 'member_1'], {'with_member_data': false}, (leaders) -> ...)
```

Retrieve members from the leaderboard in a given score range:

```javascript
highscores.membersFromScoreRange(10, 15, {'with_member_data': false}, (leaders) -> ...)
```

Retrieve a single member from the leaderboard at a given position:

```javascript
highscores.memberAt(4, {'with_member_data': false}, (member) -> ...)
```

Retrieve a range of members from the leaderboard within a given rank range:

```javascript
highscores.membersFromRankRange(5, 9, {'with_member_data': false}, (leaders) -> ...)
```

### Conditionally rank a member in the leaderboard

You can pass a function to the `rankMemberIf` method to conditionally rank a member in the leaderboard. The function is passed the following 5 parameters:

* `member`: Member name.
* `currentScore`: Current score for the member in the leaderboard. This property is currently supplied when calling the `rankMemberIf` method.
* `score`: Member score.
* `memberData`: Optional member data.
* `options`: Leaderboard options, e.g. 'reverse': Value of reverse option

```javascript
highscoreCheck = (member, currentScore, score, memberData, leaderboardOptions) ->
  return true if !currentScore?
  return true if score > currentScore
  false

highscores.rankMemberIf(highscoreCheck, 'david', 1337, null, 'Optional member data', (reply) -> ...)
```

## Performance Metrics

You can view [performance metrics](https://github.com/agoragames/leaderboard#performance-metrics) for the 
leaderboard library at the original Ruby library's page.

## Ports
{'fraction_non_alphanumeric': 0.11502546689303905, 'fraction_numerical': 0.00870118845500849, 'mean_word_length': 5.081290322580645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '547133', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1301, 'n_words': 497}