Esempio n. 1
0
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
}
Esempio n. 2
0
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
}