Code Monkey home page Code Monkey logo

players's Introduction

The Chess Centre

GitHub CircleCI Coverage Status

Chess Players

Utility for accessing chess player data

GitHub tag (latest by date)

Intro

This NodeJS package is provided to help developers quickly build applications or components which want to use the published FIDE chess player rating list data.

Use case

An example of this would be a React component which renders a players profile name country rating where you would expose this data on your backend server, via a REST or GraphQL API.

This might look something like this:

import React, { useEffect, useState } from 'react';

export default const PlayerProfile = props => {
       const { id as FIDE_ID } = props;
       const [player, updatePlayer] = useState({});
       const getPlayer = async () => updatePlayer(() => { ...await fetch(`/player/${FIDE_ID}`));
       
       useEffect(() => await getPlayer(), []);

       return (<div>
            <h1>Fide Profile</h1>
            <div>Name: {player.name}</div>
            <div>Rating: {player.rating}</div>
            <div>Country: {player.country}</div>
       </div>);
}
// App.js -> <PlayerProfile id="123456" />

Sample

Getting started

npm install chess-players

or

yarn add chess-players

Examples (typescript)

Full list

import Fide, { Player } from './fide';

(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();

  console.log(`Players: ${players.length}`); // OR res.send();
})();

player count

Top players

import Fide, { Player } from './fide';

(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();

  const topTen = players
    .sort((a: Player, b: Player) => b.rating - a.rating)
    .slice(0, 10)
    .reduce(
      (players: any, player: any) => 
      [...players, { name: player.name, rating: player.rating, nationality: player.country }],
      [],
    );

  console.log(topTen); // OR res.send();
})();

player top ten

Specific player

import Fide, { Player } from './fide';

(async () => {
  const fide = new Fide();
  const players: Array<Player> = await fide.getPlayers();

  const player = players.find(player => player.fideid === 418250)

  console.log(player); // OR res.send();
})();

player top ten

Legacy lists

import Fide, { Player, Options } from './fide';

(async () => {
  const fide = new Fide();
  const config: Options = {
    ratingType: "rapid",
    month: "jan",
    year: 2019
  }
  const players: Array<Player> = await fide.getPreviousPlayersList(config);
})();

Memoized (cached API calls)

import Fide from './fide';

(async () => {
  const fide = new Fide();
  console.time('players');
  await fide.getPlayers();
  console.timeEnd('players');

  console.time('players-memoized');
  await fide.getPlayers();
  console.timeEnd('players-memoized');
})();

player memoized

License

MIT

players's People

Contributors

dependabot[bot] avatar matt-d-webb avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fmxmoz arbitre125

players's Issues

Provide AWS lamdba handler examples

This utility would work great as a lambda call, examples can include persistening this data to an RDS or NoSQL solution like Mongo.

Or it could simply be available as a lambda call, although understanding memory consumption is key as the getPlayers() method parses a 24 mb file in memory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.