<commit_before><?php

namespace App;

/**
 * App\TeaParty
 *
 * @property int $club_id 對應社團
 * @property string $name 茶會名稱
 * @property \Illuminate\Support\Carbon|null $start_at 開始時間
 * @property \Illuminate\Support\Carbon|null $end_at 結束時間
 * @property string $location 地點
 * @property string|null $url 網址
 * @property string|null $google_event_id Google日曆活動ID
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
 * @property-read int|null $activities_count
 * @property-read \App\Club $club
 * @property-read \Spatie\GoogleCalendar\Event|null $google_event
 * @property-read string|null $google_event_url
 * @property-read bool $is_ended
 * @property-read bool $is_started
 * @property-read string $state
 * @property-read string $state_for_list
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty query()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereClubId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereEndAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereGoogleEventId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereLocation($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereStartAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereUrl($value)
 * @mixin \Eloquent
 */
class TeaParty extends LoggableModel
{
    protected $primaryKey = 'club_id';
    public $incrementing = false;
    protected static $logName = 'club';

    protected $fillable = [
        'club_id',
        'name',
        'start_at',
        'end_at',
        'location',
        'url',
        'google_event_id',
    ];

    protected $dates = [
        'start_at',
        'end_at',
    ];

    protected $appends = [
        'state',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function club()
    {
        return $this->belongsTo(Club::class);
    }

    /**
     * @return \Spatie\GoogleCalendar\Event|null
     */
    public function getGoogleEventAttribute()
    {
        if (!$this->google_event_id) {
            return null;
        }
        try {
            //TODO: 可能需要暫存？
            return \Spatie\GoogleCalendar\Event::find($this->google_event_id);
        } catch (\Google_Service_Exception $exception) {
            return null;
        }
    }

    /**
     * @return string|null
     */
    public function getGoogleEventUrlAttribute()
    {
        if (!$this->google_event_id) {
            return null;
        }
        $rememberKey = sprintf('tp_%s_gevent_url_%s', $this->id, $this->updated_at);
        try {
            $url = cache()->remember($rememberKey, now()->addDay(), function () {
                return $this->google_event->htmlLink;
            });
        } catch (\Exception $e) {
            return null;
        }

        return $url;
    }

    /**
     * @return bool
     */
    public function getIsStartedAttribute()
    {
        return $this->start_at->isPast();
    }

    /**
     * @return bool
     */
    public function getIsEndedAttribute()
    {
        return $this->end_at->isPast();
    }

    /**
     * @return string
     */
    public function getStateAttribute()
    {
        if ($this->is_ended) {
            return 'ended';
        }
        if ($this->is_started) {
            return 'in_process';
        }

        return 'not_started';
    }

    /**
     * @return string
     */
    public function getStateForListAttribute()
    {
        // 給茶會清單使用的狀態，開始超過一天也算結束
        if ($this->is_ended || $this->start_at->diffInDays() >= 1) {
            return 'ended';
        }
        if ($this->is_started) {
            return 'in_process';
        }
<commit_msg>Change limit of TeaParty to 5 days<commit_after><?php

namespace App;

/**
 * App\TeaParty
 *
 * @property int $club_id 對應社團
 * @property string $name 茶會名稱
 * @property \Illuminate\Support\Carbon|null $start_at 開始時間
 * @property \Illuminate\Support\Carbon|null $end_at 結束時間
 * @property string $location 地點
 * @property string|null $url 網址
 * @property string|null $google_event_id Google日曆活動ID
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\Spatie\Activitylog\Models\Activity[] $activities
 * @property-read int|null $activities_count
 * @property-read \App\Club $club
 * @property-read \Spatie\GoogleCalendar\Event|null $google_event
 * @property-read string|null $google_event_url
 * @property-read bool $is_ended
 * @property-read bool $is_started
 * @property-read string $state
 * @property-read string $state_for_list
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty query()
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereClubId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereEndAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereGoogleEventId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereLocation($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereStartAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|TeaParty whereUrl($value)
 * @mixin \Eloquent
 */
class TeaParty extends LoggableModel
{
    protected $primaryKey = 'club_id';
    public $incrementing = false;
    protected static $logName = 'club';

    protected $fillable = [
        'club_id',
        'name',
        'start_at',
        'end_at',
        'location',
        'url',
        'google_event_id',
    ];

    protected $dates = [
        'start_at',
        'end_at',
    ];

    protected $appends = [
        'state',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function club()
    {
        return $this->belongsTo(Club::class);
    }

    /**
     * @return \Spatie\GoogleCalendar\Event|null
     */
    public function getGoogleEventAttribute()
    {
        if (!$this->google_event_id) {
            return null;
        }
        try {
            //TODO: 可能需要暫存？
            return \Spatie\GoogleCalendar\Event::find($this->google_event_id);
        } catch (\Google_Service_Exception $exception) {
            return null;
        }
    }

    /**
     * @return string|null
     */
    public function getGoogleEventUrlAttribute()
    {
        if (!$this->google_event_id) {
            return null;
        }
        $rememberKey = sprintf('tp_%s_gevent_url_%s', $this->id, $this->updated_at);
        try {
            $url = cache()->remember($rememberKey, now()->addDay(), function () {
                return $this->google_event->htmlLink;
            });
        } catch (\Exception $e) {
            return null;
        }

        return $url;
    }

    /**
     * @return bool
     */
    public function getIsStartedAttribute()
    {
        return $this->start_at->isPast();
    }

    /**
     * @return bool
     */
    public function getIsEndedAttribute()
    {
        return $this->end_at->isPast();
    }

    /**
     * @return string
     */
    public function getStateAttribute()
    {
        if ($this->is_ended) {
            return 'ended';
        }
        if ($this->is_started) {
            return 'in_process';
        }

        return 'not_started';
    }

    /**
     * @return string
     */
    public function getStateForListAttribute()
    {
        // 給茶會清單使用的狀態，開始超過一天也算結束
        if ($this->is_ended || $this->start_at->diffInDays() >= 5) {
            return 'ended';
        }
        if ($this->is_started) {
            return 'in_process';
        }

{'fraction_non_alphanumeric': 0.1280844714793986, 'fraction_numerical': 0.00034431309537472744, 'mean_word_length': 2.644500209117524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '3659874', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2841, 'n_words': 492}