Update TBA publishing for 2018.

This commit is contained in:
Patrick Fairbank
2018-09-01 22:19:17 -07:00
parent 68d358c1ee
commit bd13887aaf
12 changed files with 330 additions and 210 deletions

View File

@@ -698,31 +698,35 @@ func (arena *Arena) handlePlcInput() {
ownershipChanged = arena.RedSwitch.UpdateState(redSwitch, currentTime) || ownershipChanged
ownershipChanged = arena.BlueSwitch.UpdateState(blueSwitch, currentTime) || ownershipChanged
if arena.MatchState == AutoPeriod {
redScore.AutoOwnershipPoints = 2 * int(arena.RedSwitch.GetRedSeconds(matchStartTime, currentTime)+
arena.Scale.GetRedSeconds(matchStartTime, currentTime))
blueScore.AutoOwnershipPoints = 2 * int(arena.BlueSwitch.GetBlueSeconds(matchStartTime, currentTime)+
arena.Scale.GetBlueSeconds(matchStartTime, currentTime))
redScore.AutoScaleOwnershipSec, _ = arena.Scale.GetRedSeconds(matchStartTime, currentTime)
redScore.AutoSwitchOwnershipSec, _ = arena.RedSwitch.GetRedSeconds(matchStartTime, currentTime)
blueScore.AutoScaleOwnershipSec, _ = arena.Scale.GetBlueSeconds(matchStartTime, currentTime)
blueScore.AutoSwitchOwnershipSec, _ = arena.BlueSwitch.GetBlueSeconds(matchStartTime, currentTime)
} else {
redScore.TeleopOwnershipPoints = int(arena.RedSwitch.GetRedSeconds(teleopStartTime, currentTime) +
arena.Scale.GetRedSeconds(teleopStartTime, currentTime))
blueScore.TeleopOwnershipPoints = int(arena.BlueSwitch.GetBlueSeconds(teleopStartTime, currentTime) +
arena.Scale.GetBlueSeconds(teleopStartTime, currentTime))
redScore.TeleopScaleOwnershipSec, redScore.TeleopScaleBoostSec =
arena.Scale.GetRedSeconds(teleopStartTime, currentTime)
redScore.TeleopSwitchOwnershipSec, redScore.TeleopSwitchBoostSec =
arena.RedSwitch.GetRedSeconds(teleopStartTime, currentTime)
blueScore.TeleopScaleOwnershipSec, blueScore.TeleopScaleBoostSec =
arena.Scale.GetBlueSeconds(teleopStartTime, currentTime)
blueScore.TeleopSwitchOwnershipSec, blueScore.TeleopSwitchBoostSec =
arena.BlueSwitch.GetBlueSeconds(teleopStartTime, currentTime)
}
// Handle vaults.
redForceDistance, redLevitateDistance, redBoostDistance, blueForceDistance, blueLevitateDistance, blueBoostDistance :=
arena.Plc.GetVaults()
redForceDistance, redLevitateDistance, redBoostDistance, blueForceDistance, blueLevitateDistance,
blueBoostDistance := arena.Plc.GetVaults()
arena.RedVault.UpdateCubes(redForceDistance, redLevitateDistance, redBoostDistance)
arena.BlueVault.UpdateCubes(blueForceDistance, blueLevitateDistance, blueBoostDistance)
redForce, redLevitate, redBoost, blueForce, blueLevitate, blueBoost := arena.Plc.GetPowerUpButtons()
arena.RedVault.UpdateButtons(redForce, redLevitate, redBoost, currentTime)
arena.BlueVault.UpdateButtons(blueForce, blueLevitate, blueBoost, currentTime)
redScore.ForceCubes, redScore.ForcePlayed = arena.RedVault.ForceCubes, arena.RedVault.ForcePowerUp != nil
redScore.ForceCubes, redScore.ForceCubesPlayed = arena.RedVault.ForceCubes, arena.RedVault.ForceCubesPlayed
redScore.LevitateCubes, redScore.LevitatePlayed = arena.RedVault.LevitateCubes, arena.RedVault.LevitatePlayed
redScore.BoostCubes, redScore.BoostPlayed = arena.RedVault.BoostCubes, arena.RedVault.BoostPowerUp != nil
blueScore.ForceCubes, blueScore.ForcePlayed = arena.BlueVault.ForceCubes, arena.BlueVault.ForcePowerUp != nil
redScore.BoostCubes, redScore.BoostCubesPlayed = arena.RedVault.BoostCubes, arena.RedVault.BoostCubesPlayed
blueScore.ForceCubes, blueScore.ForceCubesPlayed = arena.BlueVault.ForceCubes, arena.BlueVault.ForceCubesPlayed
blueScore.LevitateCubes, blueScore.LevitatePlayed = arena.BlueVault.LevitateCubes, arena.BlueVault.LevitatePlayed
blueScore.BoostCubes, blueScore.BoostPlayed = arena.BlueVault.BoostCubes, arena.BlueVault.BoostPowerUp != nil
blueScore.BoostCubes, blueScore.BoostCubesPlayed = arena.BlueVault.BoostCubes, arena.BlueVault.BoostCubesPlayed
// Check if a power up has been newly played and trigger the accompanying sound effect if so.
newRedPowerUp := arena.RedVault.CheckForNewlyPlayedPowerUp()

View File

@@ -6,32 +6,38 @@
package game
type Score struct {
AutoRuns int
AutoOwnershipPoints int
AutoEndSwitchOwnership bool
TeleopOwnershipPoints int
ForceCubes int
ForcePlayed bool
LevitateCubes int
LevitatePlayed bool
BoostCubes int
BoostPlayed bool
Climbs int
Parks int
Fouls []Foul
ElimDq bool
AutoRuns int
AutoSwitchOwnershipSec float64
AutoScaleOwnershipSec float64
AutoEndSwitchOwnership bool
TeleopScaleOwnershipSec float64
TeleopScaleBoostSec float64
TeleopSwitchOwnershipSec float64
TeleopSwitchBoostSec float64
ForceCubes int
ForceCubesPlayed int
LevitateCubes int
LevitatePlayed bool
BoostCubes int
BoostCubesPlayed int
Climbs int
Parks int
Fouls []Foul
ElimDq bool
}
type ScoreSummary struct {
AutoRunPoints int
AutoPoints int
OwnershipPoints int
VaultPoints int
ParkClimbPoints int
FoulPoints int
Score int
AutoQuest bool
FaceTheBoss bool
AutoRunPoints int
AutoOwnershipPoints int
AutoPoints int
TeleopOwnershipPoints int
OwnershipPoints int
VaultPoints int
ParkClimbPoints int
FoulPoints int
Score int
AutoQuest bool
FaceTheBoss bool
}
// Calculates and returns the summary fields used for ranking and display.
@@ -49,10 +55,13 @@ func (score *Score) Summarize(opponentFouls []Foul) *ScoreSummary {
autoRuns = 3
}
summary.AutoRunPoints = 5 * autoRuns
summary.AutoPoints = summary.AutoRunPoints + score.AutoOwnershipPoints
summary.AutoOwnershipPoints = int(2 * (score.AutoScaleOwnershipSec + score.AutoSwitchOwnershipSec))
summary.AutoPoints = summary.AutoRunPoints + summary.AutoOwnershipPoints
// Calculate teleop score.
summary.OwnershipPoints = score.AutoOwnershipPoints + score.TeleopOwnershipPoints
summary.TeleopOwnershipPoints = int(score.TeleopScaleOwnershipSec + score.TeleopScaleBoostSec +
score.TeleopSwitchOwnershipSec + score.TeleopSwitchBoostSec)
summary.OwnershipPoints = summary.AutoOwnershipPoints + summary.TeleopOwnershipPoints
forceCubes := score.ForceCubes
if forceCubes > 3 {
forceCubes = 3
@@ -100,12 +109,17 @@ func (score *Score) Summarize(opponentFouls []Foul) *ScoreSummary {
func (score *Score) Equals(other *Score) bool {
if score.AutoRuns != other.AutoRuns || score.AutoEndSwitchOwnership != other.AutoEndSwitchOwnership ||
score.AutoOwnershipPoints != other.AutoOwnershipPoints ||
score.TeleopOwnershipPoints != other.TeleopOwnershipPoints || score.ForceCubes != other.ForceCubes ||
score.ForcePlayed != other.ForcePlayed || score.LevitateCubes != other.LevitateCubes ||
score.AutoScaleOwnershipSec != other.AutoScaleOwnershipSec ||
score.AutoSwitchOwnershipSec != other.AutoSwitchOwnershipSec ||
score.TeleopScaleOwnershipSec != other.TeleopScaleOwnershipSec ||
score.TeleopScaleBoostSec != other.TeleopScaleBoostSec ||
score.TeleopSwitchOwnershipSec != other.TeleopSwitchOwnershipSec ||
score.TeleopSwitchBoostSec != other.TeleopSwitchBoostSec ||
score.ForceCubes != other.ForceCubes ||
score.ForceCubesPlayed != other.ForceCubesPlayed || score.LevitateCubes != other.LevitateCubes ||
score.LevitatePlayed != other.LevitatePlayed || score.BoostCubes != other.BoostCubes ||
score.BoostPlayed != other.BoostPlayed || score.Parks != other.Parks || score.Climbs != other.Climbs ||
score.ElimDq != other.ElimDq || len(score.Fouls) != len(other.Fouls) {
score.BoostCubesPlayed != other.BoostCubesPlayed || score.Parks != other.Parks ||
score.Climbs != other.Climbs || score.ElimDq != other.ElimDq || len(score.Fouls) != len(other.Fouls) {
return false
}

View File

@@ -100,12 +100,32 @@ func TestScoreEquals(t *testing.T) {
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.AutoOwnershipPoints += 1
score2.AutoScaleOwnershipSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.TeleopOwnershipPoints += 1
score2.AutoSwitchOwnershipSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.TeleopScaleOwnershipSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.TeleopScaleBoostSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.TeleopSwitchOwnershipSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.TeleopSwitchBoostSec += 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
@@ -115,7 +135,7 @@ func TestScoreEquals(t *testing.T) {
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.ForcePlayed = !score2.ForcePlayed
score2.ForceCubesPlayed = 1
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))
@@ -135,7 +155,7 @@ func TestScoreEquals(t *testing.T) {
assert.False(t, score2.Equals(score1))
score2 = TestScore1()
score2.BoostPlayed = !score2.BoostPlayed
score2.BoostCubesPlayed = 2
assert.False(t, score1.Equals(score2))
assert.False(t, score2.Equals(score1))

View File

@@ -76,13 +76,13 @@ func (seesaw *Seesaw) GetOwnedBy() Alliance {
}
}
// Returns the auto and teleop period scores for the red alliance.
func (seesaw *Seesaw) GetRedSeconds(startTime, endTime time.Time) float64 {
// Returns the total seconds of ownership and boost score accumulation for the red alliance.
func (seesaw *Seesaw) GetRedSeconds(startTime, endTime time.Time) (float64, float64) {
return seesaw.getAllianceSeconds(RedAlliance, startTime, endTime)
}
// Returns the auto and teleop period scores for the blue alliance.
func (seesaw *Seesaw) GetBlueSeconds(startTime, endTime time.Time) float64 {
// Returns the total seconds of ownership and boost score accumulation for the blue alliance.
func (seesaw *Seesaw) GetBlueSeconds(startTime, endTime time.Time) (float64, float64) {
return seesaw.getAllianceSeconds(BlueAlliance, startTime, endTime)
}
@@ -96,18 +96,20 @@ func (seesaw *Seesaw) getCurrentOwnership() *Ownership {
return nil
}
func (seesaw *Seesaw) getAllianceSeconds(ownedBy Alliance, startTime, endTime time.Time) float64 {
var seconds float64
func (seesaw *Seesaw) getAllianceSeconds(ownedBy Alliance, startTime, endTime time.Time) (float64, float64) {
var ownershipSec, boostSec float64
for _, ownership := range seesaw.ownerships {
if ownership.ownedBy == ownedBy {
seconds += ownership.getSeconds(startTime, endTime, false)
ownership, boost := ownership.getSeconds(startTime, endTime)
ownershipSec += ownership
boostSec += boost
}
}
return seconds
return ownershipSec, boostSec
}
// Returns the scoring value for the ownership period, whether it is past or current.
func (ownership *Ownership) getSeconds(startTime, endTime time.Time, ignoreBoost bool) float64 {
// Returns the regular and boost scoring values for the ownership period, whether it is past or current.
func (ownership *Ownership) getSeconds(startTime, endTime time.Time) (float64, float64) {
var ownershipStartTime, ownershipEndTime time.Time
if ownership.startTime.Before(startTime) {
ownershipStartTime = startTime
@@ -121,9 +123,9 @@ func (ownership *Ownership) getSeconds(startTime, endTime time.Time, ignoreBoost
}
if ownershipStartTime.After(ownershipEndTime) {
return 0
return 0, 0
}
ownershipSeconds := ownershipEndTime.Sub(ownershipStartTime).Seconds()
ownershipSec := ownershipEndTime.Sub(ownershipStartTime).Seconds()
// Find the boost power up applicable to this seesaw and alliance, if it exists.
var boostPowerUp *PowerUp
@@ -137,6 +139,7 @@ func (ownership *Ownership) getSeconds(startTime, endTime time.Time, ignoreBoost
}
}
var boostSec float64
if boostPowerUp != nil {
// Adjust for the boost.
var boostStartTime, boostEndTime time.Time
@@ -151,8 +154,9 @@ func (ownership *Ownership) getSeconds(startTime, endTime time.Time, ignoreBoost
boostEndTime = boostPowerUp.getEndTime()
}
if boostEndTime.After(boostStartTime) {
ownershipSeconds += boostEndTime.Sub(boostStartTime).Seconds()
boostSec = boostEndTime.Sub(boostStartTime).Seconds()
}
}
return ownershipSeconds
return ownershipSec, boostSec
}

View File

@@ -6,26 +6,28 @@ package game
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestOwnership(t *testing.T) {
ownership := Ownership{nil, RedAlliance, timeAfterStart(1), nil}
assert.Equal(t, 0.0, ownership.getSeconds(timeAfterStart(0), timeAfterStart(0), true))
assert.Equal(t, 0.5, ownership.getSeconds(timeAfterStart(0), timeAfterStart(1.5), true))
assert.Equal(t, 8.75, ownership.getSeconds(timeAfterStart(0), timeAfterStart(9.75), true))
ownership := &Ownership{nil, RedAlliance, timeAfterStart(1), nil}
assertSeconds(t, 0.0, 0.0, ownership, timeAfterStart(0), timeAfterStart(0))
assertSeconds(t, 0.0, 0.0, ownership, timeAfterStart(0), timeAfterStart(0))
assertSeconds(t, 0.5, 0.0, ownership, timeAfterStart(0), timeAfterStart(1.5))
assertSeconds(t, 8.75, 0.0, ownership, timeAfterStart(0), timeAfterStart(9.75))
// Check with truncated start.
assert.Equal(t, 2.5, ownership.getSeconds(timeAfterStart(1.5), timeAfterStart(4), true))
assert.Equal(t, 5.0, ownership.getSeconds(timeAfterStart(5), timeAfterStart(10), true))
assertSeconds(t, 2.5, 0.0, ownership, timeAfterStart(1.5), timeAfterStart(4))
assertSeconds(t, 5.0, 0.0, ownership, timeAfterStart(5), timeAfterStart(10))
// Check with end time.
endTime := timeAfterStart(13.5)
ownership.endTime = &endTime
assert.Equal(t, 12.5, ownership.getSeconds(timeAfterStart(0), timeAfterStart(15), true))
assert.Equal(t, 4.0, ownership.getSeconds(timeAfterStart(9.5), timeAfterStart(20), true))
assertSeconds(t, 12.5, 0.0, ownership, timeAfterStart(0), timeAfterStart(15))
assertSeconds(t, 4.0, 0.0, ownership, timeAfterStart(9.5), timeAfterStart(20))
// Check invalid/corner cases.
assert.Equal(t, 0.0, ownership.getSeconds(timeAfterStart(2), timeAfterStart(1), true))
assertSeconds(t, 0.0, 0.0, ownership, timeAfterStart(2), timeAfterStart(1))
}
func TestSecondCounting(t *testing.T) {
@@ -39,31 +41,31 @@ func TestSecondCounting(t *testing.T) {
redSwitch.UpdateState([2]bool{false, false}, timeAfterStart(-12))
redSwitch.UpdateState([2]bool{false, true}, timeAfterStart(-9))
redSwitch.UpdateState([2]bool{false, false}, timeAfterStart(-3))
assert.Equal(t, 0.0, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(0)))
assert.Equal(t, 0.0, redSwitch.GetBlueSeconds(timeAfterStart(0), timeAfterStart(0)))
assertRedSeconds(t, 0.0, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(0))
assertBlueSeconds(t, 0.0, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(0))
// Test autonomous.
redSwitch.UpdateState([2]bool{true, false}, timeAfterStart(1))
assert.Equal(t, 1.0, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(2)))
assert.Equal(t, 5.5, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(6.5)))
assertRedSeconds(t, 1.0, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(2))
assertRedSeconds(t, 5.5, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(6.5))
redSwitch.UpdateState([2]bool{false, false}, timeAfterStart(8.1))
assert.Equal(t, 7.1, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(8.5)))
assert.Equal(t, 7.1, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(10)))
assertRedSeconds(t, 7.1, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(8.5))
assertRedSeconds(t, 7.1, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(10))
redSwitch.UpdateState([2]bool{false, true}, timeAfterStart(10))
assert.Equal(t, 7.1, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(13)))
assertRedSeconds(t, 7.1, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(13))
redSwitch.UpdateState([2]bool{false, false}, timeAfterStart(13.5))
redSwitch.UpdateState([2]bool{true, false}, timeAfterStart(13.9))
assert.Equal(t, 8.2, redSwitch.GetRedSeconds(timeAfterStart(0), timeAfterStart(15)))
assertRedSeconds(t, 8.2, 0.0, redSwitch, timeAfterStart(0), timeAfterStart(15))
// Test teleop.
assert.Equal(t, 3.0, redSwitch.GetRedSeconds(timeAfterStart(17), timeAfterStart(20)))
assertRedSeconds(t, 3.0, 0.0, redSwitch, timeAfterStart(17), timeAfterStart(20))
redSwitch.UpdateState([2]bool{false, false}, timeAfterStart(30.8))
assert.Equal(t, 13.8, redSwitch.GetRedSeconds(timeAfterStart(17), timeAfterStart(34)))
assertRedSeconds(t, 13.8, 0.0, redSwitch, timeAfterStart(17), timeAfterStart(34))
redSwitch.UpdateState([2]bool{false, true}, timeAfterStart(35))
assert.Equal(t, 13.8, redSwitch.GetRedSeconds(timeAfterStart(17), timeAfterEnd(-10)))
assertRedSeconds(t, 13.8, 0.0, redSwitch, timeAfterStart(17), timeAfterEnd(-10))
redSwitch.UpdateState([2]bool{true, false}, timeAfterEnd(-5.1))
assert.Equal(t, 18.9, redSwitch.GetRedSeconds(timeAfterStart(17), timeAfterEnd(0)))
assert.Equal(t, 111.9, redSwitch.GetBlueSeconds(timeAfterStart(17), timeAfterEnd(0)))
assertRedSeconds(t, 18.9, 0.0, redSwitch, timeAfterStart(17), timeAfterEnd(0))
assertBlueSeconds(t, 111.9, 0.0, redSwitch, timeAfterStart(17), timeAfterEnd(0))
}
func TestForce(t *testing.T) {
@@ -81,14 +83,14 @@ func TestForce(t *testing.T) {
maybeActivatePowerUp(powerUp, timeAfterStart(2.5))
blueSwitch.UpdateState([2]bool{true, false}, timeAfterStart(2.5))
scale.UpdateState([2]bool{true, false}, timeAfterStart(2.5))
assert.Equal(t, 2.5, blueSwitch.GetBlueSeconds(timeAfterStart(0), timeAfterStart(5)))
assert.Equal(t, 0.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(5)))
assert.Equal(t, 10.0, blueSwitch.GetBlueSeconds(timeAfterStart(0), timeAfterStart(12.5)))
assert.Equal(t, 0.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(12.5)))
assertBlueSeconds(t, 2.5, 0.0, blueSwitch, timeAfterStart(0), timeAfterStart(5))
assertBlueSeconds(t, 0.0, 0.0, scale, timeAfterStart(0), timeAfterStart(5))
assertBlueSeconds(t, 10.0, 0.0, blueSwitch, timeAfterStart(0), timeAfterStart(12.5))
assertBlueSeconds(t, 0.0, 0.0, scale, timeAfterStart(0), timeAfterStart(12.5))
blueSwitch.UpdateState([2]bool{true, false}, timeAfterStart(12.5))
scale.UpdateState([2]bool{true, false}, timeAfterStart(12.5))
assert.Equal(t, 10.0, blueSwitch.GetBlueSeconds(timeAfterStart(0), timeAfterStart(15)))
assert.Equal(t, 0.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(15)))
assertBlueSeconds(t, 10.0, 0.0, blueSwitch, timeAfterStart(0), timeAfterStart(15))
assertBlueSeconds(t, 0.0, 0.0, scale, timeAfterStart(0), timeAfterStart(15))
// Force scale only.
powerUp = &PowerUp{Alliance: BlueAlliance, Effect: Force, Level: 2}
@@ -97,8 +99,8 @@ func TestForce(t *testing.T) {
scale.UpdateState([2]bool{true, false}, timeAfterStart(20))
blueSwitch.UpdateState([2]bool{true, false}, timeAfterStart(30))
scale.UpdateState([2]bool{true, false}, timeAfterStart(30))
assert.Equal(t, 0.0, blueSwitch.GetBlueSeconds(timeAfterStart(20), timeAfterStart(40)))
assert.Equal(t, 10.0, scale.GetBlueSeconds(timeAfterStart(20), timeAfterStart(40)))
assertBlueSeconds(t, 0.0, 0.0, blueSwitch, timeAfterStart(20), timeAfterStart(40))
assertBlueSeconds(t, 10.0, 0.0, scale, timeAfterStart(20), timeAfterStart(40))
// Force both switch and scale.
powerUp = &PowerUp{Alliance: BlueAlliance, Effect: Force, Level: 3}
@@ -107,8 +109,8 @@ func TestForce(t *testing.T) {
scale.UpdateState([2]bool{true, false}, timeAfterStart(50))
blueSwitch.UpdateState([2]bool{true, false}, timeAfterStart(60))
scale.UpdateState([2]bool{true, false}, timeAfterStart(60))
assert.Equal(t, 10.0, blueSwitch.GetBlueSeconds(timeAfterStart(50), timeAfterStart(70)))
assert.Equal(t, 10.0, scale.GetBlueSeconds(timeAfterStart(50), timeAfterStart(70)))
assertBlueSeconds(t, 10.0, 0.0, blueSwitch, timeAfterStart(50), timeAfterStart(70))
assertBlueSeconds(t, 10.0, 0.0, scale, timeAfterStart(50), timeAfterStart(70))
}
func TestBoost(t *testing.T) {
@@ -124,13 +126,13 @@ func TestBoost(t *testing.T) {
scale.UpdateState([2]bool{true, false}, timeAfterStart(20))
powerUp := &PowerUp{Alliance: BlueAlliance, Effect: Boost, Level: 2}
maybeActivatePowerUp(powerUp, timeAfterStart(25))
assert.Equal(t, 5.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(25)))
assert.Equal(t, 6.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(25.5)))
assert.Equal(t, 7.5, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(26.25)))
assert.Equal(t, 15.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(30)))
assert.Equal(t, 25.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(35)))
assert.Equal(t, 30.0, scale.GetBlueSeconds(timeAfterStart(0), timeAfterStart(40)))
assert.Equal(t, 20.0, blueSwitch.GetBlueSeconds(timeAfterStart(0), timeAfterStart(40)))
assertBlueSeconds(t, 5.0, 0.0, scale, timeAfterStart(0), timeAfterStart(25))
assertBlueSeconds(t, 5.5, 0.5, scale, timeAfterStart(0), timeAfterStart(25.5))
assertBlueSeconds(t, 6.25, 1.25, scale, timeAfterStart(0), timeAfterStart(26.25))
assertBlueSeconds(t, 10.0, 5.0, scale, timeAfterStart(0), timeAfterStart(30))
assertBlueSeconds(t, 15.0, 10.0, scale, timeAfterStart(0), timeAfterStart(35))
assertBlueSeconds(t, 20.0, 10.0, scale, timeAfterStart(0), timeAfterStart(40))
assertBlueSeconds(t, 20.0, 0.0, blueSwitch, timeAfterStart(0), timeAfterStart(40))
// Test with no ownership at the start.
ResetPowerUps()
@@ -138,33 +140,54 @@ func TestBoost(t *testing.T) {
scale.UpdateState([2]bool{false, false}, timeAfterStart(44))
powerUp = &PowerUp{Alliance: BlueAlliance, Effect: Boost, Level: 3}
maybeActivatePowerUp(powerUp, timeAfterStart(45))
assert.Equal(t, 0.0, blueSwitch.GetBlueSeconds(timeAfterStart(45), timeAfterStart(50)))
assert.Equal(t, 0.0, scale.GetBlueSeconds(timeAfterStart(45), timeAfterStart(50)))
assertBlueSeconds(t, 0.0, 0.0, blueSwitch, timeAfterStart(45), timeAfterStart(50))
assertBlueSeconds(t, 0.0, 0.0, scale, timeAfterStart(45), timeAfterStart(50))
blueSwitch.UpdateState([2]bool{false, true}, timeAfterStart(50))
scale.UpdateState([2]bool{true, false}, timeAfterStart(50))
assert.Equal(t, 10.0, blueSwitch.GetBlueSeconds(timeAfterStart(45), timeAfterStart(55)))
assert.Equal(t, 15.0, blueSwitch.GetBlueSeconds(timeAfterStart(45), timeAfterStart(60)))
assert.Equal(t, 10.0, scale.GetBlueSeconds(timeAfterStart(45), timeAfterStart(55)))
assert.Equal(t, 15.0, scale.GetBlueSeconds(timeAfterStart(45), timeAfterStart(60)))
assertBlueSeconds(t, 5.0, 5.0, blueSwitch, timeAfterStart(45), timeAfterStart(55))
assertBlueSeconds(t, 10.0, 5.0, blueSwitch, timeAfterStart(45), timeAfterStart(60))
assertBlueSeconds(t, 5.0, 5.0, scale, timeAfterStart(45), timeAfterStart(55))
assertBlueSeconds(t, 10.0, 5.0, scale, timeAfterStart(45), timeAfterStart(60))
// Test with interrupted ownership.
ResetPowerUps()
scale.UpdateState([2]bool{false, true}, timeAfterStart(65))
assert.Equal(t, 5.0, scale.GetRedSeconds(timeAfterStart(65), timeAfterStart(70)))
assertRedSeconds(t, 5.0, 0.0, scale, timeAfterStart(65), timeAfterStart(70))
powerUp = &PowerUp{Alliance: RedAlliance, Effect: Boost, Level: 2}
maybeActivatePowerUp(powerUp, timeAfterStart(70))
scale.UpdateState([2]bool{false, false}, timeAfterStart(72.5))
assert.Equal(t, 10.0, scale.GetRedSeconds(timeAfterStart(65), timeAfterStart(72.5)))
assert.Equal(t, 10.0, scale.GetRedSeconds(timeAfterStart(65), timeAfterStart(77.5)))
assertRedSeconds(t, 7.5, 2.5, scale, timeAfterStart(65), timeAfterStart(72.5))
assertRedSeconds(t, 7.5, 2.5, scale, timeAfterStart(65), timeAfterStart(77.5))
scale.UpdateState([2]bool{false, true}, timeAfterStart(77.5))
assert.Equal(t, 15.0, scale.GetRedSeconds(timeAfterStart(65), timeAfterStart(80)))
assert.Equal(t, 20.0, scale.GetRedSeconds(timeAfterStart(65), timeAfterStart(85)))
assertRedSeconds(t, 10.0, 5.0, scale, timeAfterStart(65), timeAfterStart(80))
assertRedSeconds(t, 15.0, 5.0, scale, timeAfterStart(65), timeAfterStart(85))
// Test with just the switch.
blueSwitch.UpdateState([2]bool{false, true}, timeAfterStart(100))
scale.UpdateState([2]bool{true, false}, timeAfterStart(100))
powerUp = &PowerUp{Alliance: BlueAlliance, Effect: Boost, Level: 1}
maybeActivatePowerUp(powerUp, timeAfterStart(100))
assert.Equal(t, 20.0, blueSwitch.GetBlueSeconds(timeAfterStart(100), timeAfterStart(110)))
assert.Equal(t, 10.0, scale.GetBlueSeconds(timeAfterStart(100), timeAfterStart(110)))
assertBlueSeconds(t, 10.0, 10.0, blueSwitch, timeAfterStart(100), timeAfterStart(110))
assertBlueSeconds(t, 10.0, 0.0, scale, timeAfterStart(100), timeAfterStart(110))
}
func assertSeconds(t *testing.T, expectedOwnership, expectedBoost float64, ownership *Ownership, startTime,
endTime time.Time) {
actualOwnership, actualBoost := ownership.getSeconds(startTime, endTime)
assert.Equal(t, expectedOwnership, actualOwnership)
assert.Equal(t, expectedBoost, actualBoost)
}
func assertRedSeconds(t *testing.T, expectedOwnership, expectedBoost float64, seesaw *Seesaw, startTime,
endTime time.Time) {
actualOwnership, actualBoost := seesaw.GetRedSeconds(startTime, endTime)
assert.Equal(t, expectedOwnership, actualOwnership)
assert.Equal(t, expectedBoost, actualBoost)
}
func assertBlueSeconds(t *testing.T, expectedOwnership, expectedBoost float64, seesaw *Seesaw, startTime,
endTime time.Time) {
actualOwnership, actualBoost := seesaw.GetBlueSeconds(startTime, endTime)
assert.Equal(t, expectedOwnership, actualOwnership)
assert.Equal(t, expectedBoost, actualBoost)
}

View File

@@ -8,11 +8,11 @@ package game
func TestScore1() *Score {
fouls := []Foul{{Rule{"G22", false, ""}, 25, 25.2}, {Rule{"G18", true, ""}, 25, 150},
{Rule{"G20", true, ""}, 1868, 0}}
return &Score{1, 12, true, 47, 0, false, 3, true, 0, false, 2, 0, fouls, false}
return &Score{1, 1.5, 4.5, true, 25.4, 0, 21.6, 0, 0, 0, 3, true, 0, 0, 2, 0, fouls, false}
}
func TestScore2() *Score {
return &Score{3, 20, true, 73, 3, true, 0, false, 3, true, 1, 1, []Foul{}, false}
return &Score{3, 4, 6, true, 33, 10, 20, 10, 3, 3, 0, false, 3, 3, 1, 1, []Foul{}, false}
}
func TestRanking1() *Ranking {

View File

@@ -12,9 +12,11 @@ import (
type Vault struct {
Alliance
ForceCubes int
ForceCubesPlayed int
LevitateCubes int
BoostCubes int
LevitatePlayed bool
BoostCubes int
BoostCubesPlayed int
ForcePowerUp *PowerUp
BoostPowerUp *PowerUp
newlyPlayedPowerUp string
@@ -38,6 +40,7 @@ func (vault *Vault) UpdateButtons(forceButton, levitateButton, boostButton bool,
vault.ForcePowerUp = maybeActivatePowerUp(&PowerUp{Effect: Force, Alliance: vault.Alliance,
Level: vault.ForceCubes}, currentTime)
if vault.ForcePowerUp != nil {
vault.ForceCubesPlayed = vault.ForceCubes
vault.newlyPlayedPowerUp = "force"
}
}
@@ -46,6 +49,7 @@ func (vault *Vault) UpdateButtons(forceButton, levitateButton, boostButton bool,
vault.BoostPowerUp = maybeActivatePowerUp(&PowerUp{Effect: Boost, Alliance: vault.Alliance,
Level: vault.BoostCubes}, currentTime)
if vault.BoostPowerUp != nil {
vault.BoostCubesPlayed = vault.BoostCubes
vault.newlyPlayedPowerUp = "boost"
}
}

View File

@@ -47,6 +47,9 @@ func TestVaultNumCubes(t *testing.T) {
assert.Equal(t, 3, vault.ForceCubes)
assert.Equal(t, 3, vault.LevitateCubes)
assert.Equal(t, 3, vault.BoostCubes)
assert.Equal(t, 0, vault.ForceCubesPlayed)
assert.Equal(t, 0, vault.BoostCubesPlayed)
}
func TestVaultLevitate(t *testing.T) {
@@ -97,6 +100,8 @@ func TestVaultForce(t *testing.T) {
assert.Equal(t, Force, vault.ForcePowerUp.Effect)
assert.Equal(t, 1, vault.ForcePowerUp.Level)
}
vault.UpdateCubes(zeroCubeDistance, zeroCubeDistance, zeroCubeDistance)
assert.Equal(t, 1, vault.ForceCubesPlayed)
// Activation with two cubes.
vault = Vault{Alliance: RedAlliance}
@@ -107,7 +112,10 @@ func TestVaultForce(t *testing.T) {
assert.Equal(t, RedAlliance, vault.ForcePowerUp.Alliance)
assert.Equal(t, Force, vault.ForcePowerUp.Effect)
assert.Equal(t, 2, vault.ForcePowerUp.Level)
assert.Equal(t, 2, vault.ForceCubesPlayed)
}
vault.UpdateCubes(threeCubeDistance, zeroCubeDistance, zeroCubeDistance)
assert.Equal(t, 2, vault.ForceCubesPlayed)
// Activation with three cubes.
vault = Vault{Alliance: BlueAlliance}
@@ -120,6 +128,8 @@ func TestVaultForce(t *testing.T) {
assert.Equal(t, Force, vault.ForcePowerUp.Effect)
assert.Equal(t, 3, vault.ForcePowerUp.Level)
}
vault.UpdateCubes(zeroCubeDistance, zeroCubeDistance, zeroCubeDistance)
assert.Equal(t, 3, vault.ForceCubesPlayed)
vault.UpdateCubes(threeCubeDistance, zeroCubeDistance, zeroCubeDistance)
vault.UpdateButtons(false, false, false, time.Now())
@@ -146,6 +156,8 @@ func TestVaultBoost(t *testing.T) {
assert.Equal(t, Boost, vault.BoostPowerUp.Effect)
assert.Equal(t, 1, vault.BoostPowerUp.Level)
}
vault.UpdateCubes(zeroCubeDistance, twoCubeDistance, zeroCubeDistance)
assert.Equal(t, 1, vault.BoostCubesPlayed)
// Activation with two cubes.
vault = Vault{Alliance: RedAlliance}
@@ -157,6 +169,8 @@ func TestVaultBoost(t *testing.T) {
assert.Equal(t, Boost, vault.BoostPowerUp.Effect)
assert.Equal(t, 2, vault.BoostPowerUp.Level)
}
vault.UpdateCubes(zeroCubeDistance, zeroCubeDistance, zeroCubeDistance)
assert.Equal(t, 2, vault.BoostCubesPlayed)
// Activation with three cubes.
vault = Vault{Alliance: BlueAlliance}
@@ -169,6 +183,8 @@ func TestVaultBoost(t *testing.T) {
assert.Equal(t, Boost, vault.BoostPowerUp.Effect)
assert.Equal(t, 3, vault.BoostPowerUp.Level)
}
vault.UpdateCubes(zeroCubeDistance, zeroCubeDistance, zeroCubeDistance)
assert.Equal(t, 3, vault.BoostCubesPlayed)
vault.UpdateCubes(zeroCubeDistance, zeroCubeDistance, threeCubeDistance)
vault.UpdateButtons(false, false, false, time.Now())

View File

@@ -10,6 +10,7 @@ import (
"crypto/md5"
"encoding/json"
"fmt"
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"io/ioutil"
"net/http"
@@ -40,43 +41,44 @@ type TbaMatch struct {
}
type TbaScoreBreakdown struct {
AutoFuelHigh int `json:"autoFuelHigh"`
AutoFuelLow int `json:"autoFuelLow"`
AutoFuelPoints int `json:"autoFuelPoints"`
Rotor1Auto bool `json:"rotor1Auto"`
Rotor2Auto bool `json:"rotor2Auto"`
AutoRotorPoints int `json:"autoRotorPoints"`
AutoMobilityPoints int `json:"autoMobilityPoints"`
AutoPoints int `json:"autoPoints"`
TeleopFuelHigh int `json:"teleopFuelHigh"`
TeleopFuelLow int `json:"teleopFuelLow"`
TeleopFuelPoints int `json:"teleopFuelPoints"`
Rotor1Engaged bool `json:"rotor1Engaged"`
Rotor2Engaged bool `json:"rotor2Engaged"`
Rotor3Engaged bool `json:"rotor3Engaged"`
Rotor4Engaged bool `json:"rotor4Engaged"`
TeleopRotorPoints int `json:"teleopRotorPoints"`
TeleopTakeoffPoints int `json:"teleopTakeoffPoints"`
TeleopPoints int `json:"teleopPoints"`
KPaRankingPointAchieved bool `json:"kPaRankingPointAchieved"`
KPaBonusPoints int `json:"kPaBonusPoints"`
RotorRankingPointAchieved bool `json:"rotorRankingPointAchieved"`
RotorBonusPoints int `json:"rotorBonusPoints"`
FoulPoints int `json:"foulPoints"`
TotalPoints int `json:"totalPoints"`
AutoRunPoints int `json:"autoRunPoints"`
AutoScaleOwnershipSec int `json:"autoScaleOwnershipSec"`
AutoSwitchOwnershipSec int `json:"autoSwitchOwnershipSec"`
AutoOwnershipPoints int `json:"autoOwnershipPoints"`
AutoPoints int `json:"autoPoints"`
TeleopScaleOwnershipSec int `json:"teleopScaleOwnershipSec"`
TeleopScaleBoostSec int `json:"teleopScaleBoostSec"`
TeleopSwitchOwnershipSec int `json:"teleopSwitchOwnershipSec"`
TeleopSwitchBoostSec int `json:"teleopSwitchBoostSec"`
TeleopOwnershipPoints int `json:"teleopOwnershipPoints"`
VaultForceTotal int `json:"vaultForceTotal"`
VaultForcePlayed int `json:"vaultForcePlayed"`
VaultLevitateTotal int `json:"vaultLevitateTotal"`
VaultLevitatePlayed int `json:"vaultLevitatePlayed"`
VaultBoostTotal int `json:"vaultBoostTotal"`
VaultBoostPlayed int `json:"vaultBoostPlayed"`
VaultPoints int `json:"vaultPoints"`
EndgamePoints int `json:"endgamePoints"`
TeleopPoints int `json:"teleopPoints"`
AutoQuestRankingPoint bool `json:"autoQuestRankingPoint"`
FaceTheBossRankingPoint bool `json:"faceTheBossRankingPoint"`
FoulPoints int `json:"foulPoints"`
TotalPoints int `json:"totalPoints"`
RP int `json:"rp"`
TbaGameData string `json:"tba_gameData"`
}
type TbaRanking struct {
TeamKey string `json:"team_key"`
Rank int `json:"rank"`
RP float32 `json:"RP"`
TeamKey string `json:"team_key"`
Rank int `json:"rank"`
RP float32
ParkClimb int
Auto int
Ownership int
Vault int
WinLossTie string `json:"W-L-T"`
Dqs int `json:"dqs"`
Played int `json:"played"`
WinLossTie string
Dqs int `json:"dqs"`
Played int `json:"played"`
}
type TbaRankings struct {
@@ -295,7 +297,7 @@ func (client *TbaClient) PublishRankings(database *model.Database) error {
}
// Build a JSON object of TBA-format rankings.
breakdowns := []string{"RP", "Match", "Auto", "Rotor", "Touchpad", "Pressure", "W-L-T"}
breakdowns := []string{"RP", "ParkClimb", "Auto", "Ownership", "Vault", "WinLossTie"}
tbaRankings := make([]TbaRanking, len(rankings))
for i, ranking := range rankings {
tbaRankings[i] = TbaRanking{getTbaTeam(ranking.TeamId), ranking.Rank,
@@ -425,51 +427,50 @@ func (client *TbaClient) postRequest(resource string, action string, body []byte
func createTbaScoringBreakdown(match *model.Match, matchResult *model.MatchResult, alliance string) *TbaScoreBreakdown {
var breakdown TbaScoreBreakdown
// TODO(patrick): Implement for 2018.
/*
var score *game.Score
var scoreSummary *game.ScoreSummary
if alliance == "red" {
score = matchResult.RedScore
scoreSummary = matchResult.RedScoreSummary()
} else {
score = matchResult.BlueScore
scoreSummary = matchResult.BlueScoreSummary()
}
var score *game.Score
var scoreSummary, opponentScoreSummary *game.ScoreSummary
if alliance == "red" {
score = matchResult.RedScore
scoreSummary = matchResult.RedScoreSummary()
opponentScoreSummary = matchResult.BlueScoreSummary()
} else {
score = matchResult.BlueScore
scoreSummary = matchResult.BlueScoreSummary()
opponentScoreSummary = matchResult.RedScoreSummary()
}
breakdown.AutoRunPoints = 5 * score.AutoRuns
breakdown.AutoScaleOwnershipSec = int(score.AutoScaleOwnershipSec)
breakdown.AutoSwitchOwnershipSec = int(score.AutoSwitchOwnershipSec)
breakdown.AutoOwnershipPoints = scoreSummary.AutoOwnershipPoints
breakdown.AutoPoints = scoreSummary.AutoPoints
breakdown.TeleopScaleOwnershipSec = int(score.TeleopScaleOwnershipSec)
breakdown.TeleopScaleBoostSec = int(score.TeleopScaleBoostSec)
breakdown.TeleopSwitchOwnershipSec = int(score.TeleopSwitchOwnershipSec)
breakdown.TeleopSwitchBoostSec = int(score.TeleopSwitchBoostSec)
breakdown.TeleopOwnershipPoints = scoreSummary.TeleopOwnershipPoints
breakdown.VaultForceTotal = score.ForceCubes
breakdown.VaultForcePlayed = score.ForceCubesPlayed
breakdown.VaultLevitateTotal = score.LevitateCubes
if score.LevitatePlayed {
breakdown.VaultLevitatePlayed = score.LevitateCubes
}
breakdown.VaultBoostTotal = score.BoostCubes
breakdown.VaultBoostPlayed = score.BoostCubesPlayed
breakdown.VaultPoints = scoreSummary.VaultPoints
breakdown.EndgamePoints = scoreSummary.ParkClimbPoints
breakdown.TeleopPoints = scoreSummary.Score - scoreSummary.AutoPoints - scoreSummary.FoulPoints
breakdown.AutoQuestRankingPoint = scoreSummary.AutoQuest
breakdown.FaceTheBossRankingPoint = scoreSummary.FaceTheBoss
breakdown.FoulPoints = scoreSummary.FoulPoints
breakdown.TotalPoints = scoreSummary.Score
if match.Type == "qualification" {
// Calculate and set the ranking points for the match.
var ranking game.Ranking
ranking.AddScoreSummary(scoreSummary, opponentScoreSummary, false)
breakdown.RP = ranking.RankingPoints
}
breakdown.TbaGameData = match.GameSpecificData
breakdown.AutoFuelHigh = score.AutoFuelHigh
breakdown.AutoFuelLow = score.AutoFuelLow
breakdown.AutoFuelPoints = score.AutoFuelHigh + score.AutoFuelLow/3
breakdown.Rotor1Auto = score.AutoRotors >= 1
breakdown.Rotor2Auto = score.AutoRotors >= 2
breakdown.AutoRotorPoints = 60 * score.AutoRotors
breakdown.AutoMobilityPoints = scoreSummary.AutoMobilityPoints
breakdown.AutoPoints = scoreSummary.AutoPoints
breakdown.TeleopFuelHigh = score.FuelHigh
breakdown.TeleopFuelLow = score.FuelLow
breakdown.TeleopFuelPoints = scoreSummary.PressurePoints - breakdown.AutoFuelPoints
totalRotors := score.AutoRotors + score.Rotors
breakdown.Rotor1Engaged = totalRotors >= 1
breakdown.Rotor2Engaged = totalRotors >= 2
breakdown.Rotor3Engaged = totalRotors >= 3
breakdown.Rotor4Engaged = totalRotors >= 4
breakdown.TeleopRotorPoints = scoreSummary.RotorPoints - breakdown.AutoRotorPoints
breakdown.TeleopTakeoffPoints = scoreSummary.TakeoffPoints
breakdown.TeleopPoints = breakdown.TeleopFuelPoints + breakdown.TeleopRotorPoints +
breakdown.TeleopTakeoffPoints + scoreSummary.BonusPoints
if match.Type == "elimination" {
if scoreSummary.PressureGoalReached {
breakdown.KPaBonusPoints = 20
}
if scoreSummary.RotorGoalReached {
breakdown.RotorBonusPoints = 100
}
} else {
breakdown.KPaRankingPointAchieved = scoreSummary.PressureGoalReached
breakdown.RotorRankingPointAchieved = scoreSummary.RotorGoalReached
}
breakdown.FoulPoints = scoreSummary.FoulPoints
breakdown.TotalPoints = scoreSummary.Score
*/
return &breakdown
}

View File

@@ -33,16 +33,20 @@ var renderResults = function(alliance) {
// Set the values of the form fields from the JSON results data.
$("input[name=" + alliance + "AutoRuns]").val(result.score.AutoRuns);
$("input[name=" + alliance + "AutoOwnershipPoints]").val(result.score.AutoOwnershipPoints);
$("input[name=" + alliance + "AutoScaleOwnershipSec]").val(result.score.AutoScaleOwnershipSec);
$("input[name=" + alliance + "AutoSwitchOwnershipSec]").val(result.score.AutoSwitchOwnershipSec);
$("input[name=" + alliance + "AutoEndSwitchOwnership]").prop("checked", result.score.AutoEndSwitchOwnership);
$("input[name=" + alliance + "TeleopOwnershipPoints]").val(result.score.TeleopOwnershipPoints);
$("input[name=" + alliance + "TeleopScaleOwnershipSec]").val(result.score.TeleopScaleOwnershipSec);
$("input[name=" + alliance + "TeleopScaleBoostSec]").val(result.score.TeleopScaleBoostSec);
$("input[name=" + alliance + "TeleopSwitchOwnershipSec]").val(result.score.TeleopSwitchOwnershipSec);
$("input[name=" + alliance + "TeleopSwitchBoostSec]").val(result.score.TeleopSwitchBoostSec);
$("input[name=" + alliance + "ForceCubes]").val(result.score.ForceCubes);
$("input[name=" + alliance + "ForcePlayed]").prop("checked", result.score.ForcePlayed);
$("input[name=" + alliance + "ForceCubesPlayed]").val(result.score.ForceCubesPlayed);
$("input[name=" + alliance + "LevitateCubes]").val(result.score.LevitateCubes);
$("input[name=" + alliance + "LevitatePlayed]").prop("checked", result.score.LevitatePlayed);
$("input[name=" + alliance + "BoostCubes]").val(result.score.BoostCubes);
$("input[name=" + alliance + "BoostPlayed]").prop("checked", result.score.BoostPlayed);
$("input[name=" + alliance + "BoostCubesPlayed]").val(result.score.BoostCubesPlayed);
$("input[name=" + alliance + "Climbs]").val(result.score.Climbs);
$("input[name=" + alliance + "Parks]").val(result.score.Parks);
@@ -71,15 +75,19 @@ var updateResults = function(alliance) {
});
result.score.AutoRuns = parseInt(formData[alliance + "AutoRuns"]);
result.score.AutoOwnershipPoints = parseInt(formData[alliance + "AutoOwnershipPoints"]);
result.score.AutoScaleOwnershipSec = parseFloat(formData[alliance + "AutoScaleOwnershipSec"]);
result.score.AutoSwitchOwnershipSec = parseFloat(formData[alliance + "AutoSwitchOwnershipSec"]);
result.score.AutoEndSwitchOwnership = formData[alliance + "AutoEndSwitchOwnership"] === "on";
result.score.TeleopOwnershipPoints = parseInt(formData[alliance + "TeleopOwnershipPoints"]);
result.score.TeleopScaleOwnershipSec = parseFloat(formData[alliance + "TeleopScaleOwnershipSec"]);
result.score.TeleopScaleBoostSec = parseFloat(formData[alliance + "TeleopScaleBoostSec"]);
result.score.TeleopSwitchOwnershipSec = parseFloat(formData[alliance + "TeleopSwitchOwnershipSec"]);
result.score.TeleopSwitchBoostSec = parseFloat(formData[alliance + "TeleopSwitchBoostSec"]);
result.score.ForceCubes = parseInt(formData[alliance + "ForceCubes"]);
result.score.ForcePlayed = formData[alliance + "ForcePlayed"] === "on";
result.score.ForceCubesPlayed = parseInt(formData[alliance + "ForceCubesPlayed"]);
result.score.LevitateCubes = parseInt(formData[alliance + "LevitateCubes"]);
result.score.LevitatePlayed = formData[alliance + "LevitatePlayed"] === "on";
result.score.BoostCubes = parseInt(formData[alliance + "BoostCubes"]);
result.score.BoostPlayed = formData[alliance + "BoostPlayed"] === "on";
result.score.BoostCubesPlayed = parseInt(formData[alliance + "BoostCubesPlayed"]);
result.score.Climbs = parseInt(formData[alliance + "Climbs"]);
result.score.Parks = parseInt(formData[alliance + "Parks"]);

View File

@@ -28,6 +28,12 @@
<legend>Autonomous</legend>
<div class="form-group">
<div class="row">
<div class="col-lg-6">
<label class="col-lg-8 control-label">Scale Owned Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}AutoScaleOwnershipSec">
</div>
</div>
<div class="col-lg-6">
<label class="col-lg-8 control-label">Auto Runs</label>
<div class="col-lg-4">
@@ -37,9 +43,9 @@
</div>
<div class="row">
<div class="col-lg-6">
<label class="col-lg-8 control-label">Ownership Points</label>
<label class="col-lg-8 control-label">Switch Owned Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}AutoOwnershipPoints">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}AutoSwitchOwnershipSec">
</div>
</div>
<div class="col-lg-6">
@@ -54,9 +60,29 @@
<div class="form-group">
<div class="row">
<div class="col-lg-6">
<label class="col-lg-8 control-label">Ownership Points</label>
<label class="col-lg-8 control-label">Scale Owned Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopOwnershipPoints">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopScaleOwnershipSec">
</div>
</div>
<div class="col-lg-6">
<label class="col-lg-8 control-label">Scale Boost Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopScaleBoostSec">
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<label class="col-lg-8 control-label">Switch Owned Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopSwitchOwnershipSec">
</div>
</div>
<div class="col-lg-6">
<label class="col-lg-8 control-label">Switch Boost Sec.</label>
<div class="col-lg-4">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}TeleopSwitchBoostSec">
</div>
</div>
</div>
@@ -70,7 +96,7 @@
<div class="col-lg-6">
<label class="col-lg-9 control-label">Force Played</label>
<div class="col-lg-3">
<input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}ForcePlayed">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}ForceCubesPlayed">
</div>
</div>
</div>
@@ -98,7 +124,7 @@
<div class="col-lg-6">
<label class="col-lg-9 control-label">Boost Played</label>
<div class="col-lg-3">
<input type="checkbox" class="input-sm" name="{{"{{alliance}}"}}BoostPlayed">
<input type="text" class="form-control input-sm" name="{{"{{alliance}}"}}BoostCubesPlayed">
</div>
</div>
</div>

View File

@@ -94,7 +94,7 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
assert.Contains(t, recorder.Body.String(), "QF4-3")
// Update the score to something else.
postBody := "redScoreJson={\"AutoOwnershipPoints\":60}&blueScoreJson={\"VaultCubes\":2," +
postBody := "redScoreJson={\"AutoScaleOwnershipSec\":13}&blueScoreJson={\"ForceCubes\":2,\"BoostCubes\":1," +
"\"Fouls\":[{\"TeamId\":973,\"Rule\":\"G22\"}]}&redCardsJson={\"105\":\"yellow\"}&blueCardsJson={}"
recorder = web.postHttpResponse(fmt.Sprintf("/match_review/%d/edit", match.Id), postBody)
assert.Equal(t, 303, recorder.Code)
@@ -103,6 +103,6 @@ func TestMatchReviewCreateNewResult(t *testing.T) {
recorder = web.getHttpResponse("/match_review")
assert.Equal(t, 200, recorder.Code)
assert.Contains(t, recorder.Body.String(), "QF4-3")
assert.Contains(t, recorder.Body.String(), "65") // The red score
assert.Contains(t, recorder.Body.String(), "10") // The blue score
assert.Contains(t, recorder.Body.String(), "31") // The red score
assert.Contains(t, recorder.Body.String(), "15") // The blue score
}