Skip to content

Commit

Permalink
Merge pull request #850 from project-primera/develop
Browse files Browse the repository at this point in the history
release 0.19.0
  • Loading branch information
slime-hatena committed Apr 30, 2024
2 parents ff89baf + 0be684a commit b0f5591
Show file tree
Hide file tree
Showing 18 changed files with 351 additions and 21 deletions.
61 changes: 61 additions & 0 deletions OngekiScoreLog/app/AggregateBattleScore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AggregateBattleScore extends Model
{
protected $table = "aggregate_battlescore";
protected $guarded = [
//
];
public $incrementing = false;

public static function execute(){
\App\Facades\Slack::Debug("Max Battle Scoreの集計を開始します。");

$musics = \App\MusicData::all();
$normalDifficulties = [0, 1, 2, 3];
$lunaticDifficulty = 10;

foreach ($musics as $music) {
if($music->basic_level !== null){
foreach ($normalDifficulties as $difficulty) {
\App\AggregateBattleScore::record($music->id, $difficulty);
}
}

if($music->lunatic_level !== null){
\App\AggregateBattleScore::record($music->id, $lunaticDifficulty);
}
}

\App\Facades\Slack::Debug("Max Battle Scoreの集計を行いました。");
}

public static function record($song_id, $difficulty){
$max = AggregateBattleScore::calculation($song_id, $difficulty);

$key = $song_id . "_" . $difficulty;
AggregateBattleScore::updateOrCreate(
['id' => $key],
['song_id' => $song_id, 'difficulty' => $difficulty, 'max' => $max]
);
}

private static function calculation($song_id, $difficulty){
$sql = DB::table('score_datas')
->select('song_id', 'difficulty', DB::raw('MAX(battle_high_score) as max_battle_high_score'))
->where('song_id', $song_id)
->where('difficulty', $difficulty)
->groupBy('song_id', 'difficulty')
;
try {
return $sql->get()[0]->max_battle_high_score;
} catch (\Throwable $th) {
return 0;
}
}
}
7 changes: 6 additions & 1 deletion OngekiScoreLog/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ protected function schedule(Schedule $schedule)
\App\Facades\Slack::Info("<!here> すべてのユーザーの課金情報をリセットしました。");
})->monthlyOn(1, '7:00');

// Max BattleScoreの集計
$schedule->call(function () {
\App\AggregateBattleScore::execute();
})->dailyAt('4:10');

// Max OverDamageの集計
$schedule->call(function () {
\App\AggregateOverdamage::execute();
})->dailyAt('4:30');
})->dailyAt('4:10');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions OngekiScoreLog/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public function GetApply($type, $action = null){
return redirect('/admin?message=' . $message);
}

public function GetGenerateBattleScore(){
ini_set("max_execution_time", 0);
\App\AggregateBattleScore::execute();
return redirect('/admin?message=' . "Generate Battle Score: max. 実行しました!");
}

public function GetGenerateOverDamage(){
ini_set("max_execution_time", 0);
\App\AggregateOverdamage::execute();
Expand Down
72 changes: 70 additions & 2 deletions OngekiScoreLog/app/Http/Controllers/ViewUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\User;
use App\UserStatus;
use App\ScoreData;
use App\AggregateBattleScore;
use App\AggregateOverdamage;
use App\Facades\OngekiUtility;
use DateTime;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function getUserPage(Request $request, $id, $mode = null){
}
$status[0]->badge = "";
if($user->role == 7){
$status[0]->badge .= '&nbsp;<span class="tag developer">ProjectPrimera Developer</span>';
$status[0]->badge .= '&nbsp;<a target="_blank" href="https://github.com/project-primera"><span class="tag developer">ProjectPrimera Developer</span></a>';
}
if(\App\UserInformation::IsPremiumPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-premium">OngekiNet Premium</span>';
Expand Down Expand Up @@ -340,6 +341,73 @@ public function getUserPage(Request $request, $id, $mode = null){
return view('user', compact('id', 'status', 'score', 'stat', 'mode', 'submenuActive', 'sidemark', 'archive'));
}


public function getBattleScorePage($id, $difficulty = ""){
// 存在しないdifficultyが指定された場合はリダイレクト
if(!in_array($difficulty, ["", "basic", "advanced", "expert", "master", "lunatic"])){
return redirect("/user/" . $id . "/battlescore");
}

$userStatus = new UserStatus();
$user = User::where('id' ,$id)->first();
$status = $userStatus->getRecentUserData($id);
if(count($status) === 0){
if(is_null($user)){
abort(404);
}else{
return view("user_error", ['message' => '<p>このユーザーはOngekiScoreLogに登録していますが、オンゲキNETからスコア取得を行っていません。(UserID: ' . $id . ')</p><p>スコアの取得方法は<a href="/howto">こちら</a>をお読みください。</p>']);
}
}
$status[0]->badge = "";
if($user->role == 7){
$status[0]->badge .= '&nbsp;<a target="_blank" href="https://github.com/project-primera"><span class="tag developer">ProjectPrimera Developer</span></a>';
}
if(\App\UserInformation::IsPremiumPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-premium">OngekiNet Premium</span>';
}else if(\App\UserInformation::IsStandardPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-standard">OngekiNet Standard</span>';
}

// トップランカーのスコアを取得してkey: song_id, difficulty, value: over_damage_high_score の配列を作る
$lastUpdate = (new DateTime())->setTimestamp(0);
$topRankerScore = [];
{
$temp = AggregateBattleScore::all();
foreach ($temp as $value) {
$key = $value->song_id . "_" . $value->difficulty;
$topRankerScore[$key] = $value->max;

// 最終更新日時を取得
if($lastUpdate < $value->updated_at){
$lastUpdate = $value->updated_at;
}
}
}

// 自分のスコアを取得
$score = (new ScoreData)->getRecentUserScore($id)->addMusicData()->exclusionDeletedMusic()->getValue();

// 難易度を指定のものに絞る
$scoreDatas = [];
{
foreach ($score as $value) {
$key = $value->song_id;
if($value->over_damage_high_score !== "0.00"){
if(($difficulty === "" && ($value->difficulty === 3 || $value->difficulty === 10))
|| ($difficulty === "basic" && $value->difficulty === 0)
|| ($difficulty === "advanced" && $value->difficulty === 1)
|| ($difficulty === "expert" && $value->difficulty === 2)
|| ($difficulty === "master" && $value->difficulty === 3)
|| ($difficulty === "lunatic" && $value->difficulty === 10)
){
$scoreDatas[] = $value;
}
}
}
}
return view('user_battlescore', compact('id', 'difficulty', 'status', 'lastUpdate', 'scoreDatas', 'topRankerScore'));
}

public function getOverDamegePage($id, $difficulty = ""){
// 存在しないdifficultyが指定された場合はリダイレクト
if(!in_array($difficulty, ["", "basic", "advanced", "expert", "master", "lunatic"])){
Expand All @@ -358,7 +426,7 @@ public function getOverDamegePage($id, $difficulty = ""){
}
$status[0]->badge = "";
if($user->role == 7){
$status[0]->badge .= '&nbsp;<span class="tag developer">ProjectPrimera Developer</span>';
$status[0]->badge .= '&nbsp;<a target="_blank" href="https://github.com/project-primera"><span class="tag developer">ProjectPrimera Developer</span></a>';
}
if(\App\UserInformation::IsPremiumPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-premium">OngekiNet Premium</span>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ function getIndex(int $id){

$status[0]->badge = "";
if($user->role == 7){
$status[0]->badge .= '&nbsp;<span class="tag developer">ProjectPrimera Developer</span>';
$status[0]->badge .= '&nbsp;<a target="_blank" href="https://github.com/project-primera"><span class="tag developer">ProjectPrimera Developer</span></a>';
}
if(\App\UserInformation::IsPremiumPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-premium">OngekiNet Premium</span>';
}else if(\App\UserInformation::IsStandardPlan($user->id)){
$status[0]->badge .= '&nbsp;<span class="tag net-standard">OngekiNet Standard</span>';
}

$trophies = json_decode(json_encode(UserTrophy::where('user_id', $id)->get()), true);
$trophies = json_decode(json_encode(UserTrophy::where('user_id', $id)->orderBy('grade', 'desc')->orderBy('updated_at', 'desc')->get()), true);

$trophyIdToStr = [
0 => "ノーマル",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAggregateBattleScore extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('aggregate_battlescore', function (Blueprint $table) {
$table->string('id')->primary();
$table->integer('song_id')->unsigned();
$table->integer("difficulty")->unsigned();
$table->integer("max");
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('aggregate_battlescore');
}
}
4 changes: 4 additions & 0 deletions OngekiScoreLog/resources/views/admin/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<hr>
<h3 class="title is-3">統計データ生成</h3>
<p>超絶重いので実行する時間とタイミングに注意!</p>
<h4 class="title is-4">Battle Score</h4>
<p>
<a href="/admin/generate/battle-score"><button class="button is-danger">max</button></a>
</p>
<h4 class="title is-4">Over Damage</h4>
<p>
<a href="/admin/generate/over-damage"><button class="button is-danger">max</button></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<li><a href="/mypage" class="@yield('sidemark_mypage_default')">簡易表示</a></li>
<li><a href="/mypage/details" class="@yield('sidemark_mypage_details')">詳細表示</a></li>
<li><a href="/mypage/technical" class="@yield('sidemark_mypage_technical')">Technical Score</a></li>
<li><a href="/mypage/battle" class="@yield('sidemark_mypage_battle')">Battle Score</a></li>
<li><a href="/mypage/battlescore" class="@yield('sidemark_mypage_battle')">Battle Score</a></li>
<li><a href="/mypage/overdamage" class="@yield('sidemark_mypage_overdamage')">Over Damage</a></li>
<li><a href="/mypage/trophy" class="@yield('sidemark_mypage_trophy')">称号</a></li>
<li><a href="/mypage/rating" class="@yield('sidemark_mypage_rating')">レーティング情報</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<div class="box">
<p>登録されている全ユーザーのバトルスコアのうち、一番高いものと比較することが出来ます。<br>
(※全国ランキング1位のスコアではありません!)</p>
<p>最終更新: {{$lastUpdate->format('Y-m-d H:i:s')}} (?%表示は未集計です)</p>

<div class="buttons has-addons">
<a href="/user/{{$id}}/battlescore" class="button{{($difficulty === "") ? "" : " is-primary"}}">Master + Lunatic</a>
<a href="/user/{{$id}}/battlescore/basic" class="button{{($difficulty === "basic") ? "" : " basic"}}">Basic</a>
<a href="/user/{{$id}}/battlescore/advanced" class="button{{($difficulty === "advanced") ? "" : " advanced"}}">Advanced</a>
<a href="/user/{{$id}}/battlescore/expert" class="button{{($difficulty === "expert") ? "" : " expert"}}">Expert</a>
<a href="/user/{{$id}}/battlescore/master" class="button{{($difficulty === "master") ? "" : " master"}}">Master</a>
<a href="/user/{{$id}}/battlescore/lunatic" class="button{{($difficulty === "lunatic") ? "" : " lunatic"}}">Lunatic</a>
</div>
</div>

<article class="box">
@component('layouts/components/user/table_scale_button') @endcomponent

<div id="sort_table" class="table_wrap scalable">
<table class="table">
<thead>
<tr>
<th class="sort" data-sort="sort_title">Title</th>
<th class="sort" data-sort="sort_difficulty"><abbr title="Difficulty">Dif</abbr></th>
<th class="sort" data-sort="sort_bs"><abbr title="Battle Score">BS</abbr></th>
<th class="sort" data-sort="sort_key1"><abbr title="Top Ranker Score">Top</abbr></th>
<th class="sort" data-sort="sort_key2">diff</th>
<th class="sort" data-sort="sort_key3">達成度</th>
<th class="sort desc" data-sort="sort_update">Update</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="sort" data-sort="sort_title">Title</th>
<th class="sort" data-sort="sort_difficulty"><abbr title="Difficulty">Dif</abbr></th>
<th class="sort" data-sort="sort_bs"><abbr title="Battle Score">BS</abbr></th>
<th class="sort" data-sort="sort_key1"><abbr title="Top Ranker Score">Top</abbr></th>
<th class="sort" data-sort="sort_key2">diff</th>
<th class="sort" data-sort="sort_key3">達成度</th>
<th class="sort desc" data-sort="sort_update">Update</th>
</tr>
</tfoot>
<tbody class="list">
@foreach ($score as $s)
<tr>
<td class="sort_title"><span class="sort-key">{{$s->title}}</span><a href="{{url("/user/" . $id . "/music/" . $s->song_id . "/" . strtolower($s->difficulty_str))}}">{{$s->title}}</a></td>
<td class="sort_difficulty"><span class="sort-key">{{$s->difficulty}}</span>{{substr($s->difficulty_str, 0, 3)}}</td>
<td class="sort_bs">{{number_format($s->battle_high_score)}}</td>
@if (array_key_exists($s->song_id . "_" . $s->difficulty, $topRankerScore))
<td class="sort_key1">{{number_format($topRankerScore[$s->song_id . "_" . $s->difficulty])}}</td>
<td class="sort_key2">{{number_format(abs(($s->battle_high_score - $topRankerScore[$s->song_id . "_" . $s->difficulty])))}}</td>
@if ($topRankerScore[$s->song_id . "_" . $s->difficulty] == 0)
{{-- ありえなさそうだけどDIV/0対策 --}}
<td class="sort_key3">100.00%</td>
@elseif ($s->battle_high_score == $topRankerScore[$s->song_id . "_" . $s->difficulty])
{{-- 1位なので100%! --}}
<td class="sort_key3">100.00%</td>
@elseif ($s->battle_high_score == 0)
{{-- 未プレイなので0%にする --}}
<td class="sort_key3">0.00%</td>
@else
{{-- 1位ではないので計算 --}}
<td class="sort_key3">{{number_format(floor((($s->battle_high_score / $topRankerScore[$s->song_id . "_" . $s->difficulty]))))}}%</td>
@endif
@else
<td class="sort_key1">?%</td>
<td class="sort_key2">?%</td>
<td class="sort_key3">?%</td>
@endif
<td class="sort_update">{{date('Y-m-d', strtotime($s->updated_at))}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>

</article>
2 changes: 1 addition & 1 deletion OngekiScoreLog/resources/views/user.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li class="{{$submenuActive[0]}}"><a href="/user/{{$id}}">簡易</a></li>
<li class="{{$submenuActive[1]}}"><a href="/user/{{$id}}/details">詳細</a></li>
<li class="{{$submenuActive[3]}}"><a href="/user/{{$id}}/technical">Technical</a></li>
<li class="{{$submenuActive[2]}}"><a href="/user/{{$id}}/battle">Battle</a></li>
<li><a href="/user/{{$id}}/battlescore">Battle</a></li>
<li><a href="/user/{{$id}}/overdamage">OverDamage</a></li>
<li><a href="/user/{{$id}}/trophy">称号</a></li>
<li><a href="/user/{{$id}}/rating">Rating</a></li>
Expand Down

0 comments on commit b0f5591

Please sign in to comment.