Add pre-scouting support in the scouting database
This patch prepares the database to accept pre-scouted data. A future
patch will make sure pre-scouted data gets entered into the database.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Id8967468c2e78b4826a7eb3481e98c7bef158a9c
diff --git a/scouting/db/db.go b/scouting/db/db.go
index 031f54c..1282638 100644
--- a/scouting/db/db.go
+++ b/scouting/db/db.go
@@ -28,6 +28,11 @@
}
type Stats2023 struct {
+ // This is set to `true` for "pre-scouted" matches. This means that the
+ // match information is unlikely to correspond with an entry in the
+ // `TeamMatch` table.
+ PreScouting bool `gorm:"primaryKey"`
+
TeamNumber string `gorm:"primaryKey"`
MatchNumber int32 `gorm:"primaryKey"`
SetNumber int32 `gorm:"primaryKey"`
@@ -50,6 +55,7 @@
}
type Action struct {
+ PreScouting bool `gorm:"primaryKey"`
TeamNumber string `gorm:"primaryKey"`
MatchNumber int32 `gorm:"primaryKey"`
SetNumber int32 `gorm:"primaryKey"`
@@ -155,28 +161,30 @@
}
func (database *Database) AddAction(a Action) error {
- result := database.Clauses(clause.OnConflict{
- UpdateAll: true,
- }).Create(&a)
+ // TODO(phil): Add check for a corresponding match in the `TeamMatch`
+ // table. Similar to `AddToStats2023()` below.
+ result := database.Create(&a)
return result.Error
}
func (database *Database) AddToStats2023(s Stats2023) error {
- matches, err := database.QueryMatchesString(s.TeamNumber)
- if err != nil {
- return err
- }
- foundMatch := false
- for _, match := range matches {
- if match.MatchNumber == s.MatchNumber {
- foundMatch = true
- break
+ if !s.PreScouting {
+ matches, err := database.QueryMatchesString(s.TeamNumber)
+ if err != nil {
+ return err
}
- }
- if !foundMatch {
- return errors.New(fmt.Sprint(
- "Failed to find team ", s.TeamNumber,
- " in match ", s.MatchNumber, " in the schedule."))
+ foundMatch := false
+ for _, match := range matches {
+ if match.MatchNumber == s.MatchNumber {
+ foundMatch = true
+ break
+ }
+ }
+ if !foundMatch {
+ return errors.New(fmt.Sprint(
+ "Failed to find team ", s.TeamNumber,
+ " in match ", s.MatchNumber, " in the schedule."))
+ }
}
result := database.Create(&s)