Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.1.0 #17

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
df12033
fix: pinyin
GalvinGao Aug 29, 2023
d3b445d
feat: add `userimport` scripts
GalvinGao Aug 29, 2023
b918720
feat: add `@authenticated`
GalvinGao Aug 29, 2023
0e4e72d
fix(deps): update module github.com/gofiber/fiber/v2 to v2.49.0
renovate[bot] Aug 29, 2023
e6de3a5
fix(deps): update module github.com/antonmedv/expr to v1.15.0
renovate[bot] Aug 31, 2023
a9c96d2
Merge pull request #18 from penguin-statistics/renovate/github.com-an…
GalvinGao Aug 31, 2023
8193969
Merge pull request #14 from penguin-statistics/renovate/github.com-go…
GalvinGao Aug 31, 2023
f75f87e
feat: use `ent` to generate graphql; add jsonpb support to filter
GalvinGao Aug 31, 2023
2459ef5
fix(deps): update module github.com/gofiber/fiber/v2 to v2.49.1
renovate[bot] Sep 2, 2023
5b80529
chore(deps): update actions/checkout action to v4
renovate[bot] Sep 4, 2023
ca646b2
Merge pull request #20 from penguin-statistics/renovate/actions-check…
GalvinGao Sep 4, 2023
8ff8660
fix(deps): update module golang.org/x/crypto to v0.13.0
renovate[bot] Sep 5, 2023
3750feb
Merge pull request #21 from penguin-statistics/renovate/golang.org-x-…
GalvinGao Sep 5, 2023
8d018ef
Merge pull request #19 from penguin-statistics/renovate/github.com-go…
GalvinGao Sep 5, 2023
d24ee56
fix(deps): update module github.com/antonmedv/expr to v1.15.1
renovate[bot] Sep 6, 2023
4e70676
Merge pull request #22 from penguin-statistics/renovate/github.com-an…
GalvinGao Sep 6, 2023
752b88d
chore(deps): update golang docker tag to v1.21.1
renovate[bot] Sep 6, 2023
fdd4d5d
Merge pull request #23 from penguin-statistics/renovate/golang-1.x
GalvinGao Sep 7, 2023
fd78103
chore: move schema location
GalvinGao Sep 8, 2023
5f42fbb
feat: improve escaping & quoting of identifiers & literals in jsonpb
GalvinGao Sep 8, 2023
8104d22
feat: add full schema output generator
GalvinGao Sep 8, 2023
c6dbbe4
feat: cleanup predicates
GalvinGao Sep 8, 2023
6376806
feat: improve groupCount input
GalvinGao Sep 9, 2023
4f5203f
fix: setschema
GalvinGao Sep 15, 2023
35adcce
fix: setname
GalvinGao Sep 15, 2023
b881579
chore: change json schema name to chinese and add node_surrounding sc…
AlvISsReimu Sep 16, 2023
b79f29a
fix: should add up totalCount instead of using length directly
AlvISsReimu Sep 16, 2023
9a9fd91
fix: use more clear variable name
AlvISsReimu Sep 16, 2023
15b919f
chore: add canReachOtherEnding field for node_surrounding schema
AlvISsReimu Sep 16, 2023
70d9b6e
chore: put temp csv import script stuff into separate package
AlvISsReimu Sep 16, 2023
3d2c41f
fix: update temp csv import logic
AlvISsReimu Sep 16, 2023
bcff7be
fix: do not log fatal when failed to send import request
AlvISsReimu Sep 17, 2023
40907a5
refactor: use query_preset instead of metric
AlvISsReimu Sep 18, 2023
bafa3f1
feat: add method to calc group count by query preset
AlvISsReimu Sep 18, 2023
b769524
fix: number will become json.Number for primitive
AlvISsReimu Sep 20, 2023
096fd85
feat: implement basic querypreset query resolver
AlvISsReimu Sep 20, 2023
94d4670
feat: add GroupCount to QueryPreset query temporarily
AlvISsReimu Sep 21, 2023
aa29cbb
chore: rename generated schema filename
GalvinGao Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4

- name: "Docker: Build Image for Checking"
id: ghcr-docker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4

- name: "Metadata: Git"
id: git-meta
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-auto-create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Create PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
ref: "dev"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-dispatcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
if: github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.title, 'Release')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
ref: "main"

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ debug/
**/logs/

.env
__debug_bin
__debug_bin*

node_modules
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.0-alpine AS base
FROM golang:1.21.1-alpine AS base
WORKDIR /app

# builder
Expand Down
44 changes: 5 additions & 39 deletions cmd/app/cli/script/command.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
package script

import (
"log"
"github.com/urfave/cli/v2"

"exusiai.dev/roguestats-backend/cmd/app/cli/script/syncschema"
"github.com/urfave/cli/v2"
"exusiai.dev/roguestats-backend/cmd/app/cli/script/tempcsvimport"
"exusiai.dev/roguestats-backend/cmd/app/cli/script/userimport"
)

func Command() *cli.Command {
return &cli.Command{
Name: "script",
Usage: "run scripts",
Subcommands: []*cli.Command{
{
Name: "import",
Usage: "import data from temp csv",
Action: func(c *cli.Context) error {
importType := c.Args().Get(0)
path := c.Args().Get(1)
if path == "" {
return cli.Exit("Please provide path to csv file", 1)
}
log.Default().Printf("importing %s data from '%s'\n", importType, path)
if importType == "battle" {
err := NewBattleCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "incident" {
err := NewIncidentCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "rest" {
err := NewRestCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "portal" {
err := NewPortalCSVImport(path).Run()
if err != nil {
return err
}
} else {
return cli.Exit("Unknown import type", 1)
}
log.Default().Printf("finished importing %s data from '%s'\n", importType, path)
return nil
},
},
tempcsvimport.Command(),
syncschema.Command(),
userimport.Command(),
},
}
}
5 changes: 3 additions & 2 deletions cmd/app/cli/script/syncschema/command.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package syncschema

import (
appcli "exusiai.dev/roguestats-backend/cmd/app/cli"
"github.com/urfave/cli/v2"

appcli "exusiai.dev/roguestats-backend/cmd/app/cli"
)

func Command() *cli.Command {
Expand All @@ -14,7 +15,7 @@ func Command() *cli.Command {
Name: "dir",
Aliases: []string{"d"},
Usage: "Directory containing the JSON Schemas.",
Value: "./schema",
Value: "./schema/researches",
},
},
Action: func(c *cli.Context) error {
Expand Down
17 changes: 10 additions & 7 deletions cmd/app/cli/script/syncschema/syncschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"path/filepath"
"strings"

"exusiai.dev/roguestats-backend/internal/ent"
"exusiai.dev/roguestats-backend/internal/ent/research"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"go.uber.org/fx"

"exusiai.dev/roguestats-backend/internal/ent"
"exusiai.dev/roguestats-backend/internal/ent/research"
)

type SyncSchemaCommandDeps struct {
Expand Down Expand Up @@ -41,6 +42,11 @@ func Run(c *cli.Context, d SyncSchemaCommandDeps) error {
name := segments[1]
log.Info().Str("path", path).Str("id", id).Msg("processing research")

jsonBytes, err := minifiedJsonFile(path)
if err != nil {
return err
}

// Check if the research exists.
research, err := tx.Research.Query().Where(research.ID(id)).Only(c.Context)
if err != nil {
Expand All @@ -50,6 +56,7 @@ func Run(c *cli.Context, d SyncSchemaCommandDeps) error {
research, err = tx.Research.Create().
SetID(id).
SetName(name).
SetSchema(jsonBytes).
Save(c.Context)
if err != nil {
return err
Expand All @@ -59,14 +66,10 @@ func Run(c *cli.Context, d SyncSchemaCommandDeps) error {
}
}

jsonBytes, err := minifiedJsonFile(path)
if err != nil {
return err
}

// Update the research schema.
log.Info().Str("id", id).Msg("updating research schema")
_, err = research.Update().
SetName(name).
SetSchema(jsonBytes).
Save(c.Context)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package script
package tempcsvimport

import (
"log"
Expand All @@ -21,9 +21,10 @@ func (c *BattleCSVImport) Run() error {
for _, row := range records {
log.Default().Printf("importing row '%s'\n", row)
content := c.convertRowToContent(row)
userID := c.getUserID(row)
log.Println(content)
if len(content) > 0 {
PostEvent(content, "battle")
if len(content) > 0 && userID != "" {
PostEvent(content, "rsc_01h8yfh5y5vff7sss16ra735rc", userID)
}
}
return nil
Expand Down Expand Up @@ -95,3 +96,7 @@ func (c *BattleCSVImport) convertRowToContent(row []string) map[string]any {

return content
}

func (c *BattleCSVImport) getUserID(row []string) string {
return GetColumnHandler().HandleUser(strings.TrimSpace(row[14]))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package script
package tempcsvimport

import (
"strconv"
Expand All @@ -16,6 +16,7 @@ type ColumnHandler struct {
incidentTypeMap map[string]string
variationMap map[string]string
layoutMap map[string]string
userMap map[string]string
}

var (
Expand All @@ -33,6 +34,7 @@ func GetColumnHandler() *ColumnHandler {
incidentTypeMap: initIncidentTypeMap(),
variationMap: initVariaionMap(),
layoutMap: initLayoutMap(),
userMap: initUserMap(),
}
})
return columnHandlerInstance
Expand Down Expand Up @@ -76,9 +78,15 @@ func (c ColumnHandler) HandleRecruitTickets(input1 string, input2 string) [][]st
if input1 == "" {
return nil
}
tickets := make([][]string, 2)
tickets[0] = c.handleRecruitTicketsHelper(input1)
tickets[1] = c.handleRecruitTicketsHelper(input2)
tickets := make([][]string, 0)
oneTickets := c.handleRecruitTicketsHelper(input1)
if len(oneTickets) > 0 {
tickets = append(tickets, oneTickets)
}
oneTickets = c.handleRecruitTicketsHelper(input2)
if len(oneTickets) > 0 {
tickets = append(tickets, oneTickets)
}
return tickets
}

Expand Down Expand Up @@ -160,6 +168,14 @@ func (c ColumnHandler) HandleLayout(input string) string {
return val
}

func (c ColumnHandler) HandleUser(input string) string {
val, ok := c.userMap[input]
if !ok {
return ""
}
return val
}

func initBandMap() map[string]string {
return map[string]string{
"指挥": "rogue_3_band_1",
Expand Down Expand Up @@ -328,3 +344,21 @@ func initLayoutMap() map[string]string {
"混合e:3-1": "mixed_3-1",
}
}

func initUserMap() map[string]string {
return map[string]string{
"红白": "usr_01h8ygnyfd4fkx4sy9n4gpvy3b",
"斩喵": "usr_01h8zjxfjr07h1wqg2vb41k4mn",
"天离": "usr_01h8zjxppevh1hzrbmdjc1hfmz",
"麻薯": "usr_01h8zjxzt4mkgx8ah0qnb13x91",
"锅": "usr_01h8zjy2s1vg1xt8esv6b4qe7k",
"孔明亲": "usr_01h8zjxr8r34d0hdk6deyt8xz7",
"黒沢": "usr_01h8zjxn3p5qc9zeevptc8tm8c",
"里雪": "usr_01h8zjxhtzg4a5nxh1tfwrde72",
"fl": "usr_01h8zjxsqzxwysrbpqnaxv7g5q",
"一抹晚烟": "usr_01haeckmx4a73g86a87ma8x507",
"月咏千空": "usr_01haecnyjxxta7b5p4r8c9e271",
"大世落幕": "usr_01haecp3rzvwsg2hpg3v09n4wb",
"莫邪": "usr_01haecp914w7ea81h27htkg6pc",
}
}
47 changes: 47 additions & 0 deletions cmd/app/cli/script/tempcsvimport/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package tempcsvimport

import (
"log"

"github.com/urfave/cli/v2"
)

func Command() *cli.Command {
return &cli.Command{
Name: "import",
Usage: "import data from temp csv",
Action: func(c *cli.Context) error {
importType := c.Args().Get(0)
path := c.Args().Get(1)
if path == "" {
return cli.Exit("Please provide path to csv file", 1)
}
log.Default().Printf("importing %s data from '%s'\n", importType, path)
if importType == "battle" {
err := NewBattleCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "incident" {
err := NewIncidentCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "rest" {
err := NewRestCSVImport(path).Run()
if err != nil {
return err
}
} else if importType == "portal" {
err := NewPortalCSVImport(path).Run()
if err != nil {
return err
}
} else {
return cli.Exit("Unknown import type", 1)
}
log.Default().Printf("finished importing %s data from '%s'\n", importType, path)
return nil
},
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package script
package tempcsvimport

import (
"context"
"encoding/csv"
"log"
"os"

"exusiai.dev/roguestats-backend/internal/model"
"github.com/machinebox/graphql"

"exusiai.dev/roguestats-backend/internal/model"
)

func ReadCSVFile(filePath string) [][]string {
Expand All @@ -24,7 +25,7 @@ func ReadCSVFile(filePath string) [][]string {
return records
}

func PostEvent(content map[string]any, researchID string) {
func PostEvent(content map[string]any, researchID string, userID string) {
client := graphql.NewClient("http://localhost:3500/graphql")
req := graphql.NewRequest(`
mutation CreateEvent($input: CreateEventInput!) {
Expand All @@ -38,13 +39,14 @@ func PostEvent(content map[string]any, researchID string) {
Content: content,
ResearchID: researchID,
UserAgent: userAgent,
UserID: userID,
}
req.Var("input", input)
req.Header.Set("Authorization", "Bearer <token>")
ctx := context.Background()
var respData any
if err := client.Run(ctx, req, &respData); err != nil {
log.Fatal(err)
log.Default().Println(err)
}
log.Println(respData)
}
Loading