func (h *PKUJudger) SetDetail(pid string, html string) error { log.Println(pid) pro := model.Problem{} pro.RPid, _ = strconv.Atoi(pid) pro.ROJ = "PKU" pro.Status = StatusAvailable titleMatch := h.titleRx.FindStringSubmatch(html) if len(titleMatch) < 1 { log.Println(titleMatch) return ErrMatchFailed } pro.Title = titleMatch[1] if strings.Index(html, "Special Judge") >= 0 { pro.Special = 1 } resMatch := h.resLimtRx.FindStringSubmatch(html) if len(resMatch) < 3 { log.Println(resMatch) return ErrMatchFailed } pro.Time, _ = strconv.Atoi(resMatch[1]) pro.Time /= 1000 //ms -> s pro.Memory, _ = strconv.Atoi(resMatch[2]) cxtMatch := h.ctxRx.FindAllStringSubmatch(html, 3) if len(cxtMatch) < 3 { log.Println("ctx match error, PKU pid is", pid) return ErrMatchFailed } pro.Description = template.HTML(h.ReplaceImg(cxtMatch[0][1])) pro.Input = template.HTML(h.ReplaceImg(cxtMatch[1][1])) pro.Output = template.HTML(h.ReplaceImg(cxtMatch[2][1])) test := h.testRx.FindAllStringSubmatch(html, 2) if len(test) < 2 { log.Println("test data error, PKU pid is", pid) return ErrMatchFailed } pro.In = test[0][1] pro.Out = test[1][1] src := h.srcRx.FindStringSubmatch(html) if len(src) > 1 { pro.Source = src[1] } hint := h.hintRx.FindStringSubmatch(html) if len(hint) > 1 { pro.Hint = template.HTML(hint[1]) } proModel := &model.ProblemModel{} proModel.Insert(pro) return nil }
func (this *ProblemController) Insert(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin Problem Insert") if r.Method != "POST" { this.Err400(w, r, "Error", "Error Method to Insert problem") return } this.Init(w, r) if this.Privilege != config.PrivilegeAD { this.Err400(w, r, "Warning", "Error Privilege to Insert problem") return } one := model.Problem{} one.Title = r.FormValue("title") time, err := strconv.Atoi(r.FormValue("time")) if err != nil { http.Error(w, "The value 'Time' is neither too short nor too large", 400) return } one.Time = time memory, err := strconv.Atoi(r.FormValue("memory")) if err != nil { http.Error(w, "The value 'Memory' is neither too short nor too large", 400) return } one.Memory = memory if special := r.FormValue("special"); special == "" { one.Special = 0 } else { one.Special = 1 } in := r.FormValue("in") out := r.FormValue("out") one.Description = template.HTML(r.FormValue("description")) one.Input = template.HTML(r.FormValue("input")) one.Output = template.HTML(r.FormValue("output")) one.In = in one.Out = out one.Source = r.FormValue("source") one.Hint = r.FormValue("hint") problemModel := model.ProblemModel{} pid, err := problemModel.Insert(one) if err != nil { http.Error(w, err.Error(), 500) return } createfile(config.Datapath+strconv.Itoa(pid), "sample.in", in) createfile(config.Datapath+strconv.Itoa(pid), "sample.out", out) http.Redirect(w, r, "/admin/problem?list", http.StatusFound) }
func (h *VJJudger) SetDetail(pid string, html string) error { log.Println(pid) pro := model.Problem{} pro.RPid, _ = strconv.Atoi(pid) pro.ROJ = "VJ" pro.Status = StatusReverse titleMatch := h.titleRx.FindStringSubmatch(html) if len(titleMatch) != 2 { log.Println(titleMatch) return ErrMatchFailed } pro.Title = titleMatch[1] // fmt.Println("Title",pro.Title) // if strings.Index(html, "Special Judge") >= 0 { // pro.Special = 1 // } TimeMatch := h.TimeRx.FindStringSubmatch(html) if len(TimeMatch) != 2 { log.Println(TimeMatch) return ErrMatchFailed } pro.Time, _ = strconv.Atoi(TimeMatch[1]) // fmt.Println("Time",pro.Time) MemoryMatch := h.MemoryRx.FindStringSubmatch(html) if len(MemoryMatch) != 2 { log.Println(MemoryMatch) return ErrMatchFailed } pro.Memory, _ = strconv.Atoi(MemoryMatch[1]) // fmt.Println("Memory",pro.Memory) DescriptionMatch := h.DescriptionRx.FindStringSubmatch(html) if len(DescriptionMatch) != 2 { log.Println(DescriptionMatch) return ErrMatchFailed } pro.Description = template.HTML(h.ReplaceHtml(DescriptionMatch[1])) InputMatch := h.InputRx.FindStringSubmatch(html) if len(InputMatch) != 2 { log.Println(InputMatch) return ErrMatchFailed } pro.Input = template.HTML(h.ReplaceHtml(InputMatch[1])) // fmt.Println("Input",pro.Input) OutputMatch := h.OutputRx.FindStringSubmatch(html) if len(OutputMatch) != 2 { log.Println(OutputMatch) return ErrMatchFailed } pro.Output = template.HTML(h.ReplaceHtml(OutputMatch[1])) // fmt.Println("Output",pro.Output) testIn := h.testInRx.FindStringSubmatch(html) if len(testIn) != 2 { log.Println(testIn) return ErrMatchFailed } pro.In = h.ReplaceHtml(testIn[1]) // fmt.Println("In",pro.In) testOut := h.testOutRx.FindStringSubmatch(html) if len(testOut) != 2 { log.Println(testOut) return ErrMatchFailed } pro.Out = h.ReplaceHtml(testOut[1]) // fmt.Println("Out",pro.Out) src := h.srcRx.FindStringSubmatch(html) if len(src) >= 2 { pro.Source = src[1] } hint := h.hintRx.FindStringSubmatch(html) if len(hint) != 2 { log.Println(hint) return ErrMatchFailed } pro.Hint = template.HTML(h.ReplaceHtml(hint[1])) proModel := &model.ProblemModel{} proModel.Insert(pro) return nil }