@@ -0,0 +1 @@
01001101111110101101111000001000010110000000101101011111001110001011001100011001101011110111101011110001111011011011111100100000111101011100001101011001011111000001000000001110101111100000110111010001111111010010011001100100000100111100011100110000111011001111111110001110110101101001101010010100101001001101100011110001001000110111100101110010110111011000011111100101110110001011011100100100111011000100110101100100100111001000100011110111010011110110000111001000000000000000000011010111010000001001010100100000000111001001001000000000000011110101011011011101100010100001110101101001101000101100011100000001000110100000001000011010011110000011000011100010000111110000100000000100000011011001111011111111001001101111011111101001000110000111110000010001100010100001000100010101101001101111101111011111011110110001001001111000100101110111101001101110111011111010010101011100111101111101111011110111111101101111111001110101010110101111011101111110110100011110110101111101111110011011101100001100011101111011101011011111111011101110111111101111001111011111100001000011111111100101110101001011011011110010101111100101101101111010111110101000011101011110110101101110100111000001100110001011000001001100011001011110000000000101000000000000100000100010010000000010000010000011100010000110000001001000110000000000100100010011100010010100000000011000110000000011001101010000100110010000101100000011000000000010011100001100000010000111000000010110110100111110100111011011000010000000010001101010010100010100000011101010100001110001011000010111000101010110010000100010001001000010010100100001101000001001101110110011000000000101010000000
@@ -0,0 +1 @@
110111101110101011000111101101110011101101111010111110010010111110100011111111110111001101011010010100110001100010011010111011101101011110001111111001101111001001000101110100110111111110011111001111101011100111100101111111001110011011100011010110110100010011011011011110011001100111111101010111010100110101011011111001100010111000001001100101101000010101001100000011101000010001010011110001110011001111011111011010110010010001110010000101100101010011011011110001001100011101000100000010100011000000111100010001000000001101000010011010100011011111001111111110111111111110111111100000011111011101101101111010111011111100111110011001010111111111000101011110111011011001101110111111111110101100110011001011001101000011011111111111111101011111111111111111010110001111101111110011010111011111001011011111111001111100101010111101101011110111010110101010010011111110011101011011101110110110011100001101101011101110010001100101100111010110000001111110001101011111110111101101111001001010100101101101000010100111110101111101101011111111110101110100110111000101011100010100001000101111100011101110101111010100001101000010010011001010110000011000101011101000011011101101111001100111011010101000010011010001101000000011110000001000001001100100100001000111001000010000000000101011010110000110110011111011101101010001011011111001011100011010001101111110011100011101001100111101001100000011111100111100111100110001000001100110010111100000100000011010011101000010000110100100000000010000001000000000000010011000101010000000110100001100100010010010001010000100100110010011000001000100100011100100000000000001100001101100000100110001001000001101
@@ -0,0 +1 @@
000010100110100000011001011001011110110000011001011110000000110000000000001000000001100111000100101100011000011010010110011111011111101111111101010100100010111100111111101010010011001000010111100111010101010001000010101111101110111100111011101011011110101110001010111011011111010110111001111100101111001110111011101111001100111111111111011111010110100110011110111011111111111010111000111011111101111110111001101111011011100010010110111110111101011111101111101111010010111111110111101111001111011111010011110111101111011101110100110010011001000001011111110111110110110011101011111101011011000010010110001110101011010101111001001001011001110000011100000110100101110001001011101101011101111100101001110111011101011110001110000010100011011000000010110001111100010010111100000100010000101001000001010011000101100101011000010011010111001111010001110000100011011000101111001100000011101000100000000100100000010000010100000000100000010001001000001001000000000100010111100001111000010101100100000100000001000000110000011010001010010000000010001011000000100000000100000000101010001000010110000010001001000000100101111001100100100010010010001100000111010000001100001100011100001010000000100101000110000010100011100000101011011000011010000100001100000010100101011001100001000010000010011000000110010001010100111010010000000110001011000110001001010001100000100111110001011100001010000010010010101000000001000100101001000010000111100000100011010000001110010100100011101010001101001111100001000011100001000001001001101010011010100001100001101000100101011110010001000001101000101111010000000011000011001100100100000001100010010101001010011
@@ -0,0 +1 @@
11011110010010101000111111101111101111101101111100110011110011101101101111100101111100011001010011111111101110111111010111111101111111101110101111111000101110100110011100101110110110110110100111010101111100011101111110101110101101001100111101011111000011111111011110011011111111101110110111110110101011111110101111111111000110111001100101000110011110010111111111111100011111111110111010011110010101011011110100111011110110111111111011110111111010111111111110101010100110110110000111111111111101111000101100101111110110101110110011011111111111110111111001111111100111101111101110110111101111101011011111001110001110110111010011011101111101111110111001101111101011110111111111001111111010111110101111001101111011111011110100111101111101011000111100111011001001111111111111001111110111111000111011110111110111110010011010110011001110001111011111111111001000011111111010101100010101110111100111111001111101111010111101111011001111001011101010011100101011111010011000111110001110111011111010111001000110101011001011110111101010110111100110101111111111110110111111111101111001111111101110111101101110110111011100000011110011010111001110100110011111111111010101011101111111111100111111111111110111010111110111110010011111110101011111111111011111010111010111101100101010001101111111111101010111101101011101111110101000111010111011111111111111111110101100101001110111111110110101000010010110110111101110110110000111111010111011111111111001110111111011111011110111111101111111111111010111111011111111011111101101111000111111010011111111101111011111011110111010111110011101101111111110110011111011101000111100001110110110111101111001110
@@ -0,0 +1 @@
01001011100111111010101101101111111011101011011111110111111111110111110111111011101111110111011011011111100110011111111111001100110101011011011001011111110100111111011011100000011011111011111111101111011011100101011111100110111111011100100111000001111011101111101111101101111010110100011001101010001001010100101001111010100111101110110010001110011111101011000011011011101000110000100101001111110111000011101111011011110001110011011010001100110011111101100011001011010010101111010010100101101001011100000111000011000101111001110011101010110100111101100100100000010100010000000001100100100010010000111000000000101000101001001011010100000110001010110100011111011100100100011011000101010110001010011010111110011111011111111001011011010101101101000011110100111111011011111100001011101000001011101011111001110111000000100101001101111011111111110111010101111101101011101111011011111010001101011010101100110010101111010100001011101111111111110001110110001000100100101010111011110101101010011000101111011111111101111010101111001101110111010110001101111101011111110101010111010110011100000010101010000010001010011000000001001100101111101110100110010001001000011011001011111101000101011001111110001011001110110001111001001000110110111101011011001110001000010100001111101101100000000010000001011000011001010101101010100110000111000110000010000001000001000001001010100101000000000100011011010101000100110010001101101110111111010000111011011001101100011001100101000011001011000110010010111111100101000001001111011011011001000101101101100001111011101111000111100101111110010111100011100111101100010111011011101001110000100010111111000010001
@@ -0,0 +1 @@
0011001100000010111100011111100101110001101001110110000110110110100110000110001111010001110000101101001001010101000001011000000010101000000010110010000001011101001000100000100101000000010010101100011101101101001000010010000010010000000001000000110000000001111100000010000000101100010001000000100001100000000101100111111111001111000010011011111001000000011000001011001100001010010100111011000000110100111000101111101010100010011010010111001001010001100001101000100110000110010000100001000001000010001101001001100000110110000000110010000010100011001001110111101100101001001111111001111000011110001001010011010101111000001111001110110000010101000100011100001011110101011011111001110001001110101011001100000111010110001000011011101110111110110100111101110010011100001110001101000101000000100100000111111001001101111000101011011101101010000000010011011010111011101100011101100000010000010010001000000001100100000010100000100010011001000001001000001000100100101000000100110110000001011000010100001100001100101101001000000000000000010110100100100100101010000100000001000100010101100100000000101000000010000001000010111001100000000010000100010100001001100000010100010010000010000011001111110000000000001010010000000010000011101010110000111100111001001011101101001101000000000110000110111011000011101100011001110101010110010001111110110011001001101100111101111011101100111101111110011100011101101100110000011000000101011111000010111101001101000111000010101001001111001000111100100010010101101011110000011111001001010111000100100010110100101101110101110011101111011111110111100110111110010011110001101011100100101111001001010110011010
@@ -9,47 +9,31 @@ const csvToArray = require('./utils/csvToArray');
const generateUpDownString = require('./utils/generateUpDownString');

// predictFns
const findPatternsAndReturnTodaysOutlook = require('./predictFns/findPatternsAndReturnTodaysOutlook');
const createPredictions = require('./predictFns/createPredictions');
const executePerms = require('./predictFns/executePerms');

const testPredictions = require('./predictFns/testPredictions');


const findPatternsAndReturnTodaysOutlook = (upDownString, options = {}) => {
const permsExecuted = executePerms(upDownString, MAX_DIGITS);

const forPresenting = permsExecuted
.filter(perm => perm.count > 10)
.sort((a, b) => b.perc - a.perc);

if (options.showPerms) {
console.log('permutation patterns found in desc order')
console.log(forPresenting);
}
if (options.runTests) {
testPredictions(upDownString, 300, options.executePermsEveryDay ? null : permsExecuted);
}
const todaysOutlook = createPredictions(upDownString, permsExecuted);
return todaysOutlook;
};


(async () => {

// STOCKS
const dayArray = await csvToArray(csvFilePath);
console.log('dayarray', dayArray);
const upDownString = generateUpDownString(dayArray);
// const dayArray = await csvToArray(csvFilePath);
// console.log('dayarray', dayArray);
// const upDownString = generateUpDownString(dayArray);

// BBALL
// const upDownString = await fs.readFile('./basketball-data/LAL.txt', 'utf8');
// console.log('upDownString', upDownString);
// console.log('\n');
const upDownString = await fs.readFile('./basketball-data/LAL.txt', 'utf8');
console.log('upDownString', upDownString);
console.log('\n');

const todaysOutlook = findPatternsAndReturnTodaysOutlook(upDownString, {
showPerms: true,
// runTests: true,
// executePermsEveryDay: true
runTests: true,
executePermsEveryDay: true,
numTests: 4
});
console.log('todays outlook', todaysOutlook);

Large diffs are not rendered by default.

@@ -10,7 +10,7 @@ function everyPermutation(maxDigits) {
}
}
recurse('');
return returnArr.filter(perm => perm.length >= 3);
return returnArr.filter(perm => perm.length >= 2);
}

module.exports = everyPermutation;
@@ -0,0 +1,25 @@
const { MAX_DIGITS } = require('../settings');

const executePerms = require('./executePerms');
const testPredictions = require('./testPredictions');
const createPredictions = require('./createPredictions');

const findPatternsAndReturnTodaysOutlook = (upDownString, options = {}) => {
const permsExecuted = executePerms(upDownString, MAX_DIGITS);

const forPresenting = permsExecuted
.filter(perm => perm.count > 10)
.sort((a, b) => b.perc - a.perc);

if (options.showPerms) {
console.log('permutation patterns found in desc order')
console.log(forPresenting);
}
if (options.runTests) {
testPredictions(upDownString, options.numTests || 30, options.executePermsEveryDay ? null : permsExecuted);
}
const todaysOutlook = createPredictions(upDownString, permsExecuted);
return todaysOutlook;
};

module.exports = findPatternsAndReturnTodaysOutlook;
@@ -4,7 +4,7 @@ const executePerms = require('./executePerms');
const testPredictions = (upDownString, numDaysToTest, permsExecuted) => {

const testResults = [];
for (var i = 1; i < numDaysToTest; i++) {
for (var i = 1; i <= numDaysToTest; i++) {
console.log('testing for today - ' + i + ' days');

// let goBackRandomDays = upDownString.length / 2;
@@ -15,7 +15,7 @@ const testPredictions = (upDownString, numDaysToTest, permsExecuted) => {
const todaysExecutePerms = permsExecuted || executePerms(todaysUpDownString);
const prediction = createPredictions(todaysUpDownString, todaysExecutePerms);
const whatActuallyHappened = upDownString.substring(upDownString.length - i, upDownString.length - i + 1);
// console.log('whatActuallyHappened', whatActuallyHappened);
// console.log('prediction', prediction);
const weightedPredictedUp = prediction.weightedPerc > 50;
const avgPredictedUp = prediction.avgPerc > 50;
const didGoUp = whatActuallyHappened === '1';
@@ -29,14 +29,15 @@ const testPredictions = (upDownString, numDaysToTest, permsExecuted) => {
weightedCorrect: (weightedPredictedUp === didGoUp),
didGoUp
});
console.log('finished test ', i, ' of ', 100);
console.log('finished test ', i, ' of ', numDaysToTest);
}

const percAvgCorrectOfTestGroup = tests => Math.round(tests.filter(test => test.avgCorrect).length / tests.length * 10000) / 100;
const percWeightedCorrectOfTestGroup = tests => Math.round(tests.filter(test => test.weightedCorrect).length / tests.length * 10000) / 100;
const displayTestGroup = (name, tests) => {
console.log('------------------------------');
console.log('test results for ' + name);
console.log(tests);
console.log('test count: ', tests.length);
console.log('avg perc ', percAvgCorrectOfTestGroup(tests));
console.log('weighted perc ', percWeightedCorrectOfTestGroup(tests));
@@ -0,0 +1,55 @@

const { MAX_DIGITS } = require('./settings.js');

const csvFilePath = './stock-data/GSPC.csv';
const fs = require('mz/fs')

// utils
const csvToArray = require('./utils/csvToArray');
const generateUpDownString = require('./utils/generateUpDownString');

// nba scraping
const getNbaGamesToday = require('./scraping/getNbaGamesToday');
const basketballWlScraperCheerio = require('./scraping/basketballWlScraperCheerio');

// predictFns
const findPatternsAndReturnTodaysOutlook = require('./predictFns/findPatternsAndReturnTodaysOutlook');
const createPredictions = require('./predictFns/createPredictions');
const executePerms = require('./predictFns/executePerms');

const testPredictions = require('./predictFns/testPredictions');



(async () => {

const todaysGames = await getNbaGamesToday();
const todaysPredictions = [];
for (let matchup of todaysGames) {
console.log('scraping team ', matchup[0]);
await basketballWlScraperCheerio(matchup[0]);
console.log('scraping team ', matchup[1]);
await basketballWlScraperCheerio(matchup[1]);
console.log('----------------');
console.log('now predicting...');
const t1UpDownString = await fs.readFile(`./basketball-data/${matchup[0]}.txt`, 'utf8');
const t1Outlook = findPatternsAndReturnTodaysOutlook(t1UpDownString);
const t2UpDownString = await fs.readFile(`./basketball-data/${matchup[1]}.txt`, 'utf8');
const t2Outlook = findPatternsAndReturnTodaysOutlook(t2UpDownString);
const winnerPrediction = t1Outlook.avgPerc > t2Outlook.avgPerc ? matchup[0] : matchup[1];
todaysPredictions.push({
team1: matchup[0],
team2: matchup[1],
winnerPrediction,
confidence: Math.abs(t1Outlook.avgPerc - t2Outlook.avgPerc)
});
console.log('predicted', winnerPrediction);
console.log('done predicting');
console.log('----------------');
}

todaysPredictions.forEach(pred => {
console.log(`game ${pred.team1} vs ${pred.team2} predicted winner: ${pred.winnerPrediction} with ${pred.confidence} confidence`);
});

})();
@@ -21,6 +21,8 @@ const scrapeTeam = async(team) => {
.join('');
console.log(upDownString, 'here')
resolve(upDownString);
} else {
reject(error);
}
});
});
@@ -30,16 +32,17 @@ const scrapeTeam = async(team) => {
for (let yr = 2018; yr > 2017 - 20; yr--) {
years.push(yr);
}
console.log(years);
// console.log(years);

let totalUpDownString = '';
for (let yr of years) {
try {
totalUpDownString = await scrapeSeason(yr) + totalUpDownString;
} catch (e) {
console.error('y', e);
break;
}
console.log(totalUpDownString, 'totalUpDownString');
// console.log(totalUpDownString, 'totalUpDownString');
}

console.log('saving...')
@@ -51,11 +54,11 @@ const scrapeTeam = async(team) => {
}
};

(async() => {
console.log(process.argv.slice(2));
for (let team of process.argv.slice(2)) {
await scrapeTeam(team);
}
})();
// (async() => {
// console.log(process.argv.slice(2));
// for (let team of process.argv.slice(2)) {
// await scrapeTeam(team);
// }
// })();

module.exports = scrapeTeam;
@@ -0,0 +1,53 @@
const request = require('request');
const cheerio = require('cheerio');
const fs = require('mz/fs');

const getMonthName = date => {
console.log('month name')
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return monthNames[date.getMonth()].toLowerCase();
};
const dayCommaYear = date => {
console.log('day comma')
return date.getDate() + ", " + date.getFullYear();
};

const scrapeTodaysGames = async () => {

console.log('scraping todays games');
const d = new Date();
const currentMonth = getMonthName(d);
const dayCommaYearStr = dayCommaYear(d);
console.log('dayCommaYearStr', dayCommaYearStr);
return new Promise((resolve, reject) => {
const url = `https://www.basketball-reference.com/leagues/NBA_2018_games-${currentMonth}.html`;
console.log('url', url);
request(url, function (error, response, html) {
if (!error && response.statusCode == 200) {
// console.log(html);
var $ = cheerio.load(html);
const gamesToday = [];
$('table#schedule tr').each(function(i, el) {
const $this = $(this);
console.log($this.text());
const isGameToday = $this.find('th').text().includes(' ' + dayCommaYearStr);
if (isGameToday) {
gamesToday.push([
$this.find('td:nth-child(3) a').attr('href').split('/')[2],
$this.find('td:nth-child(5) a').attr('href').split('/')[2]
]);
}
});
resolve(gamesToday);
}
});
});

};

// (async() => {
// const todaysGames = await scrapeTodaysGames();
// console.log('todaysGames', todaysGames);
// })();

module.exports = scrapeTodaysGames;