Sign inSign up

neamar/teamward-server

By neamar

Updated almost 9 years ago

Server for teamward

Image
1

2.9K

neamar/teamward-server repository overview

Teamward: League Of Legends game statistics

This is the server component. The client is here.

Get information about your current games:

  • Champions you're facing
  • Champions mastery score
  • Summoner rank
  • Is it his main champ?
  • Premade information
  • Matchup statistics based on 100m+ games
  • And more!

Credits

Uses Riot Public API https://developer.riotgames.com/api TeamWard isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing League of Legends. League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc. League of Legends © Riot Games, Inc.

Uses http://champion.gg data for matchups.

How is this app working?

Using the Riot API, this app will retrieve information about the current game for the given summoner, and build a single unified JSON (GET /game/data) with all the informations you'll need to know if you should play safe or very agressively.

Architecture

Don't forget to set an environment variable named RIOT_API_KEY to use the project (get a key here).

Most of the code is in the lib/ folder.

  • lib/ddragon contains helpers to deal with the Riot Static Data: champion avatar, champions stats, summoner icons, etc.
  • lib/handler contains the actual HTTP handler used by Express to serve your requests. The most interesting one is probably lib/handler/game/data.js.
  • lib/helper is a set of useful helpers used throughout the code
    • lib/helper/game is the main helper for the game data endpoint
    • lib/helper/roles will try to ifner role based on summoner spell and usual champion roles
    • lib/helper/matchups will return information about a specific matchup
  • lib/middleware is a collection of small composable middlewares used with express
  • lib/model defines the data model used for persisting data
  • lib/riot-api communicates with the Riot API. An interesting file in here is lib/riot-api/request.js: it will handle all the rate limiting and is used as a low-level library for all requests to the Riot API. It will also cache requests, and serve data from cache.
  • lib/worker contains a list of useful worker. They can be started with node bin/worker-<worker-name>.js.
  • lib/task contains a list of useful tasks (one off processes). They can be started with node bin/<task-name>.js. The most important one is champion-stats, which will get the aggregated matchup / lanes stats.

Using locally

Run npm install. You'll need the nodeJS version specified in the package.json, MongoDB, Redis and PostgresSQL.

  • Redis is used as a transient store for anything that can be lost without any impact; this includes Riot API caching and cached summonerId to accountId mapping.
  • MongoDB is used to store all aggregated and user data. It contains all the high value data; you probably want to back it up regularly
  • PostgresSQL will store all the games and be used to compute the aggregated stats. The worker worker-download-games will fill the DB, but the web worker will also interact with PG. You'll find the fixtures to set up the DB in model/sql/fixtures.sql.

To initialize the Mongo DB, you'll also need to run node bin/champion-stats.js. On first run, this will just create the objects in the DB -- subsequent runs, once data starts accumulating in PG, will compute the aggregated stats.

Create a .env file at project root using this template:

RIOT_API_KEY="your riot key from developer.riotgames.com"
DEBUG="teamward:*"
GCM_API_KEY="your gcm api key, or a fake value if you don't plan to develop on GCM"

Run npm test to make sure everything is correctly setup.

To test locally, simply run npm start. You may want to use nodemon instead to hot-reload you changes.

Deploying

The app can easily be deployed in many services -- start the app with PORT=yourport npm start and you're good to go.

More environment variables are available, see config/index.js for details.

By default, the app is set up to use NewRelic for monitoring, HostedGraphite for metric tracking and Opbeat for error reporting. If you don't specify the keys in your environement however, the services just won't be used. If you want to use your own services, have a look in lib/error-logger.js and lib/metric-tracker.js which provide an high level interface easily reconfigurable.

Don't forget to wire up the workers too: in addition to npm start, you'll probably want to always run node bin/worker-push-notifier.js (send notifications to your users), node bin/worker-download-games (download enqueued games and store them in DB) and run every day node bin/champion-stats to ensure matchups stats are up to date.

Using the app

Interested in using the API in your own app? Great! You can use the API already hosted at https://app.teamward.xyz, or host it on your own server.

If you plan to use the server I already provider, please drop me an email at [email protected] so that I know what to expect! If you don't, an email will still be appreciated to see what you're doing :)

Please keep in mind that this project is free, open-source and ad-free. I'm not making any money out of it (I'm actually paying quite a lot for the server), so use responsibly and do not abuse the server I provide <3

The following section documents the endpoints you're most likely to use. If you plan to use the push-notifier endpoints (undocumented here), please give me notice before!

Game data

Endpoint: https://app.teamward.xyz/game/data?summoner=Psykzz&region=euw

Parameters: summoner name (url escaped), region (lowercase, riot regions only).

Result: 404 when the summoner isn't in game, otherwise 200 with game data as a JSON. (sample)

Counters

Endpoint: https://app.teamward.xyz/summoner/counter?summoner=Psykzz&region=euw&role=mid&level=0

Parameters: summoner name (url escaped), region (lowercase, riot regions only), role (top, jungle, mid, bot or support) and level (minimum champion masteries required for champion to be displayed)

Result: 200 with a JSON object containing this summoner counters on the specified lane.

Performance

Endpoint: https://app.teamward.xyz/summoner/performance?summoner=Psykzz&region=euw&champion=Janna

Parameters: summoner name (url escaped), region (lowercase, riot regions only), champion (name or id)

Result: JSON object containing this summoner counters on specified lane.

Static champion info

Endpoint: https://app.teamward.xyz/champion/Illaoi

Parameters: replace Illaoi with any champion name or id

Result: JSON listing spells and cooldowns.

Tag summary

Content type

Image

Digest

Size

266.9 MB

Last updated

almost 9 years ago

docker pull neamar/teamward-server