GithubHelp home page GithubHelp logo

o-in25 / hat-trick-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 114 KB

Uses the MySportsFeeds API to gather sports statistics about professional athletes. The server uses MySportsFeeds's RESTful API architecture to deliver content such as a player's free throw percentage, where a player played college ball, and more.

Home Page: https://www.mysportsfeeds.com/

License: GNU General Public License v3.0

JavaScript 99.27% CSS 0.21% HTML 0.52%

hat-trick-server's Introduction

Hat Trick Server

The Hat Trick server is the content server for the (soon-to-be) Hat Trick sports statistics application. This application is both a reqrite and an upgrade to the SportsStats application. Hat Trick the MySportsFeeds API to gather sports statistics about professional athletes. The server uses MySportsFeeds's RESTful API architecture to deliver content such as a player's free throw percentage, where a player played college ball, and more. Click here for API documentation

Courtesy of the MySportsFeeds API

Features

Rich API

The MySportsFeeds RESTful APIs provides full support for getting stats such as active players or cumulative player stats. The Hat Trick API server consumes these HTTP requests and provides a rich and compact service for retrieving them.

    
getActivePlayers: function(requestParams, callback) {
        // build the request
        let requestData = manager.buildRequest('nba', season, 'active_players', requestParams);
        // make the request
        return service.makeRequest(requestData).then((data) => {
            let obj = JSON.parse(data);
            /** player stats entry is of type array and returns information about the player **/
            callback(obj.activeplayers.playerstatsentry);
        }).catch((err) => {
            console.log('Request failed...');
            throw err;
        });
}

Flexibility That Scales

The Hat Trick Server takes advantage of MongoDB's NoSQL schema achitecture, which allows for seemless integration with MySportsFeeds. As MySportsFeeds API's changes, Hat Trick's schemas naturally follow.

https://api.mysportsfeeds.com/v1.2/pull/nba/{season-name}/cumulative_player_stats.{format}

team={list-of-teams} (filter teams)
player={list-of-players} (filter players)
position={list-of-positions} (filter player positions)
country={list-of-countries} (filter player countries of birth)
playerstats={list-of-player-stats} (filter player stats)
sort={sort-specifier} (sort the feed's content)
offset={offset-specifier} (filter results starting at the given offset)
limit={limit-specifier} (limit the maximum # of results)
force={force-if-not-modified} (force content)


 let SchemaManager = {
          player: {
              ID: String,
                  LastName: String,
                  FirstName: String,
                  JerseyNumber: String,
                  Position: String
          },
          team: {
              ID: String,
                  City: String,
                  Name: String,
                  Abbreviation: String
          },
          stats: {
              GamesPlayed: {
                  abbreviation: String,
                      text: String
              },
              Fg2PtAtt: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg2PtAttPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg2PtMade: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg2PtMadePerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg2PtPct: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg3PtAtt: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg3PtAttPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg3PtMade: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg3PtMadePerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fg3PtPct: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FgAtt: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FgAttPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FgMade: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FgMadePerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FgPct: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FtAtt: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FtAttPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FtMade: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FtMadePerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FtPct: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              OffReb: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              OffRebPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              DefReb: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              DefRebPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Reb: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              RebPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Ast: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              AstPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Pts: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              PtsPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Tov: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              TovPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Stl: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              StlPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Blk: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              BlkPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              BlkAgainst: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              BlkAgainstPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Fouls: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulsPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulsDrawn: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulsDrawnPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulPers: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulPersPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulPersDrawn: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulPersDrawnPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulTech: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulTechPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulTechDrawn: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulTechDrawnPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag1: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag1PerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag1Drawn: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag1DrawnPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag2: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag2PerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag2Drawn: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              FoulFlag2DrawnPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              Ejections: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              PlusMinus: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              PlusMinusPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              MinSeconds: {
                  category: String,
                      abbreviation: String,
                      text: String
              },
              MinSecondsPerGame: {
                  category: String,
                      abbreviation: String,
                      text: String
              }
          }
      };

CRUD Services. Managed.

Need not worry about building GET requests. The Hat Trick Server handles building requests. All you need to do, is supply your request parameters - or let the Hat Trick Server supply them for you.


buildRequest: function (sport, season, statType, requestParameters) {
        // ex: buildRequest('nba', '2017-2018', 'plus-minus', {'team':'cleveland-cavaliers, 'position':'pg'}
        // take a object
        // with 2 arrays containing the
        // request and its value
        let res = '';
        let count = 0;
        for(let prop in requestParameters) {
            // will remove the first & on the first param
            if(count == 0) {// if its the first one
                res += requestParameters.hasOwnProperty(prop)?  prop + '=' + requestParameters[prop] : '';
                count++;
            } else {// if its not the first one
                res += requestParameters.hasOwnProperty(prop)?  '&' + prop + '=' + requestParameters[prop] : '';
            }
        }
        return {
            hostname: 'api.mysportsfeeds.com',
            path: '/v1.2/pull/' + sport + '/' + season + '/' + statType + '.json?' + res,
            method: 'GET',
            headers: {
                'Content-Type': 'application/json', "Authorization": 'Basic ' + btoa('user' + ':' + 'password')
            }
        }
    }

hat-trick-server's People

Contributors

o-in25 avatar

Stargazers

 avatar

Watchers

 avatar Brad Barkhouse avatar

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.