style: rename config -> conf for consistency
This commit is contained in:
		
							parent
							
								
									380762a2e3
								
							
						
					
					
						commit
						8e49684abe
					
				
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							|  | @ -1,10 +1,10 @@ | |||
| .PHONY: all clean test | ||||
| 
 | ||||
| BUILD_DIR = ./build | ||||
| APP_NAME = joj3 | ||||
| APPS := $(notdir $(wildcard ./cmd/*)) | ||||
| 
 | ||||
| all: | ||||
| 	go build -o $(BUILD_DIR)/$(APP_NAME) ./cmd/$(APP_NAME) | ||||
| 	$(foreach APP,$(APPS), go build -o $(BUILD_DIR)/$(APP) ./cmd/$(APP);) | ||||
| 
 | ||||
| clean: | ||||
| 	rm -rf $(BUILD_DIR)/* | ||||
|  |  | |||
|  | @ -46,7 +46,7 @@ Each stage contains a executor and parser. | |||
| 
 | ||||
| Executor takes a `Cmd` and returns a `ExecutorResult`. | ||||
| 
 | ||||
| Parser takes a `ExecutorResult` and its config and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. | ||||
| Parser takes a `ExecutorResult` and its conf and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. | ||||
| 
 | ||||
| ### `Cmd` | ||||
| 
 | ||||
|  |  | |||
|  | @ -68,7 +68,7 @@ func parseConfFile(path string) Conf { | |||
| 	conf := Conf{} | ||||
| 	err := m.Load(&conf) | ||||
| 	if err != nil { | ||||
| 		slog.Error("parse stages config", "error", err) | ||||
| 		slog.Error("parse stages conf", "error", err) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
| 	return conf | ||||
|  |  | |||
|  | @ -51,13 +51,13 @@ func generateStages(conf Conf) []stage.Stage { | |||
| 		if len(s.Executor.With.Cases) == 0 { | ||||
| 			cmds = []stage.Cmd{defaultCmd} | ||||
| 		} | ||||
| 		slog.Debug("parse stages config", "cmds", cmds) | ||||
| 		slog.Debug("parse stages conf", "cmds", cmds) | ||||
| 		stages = append(stages, stage.Stage{ | ||||
| 			Name:         s.Name, | ||||
| 			ExecutorName: s.Executor.Name, | ||||
| 			ExecutorCmds: cmds, | ||||
| 			ParserName:   s.Parser.Name, | ||||
| 			ParserConfig: s.Parser.With, | ||||
| 			ParserConf:   s.Parser.With, | ||||
| 		}) | ||||
| 	} | ||||
| 	return stages | ||||
|  |  | |||
|  | @ -8,7 +8,7 @@ var name = "sandbox" | |||
| 
 | ||||
| func init() { | ||||
| 	stage.RegisterExecutor(name, &Sandbox{ | ||||
| 		// TODO: read from config
 | ||||
| 		// TODO: read from conf
 | ||||
| 		execClient: createExecClient("localhost:5051", ""), | ||||
| 		cachedMap:  make(map[string]string), | ||||
| 	}) | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ import ( | |||
| 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||
| ) | ||||
| 
 | ||||
| type Config struct { | ||||
| type Conf struct { | ||||
| 	Cases []struct { | ||||
| 		Score      int | ||||
| 		StdoutPath string | ||||
|  | @ -16,27 +16,27 @@ type Config struct { | |||
| 
 | ||||
| type Diff struct{} | ||||
| 
 | ||||
| func (*Diff) Run(results []stage.ExecutorResult, configAny any) ( | ||||
| func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( | ||||
| 	[]stage.ParserResult, bool, error, | ||||
| ) { | ||||
| 	config, err := stage.DecodeConfig[Config](configAny) | ||||
| 	conf, err := stage.DecodeConf[Conf](confAny) | ||||
| 	if err != nil { | ||||
| 		return nil, true, err | ||||
| 	} | ||||
| 	if len(config.Cases) != len(results) { | ||||
| 	if len(conf.Cases) != len(results) { | ||||
| 		return nil, true, fmt.Errorf("cases number not match") | ||||
| 	} | ||||
| 	var res []stage.ParserResult | ||||
| 	for i, caseConfig := range config.Cases { | ||||
| 	for i, caseConf := range conf.Cases { | ||||
| 		result := results[i] | ||||
| 		score := 0 | ||||
| 		stdout, err := os.ReadFile(caseConfig.StdoutPath) | ||||
| 		stdout, err := os.ReadFile(caseConf.StdoutPath) | ||||
| 		if err != nil { | ||||
| 			return nil, true, err | ||||
| 		} | ||||
| 		// TODO: more compare strategies
 | ||||
| 		if string(stdout) == result.Files["stdout"] { | ||||
| 			score = caseConfig.Score | ||||
| 			score = caseConf.Score | ||||
| 		} | ||||
| 		res = append(res, stage.ParserResult{ | ||||
| 			Score: score, | ||||
|  |  | |||
|  | @ -6,27 +6,27 @@ import ( | |||
| 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||
| ) | ||||
| 
 | ||||
| type Config struct { | ||||
| type Conf struct { | ||||
| 	Score   int | ||||
| 	Comment string | ||||
| } | ||||
| 
 | ||||
| type Dummy struct{} | ||||
| 
 | ||||
| func (*Dummy) Run(results []stage.ExecutorResult, configAny any) ( | ||||
| func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( | ||||
| 	[]stage.ParserResult, bool, error, | ||||
| ) { | ||||
| 	config, err := stage.DecodeConfig[Config](configAny) | ||||
| 	conf, err := stage.DecodeConf[Conf](confAny) | ||||
| 	if err != nil { | ||||
| 		return nil, true, err | ||||
| 	} | ||||
| 	var res []stage.ParserResult | ||||
| 	for _, result := range results { | ||||
| 		res = append(res, stage.ParserResult{ | ||||
| 			Score: config.Score, | ||||
| 			Score: conf.Score, | ||||
| 			Comment: fmt.Sprintf( | ||||
| 				"%s, executor status: run time: %d ns, memory: %d bytes", | ||||
| 				config.Comment, result.RunTime, result.Memory, | ||||
| 				conf.Comment, result.RunTime, result.Memory, | ||||
| 			), | ||||
| 		}) | ||||
| 	} | ||||
|  |  | |||
|  | @ -7,15 +7,15 @@ import ( | |||
| 	"github.com/criyle/go-judge/envexec" | ||||
| ) | ||||
| 
 | ||||
| type Config struct{} | ||||
| type Conf struct{} | ||||
| 
 | ||||
| type ResultStatus struct{} | ||||
| 
 | ||||
| func (*ResultStatus) Run(results []stage.ExecutorResult, configAny any) ( | ||||
| func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( | ||||
| 	[]stage.ParserResult, bool, error, | ||||
| ) { | ||||
| 	// TODO: more config options
 | ||||
| 	_, err := stage.DecodeConfig[Config](configAny) | ||||
| 	// TODO: more conf options
 | ||||
| 	_, err := stage.DecodeConf[Conf](confAny) | ||||
| 	if err != nil { | ||||
| 		return nil, true, err | ||||
| 	} | ||||
|  |  | |||
|  | @ -155,7 +155,7 @@ type Stage struct { | |||
| 	ExecutorName string | ||||
| 	ExecutorCmds []Cmd | ||||
| 	ParserName   string | ||||
| 	ParserConfig any | ||||
| 	ParserConf   any | ||||
| } | ||||
| 
 | ||||
| type ParserResult struct { | ||||
|  |  | |||
|  | @ -19,9 +19,9 @@ func Run(stages []Stage) []StageResult { | |||
| 			break | ||||
| 		} | ||||
| 		slog.Debug("executor run done", "results", executorResults) | ||||
| 		slog.Debug("parser run start", "config", stage.ParserConfig) | ||||
| 		slog.Debug("parser run start", "conf", stage.ParserConf) | ||||
| 		parser := parserMap[stage.ParserName] | ||||
| 		parserResults, end, err := parser.Run(executorResults, stage.ParserConfig) | ||||
| 		parserResults, end, err := parser.Run(executorResults, stage.ParserConf) | ||||
| 		if err != nil { | ||||
| 			slog.Error("parser run error", "name", stage.ExecutorName, "error", err) | ||||
| 			break | ||||
|  |  | |||
|  | @ -2,11 +2,11 @@ package stage | |||
| 
 | ||||
| import "github.com/mitchellh/mapstructure" | ||||
| 
 | ||||
| func DecodeConfig[T any](configAny any) (*T, error) { | ||||
| 	var config T | ||||
| 	err := mapstructure.Decode(configAny, &config) | ||||
| func DecodeConf[T any](confAny any) (*T, error) { | ||||
| 	var conf T | ||||
| 	err := mapstructure.Decode(confAny, &conf) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return &config, nil | ||||
| 	return &conf, nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user