the sidebet module for fantasylabs.co sidebet system

Usage no npm install needed!

<script type="module">
  import oayomideSidebetFantasyLabs from 'https://cdn.skypack.dev/@oayomide/sidebet-fantasy-labs';


This project contains a broken away code for the sidebet system. The aim is to make it more maintainable and not tied to one aspect so it can be extended and used in other projects

What does this project contain?

This module contains the following:

  • parser -- for parsing the sample data
  • feed API -- this connects to the mysportsfeed API for getting the sports data needed to calculate our points
  • precalculator -- this contains the precalculator for precalculating the winning choice, extract the operand and the operator and evaluate the sidebet backend query.

Public API

Feed API:

In this example, we want to get the winning team for the current tournament

const { Feed } = require('sidebet-fantasy-labs')
(async () => {
  const feedAPI = new Feed('20181108-BUF-MTL')
  const winningTeam = await feedAPI.WinningTeam()
  console.log(winningTeam) //logs 'BUF'

The following are the API methods available:

  • WinningTeam()

    • returns the winning team for the tournament
  • PlayerScore(playername)

    • takes the playername as an argument.
    • returns the score for the passed player name.
  • TotalGoals(team)

    • takes the team to get the total goals, as an argument. Either the home or away team
    • if the team parameter is null, the sum of the score of both teams is returned
    • returns the score of the passed team
  • TotalShots(team)

    • same as TeamGoals except for played shots
  • PowerPlay(param)

    • the class method to get the powerplay for a team for a particular game
    • param -- the team we want to get the power play for
    • returns the power play for the particular team


The following are the available API methods:

  • getQueryResult(param)
    • this method takes the query coming from the chatfuel front-end and returns the value needed
    • param contains the query coming from chatfuel
    • returns the result for the query
const { EvalClass } = require('sidebet-fantasy-labs')
(async () => {
  const evalAPI = new EvalClass('20181108-BUF-MTL') // the gameID for the current tournament

  const queryResult = await evalAPI.getQueryResult('query_win_team()')
  console.log(queryResult) // logs 'BUF'
  • Eval(query)
    • used to evaluate the sidebetquery from chatfuel. It differs from getQueryResult(param) because we can have queries like: Math.max(query_player_scores('Vladimir Sobotka), query_player_scores('Jonathan Drouine')).
    • query the query coming from chatfuel. Its always {{sb_back_end_query}}


The following are the class API methods available for the parser

  • BuildParsedContent(x)

    • this method is used to build the parsed objects to be saved into the DB
    • x each JSON object representing the data for each (fake) user
    • object containing 6 objects, each representing one sidebet data
  • extractData(d, n)

    • the method to extract the data from the json files
    • d the file number we want to parse first. Sample data is split into 3 files. Each file contains two sidebet data
    • n the sidebet number to parse. For example, since file one contains sidebet 1 and sidebet 2, if n is 2, it'll parse for sidebet 2 and if d is 3 and n is 2, it'll parse for sidebet 6
    • the final data parsed, ready to mapped and POSTed to DB
  • parseGameMasterCSV(d, n)

    • this method is used to parse the csv file containing the game master selection/data
    • d the filenumber we want to parse. Similar to this.extractData(d, n)
    • n the sidebet number we want to parse. Similar to this.extractData(d, n)
    • returns the parsed data. Ready to be saved to DB


The following are the API methods available for the precalculator:

  • GetOperandAndOperator()

    • this method gets the operand and operator from each sidebet choices (there are 5)
    • returns the array of object that contains the operands and operators and the selections themselves
  • EvalQuery()

    • this method evals the user selection in order to return the value of the sidebet backend query.
    • returns the array of correct answers
  • GetWinningChoice()

    • this method is used to get the winning choice out of all the 5 sidebet choices for a single sidebet
    • the array of the object that contains the selection and point


The following are the methods available under the hash class:

  • getHash(x)

    • this method is used to get the hash value of the passed string
    • x is the key we want to get the hash value
    • returns the value of the hash value of the key
  • setHash(x)

    • this method is used to set the key-value hash
    • x the key to set the hash with
    • y is the value corresponding to the key. In this case, the point