Пример #1
0
func ProcessRunHandler(w http.ResponseWriter, r *http.Request) {
	faulty := mux.Vars(r)["faulty"]
	faultyInt, _ := strconv.Atoi(faulty)
	row := model.GetQueueWithProfileById(faultyInt)
	defer row.Close()

	owner := mux.Vars(r)["owner"]
	previous := mux.Vars(r)["previous"]

	row.Next()
	faultyProfile := rowToQueueProfile(row)

	var start = time.Now()
	o := ocr.New(faultyProfile.File, 0)

	o.Split()
	o.Process()
	o.CleanUp()

	model.UpdateProfile(faultyProfile.Profile.Id, o.Profile)

	processTime := time.Now().Sub(start).Nanoseconds() / 1e6
	model.SetQueueProcessed(faultyInt, processTime, faultyProfile.Profile.Id)

	http.Redirect(
		w, r,
		fmt.Sprintf("/admin/process/%s/%s/%s", owner, faulty, previous),
		302,
	)
}
Пример #2
0
func ProcessQueueHandler(w http.ResponseWriter, r *http.Request) {
	session, _ := session.Get(r, "tiers")
	userid, _ := session.Values["user"]

	owner := mux.Vars(r)["owner"]
	ownerInt, _ := strconv.Atoi(owner)

	faulty := mux.Vars(r)["faulty"]
	faultyInt, _ := strconv.Atoi(faulty)
	row := model.GetQueueWithProfileById(faultyInt)
	defer row.Close()

	row.Next()
	faultyProfile := rowToQueueProfile(row)

	previous := mux.Vars(r)["previous"]
	previousInt, _ := strconv.Atoi(previous)
	row = model.GetQueueWithProfileById(previousInt)
	defer row.Close()

	row.Next()
	previousProfile := rowToQueueProfile(row)

	o := ocr.New(faultyProfile.File, 0)

	o.Split()
	o.Process()
	o.CleanUp()

	templates := loadTemplates(
		"header.html",
		"footer.html",
		"nav.html",
		"admin/processQueue.html",
	)

	templates.ExecuteTemplate(w, "processQueue", struct {
		User     int
		Owner    int
		File     string
		Faulty   userQueueEntry
		Previous userQueueEntry
		Dry      profile.Profile
	}{
		User:     userid.(int),
		Owner:    ownerInt,
		Faulty:   faultyProfile,
		Previous: previousProfile,
		Dry:      o.Profile,
	})
}
Пример #3
0
func ProcessQueue() {
	ocr.InitConfig()
	for {
		<-Queue
		log.Println("Queue: Processing.")

		queue := model.GetPendingQueues()

		for queue.Next() {
			var start = time.Now()

			var id, user_id, timestamp int
			var file string
			var processed bool
			var ocrProfile int

			if err := queue.Scan(&id, &user_id, &timestamp, &file, &processed, &ocrProfile); err != nil {
				log.Fatal(err)
			}

			o := ocr.New(file, ocrProfile)

			o.Split()
			o.Process()
			o.CleanUp()

			p := o.Profile
			profileId := model.InsertProfile(user_id, timestamp, p)

			processTime := time.Now().Sub(start).Nanoseconds() / 1e6
			model.SetQueueProcessed(id, processTime, profileId)

			log.Printf("Queue: Entry processed in %dms: %s L%d %dAP", processTime, p.Nick, p.Level, p.AP)
		}

		log.Println("Queue: Done.")

		queue.Close()
	}
}