Skip to content

Commit

Permalink
chore: textables refactor + bump go/linter versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed May 30, 2024
1 parent 371cbe1 commit 3aa9f7d
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
version: v1.59

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
12 changes: 2 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ linters:
enable-all: true
disable:
- gofumpt
- varcheck
- nosnakecase
- interfacer
- scopelint
- exhaustivestruct
- maligned
- structcheck
- ifshort
- deadcode
- golint
- depguard
- wsl
- wrapcheck
- exhaustruct
- execinquery
- gomnd
- godox

linters-settings:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| [valeria](#valeria) | valuer.cfg + tex scoring | | 🦍 ||
| [wooda](#wooda) | glob problem files upload | | 🦍 | 🧑‍💻 |
| ⚙️ | move json config to ini | | | 🧑‍💻 |
| 👻 | jq alternative for serve.cfg | 🦍 | | 🤔 |
| 👻 | list/commit problems | | 🦍 | 🤔 |
| 👻 | set good random group scores | | 🦍 | 🤔 |
| 👻 | generate hasher solution for `.a` | | 🦍 | 🤔 |
Expand Down Expand Up @@ -259,6 +260,8 @@ Thanks to Mike, it's been working fast since 30.01.2024.
### Flags
- `-i` - problem id (required)
- `-v` - print valuer.cfg in stderr
- `-t` - textable type (universal | moscow, default: universal)
- `-c` - depvars count, useful for some textables (default: 0)

### Config
- `polygon.url`
Expand All @@ -271,6 +274,7 @@ valeria --help
valeria -i 288808 -v
valeria -i 318511 > scoring.tex
valeria -i 318882 | bat -l tex
valeria -i 285375 -t moscow
```

![valeria logo](https://algolymp.ru/static/img/valeria.png)
Expand Down
23 changes: 18 additions & 5 deletions cmd/valeria/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/sirupsen/logrus"
)

const (
universalTag = "universal"
moscowTag = "moscow"
)

var (
ErrUnknownTexTable = errors.New("unknown textable")
)
Expand All @@ -27,12 +32,13 @@ func main() {
Required: false,
Help: "Print valuer.cfg in stderr",
})
tableTyp := parser.Selector("t", "table-type", []string{
textables.UniversalTag,
tableTyp := parser.Selector("t", "textable-type", []string{
universalTag,
moscowTag,
}, &argparse.Options{
Required: false,
Default: textables.UniversalTag,
Help: "Tex table type",
Default: universalTag,
Help: "Textable type",
})
cntVars := parser.Int("c", "count-depvars", &argparse.Options{
Required: false,
Expand All @@ -47,7 +53,14 @@ func main() {
pClient := polygon.NewPolygon(&cfg.Polygon)
val := valeria.NewValeria(pClient)

table := textables.GetTexTable(*tableTyp, *cntVars)
logrus.WithFields(logrus.Fields{"type": *tableTyp, "vars": *cntVars}).Info("select textable")
var table textables.Table
switch *tableTyp {
case universalTag:
table = new(textables.UniversalTable)
case moscowTag:
table = textables.NewMoscowTable(*cntVars)
}
if table == nil {
logrus.WithError(ErrUnknownTexTable).Fatal("failed to get textable")
}
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"encoding/json"
"fmt"
"os"

"github.com/Gornak40/algolymp/ejudge"
Expand All @@ -22,7 +21,7 @@ type Config struct {

func NewConfig() *Config {
confDir, _ := os.UserHomeDir()
path := fmt.Sprintf("%s/.config/algolymp/config.json", confDir)
path := confDir + "/.config/algolymp/config.json"
data, err := os.ReadFile(path)
if err != nil {
logrus.WithError(err).Fatal("failed to read config")
Expand Down
2 changes: 1 addition & 1 deletion ejudge/ejudge.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
ErrUnknownVerdict = errors.New("unknown verdict")
)

//nolint:gochecknoglobals,gomnd // ejudge constants
//nolint:gochecknoglobals,mnd // ejudge constants
var Verdicts = map[string]int{
"OK": 0,
"IG": 9,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Gornak40/algolymp

go 1.20
go 1.22

require (
github.com/PuerkitoBio/goquery v1.8.1
Expand Down
56 changes: 56 additions & 0 deletions polygon/valeria/textables/moscow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package textables

import (
"fmt"
"strings"
)

// If cntVars != 0 works only in PDF render.
// Otherwise works both in HTML and PDF render.
type MoscowTable struct {
groups []string
cntVars int
}

var _ Table = &MoscowTable{}

func NewMoscowTable(cntVars int) *MoscowTable {
return &MoscowTable{
cntVars: cntVars,
}
}

func (t *MoscowTable) AddGroup(info GroupInfo) {
var comment, limits string
if info.Type == Group0 {
comment = "Тесты из условия."
}
row := fmt.Sprintf("%s & %d & %s & %s & %s \\\\ \\hline",
info.Name,
info.Score,
limits,
strings.Join(info.Dependencies, ", "),
comment,
)
t.groups = append(t.groups, row)
}

func (t *MoscowTable) String() string {
table := []string{
"\\begin{center}",
"\\renewcommand{\\arraystretch}{1.5}",
"\\begin{tabular}{|c|c|c|c|c|}",
"\\hline",
"Группа",
"& Баллы",
"& Доп. ограничения",
"& Необх. группы",
"& Комментарий",
"\\\\",
"\\hline",
}
table = append(table, t.groups...)
table = append(table, "\\end{tabular}", "\\end{center}")

return strings.Join(table, "\n")
}
25 changes: 9 additions & 16 deletions polygon/valeria/textables/table.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package textables

import "github.com/sirupsen/logrus"
type GroupType int

const (
Group0 GroupType = iota
GroupRegular
GroupLast
)

type GroupInfo struct {
Group string
Name string
Score int
Dependencies []string
Type GroupType
}

type Table interface {
AddGroup0(info GroupInfo)
AddGroup(info GroupInfo)
AddLastGroup(info GroupInfo)

String() string
}

func GetTexTable(tableTyp string, cntVars int) Table { //nolint:ireturn
logrus.WithFields(logrus.Fields{"type": tableTyp, "vars": cntVars}).Info("select textable")

switch tableTyp {
case UniversalTag:
return &UniversalTable{}
default:
return nil
}
}
30 changes: 11 additions & 19 deletions polygon/valeria/textables/universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,31 @@ import (
"strings"
)

const (
UniversalTag = "universal"
)

// Works both in HTML and PDF render.
type UniversalTable struct {
groups []string
}

var _ Table = &UniversalTable{}

func (t *UniversalTable) addGroupRow(info GroupInfo, comment string) {
func (t *UniversalTable) AddGroup(info GroupInfo) {
var limits string
switch info.Type {
case Group0:
limits = "тесты из условия"
case GroupLast:
limits = "---"
case GroupRegular:
}
row := fmt.Sprintf("%s & %d & %s & %s \\\\ \\hline",
info.Group,
info.Name,
info.Score,
comment,
limits,
strings.Join(info.Dependencies, ", "),
)
t.groups = append(t.groups, row)
}

func (t *UniversalTable) AddGroup0(info GroupInfo) {
t.addGroupRow(info, "тесты из условия")
}

func (t *UniversalTable) AddGroup(info GroupInfo) {
t.addGroupRow(info, "")
}

func (t *UniversalTable) AddLastGroup(info GroupInfo) {
t.addGroupRow(info, "---")
}

func (t *UniversalTable) String() string {
table := []string{
"\\begin{center}",
Expand Down
17 changes: 9 additions & 8 deletions polygon/valeria/valeria.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func newScoring(tests []polygon.TestAnswer, groups []polygon.GroupAnswer) (*scor
dependencies: map[string][]string{},
}
for _, test := range tests {
scorer.score[test.Group] += int(test.Points) // TODO: ensure ejudge doesn't support float points
scorer.score[test.Group] += int(test.Points)
scorer.count[test.Group]++
if val, ok := scorer.first[test.Group]; !ok || val > test.Index {
scorer.first[test.Group] = test.Index
Expand Down Expand Up @@ -82,20 +82,21 @@ func (s *scoring) buildValuer() string {
}

func (s *scoring) buildScoring(table textables.Table) {
for index, group := range s.groups {
for index, groupName := range s.groups {
info := textables.GroupInfo{
Group: group,
Score: s.score[group],
Dependencies: s.dependencies[group],
Name: groupName,
Score: s.score[groupName],
Dependencies: s.dependencies[groupName],
}
switch index {
case 0:
table.AddGroup0(info)
info.Type = textables.Group0
case len(s.groups) - 1:
table.AddLastGroup(info)
info.Type = textables.GroupLast
default:
table.AddGroup(info)
info.Type = textables.GroupRegular
}
table.AddGroup(info)
}
}

Expand Down

0 comments on commit 3aa9f7d

Please sign in to comment.