sync: Extract function that import flags from importer

This commit is contained in:
nemunaire 2019-07-05 22:28:56 +02:00
commit 4039a394b5
8 changed files with 438 additions and 294 deletions

View file

@ -20,35 +20,35 @@ var ExerciceCurrentCoefficient = 1.0
// Exercice represents a challenge inside a Theme.
type Exercice struct {
Id int64 `json:"id"`
IdTheme int64 `json:"id_theme"`
Title string `json:"title"`
Id int64 `json:"id"`
IdTheme int64 `json:"id_theme"`
Title string `json:"title"`
// URLid is used to reference the challenge from the URL path
URLId string `json:"urlid"`
URLId string `json:"urlid"`
// Path is the relative import location where find challenge data
Path string `json:"path"`
Path string `json:"path"`
// Statement is the challenge description shown to players
Statement string `json:"statement"`
Statement string `json:"statement"`
// Overview is the challenge description shown to public
Overview string `json:"overview"`
Overview string `json:"overview"`
// Headline is the challenge headline to fill in small part
Headline string `json:"headline"`
Headline string `json:"headline"`
// Finished is the text shown when the exercice is solved
Finished string `json:"finished"`
Finished string `json:"finished"`
// Issue is an optional text describing an issue with the exercice
Issue string `json:"issue"`
Issue string `json:"issue"`
// IssueKind is the criticity level of the previous issue
IssueKind string `json:"issuekind"`
Depend *int64 `json:"depend"`
IssueKind string `json:"issuekind"`
Depend *int64 `json:"depend"`
// Gain is the basis amount of points player will earn if it solve the challenge
// If this value fluctuate during the challenge, players' scores will follow changes.
// Use Coefficient value to create temporary bonus/malus.
Gain int64 `json:"gain"`
Gain int64 `json:"gain"`
// Coefficient is a temporary bonus/malus applied on Gain when the challenge is solved.
// This value is saved along with solved informations: changing it doesn't affect Team that already solved the challenge.
Coefficient float64 `json:"coefficient"`
// VideoURI is the link to the resolution video
VideoURI string `json:"videoURI"`
VideoURI string `json:"videoURI"`
}
// GetExercice retrieves the challenge with the given id.
@ -163,7 +163,7 @@ func (t Theme) addExercice(e *Exercice) (err error) {
cc = fmt.Sprintf("%f", e.Coefficient)
}
if res, err := DBExec("INSERT INTO exercices (id_theme, title, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " + ik + ", " + cc + ")", t.Id, e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI); err != nil {
if res, err := DBExec("INSERT INTO exercices (id_theme, title, url_id, path, statement, overview, finished, headline, issue, depend, gain, video_uri, issue_kind, coefficient_cur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "+ik+", "+cc+")", t.Id, e.Title, e.URLId, e.Path, e.Statement, e.Overview, e.Finished, e.Headline, e.Issue, e.Depend, e.Gain, e.VideoURI); err != nil {
return err
} else if eid, err := res.LastInsertId(); err != nil {
return err
@ -182,16 +182,16 @@ func (t Theme) AddExercice(title string, urlId string, path string, statement st
}
e = Exercice{
Title: title,
URLId: urlId,
Path: path,
Title: title,
URLId: urlId,
Path: path,
Statement: statement,
Overview: overview,
Headline: headline,
Depend: dpd,
Finished: finished,
Gain: gain,
VideoURI: videoURI,
Overview: overview,
Headline: headline,
Depend: dpd,
Finished: finished,
Gain: gain,
VideoURI: videoURI,
}
err = t.addExercice(&e)
@ -313,7 +313,7 @@ func (e Exercice) UpdateTry(t Team, nbdiff int) error {
// Solved registers that the given Team solves the challenge.
func (e Exercice) Solved(t Team) error {
if _, err := DBExec("INSERT INTO exercice_solved (id_exercice, id_team, time, coefficient) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), e.Coefficient * ExerciceCurrentCoefficient); err != nil {
if _, err := DBExec("INSERT INTO exercice_solved (id_exercice, id_team, time, coefficient) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), e.Coefficient*ExerciceCurrentCoefficient); err != nil {
return err
} else {
return nil
@ -338,7 +338,7 @@ func (e Exercice) TriedTeamCount() int64 {
}
var nb int64
if err := DBQueryRow("SELECT COUNT(DISTINCT id_team) FROM " + tries_table + " WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
if err := DBQueryRow("SELECT COUNT(DISTINCT id_team) FROM "+tries_table+" WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
return 0
} else {
return nb
@ -353,7 +353,7 @@ func (e Exercice) TriedCount() int64 {
}
var nb int64
if err := DBQueryRow("SELECT COUNT(id_team) FROM " + tries_table + " WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
if err := DBQueryRow("SELECT COUNT(id_team) FROM "+tries_table+" WHERE id_exercice = ?", e.Id).Scan(&nb); err != nil {
return 0
} else {
return nb