-
Notifications
You must be signed in to change notification settings - Fork 9
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 #1153 from shikorism/develop
Release 2024.1.0
- Loading branch information
Showing
49 changed files
with
5,317 additions
and
2,961 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
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
53 changes: 53 additions & 0 deletions
53
app/Http/Controllers/Api/V1/UserStats/DailyCheckinSummary.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,53 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\V1\UserStats; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Queries\EjaculationCountByDay; | ||
use App\User; | ||
use Carbon\CarbonImmutable; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
|
||
class DailyCheckinSummary extends Controller | ||
{ | ||
public function __invoke(Request $request, User $user) | ||
{ | ||
if (!$user->isMe() && $user->is_protected) { | ||
throw new AccessDeniedHttpException('このユーザはチェックイン履歴を公開していません'); | ||
} | ||
|
||
$validated = $request->validate([ | ||
'since' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
'until' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
]); | ||
|
||
if (!empty($validated['since']) && !empty($validated['until'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
if ($until->isBefore($since)) { | ||
[$since, $until] = [$until, $since]; | ||
} | ||
} elseif (!empty($validated['since'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = null; | ||
} elseif (!empty($validated['until'])) { | ||
$since = null; | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
} else { | ||
$since = null; | ||
$until = null; | ||
} | ||
|
||
$countByDay = (new EjaculationCountByDay($user))->query(); | ||
if ($since !== null) { | ||
$countByDay = $countByDay->where('ejaculated_date', '>=', $since); | ||
} | ||
if ($until !== null) { | ||
$countByDay = $countByDay->where('ejaculated_date', '<', $until); | ||
} | ||
|
||
return response()->json($countByDay->get()); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
app/Http/Controllers/Api/V1/UserStats/HourlyCheckinSummary.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,76 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\V1\UserStats; | ||
|
||
use App\Ejaculation; | ||
use App\Http\Controllers\Controller; | ||
use App\User; | ||
use Carbon\CarbonImmutable; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
|
||
class HourlyCheckinSummary extends Controller | ||
{ | ||
public function __invoke(Request $request, User $user) | ||
{ | ||
if (!$user->isMe() && $user->is_protected) { | ||
throw new AccessDeniedHttpException('このユーザはチェックイン履歴を公開していません'); | ||
} | ||
|
||
$validated = $request->validate([ | ||
'since' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
'until' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
]); | ||
|
||
if (!empty($validated['since']) && !empty($validated['until'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
if ($until->isBefore($since)) { | ||
[$since, $until] = [$until, $since]; | ||
} | ||
} elseif (!empty($validated['since'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = null; | ||
} elseif (!empty($validated['until'])) { | ||
$since = null; | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
} else { | ||
$since = null; | ||
$until = null; | ||
} | ||
|
||
$dateCondition = []; | ||
if ($since !== null) { | ||
$dateCondition[] = ['ejaculated_date', '>=', $since]; | ||
} | ||
if ($until !== null) { | ||
$dateCondition[] = ['ejaculated_date', '<', $until]; | ||
} | ||
|
||
$groupByHour = Ejaculation::select(DB::raw( | ||
<<<'SQL' | ||
to_char(ejaculated_date, 'HH24') AS "hour", | ||
count(*) AS "count" | ||
SQL | ||
)) | ||
->where('user_id', $user->id) | ||
->where($dateCondition) | ||
->groupBy(DB::raw("to_char(ejaculated_date, 'HH24')")) | ||
->orderBy(DB::raw('1')) | ||
->get(); | ||
|
||
$results = []; | ||
for ($hour = 0; $hour < 24; $hour++) { | ||
if (!empty($groupByHour) && (int)($groupByHour->first()->hour) === $hour) { | ||
$data = $groupByHour->shift(); | ||
$results[] = ['hour' => $hour, 'count' => $data->count]; | ||
} else { | ||
$results[] = ['hour' => $hour, 'count' => 0]; | ||
} | ||
} | ||
|
||
return response()->json($results); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/Http/Controllers/Api/V1/UserStats/MostlyUsedCheckinTags.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,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\V1\UserStats; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Queries\CountUsedTags; | ||
use App\User; | ||
use Carbon\CarbonImmutable; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
|
||
class MostlyUsedCheckinTags extends Controller | ||
{ | ||
public function __invoke(Request $request, User $user) | ||
{ | ||
if (!$user->isMe() && $user->is_protected) { | ||
throw new AccessDeniedHttpException('このユーザはチェックイン履歴を公開していません'); | ||
} | ||
|
||
$validated = $request->validate([ | ||
'since' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
'until' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
]); | ||
|
||
if (!empty($validated['since']) && !empty($validated['until'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
if ($until->isBefore($since)) { | ||
[$since, $until] = [$until, $since]; | ||
} | ||
} elseif (!empty($validated['since'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = null; | ||
} elseif (!empty($validated['until'])) { | ||
$since = null; | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
} else { | ||
$since = null; | ||
$until = null; | ||
} | ||
|
||
$result = (new CountUsedTags(Auth::user(), $user)) | ||
->since($since) | ||
->until($until) | ||
->setIncludesMetadata($request->boolean('includesMetadata')) | ||
->query(); | ||
|
||
return response()->json($result); | ||
} | ||
} |
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,74 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\V1\UserStats; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\User; | ||
use Carbon\CarbonImmutable; | ||
use Carbon\CarbonInterface; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | ||
|
||
class MostlyUsedLinks extends Controller | ||
{ | ||
public function __invoke(Request $request, User $user) | ||
{ | ||
if (!$user->isMe() && $user->is_protected) { | ||
throw new AccessDeniedHttpException('このユーザはチェックイン履歴を公開していません'); | ||
} | ||
|
||
$validated = $request->validate([ | ||
'since' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
'until' => 'nullable|date_format:Y-m-d|after_or_equal:2000-01-01|before_or_equal:2099-12-31', | ||
]); | ||
|
||
if (!empty($validated['since']) && !empty($validated['until'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
if ($until->isBefore($since)) { | ||
[$since, $until] = [$until, $since]; | ||
} | ||
|
||
if ($until->diffInYears($since) >= 1) { | ||
$until = $since->addYear(); | ||
} | ||
} elseif (!empty($validated['since'])) { | ||
$since = CarbonImmutable::createFromFormat('Y-m-d', $validated['since'])->startOfDay(); | ||
$until = $since->addYear(); | ||
} elseif (!empty($validated['until'])) { | ||
$until = CarbonImmutable::createFromFormat('Y-m-d', $validated['until'])->startOfDay()->addDay(); | ||
$since = $until->subYear(); | ||
} else { | ||
$since = CarbonImmutable::now()->startOfDay()->firstOfYear(); | ||
$until = CarbonImmutable::now()->startOfDay()->firstOfYear()->addYear(); | ||
} | ||
|
||
return response()->json($this->countMostFrequentlyUsedOkazu($user, $since, $until)); | ||
} | ||
|
||
private function countMostFrequentlyUsedOkazu(User $user, CarbonInterface $dateSince = null, CarbonInterface $dateUntil = null) | ||
{ | ||
$sql = <<<SQL | ||
SELECT normalized_link as link, count(*) as count | ||
FROM ejaculations e | ||
WHERE user_id = ? AND is_private IN (?, ?) AND ejaculated_date >= ? AND ejaculated_date < ? AND normalized_link <> '' | ||
GROUP BY normalized_link HAVING count(*) >= 2 | ||
ORDER BY count DESC, normalized_link | ||
LIMIT 10 | ||
SQL; | ||
|
||
if ($dateSince === null) { | ||
$dateSince = CarbonImmutable::minValue(); | ||
} | ||
if ($dateUntil === null) { | ||
$dateUntil = now()->addMonth()->startOfMonth(); | ||
} | ||
|
||
return DB::select(DB::raw($sql), [ | ||
$user->id, false, Auth::check() && $user->id === Auth::id(), $dateSince, $dateUntil | ||
]); | ||
} | ||
} |
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
Oops, something went wrong.