<commit_before>package com.quizdeck.controllers;

import com.quizdeck.analysis.*;
import com.quizdeck.analysis.exceptions.*;
import com.quizdeck.analysis.outputs.AnalysisResult;
import com.quizdeck.exceptions.InvalidJsonException;
import com.quizdeck.model.database.CompleteQuiz;
import com.quizdeck.model.inputs.OwnerLabelsInput;
import com.quizdeck.repositories.CompletedQuizRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Cade on 2/17/2016.
 */

@RestController
@RequestMapping("/rest/secure/analysis/")
public class AnalysisController {

    @Autowired
    CompletedQuizRepository completedQuizRepository;

    private Logger log = LoggerFactory.getLogger(AnalysisController.class);

    @RequestMapping(value="accuracy/{Id}", method = RequestMethod.GET)
    public AnalysisResult accuracyResponse (@PathVariable String Id) throws AnalysisException{
        return processQuizWith(completedQuizRepository.findById(Id).getQuiz().getId(), QuizAnalysisAlgorithm.ACCURACY);
    }

    @RequestMapping(value="indecisiveness/{Id}", method = RequestMethod.GET)
    public AnalysisResult indecisivenessResponse (@PathVariable String Id) throws AnalysisException {
        return processQuizWith(Id, QuizAnalysisAlgorithm.INDECISIVENESS);
    }

    private AnalysisResult processQuizWith(String id, QuizAnalysisAlgorithm algorithm) throws AnalysisClassException, AnalysisConstructionException, InsufficientDataException, AnalysisResultsUnavailableException {
        CompleteQuiz completeQuiz = completedQuizRepository.findById(id);
        QuizAnalysisFactory factory = new QuizAnalysisFactory();

        factory.autoFillWith(completeQuiz);
        Analysis analysis = factory.getAnalysisUsing(algorithm);
        analysis.performAnalysis();

        return analysis.getResults();
    }

    @RequestMapping(value="label/net-accuracy/", method = RequestMethod.POST)
    public AnalysisResult groupNetAccuracyResponse(@Valid @RequestBody OwnerLabelsInput input, BindingResult result) throws InvalidJsonException, InsufficientDataException, AnalysisClassException, AnalysisConstructionException, AnalysisResultsUnavailableException {
        if(result.hasErrors())
            throw new InvalidJsonException();

        return processGroupWith(input.getOwner(), input.getLabels(), GroupAnalysisAlgorithm.ACCURACY);<commit_msg>revert dumb changes that somehow got committed<commit_after>package com.quizdeck.controllers;

import com.quizdeck.analysis.*;
import com.quizdeck.analysis.exceptions.*;
import com.quizdeck.analysis.outputs.AnalysisResult;
import com.quizdeck.exceptions.InvalidJsonException;
import com.quizdeck.model.database.CompleteQuiz;
import com.quizdeck.model.inputs.OwnerLabelsInput;
import com.quizdeck.repositories.CompletedQuizRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Cade on 2/17/2016.
 */

@RestController
@RequestMapping("/rest/secure/analysis/")
public class AnalysisController {

    @Autowired
    CompletedQuizRepository completedQuizRepository;

    @RequestMapping(value="accuracy/{quizId}", method = RequestMethod.GET)
    public AnalysisResult accuracyResponse (@PathVariable String quizId) throws AnalysisException{
        return processQuizWith(quizId, QuizAnalysisAlgorithm.ACCURACY);
    }

    @RequestMapping(value="indecisiveness/{quizId}", method = RequestMethod.GET)
    public AnalysisResult indecisivenessResponse (@PathVariable String quizId) throws AnalysisException {
        return processQuizWith(quizId, QuizAnalysisAlgorithm.INDECISIVENESS);
    }

    private AnalysisResult processQuizWith(String id, QuizAnalysisAlgorithm algorithm) throws AnalysisClassException, AnalysisConstructionException, InsufficientDataException, AnalysisResultsUnavailableException {
        CompleteQuiz completeQuiz = completedQuizRepository.findByQuizId(id);
        QuizAnalysisFactory factory = new QuizAnalysisFactory();

        factory.autoFillWith(completeQuiz);
        Analysis analysis = factory.getAnalysisUsing(algorithm);
        analysis.performAnalysis();

        return analysis.getResults();
    }

    @RequestMapping(value="label/net-accuracy/", method = RequestMethod.POST)
    public AnalysisResult groupNetAccuracyResponse(@Valid @RequestBody OwnerLabelsInput input, BindingResult result) throws InvalidJsonException, InsufficientDataException, AnalysisClassException, AnalysisConstructionException, AnalysisResultsUnavailableException {
        if(result.hasErrors())
            throw new InvalidJsonException();

        return processGroupWith(input.getOwner(), input.getLabels(), GroupAnalysisAlgorithm.ACCURACY);
{'fraction_non_alphanumeric': 0.08549890894663757, 'fraction_numerical': 0.0031739734179726245, 'mean_word_length': 5.758713136729223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3018790', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1255, 'n_words': 247}