squash! WIP: apply a coeff on given points

This commit is contained in:
nemunaire 2017-01-15 23:40:58 +01:00
parent da29071ad1
commit 1c879fe50e
5 changed files with 28 additions and 24 deletions

View file

@ -8,17 +8,18 @@ import (
var PartialValidation bool
type Exercice struct {
Id int64 `json:"id"`
Title string `json:"title"`
Statement string `json:"statement"`
Depend *int64 `json:"depend"`
Gain int64 `json:"gain"`
VideoURI string `json:"videoURI"`
Id int64 `json:"id"`
Title string `json:"title"`
Statement string `json:"statement"`
Depend *int64 `json:"depend"`
Gain int64 `json:"gain"`
Coefficient float64 `json:"coefficient"`
VideoURI string `json:"videoURI"`
}
func GetExercice(id int64) (Exercice, error) {
var e Exercice
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.VideoURI); err != nil {
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_exercice = ?", id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
return Exercice{}, err
}
@ -27,7 +28,7 @@ func GetExercice(id int64) (Exercice, error) {
func (t Theme) GetExercice(id int) (Exercice, error) {
var e Exercice
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.VideoURI); err != nil {
if err := DBQueryRow("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ? AND id_exercice = ?", t.Id, id).Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
return Exercice{}, err
}
@ -35,7 +36,7 @@ func (t Theme) GetExercice(id int) (Exercice, error) {
}
func GetExercices() ([]Exercice, error) {
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, video_uri FROM exercices"); err != nil {
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices"); err != nil {
return nil, err
} else {
defer rows.Close()
@ -43,7 +44,7 @@ func GetExercices() ([]Exercice, error) {
var exos = make([]Exercice, 0)
for rows.Next() {
var e Exercice
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.VideoURI); err != nil {
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
return nil, err
}
exos = append(exos, e)
@ -57,7 +58,7 @@ func GetExercices() ([]Exercice, error) {
}
func (t Theme) GetExercices() ([]Exercice, error) {
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
if rows, err := DBQuery("SELECT id_exercice, title, statement, depend, gain, coefficient_cur, video_uri FROM exercices WHERE id_theme = ?", t.Id); err != nil {
return nil, err
} else {
defer rows.Close()
@ -65,7 +66,7 @@ func (t Theme) GetExercices() ([]Exercice, error) {
var exos = make([]Exercice, 0)
for rows.Next() {
var e Exercice
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.VideoURI); err != nil {
if err := rows.Scan(&e.Id, &e.Title, &e.Statement, &e.Depend, &e.Gain, &e.Coefficient, &e.VideoURI); err != nil {
return nil, err
}
exos = append(exos, e)
@ -91,15 +92,15 @@ func (t Theme) AddExercice(title string, statement string, depend *Exercice, gai
return Exercice{}, err
} else {
if depend == nil {
return Exercice{eid, title, statement, nil, gain, videoURI}, nil
return Exercice{eid, title, statement, nil, gain, 1.0, videoURI}, nil
} else {
return Exercice{eid, title, statement, &depend.Id, gain, videoURI}, nil
return Exercice{eid, title, statement, &depend.Id, gain, 1.0, videoURI}, nil
}
}
}
func (e Exercice) Update() (int64, error) {
if res, err := DBExec("UPDATE exercices SET title = ?, statement = ?, depend = ?, gain = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Statement, e.Depend, e.Gain, e.VideoURI, e.Id); err != nil {
if res, err := DBExec("UPDATE exercices SET title = ?, statement = ?, depend = ?, gain = ?, coefficient_cur = ?, video_uri = ? WHERE id_exercice = ?", e.Title, e.Statement, e.Depend, e.Gain, e.Coefficient, e.VideoURI, e.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err
@ -157,7 +158,7 @@ func (e Exercice) NewTry(t Team) error {
}
func (e Exercice) Solved(t Team) error {
if _, err := DBExec("INSERT INTO exercice_solved (id_exercice, id_team, time) VALUES (?, ?, ?)", e.Id, t.Id, time.Now()); err != nil {
if _, err := DBExec("INSERT INTO exercice_solved (id_exercice, id_team, time, coefficient) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), e.Coefficient); err != nil {
return err
} else {
return nil