<commit_before><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Town;
use SimpleBrowser;

class TownsController extends Controller
{

    private $browser;
    private $miNube;
    private $hotelBeds;
    private $cabifys;

    public function __construct()
    {
        $this->browser = new SimpleBrowser();
        $this->miNube = new MiNubeController();
        $this->hotelBeds = new HotelBedsController();
        $this->cabifys = new CabifyController();
    }

    /**
     * Display a listing of the resource.
     *
     *
     */
    public function index($province = null)
    {
        //
        return Town::query()->where("province", $province)->get()->map(function($model){
            $model->image_url = ($model->image_url) ? $model->image_url :
                @$this->miNube->getInterestPointsByTownId(
                    $this->miNube->getTownByName($model->name)['city_id']
                )[0]['picture_url'] ?: "default";
            $model->save();
            return $model;
        })->toJson();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
        $town = Town::query()->findOrFail($id)->toArray();

        $miNubeTown = array_except($this->miNube->getTownByName($town['name']),
            [
                'city_name',
                'zone_id',
                'zone_name',
                'country_id',
                'country_name'
            ]
        ) ?: [];

        $townInterests = ( ! empty($miNubeTown)) ?
            array_map(function($value){
                return $value + ['picture_url' => 'default'];
            }, $this->miNube->getInterestPointsByTownId($miNubeTown['city_id'])) :
            []
        ;

        $hotels = $this->hotelBeds->getHotelsByTownCoordinates(
            ($town + $miNubeTown)['latitude'],
            ($town + $miNubeTown)['longitude']
        );

        $cabifys = $this->cabifys->getEstimationByCoordinates(
            ($town + $miNubeTown)['latitude'],
            ($town + $miNubeTown)['longitude']
        );

        return json_encode(
                $town +
                $miNubeTown +
                ["pois" => $townInterests] +
                ['hotels' => $hotels] +
                ['cabifys' => $cabifys]
            , true);
    }

    public function showByCartoId($cartoId){
        return $this->show(
            Town::query()->where('cartodb_id', $cartoId)->firstOrFail()->id
        ) ?: json_encode([]);
    }<commit_msg>Returning sellingRate on hotelbeds ratings<commit_after><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Town;
use SimpleBrowser;

class TownsController extends Controller
{

    private $browser;
    private $miNube;
    private $hotelBeds;
    private $cabifys;

    public function __construct()
    {
        $this->browser = new SimpleBrowser();
        $this->miNube = new MiNubeController();
        $this->hotelBeds = new HotelBedsController();
        $this->cabifys = new CabifyController();
    }

    /**
     * Display a listing of the resource.
     *
     *
     */
    public function index($province = null)
    {
        //
        return Town::query()->where("province", $province)->get()->map(function($model){
            $model->image_url = ($model->image_url) ? $model->image_url :
                @$this->miNube->getInterestPointsByTownId(
                    $this->miNube->getTownByName($model->name)['city_id']
                )[0]['picture_url'] ?: "default";
            $model->save();
            return $model;
        })->toJson();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
        $town = Town::query()->findOrFail($id)->toArray();

        $miNubeTown = array_except($this->miNube->getTownByName($town['name']),
            [
                'city_name',
                'zone_id',
                'zone_name',
                'country_id',
                'country_name'
            ]
        ) ?: [];

        $townInterests = ( ! empty($miNubeTown)) ?
            array_map(function($value){
                return $value + ['picture_url' => 'default'];
            }, $this->miNube->getInterestPointsByTownId($miNubeTown['city_id'])) :
            []
        ;

        $hotels = $this->hotelBeds->getHotelsByTownCoordinates(
            ($town + $miNubeTown)['latitude'],
            ($town + $miNubeTown)['longitude']
        );

        $cabifys = $this->cabifys->getEstimationByCoordinates(
            ($town + $miNubeTown)['latitude'],
            ($town + $miNubeTown)['longitude']
        );

        return json_encode(
                $town +
                $miNubeTown +
                ["pois" => $townInterests] +
                ['hotels' => array_map(function($value){
                    array_map(function($rooms){
                        array_map(function($rate){
                            return $rate + ["sellingRate" => ""];
                        }, $rooms["rates"]);
                    }, $value["rooms"]);
                }, $hotels)] +
                ['cabifys' => $cabifys]
            , true);
    }

    public function showByCartoId($cartoId){
        return $this->show(
            Town::query()->where('cartodb_id', $cartoId)->firstOrFail()->id
        ) ?: json_encode([]);
    }
{'fraction_non_alphanumeric': 0.1541108294096342, 'fraction_numerical': 0.0003621876131836291, 'mean_word_length': 1.782367758186398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, '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': '4998297', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1626, 'n_words': 252}