Beispiel #1
0
func getLatestSubmissionKey(ctx context.Context, resultKey, taskKey *datastore.Key) (*datastore.Key, error) {
	keys, err := model.NewQueryForSubmission().
		Ancestor(resultKey).
		Filter("Task =", taskKey).
		Order("-Time").
		KeysOnly().
		Limit(1).
		GetAll(ctx, nil)
	if err != nil {
		return nil, err
	}
	if len(keys) != 1 {
		return nil, nil
	}
	return keys[0], nil
}
Beispiel #2
0
func diffTasker(ctx context.Context, result model.KeyedResult, task model.KeyedTask, user model.User, startTime time.Time) (skills model.Skills, err error) {
	var submissions model.Submissions
	var submissionKeys []*datastore.Key
	submissionKeys, err = model.NewQueryForSubmission().
		Ancestor(result.Key).
		Filter("Task =", task.Key).
		Order("Time").
		GetAll(ctx, &submissions)
	if err != nil {
		return
	}

	var cs float64
	if len(submissions) > 0 {
		cs, err = diffCodingSpeed(ctx, submissions.Key(submissionKeys), task, startTime)
		if err != nil {
			return
		}
	}

	skills.CodingSpeed = cs
	return
}
Beispiel #3
0
func GetSubmissionsForResult(ctx context.Context, w http.ResponseWriter, r *http.Request) (status int, err error) {
	if r.Method != "GET" {
		return http.StatusMethodNotAllowed, nil
	}

	// TODO(victorbalan): Check if user is company or if user is parent of result
	// else return http.StatusUnauthorized
	_, ok := passenger.FromContext(ctx)
	if !ok {
		return http.StatusUnauthorized, nil
	}

	resultKey, err := datastore.DecodeKey(mux.Vars(r)["resultKey"])
	if err != nil {
		return http.StatusNotFound, err
	}

	taskKey, err := datastore.DecodeKey(mux.Vars(r)["taskKey"])
	if err != nil {
		return http.StatusNotFound, err
	}

	var submissions model.Submissions
	var keys []*datastore.Key
	keys, err = model.NewQueryForSubmission().
		Ancestor(resultKey).
		Filter("Task =", taskKey).
		Order("Time").
		GetAll(ctx, &submissions)
	if err != nil {
		return http.StatusInternalServerError, err
	}

	json.NewEncoder(w).Encode(submissions.Key(keys))
	return http.StatusOK, nil
}