站長阿川 🌏  ·  4年前

關於程式設計討論專區~

哈囉大家~不知道有沒有跟站長一樣~程式相關的從業人員呢~

討論區文章格式,是支援程式碼的唷~

歡迎大家多多利用這個專區,來互相交流~

作為功能示範,站長貼一段梗圖倉庫的程式碼~

是一段很簡單的熱門分數演算法~

function refreshTrendingScore()
{
    if ($this->approved_at < \Carbon\Carbon::now()->subHours(
        24 * trending_image_beginning_live_days() + $this->total_like_count * trending_image_extra_hours_per_like()
    )) {
        $this->trending_score = 0;

        $this->save();

        return;
    }

    $score = 0;

    if ($this->user_id != 0) {
        $score += 100;

        if ($this->user->intro) $score += 2;

        if ($this->user->photo) $score += 2;

        if ($this->user->created_at >= \Carbon\Carbon::now()->subDays(2) ||
            $this->user->wtf_total_count < 4)
        {
            $score += 4;
        }
    }

    if ($this->hashtag != '') $score += 2;

    if ($this->contest_id != 0) $score += 2;

    // $score = $score + floor($this->pageview / 1000) * 0;

    $userId = $this->user_id;

    $score += $this->likes->filter(function($like) use ($userId) { return $userId != $like->user_id; })->count() * 10;

    if ($this->comments->filter(function($comment) use ($userId) { return $userId != $comment->user_id; })->count() > 0) {
        $score += 10;
    }

    if ($score >= 10) {
        $this->trending_score = $score;
    } else {
        $this->trending_score = 0;
    }

    if ($this->is_sensitive) {
        $this->trending_score = 0;
    }

    $this->save();
}

拋磚引玉,歡迎大家多多利用這個專區交流~

謝謝大家~

按讚的人:

共有 2 則留言

鞏毓靈 🇹🇼 4年前

請問站長,要如何在討論區使用這個格式呢?

按讚的人:
站長阿川 🌏 PRO 4年前

這個```當第一行

再用```當最後一行

按讚的人:
程式設計討論
程式設計、軟體工程相關的自由交流區~
  加入部落
建立日期:2021年06月20日