<commit_before><?php

namespace SyntaxError\ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use SyntaxError\ApiBundle\Tools\Jsoner;

class MonthController extends Controller
{
    public function recordsAction(Request $request, $ext)
    {
        $dateTime = new \DateTime(
            $request->query->has('date') ? $request->query->get('date')." 00:00:00" : 'now'
        );
        $call = null;
        if( $request->query->has('callback') ) {
            $call = $request->query->get('callback');
            $request->query->remove('callback');
        }
        $request->query->remove('date');
        $day = $this->get('syntax_error_api.month');
        $data = [];
        if( !$request->query->count() ) {
            foreach(get_class_methods('SyntaxError\ApiBundle\Service\MonthService') as $method) {
                if( preg_match('/create/', $method) ) {
                    $key = strtolower( str_replace('create', '', $method) );
                    $data[$key] = call_user_func_array([$day, $method], [$dateTime]);
                }
            }
        }

        foreach($request->query->all() as $key => $param) {
            $methodName = "create".ucfirst($key);
            if( method_exists($day, $methodName) ) {
                $data[$key] = call_user_func_array([$day, $methodName], [$dateTime]);
            }
        }
        $jsoner = new Jsoner();
        $jsoner->createJson($data);

        return $ext == 'json' ? $jsoner->createResponse($call) : $this->render(
            "SyntaxErrorApiBundle:Month:records.html.twig", [
            'title' => 'Month records: '.$dateTime->format("Y M") ,
            'json' => $jsoner->getJsonString()
        ]);
    }

    public function chartsAction(Request $request, $type, $ext)
    {
        $dateTime = new \DateTime(
            $request->query->has('date') ? $request->query->get('date')." 00:00:00" : 'now'
        );
        $call = null;
        if( $request->query->has('callback') ) {
            $call = $request->query->get('callback');
            $request->query->remove('callback');
        }
        $month = $this->get('syntax_error_api.month');

        $jsoner = new Jsoner();
        $jsoner->createJson( $month->highDoubleFormatter($dateTime, ucfirst(strtolower($type)) ) );

        return $ext == 'json'  ? $jsoner->createResponse($call) : $this->render(
            "SyntaxErrorApiBundle:Month:charts.html.twig", [
            'title' => 'Month '.ucfirst($type).": ".$dateTime->format("Y M"),
            'json' => $jsoner->getJsonString()
        ]);
    }
}
<commit_msg>refactor MonthController with ArchiveDayService usage<commit_after><?php

namespace SyntaxError\ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class MonthController extends Controller
{
    public function recordsAction(Request $request, $ext)
    {
        $dateTime = new \DateTime(
            $request->query->has('date') ? $request->query->get('date')." 00:00:00" : 'now'
        );
        $call = $request->query->has('callback') ? $request->query->get('callback') : null;

        $archive = $this->get('syntax_error_api.archive')->handleDate($dateTime)->initService('month');
        $jsoner = $archive->getRecords($request->query);

        return $ext == 'json' ? $jsoner->createResponse($call) : $this->render(
            "SyntaxErrorApiBundle:Month:records.html.twig", [
            'title' => 'Month records: '.$dateTime->format("Y M") ,
            'json' => $jsoner->getJsonString()
        ]);
    }

    public function chartsAction(Request $request, $type, $ext)
    {
        $dateTime = new \DateTime(
            $request->query->has('date') ? $request->query->get('date')." 00:00:00" : 'now'
        );
        $call = $request->query->has('callback') ? $request->query->get('callback') : null;

        $archive = $this->get('syntax_error_api.archive')->handleDate($dateTime)->initService('month');
        $jsoner = $archive->getChart($type);

        return $ext == 'json'  ? $jsoner->createResponse($call) : $this->render(
            "SyntaxErrorApiBundle:Month:charts.html.twig", [
            'title' => 'Month '.ucfirst($type).": ".$dateTime->format("Y M"),
            'json' => $jsoner->getJsonString()
        ]);
    }
}

{'fraction_non_alphanumeric': 0.1837013430457546, 'fraction_numerical': 0.005463236967903483, 'mean_word_length': 2.62242374278648, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 84, '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': '4040551', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1292, 'n_words': 205}