Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 0.17.1 #827

Merged
merged 9 commits into from
Apr 15, 2024
61 changes: 61 additions & 0 deletions OngekiScoreLog/app/AggregateOverdamage.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 AggregateOverdamage extends Model
{
protected $table = "aggregate_overdamage";
protected $guarded = [
//
];
public $incrementing = false;

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

$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\AggregateOverdamage::record($music->id, $difficulty);
}
}

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

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

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

$key = $song_id . "_" . $difficulty;
AggregateOverdamage::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(over_damage_high_score) as max_over_damage_high_score'))
->where('song_id', $song_id)
->where('difficulty', $difficulty)
->groupBy('song_id', 'difficulty')
;
try {
return $sql->get()[0]->max_over_damage_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 @@ -30,7 +30,12 @@ protected function schedule(Schedule $schedule)
$schedule->call(function () {
\App\UserInformation::ResetAllUserPaymentState();
\App\Facades\Slack::Info("<!here> すべてのユーザーの課金情報をリセットしました。");
})->monthlyOn(1, '4:00');
})->monthlyOn(1, '7:00');

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

/**
Expand Down
11 changes: 11 additions & 0 deletions OngekiScoreLog/app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public function GetConfig(){
return view('admin/config', compact(['result']));
}

public function GetAggregate(){
$result = \App\AggregateOverdamage::all();
return view('admin/aggregate', compact(['result']));
}

/**
* '/config'にgetリクエストがあったときに呼び出されます。
* パラメータに合致する処理を行い、'/'にリダイレクトします。
Expand Down Expand Up @@ -124,4 +129,10 @@ public function GetApply($type, $action = null){

return redirect('/admin?message=' . $message);
}

public function GetGenerateOverDamage(){
ini_set("max_execution_time", 0);
\App\AggregateOverdamage::execute();
return redirect('/admin?message=' . "Generate Over Damage: max. 実行しました!");
}
}
15 changes: 11 additions & 4 deletions OngekiScoreLog/app/Http/Controllers/ViewUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
use App\User;
use App\UserStatus;
use App\ScoreData;
use App\AggregateOverdamage;
use App\Facades\OngekiUtility;
use DateTime;

use function GuzzleHttp\json_encode;

class ViewUserController extends Controller
Expand Down Expand Up @@ -386,13 +389,17 @@ public function getOverDamegePage($id){
}

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

// 最終更新日時を取得
if($lastUpdate < $value->updated_at){
$lastUpdate = $value->updated_at;
}
}
}
Expand Down Expand Up @@ -422,6 +429,6 @@ public function getOverDamegePage($id){
}
}

return view('user_overdamage', compact('id', 'status', 'scoreDatas', 'topRankerScore'));
return view('user_overdamage', compact('id', 'status', 'lastUpdate', 'scoreDatas', 'topRankerScore'));
}
}
13 changes: 0 additions & 13 deletions OngekiScoreLog/app/ScoreData.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,6 @@ function getRecentUserScore($id){
return $this;
}

function getTopRankerScore(){
$sql = DB::table($this->table)
->select('song_id', 'difficulty',
DB::raw('MAX(over_damage_high_score) as max_over_damage_high_score'),
DB::raw('MAX(battle_high_score) as max_battle_high_score'),
DB::raw('MAX(technical_high_score) as max_technical_high_score'),)
->from($this->table)
->groupBy('song_id', 'difficulty')
;
$this->value = $sql->get();
return $this;
}

/**
* 指定した世代のスコアデータを取得します。
*
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 CreateAggregateOverdamage extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('aggregate_overdamage', function (Blueprint $table) {
$table->string('id')->primary();
$table->integer('song_id')->unsigned();
$table->integer("difficulty")->unsigned();
$table->decimal("max", 6, 2);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('aggregate_overdamage');
}
}
9 changes: 8 additions & 1 deletion OngekiScoreLog/resources/views/admin/_submenu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@
@else
<li>
@endif
<a href="/admin/config">config</a></li>
<a href="/admin/config">config</a></li>

@if (isset($active) && $active === 'aggregate')
<li class="is-active">
@else
<li>
@endif
<a href="/admin/aggregate">aggregate</a></li>
33 changes: 33 additions & 0 deletions OngekiScoreLog/resources/views/admin/aggregate.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@extends('layouts.app')

@section('title', '管理ページ')
@section('hero_title', "管理ページ")
@section('hero_subtitle', "config")

@section('submenu')
@include('admin/_submenu', ['active' => 'aggregate'])
@endsection

@section('content')
<article class="box">
<h3 class="title is-3">集計一覧</h3>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>max</th>
<th>updated_at</th>
</tr>
</thead>
<tbody>
@foreach ($result as $key => $value)
<tr>
<td>{{$value->id}}</td>
<td>{{$value->max}}</td>
<td>{{$value->updated_at}}</td>
</tr>
@endforeach
</tbody>
</table>
</article>
@endsection
7 changes: 7 additions & 0 deletions OngekiScoreLog/resources/views/admin/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@
<p>
<a href="/admin/apply/cache"><button class="button is-danger">cache:clear</button></a>
</p>
<hr>
<h3 class="title is-3">統計データ生成</h3>
<p>超絶重いので実行する時間とタイミングに注意!</p>
<h4 class="title is-4">Over Damage</h4>
<p>
<a href="/admin/generate/over-damage"><button class="button is-danger">max</button></a>
</p>
</article>
@endsection
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<p>登録されている全ユーザーのオーバーダメージのうち、一番高いものと比較することが出来ます。<br>
OD埋めなどにご活用ください。</p>
<p>プレイしている楽曲内で、一番ODが高い難易度のみ表示されます。全難易度のODが0の曲は表示されません。なお削除楽曲等も表示されます。ご了承下さい。</p>
最終更新: {{$lastUpdate->format('Y-m-d H:i:s')}} (?%表示は未集計です)
</div>

<article class="box">
Expand Down Expand Up @@ -42,9 +43,15 @@
<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_od">{{$s->over_damage_high_score . "%"}}</td>
<td class="sort_key1">{{$topRankerScore[$s->song_id . "_" . $s->difficulty] . "%"}}</td>
<td class="sort_key2">{{$s->over_damage_high_score - $topRankerScore[$s->song_id . "_" . $s->difficulty]}}%</td>
<td class="sort_key3">{{($topRankerScore[$s->song_id . "_" . $s->difficulty] != 0) ? ($s->over_damage_high_score / $topRankerScore[$s->song_id . "_" . $s->difficulty]) * 100 : 100}}%</td>
@if (array_key_exists($s->song_id . "_" . $s->difficulty, $topRankerScore))
<td class="sort_key1">{{$topRankerScore[$s->song_id . "_" . $s->difficulty] . "%"}}</td>
<td class="sort_key2">{{$s->over_damage_high_score - $topRankerScore[$s->song_id . "_" . $s->difficulty]}}%</td>
<td class="sort_key3">{{($topRankerScore[$s->song_id . "_" . $s->difficulty] != 0) ? ($s->over_damage_high_score / $topRankerScore[$s->song_id . "_" . $s->difficulty]) * 100 : 100}}%</td>
@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
Expand Down
5 changes: 4 additions & 1 deletion OngekiScoreLog/resources/views/user_overdamage.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
@section('title', $status[0]->name)
@section('hero_subtitle', $status[0]->trophy)
@section('hero_title', $status[0]->name)
@section('additional_head')
<meta name="robots" content="noindex">
@endsection
@section('additional_footer')
<script type="text/javascript" src="{{ mix('/js/sortTable.js') }}"></script>
<script type="text/javascript" src="{{ mix('/js/tableScalable.js') }}"></script>
Expand Down Expand Up @@ -63,7 +66,7 @@
{{-- @component('layouts/components/user/song_filter')
@endcomponent --}}

@component('layouts/components/user/song_status_overdamage', ['score' => $scoreDatas, 'topRankerScore' => $topRankerScore, 'id' => $id])
@component('layouts/components/user/song_status_overdamage', ['score' => $scoreDatas, 'topRankerScore' => $topRankerScore, 'id' => $id, 'lastUpdate' => $lastUpdate])
@endcomponent

@endsection
6 changes: 5 additions & 1 deletion OngekiScoreLog/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
Route::get('/user/{id}/trophy', 'ViewUserTrophyController@getIndex')->where(['id' => '\d+']);
Route::get('/user/{id}/music/{music}/{difficulty}', 'ViewUserMusicController@getIndex')->where(['id' => '\d+', 'music' => '\d+', 'difficulty' => '\w+']);
Route::get('/user/{id}/music/{music}', 'ViewUserMusicController@getRedirect')->where(['id' => '\d+', 'music' => '\d+']);
Route::get('/user/{id}/overdamage', 'ViewUserController@getOverDamegePage')->where(['id' => '\d+']);
Route::middleware('throttle:5,1')->group(function () {
Route::get('/user/{id}/overdamage', 'ViewUserController@getOverDamegePage')->where(['id' => '\d+']);
});
Route::get('/user/{id}/{mode?}', 'ViewUserController@getUserPage')->where(['id' => '\d+']);

Route::middleware('throttle:3,1')->group(function () {
Expand Down Expand Up @@ -57,7 +59,9 @@
Route::group(['middleware' => ['auth', 'can:admin']], function () {
Route::get('/admin', 'AdminController@GetIndex');
Route::get('/admin/config', 'AdminController@GetConfig');
Route::get('/admin/aggregate', 'AdminController@GetAggregate');
Route::get('/admin/apply/{type}/{action?}', 'AdminController@GetApply');
Route::get('/admin/generate/over-damage', 'AdminController@GetGenerateOverDamage');
Route::get('/admin/log/{path}/{fileName}', 'SimpleViewController@getLogFile');
});

Expand Down
Loading