<commit_before><?php

namespace TmlpStats\Http\Controllers;

use App;
use Carbon\Carbon;
use TmlpStats as Models;
use TmlpStats\Api;

class CenterController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->context = App::make(Api\Context::class);
    }
    public function dashboard($abbr)
    {
        $center = Models\Center::abbreviation($abbr)->first();
        if (!$center) {
            abort(404);
        }
        $context = App::make(Api\Context::class);
        $context->setCenter($center);
        $this->setCenter($center);

        $statsReport = Models\StatsReport::byCenter($center)
            ->official()
            ->orderBy('reporting_date', 'desc')
            ->first();

        $weekData = [];
        $reportUrl = '';
        if ($statsReport) {
            try {
                $weekData = App::make(StatsReportController::class)->getSummaryPageData($statsReport);
                $reportUrl = StatsReportController::getUrl($statsReport);
            } catch (\Exception $e) {
                // An exception may be thrown if a stats report is from a previous quarter and there is incomplete promise data.
                $statsReport = null;
            }
        }

        $weekData = $weekData ?: [];

        $liveScoreboard = true;

        $data = compact(
            'center',
            'statsReport',
            'reportUrl',
            'liveScoreboard'
        );

        return redirect($statsReport->getUriLocalReport());

        return view('centers.dashboard')->with(array_merge($data, $weekData));
    }

    public function submission($abbr, $reportingDate)
    {
        $center = Models\Center::abbreviation($abbr)->firstOrFail();
        $reportingDate = Carbon::parse($reportingDate, 'UTC');

        $this->context->setDateSelectAction('CenterController@submission', ['abbr' => $abbr]);
        $this->context->setReportingDate($reportingDate);<commit_msg>Fix redirects from center dashboard so they handle errors properly<commit_after><?php

namespace TmlpStats\Http\Controllers;

use App;
use Carbon\Carbon;
use TmlpStats as Models;
use TmlpStats\Api;

class CenterController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->context = App::make(Api\Context::class);
    }
    public function dashboard($abbr)
    {
        $center = Models\Center::abbreviation($abbr)->firstOrFail();

        $this->context->setCenter($center);
        $this->setCenter($center);

        $statsReport = Models\StatsReport::byCenter($center)
            ->official()
            ->orderBy('reporting_date', 'desc')
            ->firstOrFail();

        // Short circuit to most recent local report until we make a more useful dashboard
        return redirect($statsReport->getUriLocalReport());

        $weekData = [];
        $reportUrl = '';
        if ($statsReport) {
            try {
                $weekData = App::make(StatsReportController::class)->getSummaryPageData($statsReport);
                $reportUrl = StatsReportController::getUrl($statsReport);
            } catch (\Exception $e) {
                // An exception may be thrown if a stats report is from a previous quarter and there is incomplete promise data.
                $statsReport = null;
            }
        }

        $weekData = $weekData ?: [];

        $liveScoreboard = true;

        $data = compact(
            'center',
            'statsReport',
            'reportUrl',
            'liveScoreboard'
        );

        return view('centers.dashboard')->with(array_merge($data, $weekData));
    }

    public function submission($abbr, $reportingDate)
    {
        $center = Models\Center::abbreviation($abbr)->firstOrFail();
        $reportingDate = Carbon::parse($reportingDate, 'UTC');

        $this->context->setDateSelectAction('CenterController@submission', ['abbr' => $abbr]);
        $this->context->setReportingDate($reportingDate);
{'fraction_non_alphanumeric': 0.1322169457635591, 'fraction_numerical': 0.0007498125468632841, 'mean_word_length': 2.4146757679180886, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '2358491', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1050, 'n_words': 223}