forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
132 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,12 +51,56 @@ drop me an email at [email protected], and we'll discuss it. | |
```javascript | ||
{ | ||
"username": "thibault", | ||
"title": null, // chess title like FM or LM (lichess master) | ||
"url": "http://lichess.org/@/thibault", // profile url | ||
"rating": 1503, // standard Glicko2 rating | ||
"progress": 36, // rating change over the last ten games | ||
"online": true, // is the player currently using lichess? | ||
"playing": "http://lichess.org/abcdefgh", // game being played, if any | ||
"engine": false // true if the user is known to use a chess engine | ||
"engine": false, // true if the user is known to use a chess engine | ||
"language": "en", // prefered language | ||
"profile": { | ||
"bio": "Developer of lichess", | ||
"country": "FR", | ||
"firstName": "Thibault", | ||
"lastName": "Duplessis", | ||
"location": "Paris" | ||
}, | ||
"perfs": { // user performances in different games | ||
"bullet": { | ||
"games": 35, // number of rated games played | ||
"rating": 1624, // Glicko2 rating | ||
"rd": 80 // Glicko2 rating deviation | ||
}, | ||
"chess960": { | ||
"games": 1, | ||
"rating": 1739, | ||
"rd": 277 | ||
}, | ||
"classical": { | ||
"games": 331, | ||
"rating": 1603, | ||
"rd": 65 | ||
}, | ||
"kingOfTheHill": { | ||
"games": 3, | ||
"rating": 1622, | ||
"rd": 223 | ||
}, | ||
"puzzle": { | ||
"games": 9, | ||
"rating": 902, | ||
"rd": 117 | ||
}, | ||
"standard": { | ||
"games": 736, | ||
"rating": 1576, | ||
"rd": 79 | ||
}, | ||
"threeCheck": { | ||
"games": 1, | ||
"rating": 1662, | ||
"rd": 290 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
@@ -91,12 +135,7 @@ name | type | default | description | |
{ | ||
"list": [ | ||
{ | ||
"username": "thibault", | ||
"url": "http://lichess.org/@/thibault", // profile url | ||
"rating": 1503, // standard Glicko2 rating | ||
"progress": 36, // rating change over the last ten games | ||
"online": true, // is the player currently using lichess? | ||
"engine": false // true if the user is known to use a chess engine | ||
... // see user document above | ||
}, | ||
... // other users | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
package lila.user | ||
|
||
import lila.rating.{ Perf, Glicko } | ||
import play.api.libs.json.Json | ||
import play.api.libs.json._ | ||
import lila.common.PimpedJson._ | ||
|
||
final class JsonView { | ||
final class JsonView(isOnline: String => Boolean) { | ||
|
||
private implicit val countWrites = Json.writes[Count] | ||
private implicit val glickoWrite = Json.writes[Glicko] | ||
private implicit val perfWrite = Json.writes[Perf] | ||
private implicit val perfsWrites = Json.writes[Perfs] | ||
|
||
def me(u: User) = user(u) | ||
|
||
def user(u: User) = Json.obj( | ||
"id" -> u.id, | ||
"username" -> u.username, | ||
"title" -> u.title, | ||
"rating" -> u.rating, | ||
"rd" -> u.perfs.standard.glicko.deviation, | ||
"progress" -> u.progress, | ||
"playTime" -> u.playTime.map { p => | ||
Json.obj( | ||
"total" -> p.total, | ||
"tv" -> p.tv) | ||
private implicit val perfWrites: Writes[Perf] = Writes { o => | ||
Json.obj( | ||
"games" -> o.nb, | ||
"rating" -> o.glicko.rating.toInt, | ||
"rd" -> o.glicko.deviation.toInt) | ||
} | ||
private implicit val perfsWrites: Writes[Perfs] = Writes { o => | ||
JsObject(o.perfsMap.toList map { | ||
case (name, perf) => name -> perfWrites.writes(perf) | ||
}) | ||
} | ||
private implicit val profileWrites = Json.writes[Profile] | ||
|
||
def full(u: User) = user(u) ++ Json.obj( | ||
"count" -> countWrites.writes(u.count), | ||
"perfs" -> perfsWrites.writes(u.perfs) | ||
) | ||
def apply(u: User, extended: Boolean) = Json.obj( | ||
"id" -> u.id, | ||
"username" -> u.username | ||
) ++ extended.??(Json.obj( | ||
"title" -> u.title, | ||
"online" -> isOnline(u.id), | ||
"engine" -> u.engine, | ||
"language" -> u.lang, | ||
"profile" -> u.profile.??(profileWrites.writes).noNull, | ||
"perfs" -> u.perfs | ||
)).noNull | ||
} |