-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #850 from project-primera/develop
release 0.19.0
- Loading branch information
Showing
18 changed files
with
351 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
OngekiScoreLog/database/migrations/2024_04_26_000000_create_aggregate_battlescore.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
OngekiScoreLog/resources/views/layouts/components/user/song_status_battlescore.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.