Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match Probability in Simulate Match #74

Merged
merged 26 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7ab83b4
started stats
AidanDonnelly1 Jan 17, 2023
660fbb4
implementing statistics
Jan 18, 2023
8cc0d31
finished compareAlliances; added documentation
AidanDonnelly1 Jan 19, 2023
f12f095
started comparing all Alliances
AidanDonnelly1 Jan 19, 2023
52d6d08
Trying to add to simulate match
AidanDonnelly1 Jan 20, 2023
e9f8552
Confirmed Math Works by logging
AidanDonnelly1 Jan 25, 2023
283c09a
trying to create new module for sim match
AidanDonnelly1 Jan 30, 2023
a7b199e
all alliances are collected; working on aggr method
AidanDonnelly1 Feb 3, 2023
d7695a3
Ready compute for formattedDisplay
AidanDonnelly1 Feb 4, 2023
ec7476d
formattedData; Updated Display module
AidanDonnelly1 Feb 4, 2023
7ae0f83
Merge remote-tracking branch 'origin/2023-config' into autoPick/function
AidanDonnelly1 Feb 4, 2023
54ac750
debugging autopick
AidanDonnelly1 Feb 4, 2023
5635b91
broke n
AidanDonnelly1 Feb 7, 2023
7078911
teams array is wrong
AidanDonnelly1 Feb 8, 2023
0c9140e
hard coded team; resolved some errors
AidanDonnelly1 Feb 9, 2023
9b4a11b
Trying to comment out and work backwards
AidanDonnelly1 Feb 10, 2023
3cbd789
able to predict with hardcoded alliances;
AidanDonnelly1 Feb 14, 2023
73581c3
teams being passed into method aren't as expected
AidanDonnelly1 Feb 15, 2023
1cb82cc
Computes chance of winning; sometimes it seems buggy, but need more t…
AidanDonnelly1 Feb 16, 2023
a517878
Got rid of random boxes
AidanDonnelly1 Feb 16, 2023
660ea4b
cleaned up comments and console.logs; updated to use aggr method
AidanDonnelly1 Feb 17, 2023
de570d3
Documented my fucntions
AidanDonnelly1 Feb 17, 2023
f29b23d
documented funtions; cleaned up comments; removed autopick.js for lat…
AidanDonnelly1 Feb 17, 2023
2f1100e
removed comment about potential bug after testing
AidanDonnelly1 Feb 17, 2023
4e9c529
removed a commented out potential bug and documented in trello; conve…
AidanDonnelly1 Feb 17, 2023
f913c95
Merge branch 'main' into autoPick/function
AidanDonnelly1 Feb 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/analysis-modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"module": "Pie",
"position":"main",
"name":"Avg Cone Pickups",
"wholeMatch": false,
"options":{
"slices":[
{
Expand Down Expand Up @@ -115,6 +116,7 @@
"module": "Pie",
"position":"main",
"name":"Avg Cube Pickups",
"wholeMatch": false,
"options":{
"slices":[
{
Expand Down Expand Up @@ -521,6 +523,17 @@
"decimals": 2
}
},
{
"view": "match",
"module": "SingleDisplay",
"name": "Percent Chance of Winning",
"position": "main",
"wholeMatch": true,
"options": {
"aggrMethod" : "percentChanceOfWinning",
"decimals": 2
}
},
{
"view": "match",
"module": "ColumnDisplay",
Expand Down Expand Up @@ -549,6 +562,7 @@
"module": "Pie",
"position":"main",
"name":"Avg Cone Pickups",
"wholeMatch": false,
"options":{
"slices":[
{
Expand Down
12 changes: 11 additions & 1 deletion config/analysis-pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,5 +491,15 @@
"options": {
"path": "scores"
}
}
},

{
"type": "team",
"name": "standardDeviation",
"outputPath": "standardDeviation",
"options": {
"path" : "scores.total"
}
}

]
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spot",
"version": "1.0.0",
"description": "",
"description": "SPOT is an open-source modular scouting app framework for FRC developed by Team 3061 Huskie Robotics. SPOT provides a simple platform upon which a team can build a scouting app with little to no prior experience.",
"main": "./src/app.js",
"scripts": {
"start": "node src/app.js",
Expand Down Expand Up @@ -33,6 +33,7 @@
"mongoose": "^6.0.6",
"nodemon": "^2.0.15",
"qrcode": "^1.4.4",
"simple-statistics": "^7.8.2",
"socket.io": "^4.4.1"
}
}
2 changes: 1 addition & 1 deletion src/analysis/modules/Grid/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Grid {
let newObj = {
x:cell.x,
y:cell.y,
data:teams.map((team)=>{let data = getPath(dataset.teams[team],cell.path,0).toFixed(this.moduleConfig.options.decimals);console.log(data);return data }).reduce((acc, i) => acc + parseFloat(i), 0).toFixed(this.moduleConfig.options.decimals),
data:teams.map((team)=>{let data = getPath(dataset.teams[team],cell.path,0).toFixed(this.moduleConfig.options.decimals);return data }).reduce((acc, i) => acc + parseFloat(i), 0).toFixed(this.moduleConfig.options.decimals),
hex:cell.hex,
}
return newObj
Expand Down
5 changes: 3 additions & 2 deletions src/analysis/modules/Pie/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class Pie {
}

formatData(teams, dataset) {
console.log(`pie teams recieved: ${teams}`);
let filteredTeams = teams.filter(team=>team!="|");
const values = this.moduleConfig.options.slices.map((slice) => {
const summed = teams.map(team => {console.log(team);return getPath(dataset.teams[team], slice.path)}).flat().reduce((acc, i) => acc + i, 0)
const summed = filteredTeams.map(team => {let data = getPath(dataset.teams[team], slice.path); console.log(`${slice.path}: ${data}`);return data}).flat().reduce((acc, i) => acc + i, 0)
if (slice.aggrMethod == "sum") { //optionally summed
return summed
} else { //default is average
Expand All @@ -32,7 +34,6 @@ class Pie {
}
]

console.log(data)

return data
}
Expand Down
102 changes: 89 additions & 13 deletions src/analysis/modules/SingleDisplay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,44 @@ class SingleDisplay {
}

formatData(teams, dataset) {
let summed
if (teams.length > 1) {
summed = teams.map(team => getPath(dataset.teams[team], this.moduleConfig.options.path, 0)).flat().reduce((acc, i) => acc + i, 0)
// teams = [b1,b2,b3,|,r1,r3,r3,|]
let teamsArray = teams
let summed
let formattedDisplay
if(this.moduleConfig.wholeMatch) {
let indexOfPipe = teamsArray.indexOf("|")
let alliance1 = teamsArray.slice(0, indexOfPipe)
// alliance 1 = [b1,b2,b3]
let alliance2 = teamsArray.slice(indexOfPipe+1, teamsArray.length)
alliance2 = alliance2.filter(team => team != "|")
// alliance 2 = [r1,r2,r3]
if (this.moduleConfig.options.aggrMethod == "percentChanceOfWinning") { //optionally percent chance of winning
formattedDisplay = this.compareAlliances(alliance1, alliance2, dataset)
formattedDisplay = (formattedDisplay * 100).toFixed(2).toString()+"%";
} else { //default is undefined
formattedDisplay = "0%"
}

} else {
summed = getPath(dataset.teams[teams[0]], this.moduleConfig.options.path, 0)
}
if (teams.length > 1) {
summed = teams.map(team => getPath(dataset.teams[team], this.moduleConfig.options.path, 0)).flat().reduce((acc, i) => acc + i, 0)
} else {
summed = getPath(dataset.teams[teams[0]], this.moduleConfig.options.path, 0)
}

let formattedDisplay
if (this.moduleConfig.options.aggrMethod == "sum") { //optionally summed
formattedDisplay = summed
} else { //default is average
formattedDisplay = summed / teams.length
if (this.moduleConfig.options.aggrMethod == "sum") { //optionally summed
formattedDisplay = summed
} else { //default is average
formattedDisplay = summed / teams.length
}
}

formattedDisplay = this.applyModifiers(formattedDisplay)

if (isNaN(formattedDisplay) || formattedDisplay == this.moduleConfig.options.hideIfValue) {
formattedDisplay = "—"
if(!this.moduleConfig.wholeMatch){
formattedDisplay = "—"
}

} else {
if (this.moduleConfig.options.decimals !== undefined) {
formattedDisplay = formattedDisplay.toFixed(this.moduleConfig.options.decimals)
Expand All @@ -41,7 +61,6 @@ class SingleDisplay {
formattedDisplay += this.moduleConfig.options.unit
}
}

return formattedDisplay
}

Expand All @@ -61,4 +80,61 @@ class SingleDisplay {
this.header.innerText = this.moduleConfig.name
this.display.innerText = data
}

/**
*
* @param {*an allaicne of any length*} alliance1
* @param {*an alliance to compare to of any length*} alliance2
* @param {*the data set that holds the infomation of the teams*} dataset
* @returns {*the avg difference in score between allaicne 1 and allaicne 2*}
*/
matchAverage(alliance1, alliance2, dataset){
let alliance1Avg = 0
for (const a of alliance1) {
alliance1Avg += getPath(dataset.teams[a],"averageScores.total",0)
}
let alliance2Avg = 0
for (const a of alliance2) {
alliance2Avg += getPath(dataset.teams[a],"averageScores.total",0)
}
return alliance1Avg - alliance2Avg
}

/**
*
* @param {*an allaicne of any length*} alliance1
* @param {*an alliance to compare to of any length*} alliance2
* @param {*the data set that holds the infomation of the teams*} dataset
* @returns {*the standard deveation of the given match*}
*/
matchStandardDeviation(alliance1, alliance2, dataset) {
let alliance1SD = 0
for (const a of alliance1) {
let data = getPath(dataset.teams[a],"standardDeviation",0)
alliance1SD += Math.pow(data, 2)
}
alliance1SD = Math.sqrt(alliance1SD)
let alliance2SD = 0
for (const a of alliance2) {
let data = getPath(dataset.teams[a],"standardDeviation",0)
alliance2SD += Math.pow(data, 2)
}
alliance2SD = Math.sqrt(alliance2SD)
return Math.sqrt(Math.pow(alliance1SD, 2) + Math.pow(alliance2SD, 2))
}

/**
*
* @param {*an allaicne of any length*} alliance1
* @param {*an alliance to compare to of any length*} alliance2
* @param {*the data set that holds the infomation of the teams*} dataset
* @returns {*the percent chance that alliance1 will win this match*}
*/
compareAlliances(alliance1, alliance2, dataset) {
let zscore = ss.zScore(0, this.matchAverage(alliance1, alliance2, dataset), this.matchStandardDeviation(alliance1, alliance2, dataset))
let probAlliance2Wins = ss.cumulativeStdNormalProbability(zscore)
return 1 - probAlliance2Wins;
}


}
3 changes: 2 additions & 1 deletion src/analysis/public/js/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const sideList = document.getElementById("side-list")
const searchInput = document.getElementById("search-input")
const matchViewSwitch = document.getElementById("match-view-switch")
const leftAllianceModules = document.getElementById("left-alliance-modules")
const rightAllianceModules = document.getElementById("right-alliance-modules")
const rightAllianceModules = document.getElementById("right-alliance-modules")
// const bothAllianceModules = document.getElementById("both-alliance-modules")
61 changes: 52 additions & 9 deletions src/analysis/public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ if ('serviceWorker' in navigator) {
team: [],
match: {
left: [],
right: []
right: [],
both: []
}
}

Expand Down Expand Up @@ -222,7 +223,7 @@ if ('serviceWorker' in navigator) {
}
})

//create match module objects and append placeholders to module list elements
//create match module objects and append placeholders to module list elements
for (const module of modulesConfig.filter(m => m.view == "match")) {
const leftModuleObject = new moduleClasses[module.module](module)
leftAllianceModules.appendChild(leftModuleObject.container)
Expand All @@ -237,14 +238,35 @@ if ('serviceWorker' in navigator) {
//call setData on every module in matches
async function setMatchModules(alliances) {
for (const module of modules.match.left) {
const displayedAlliances = alliances[0].filter(teamNumber => {
if (!module.moduleConfig.separate && Object.keys(dataset.teams[teamNumber]).filter(prop => prop !== "manual").length == 0) {
console.log(module.moduleConfig.name)
var displayedAlliances = alliances[0].filter(teamNumber => {
if(teamNumber == "|"){return false}
if (!module.moduleConfig.separate && Object.keys(dataset.teams[teamNumber]).filter(prop => prop !== "manual").length == 0) {
return false
}

return true
})

if(module.moduleConfig.wholeMatch) {
let allTeams = alliances[0]
console.log(`alliances script.js ${alliances}`)
allTeams.push('|')
allTeams = allTeams.concat(alliances[1])
console.log(`all teams: ${allTeams}`)
displayedAlliances = allTeams.filter(teamNumber => {
if (!module.moduleConfig.separate && teamNumber != "|" && Object.keys(dataset.teams[teamNumber]).filter(prop => prop !== "manual").length == 0) {
return false
}
return true
})
console.log(`displayed alliances: ${displayedAlliances}`)
if (displayedAlliances.length !== 0) {
module.container.classList.remove("hidden")
await module.setData(await module.formatData(allTeams, dataset))
} else {
module.container.classList.add("hidden")
}
}
if (displayedAlliances.length !== 0) {
module.container.classList.remove("hidden")
await module.setData(await module.formatData(displayedAlliances, dataset))
Expand All @@ -254,14 +276,35 @@ if ('serviceWorker' in navigator) {
}

for (const module of modules.match.right) {
const displayedAlliances = alliances[1].filter(teamNumber => {
console.log(module.moduleConfig.name)
var displayedAlliances = alliances[1].filter(teamNumber => {
if(teamNumber == "|"){return false}
if (!module.moduleConfig.separate && Object.keys(dataset.teams[teamNumber]).filter(prop => prop !== "manual").length == 0) {
return false
}

return true
})

if(module.moduleConfig.wholeMatch) {
let allTeams = alliances[1]
allTeams.push('|')
allTeams = allTeams.concat(alliances[0])
console.log(`all teams: ${allTeams}`)
var displayedAlliances = allTeams.filter(teamNumber => {
if (!module.moduleConfig.separate && teamNumber != "|" && Object.keys(dataset.teams[teamNumber]).filter(prop => prop !== "manual").length == 0) {
return false
}

return true
})
console.log(`displayed alliances: ${displayedAlliances}`)
if (displayedAlliances.length !== 0) {
module.container.classList.remove("hidden")
await module.setData(await module.formatData(displayedAlliances, dataset))
} else {
module.container.classList.add("hidden")
}
}
if (displayedAlliances.length !== 0) {
module.container.classList.remove("hidden")
await module.setData(await module.formatData(displayedAlliances, dataset))
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/public/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function clearDiv(div) {
function getPath(obj,path,ifnone=ThrowError) {
if (typeof obj === "undefined") {
if (ifnone == ThrowError) {
throw new Error("path not traversable!");
throw new Error(`path ${path} not traversable!`);
} else {
return ifnone;
}
Expand Down
Loading