2018-01-09 14:16:16 +00:00
|
|
|
package fic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-11-25 02:20:03 +00:00
|
|
|
"path"
|
2018-12-02 15:24:33 +00:00
|
|
|
"strings"
|
2018-01-09 14:16:16 +00:00
|
|
|
)
|
|
|
|
|
2021-09-06 09:58:03 +00:00
|
|
|
var GlobalScoreCoefficient float64 = 1
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
// exportedExercice is a structure representing a challenge, as exposed to players.
|
|
|
|
type exportedExercice struct {
|
2018-12-02 10:43:24 +00:00
|
|
|
Title string `json:"title"`
|
|
|
|
Headline string `json:"headline,omitempty"`
|
|
|
|
URLId string `json:"urlid"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Gain int64 `json:"gain"`
|
|
|
|
Coeff float64 `json:"curcoeff"`
|
|
|
|
Solved int64 `json:"solved"`
|
|
|
|
Tried int64 `json:"tried"`
|
2018-01-09 14:16:16 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
// exportedTheme is a structure representing a Theme, as exposed to players.
|
2018-01-09 14:16:16 +00:00
|
|
|
type exportedTheme struct {
|
2021-09-01 08:15:26 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
URLId string `json:"urlid"`
|
|
|
|
Authors string `json:"authors"`
|
|
|
|
Headline string `json:"headline,omitempty"`
|
|
|
|
Intro string `json:"intro"`
|
|
|
|
Image string `json:"image,omitempty"`
|
|
|
|
PartnerImage string `json:"partner_img,omitempty"`
|
|
|
|
PartnerLink string `json:"partner_href,omitempty"`
|
|
|
|
PartnerText string `json:"partner_txt,omitempty"`
|
|
|
|
Exercices map[string]exportedExercice `json:"exercices"`
|
2018-01-09 14:16:16 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:07:08 +00:00
|
|
|
// Exportedthemes exports themes from the database, to be displayed to players.
|
2018-01-09 14:16:16 +00:00
|
|
|
func ExportThemes() (interface{}, error) {
|
|
|
|
if themes, err := GetThemes(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
ret := map[string]exportedTheme{}
|
|
|
|
for _, theme := range themes {
|
|
|
|
if exercices, err := theme.GetExercices(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
2018-03-09 18:07:08 +00:00
|
|
|
exos := map[string]exportedExercice{}
|
2018-01-09 14:16:16 +00:00
|
|
|
for _, exercice := range exercices {
|
2018-11-18 21:44:23 +00:00
|
|
|
tags, _ := exercice.GetTags()
|
2018-03-09 18:07:08 +00:00
|
|
|
exos[fmt.Sprintf("%d", exercice.Id)] = exportedExercice{
|
2018-01-09 14:16:16 +00:00
|
|
|
exercice.Title,
|
2018-12-02 10:43:24 +00:00
|
|
|
exercice.Headline,
|
2018-01-18 10:07:50 +00:00
|
|
|
exercice.URLId,
|
2018-11-18 21:44:23 +00:00
|
|
|
tags,
|
2021-09-06 09:58:03 +00:00
|
|
|
int64(float64(exercice.Gain) * GlobalScoreCoefficient),
|
2018-01-09 14:16:16 +00:00
|
|
|
exercice.Coefficient,
|
|
|
|
exercice.SolvedCount(),
|
|
|
|
exercice.TriedTeamCount(),
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 02:20:03 +00:00
|
|
|
|
|
|
|
imgpath := ""
|
|
|
|
if len(theme.Image) > 0 {
|
|
|
|
imgpath = path.Join(FilesDir, theme.Image)
|
|
|
|
}
|
|
|
|
|
2021-09-01 08:15:26 +00:00
|
|
|
partnerImgpath := ""
|
|
|
|
if len(theme.PartnerImage) > 0 {
|
|
|
|
partnerImgpath = path.Join(FilesDir, theme.PartnerImage)
|
|
|
|
}
|
|
|
|
|
2018-01-09 14:16:16 +00:00
|
|
|
ret[fmt.Sprintf("%d", theme.Id)] = exportedTheme{
|
|
|
|
theme.Name,
|
2018-01-18 10:07:50 +00:00
|
|
|
theme.URLId,
|
2018-01-09 14:16:16 +00:00
|
|
|
theme.Authors,
|
2018-12-02 10:43:24 +00:00
|
|
|
theme.Headline,
|
2018-12-02 15:24:33 +00:00
|
|
|
strings.Replace(theme.Intro, "$FILES$", FilesDir, -1),
|
2018-11-25 02:20:03 +00:00
|
|
|
imgpath,
|
2021-09-01 08:15:26 +00:00
|
|
|
partnerImgpath,
|
|
|
|
theme.PartnerLink,
|
|
|
|
theme.PartnerText,
|
2018-01-09 14:16:16 +00:00
|
|
|
exos,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
}
|