예제 #1
0
파일: result.go 프로젝트: flowlo/coduno-api
func createFinalResult(ctx context.Context, w http.ResponseWriter, result model.KeyedResult) (int, error) {
	var challenge model.Challenge
	if err := datastore.Get(ctx, result.Challenge, &challenge); err != nil {
		return http.StatusInternalServerError, nil
	}

	result.Finished = time.Now()

	for i, taskKey := range challenge.Tasks {
		key, err := getLatestSubmissionKey(ctx, result.Key, taskKey)
		if err != nil {
			return http.StatusInternalServerError, err
		}
		result.FinalSubmissions[i] = key
	}
	_, err := result.Put(ctx, result.Key)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	json.NewEncoder(w).Encode(result)

	go computeFinalScore(ctx, result, challenge)

	return http.StatusOK, nil
}
예제 #2
0
func averageResulter(ctx context.Context, result model.KeyedResult, challenge model.Challenge) error {
	tasks := make([]model.Task, len(challenge.Tasks))
	if err := datastore.GetMulti(ctx, challenge.Tasks, tasks); err != nil {
		return err
	}

	var user model.User
	if err := datastore.Get(ctx, result.Key.Parent().Parent(), &user); err != nil {
		return err
	}

	var nrOfComputations float64
	average := model.Skills{}

	for i, task := range tasks {
		taskResult, err := Tasker(task.Tasker).Call(ctx, result, *task.Key(challenge.Tasks[i]), user, result.StartTimes[getTaskIndex(challenge, challenge.Tasks[i])])
		if err != nil {
			// TODO: ignore error for now. We`ll treat it after we have all the taskers available
			//return err
		} else {
			average = average.Add(taskResult)
			nrOfComputations++
		}
	}

	result.Skills = average.DivBy(nrOfComputations)
	result.Computed = time.Now()

	_, err := result.Put(ctx, result.Key)
	return err
}