<commit_before><?php namespace App\Http\Controllers;

use App\City;
use App\Country;
use App\Gig;
use App\Http\Requests\LifeIndexRequest;
use App\Trip;
use App\TripFactory;
use Illuminate\Database\Eloquent\Builder;

class Life extends Controller
{
    public function index(LifeIndexRequest $request)
    {
        if ($request->shouldRedirectInstagrammer()) {
            return $request->redirectInstagrammer();
        }

        $to = $request->to();
        $from = $request->from();

        $trips = Trip::withCount('photos')
            ->where('user_id', 1)
            ->visible()
            ->when($from, fn (Builder $query) => $query->where('date_start', '>=', $from))
            ->when($to, fn (Builder $query) => $query->where('date_start', '<=', $to))
            ->orderBy('date_start', $from || $to ? 'asc' : 'desc')
            ->get();

        $gigs = Gig::with('artist')
            ->when($from, fn (Builder $query) => $query->where('date', '>=', $from))
            ->when($to, fn (Builder $query) => $query->where('date', '<=', $to))
            ->orderByDesc('date')
            ->get();

        $models = $trips->merge($gigs)
            ->sortByDesc(fn ($model) => $model->date())
            ->groupBy(fn ($model) => $model->year);

        return view('life.index', [
            'modelsByYears' => $models,
        ]);
    }

    public function cities()
    {
        $trips = TripFactory::tripsByCities(1);

        $cities = \CityHelper::cachedById()
            ->filter(fn (City $city) => isset($trips[$city->id]))
            ->each(function (City $city) use (&$trips) {
                $city->trips_count = $trips[$city->id]['total'] ?? 0;
                $city->trips_published_count = $trips[$city->id]['published'] ?? 0;
            })
            ->sortBy(City::titleField());

        return view('life.cities', [
            'cities' => $cities,
        ]);
    }

    public function city(City $city)
    {
        $trips = $city->trips()
            ->where('user_id', 1)<commit_msg>Поездки и концерты в одном списке<commit_after><?php namespace App\Http\Controllers;

use App\City;
use App\Country;
use App\Gig;
use App\Http\Requests\LifeIndexRequest;
use App\Trip;
use App\TripFactory;
use Illuminate\Database\Eloquent\Builder;

class Life extends Controller
{
    public function index(LifeIndexRequest $request)
    {
        if ($request->shouldRedirectInstagrammer()) {
            return $request->redirectInstagrammer();
        }

        $to = $request->to();
        $from = $request->from();

        $trips = Trip::withCount('photos')
            ->where('user_id', 1)
            ->visible()
            ->when($from, fn (Builder $query) => $query->where('date_start', '>=', $from))
            ->when($to, fn (Builder $query) => $query->where('date_start', '<=', $to))
            ->orderBy('date_start', $from || $to ? 'asc' : 'desc')
            ->get();

        $gigs = Gig::with('artist')
            ->when($from, fn (Builder $query) => $query->where('date', '>=', $from))
            ->when($to, fn (Builder $query) => $query->where('date', '<=', $to))
            ->orderByDesc('date')
            ->get();

        $models = collect([...$trips, ...$gigs])
            ->sortByDesc(fn ($model) => $model->date())
            ->groupBy(fn ($model) => $model->year);

        return view('life.index', [
            'modelsByYears' => $models,
        ]);
    }

    public function cities()
    {
        $trips = TripFactory::tripsByCities(1);

        $cities = \CityHelper::cachedById()
            ->filter(fn (City $city) => isset($trips[$city->id]))
            ->each(function (City $city) use (&$trips) {
                $city->trips_count = $trips[$city->id]['total'] ?? 0;
                $city->trips_published_count = $trips[$city->id]['published'] ?? 0;
            })
            ->sortBy(City::titleField());

        return view('life.cities', [
            'cities' => $cities,
        ]);
    }

    public function city(City $city)
    {
        $trips = $city->trips()
            ->where('user_id', 1)
{'fraction_non_alphanumeric': 0.19574780058651026, 'fraction_numerical': 0.0024437927663734115, 'mean_word_length': 2.1876947040498442, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 90, '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': '3718214', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1278, 'n_words': 243}