Skip to content

Commit

Permalink
fix: rejudge for rejudge, not empty; less verdicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gornak40 committed Feb 22, 2024
1 parent 903416c commit 70627a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
| [boban](#boban) | filter runs | 🦍 | ||
| [casper](#casper) | change visibility | 🦍 | ||
| [ejik](#ejik) | commit + check + reload | 🦍 | ||
| [ripper](#ripper) | change runs status | 🦍 | ||
| [scalp](#scalp) | incremental scoring | | 🦍 ||
| [valeria](#valeria) | valuer.cfg + tex scoring | | 🦍 ||
| 👻 | change runs status | 🦍 | | 🧑‍💻 |
| 👻 | list/commit problems | | 🦍 | 🧑‍💻 |
| 👻 | regexp problem upload | | 🦍 | 🤔 |
| 👻 | download/upload package | | 🦍 | 🤔 |
Expand Down Expand Up @@ -65,7 +65,7 @@ Put your config file in `~/.config/algolymp/config.json`.
2. Commit changes;
3. *(Optional)* Open contest xml config for editing.

Useful before running `polygon-to-ejudge`.
Useful before running [polygon-to-ejudge](https://github.com/grphil/polygon-to-ejudge).

### Flags
- `-i` - new contest id (required)
Expand Down Expand Up @@ -123,7 +123,7 @@ boban -i 50014 -c 10000 2> /dev/null | wc -l
- Make contest visible;
- Make contest invisible.

Useful with bash `for` loop after the end of the year.
Useful with bash `for` loop at the end of the year.

### Flags
- `-i` - contest id (required)
Expand Down Expand Up @@ -153,7 +153,9 @@ for i in {41014..41023}; do casper -i $i; done
2. Check contest settings;
3. Reload config files.

Useful after running `polygon-to-ejudge`.
Useful after running [polygon-to-ejudge](https://github.com/grphil/polygon-to-ejudge).

Feel free to use it after every change

### Flags
- `-i` - contest id (required)
Expand All @@ -180,9 +182,13 @@ ejik -i 40507

Change runs status. Designed to work with [boban](#boban) or with raw ids from `stdin`.

**Be careful** using it, double check the [parameters](https://ejudge.ru/wiki/index.php/%D0%92%D0%B5%D1%80%D0%B4%D0%B8%D0%BA%D1%82%D1%8B_%D1%82%D0%B5%D1%81%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F).

`RJ` is reject, not rejudge. Use `rejudge` status for rejudge.

### Flags
- `-i` - contest id (required)
- `-s` - new status (default: rejudge)
- `-s` - new status (required, `DQ|IG|OK|PR|RJ|SM|SV|rejudge`)

### Config
- `ejudge.url`
Expand All @@ -193,11 +199,11 @@ Change runs status. Designed to work with [boban](#boban) or with raw ids from `

```bash
ripper --help
ripper -i 51023 -s RJ
cat banlist.txt | ripper -i 47110 -s DQ
boban -i 52010 -f "prob == 'D' && score >= 50" -c 10000 | ripper -i 52010
boban -i 50014 -f "login == 'barmaley' && status == PR" | ripper -i 50014 -s SM
boban -i 48001 -f "status == PR" -c 2000 | ripper -i 48001 -s OK
ripper -i 51023 -s RJ # read from stdin
cat banlist.txt | ripper -i 47110 -s DQ # ban submits with list
boban -i 52010 -f "prob == 'D' && score >= 50" -c 10000 | ripper -i 52010 -s rejudge # rejudge incorrect group
boban -i 50014 -f "login == 'barmaley' && status == OK" | ripper -i 50014 -s SM # torture a participant
boban -i 48001 -f "status == PR" -c 2000 | ripper -i 48001 -s OK # smart code-review
```

![ripper logo](https://algolymp.ru/static/img/ripper.png)
Expand Down
15 changes: 11 additions & 4 deletions cmd/ripper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"sort"

"github.com/Gornak40/algolymp/config"
"github.com/Gornak40/algolymp/ejudge"
Expand All @@ -13,14 +14,20 @@ import (
)

func main() {
parser := argparse.NewParser("ripper", "Change Ejudge runs status.")
verdicts := make([]string, 0, len(ejudge.Verdicts))
for v := range ejudge.Verdicts {
verdicts = append(verdicts, v)
}
sort.Strings(verdicts)

parser := argparse.NewParser("ripper", "Change Ejudge runs status (stdin input).")
cID := parser.Int("i", "cid", &argparse.Options{
Required: true,
Help: "Ejudge contest ID",
})
status := parser.Selector("s", "status", ejudge.Verdicts, &argparse.Options{
Required: false,
Help: "New runs status (rejudge if not set)",
status := parser.Selector("s", "status", verdicts, &argparse.Options{
Required: true,
Help: "New runs status",
})
if err := parser.Parse(os.Args); err != nil {
logrus.WithError(err).Fatal("bad arguments")
Expand Down
37 changes: 18 additions & 19 deletions ejudge/ejudge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,31 @@ import (
"net/http/cookiejar"
"net/url"
"regexp"
"slices"
"strconv"

"github.com/PuerkitoBio/goquery"
"github.com/sirupsen/logrus"
)

const (
BadSID = "0000000000000000"
DefaultRunStatus = 99 // rejudge
)
const BadSID = "0000000000000000"

var (
ErrParseMasterSID = errors.New("can't parse master SID")
ErrBadStatusCode = errors.New("bad status code")
ErrUnknownRunStatus = errors.New("unknown run status")
ErrBadFilter = errors.New("bad filter expression")
ErrParseMasterSID = errors.New("can't parse master SID")
ErrBadStatusCode = errors.New("bad status code")
ErrBadFilter = errors.New("bad filter expression")
ErrUnknownVerdict = errors.New("unknown verdict")
)

//nolint:gochecknoglobals // Ejudge constants
var Verdicts = []string{
"OK", "CE", "RT", "TL", "PE", "WA", "CF", "PT", "AC", "IG",
"DQ", "PD", "ML", "SE", "SV", "WT", "PR", "RJ", "SM",
//nolint:gochecknoglobals,gomnd // ejudge constants
var Verdicts = map[string]int{
"OK": 0,
"IG": 9,
"DQ": 10,
"SV": 14,
"PR": 16,
"RJ": 17,
"SM": 23,
"rejudge": 99,
}

type Config struct {
Expand Down Expand Up @@ -137,12 +139,9 @@ func (ej *Ejudge) Commit(sid string) error {
}

func (ej *Ejudge) ChangeRunStatus(csid string, runID int, status string) error {
idx := DefaultRunStatus
if status != "" {
idx = slices.Index(Verdicts, status)
if idx == -1 {
return fmt.Errorf("%w: %s", ErrUnknownRunStatus, status)
}
idx, ok := Verdicts[status]
if !ok {
return fmt.Errorf("%w: %s", ErrUnknownVerdict, status)
}
_, _, err := ej.postRequest("new-master", url.Values{
"SID": {csid},
Expand Down

0 comments on commit 70627a7

Please sign in to comment.