From 162e8069c72fc38749590ffd8b30355a588a8a1f Mon Sep 17 00:00:00 2001 From: Takaya Kakizaki Date: Wed, 7 Feb 2024 22:01:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B5=B1=E8=A8=88=E7=B5=90=E6=9E=9C?= =?UTF-8?q?=E5=87=BA=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 4 +- src/apis/analysis/index.ts | 6 + src/apis/analysis/models/AverageScore.ts | 11 ++ src/apis/analysis/models/Dataset.ts | 9 ++ src/apis/analysis/models/NagareCount.ts | 9 ++ src/apis/analysis/models/YakuCount.ts | 10 ++ src/apis/analysis/services/DatasetsService.ts | 21 ++++ .../analysis/services/StatisticsService.ts | 90 ++++++++++++++ src/hooks/swr/dataset/index.ts | 11 ++ src/hooks/swr/statistics/index.ts | 38 ++++++ src/pages/games/index.tsx | 8 +- src/pages/statistics/index.tsx | 116 ++++++++++++++++++ 12 files changed, 328 insertions(+), 5 deletions(-) create mode 100644 src/apis/analysis/models/AverageScore.ts create mode 100644 src/apis/analysis/models/Dataset.ts create mode 100644 src/apis/analysis/models/NagareCount.ts create mode 100644 src/apis/analysis/models/YakuCount.ts create mode 100644 src/apis/analysis/services/DatasetsService.ts create mode 100644 src/apis/analysis/services/StatisticsService.ts create mode 100644 src/hooks/swr/dataset/index.ts create mode 100644 src/hooks/swr/statistics/index.ts create mode 100644 src/pages/statistics/index.tsx diff --git a/src/App.tsx b/src/App.tsx index 0013db5..e49677b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,7 +10,7 @@ import { DefaultLayout } from './layouts/default' import { RequireAuth } from './components/atoms/RequireAuth' import { SignIn } from './pages/signin' import { OpenAPI } from './apis/analysis' -import { GamesIndex } from './pages/games' +import { StatisticsIndex } from './pages/statistics' const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes) @@ -33,7 +33,7 @@ function App() { index element={ - + } /> diff --git a/src/apis/analysis/index.ts b/src/apis/analysis/index.ts index 64f3127..a2339f0 100644 --- a/src/apis/analysis/index.ts +++ b/src/apis/analysis/index.ts @@ -7,13 +7,19 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise'; export { OpenAPI } from './core/OpenAPI'; export type { OpenAPIConfig } from './core/OpenAPI'; +export type { AverageScore } from './models/AverageScore'; +export type { Dataset } from './models/Dataset'; export type { Element_int_ } from './models/Element_int_'; export type { Game } from './models/Game'; export type { GenericList_int_ } from './models/GenericList_int_'; export type { HTTPValidationError } from './models/HTTPValidationError'; export type { Kyoku } from './models/Kyoku'; +export type { NagareCount } from './models/NagareCount'; export type { ValidationError } from './models/ValidationError'; +export type { YakuCount } from './models/YakuCount'; +export { DatasetsService } from './services/DatasetsService'; export { DefaultService } from './services/DefaultService'; export { GamesService } from './services/GamesService'; export { KyokusService } from './services/KyokusService'; +export { StatisticsService } from './services/StatisticsService'; diff --git a/src/apis/analysis/models/AverageScore.ts b/src/apis/analysis/models/AverageScore.ts new file mode 100644 index 0000000..448d070 --- /dev/null +++ b/src/apis/analysis/models/AverageScore.ts @@ -0,0 +1,11 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type AverageScore = { + player_name: string; + score: number; + point: number; + game_count: number; +}; + diff --git a/src/apis/analysis/models/Dataset.ts b/src/apis/analysis/models/Dataset.ts new file mode 100644 index 0000000..23e4571 --- /dev/null +++ b/src/apis/analysis/models/Dataset.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type Dataset = { + id: string; + friendly_name: (string | null); +}; + diff --git a/src/apis/analysis/models/NagareCount.ts b/src/apis/analysis/models/NagareCount.ts new file mode 100644 index 0000000..8800ed2 --- /dev/null +++ b/src/apis/analysis/models/NagareCount.ts @@ -0,0 +1,9 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type NagareCount = { + name: string; + count: number; +}; + diff --git a/src/apis/analysis/models/YakuCount.ts b/src/apis/analysis/models/YakuCount.ts new file mode 100644 index 0000000..25f044f --- /dev/null +++ b/src/apis/analysis/models/YakuCount.ts @@ -0,0 +1,10 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type YakuCount = { + name: string; + han_count: number; + count: number; +}; + diff --git a/src/apis/analysis/services/DatasetsService.ts b/src/apis/analysis/services/DatasetsService.ts new file mode 100644 index 0000000..a53ffc5 --- /dev/null +++ b/src/apis/analysis/services/DatasetsService.ts @@ -0,0 +1,21 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { Dataset } from '../models/Dataset'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; +export class DatasetsService { + /** + * Get Datasets + * @returns Dataset Successful Response + * @throws ApiError + */ + public static getDatasetsDatasetsGet(): CancelablePromise> { + return __request(OpenAPI, { + method: 'GET', + url: '/datasets', + }); + } +} diff --git a/src/apis/analysis/services/StatisticsService.ts b/src/apis/analysis/services/StatisticsService.ts new file mode 100644 index 0000000..c8e27d5 --- /dev/null +++ b/src/apis/analysis/services/StatisticsService.ts @@ -0,0 +1,90 @@ +/* generated using openapi-typescript-codegen -- do no edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +import type { AverageScore } from '../models/AverageScore'; +import type { NagareCount } from '../models/NagareCount'; +import type { YakuCount } from '../models/YakuCount'; +import type { CancelablePromise } from '../core/CancelablePromise'; +import { OpenAPI } from '../core/OpenAPI'; +import { request as __request } from '../core/request'; +export class StatisticsService { + /** + * Get Average Score By Player + * @param datasetId + * @param startDate + * @param endDate + * @returns AverageScore Successful Response + * @throws ApiError + */ + public static getAverageScoreByPlayerStatisticsAverageScoreByPlayerGet( + datasetId: string, + startDate: string, + endDate: string, + ): CancelablePromise> { + return __request(OpenAPI, { + method: 'GET', + url: '/statistics/average_score_by_player', + query: { + 'dataset_id': datasetId, + 'start_date': startDate, + 'end_date': endDate, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Get Yaku Count + * @param datasetId + * @param startDate + * @param endDate + * @returns YakuCount Successful Response + * @throws ApiError + */ + public static getYakuCountStatisticsYakuCountGet( + datasetId: string, + startDate: string, + endDate: string, + ): CancelablePromise> { + return __request(OpenAPI, { + method: 'GET', + url: '/statistics/yaku_count', + query: { + 'dataset_id': datasetId, + 'start_date': startDate, + 'end_date': endDate, + }, + errors: { + 422: `Validation Error`, + }, + }); + } + /** + * Get Nagare Count + * @param datasetId + * @param startDate + * @param endDate + * @returns NagareCount Successful Response + * @throws ApiError + */ + public static getNagareCountStatisticsNagareCountGet( + datasetId: string, + startDate: string, + endDate: string, + ): CancelablePromise> { + return __request(OpenAPI, { + method: 'GET', + url: '/statistics/nagare_count', + query: { + 'dataset_id': datasetId, + 'start_date': startDate, + 'end_date': endDate, + }, + errors: { + 422: `Validation Error`, + }, + }); + } +} diff --git a/src/hooks/swr/dataset/index.ts b/src/hooks/swr/dataset/index.ts new file mode 100644 index 0000000..7b1ca39 --- /dev/null +++ b/src/hooks/swr/dataset/index.ts @@ -0,0 +1,11 @@ +import useSWR, { SWRConfiguration } from 'swr' +import { DatasetsService } from '../../../apis/analysis' +import { useAPIToken } from '../../common/useToken' + +export const useDatasets = (config?: Partial) => { + const { data: token } = useAPIToken() + + return useSWR(['datasets', token], DatasetsService.getDatasetsDatasetsGet, { + ...config, + }) +} diff --git a/src/hooks/swr/statistics/index.ts b/src/hooks/swr/statistics/index.ts new file mode 100644 index 0000000..d7bab72 --- /dev/null +++ b/src/hooks/swr/statistics/index.ts @@ -0,0 +1,38 @@ +import { StatisticsService } from '../../../apis/analysis' + +// hooksじゃないので本来ここに置くのはおかしいが、あとで移動する +export const getAverageScoreByPlayer = async ( + datasetId: string, + startDate: string, + endDate: string +) => { + return await StatisticsService.getAverageScoreByPlayerStatisticsAverageScoreByPlayerGet( + datasetId, + startDate, + endDate + ) +} + +export const getYakuCount = async ( + datasetId: string, + startDate: string, + endDate: string +) => { + return await StatisticsService.getYakuCountStatisticsYakuCountGet( + datasetId, + startDate, + endDate + ) +} + +export const getNagareCount = async ( + datasetId: string, + startDate: string, + endDate: string +) => { + return await StatisticsService.getNagareCountStatisticsNagareCountGet( + datasetId, + startDate, + endDate + ) +} diff --git a/src/pages/games/index.tsx b/src/pages/games/index.tsx index 12db771..07c7dce 100644 --- a/src/pages/games/index.tsx +++ b/src/pages/games/index.tsx @@ -10,14 +10,15 @@ import { Stack, Table, TableBody, - TableCell, TableContainer, TableRow, } from '@mui/material' import { useGames } from '../../hooks/swr/games' import { JsonViewer } from '@textea/json-viewer' +import { useDatasets } from '../../hooks/swr/dataset' export const GamesIndex = () => { + const { data: datasets } = useDatasets() const [startDate, setStartDate] = useState( dayjs().subtract(1, 'day') ) @@ -47,8 +48,9 @@ export const GamesIndex = () => { value={datasetId} onChange={handleChangeDatasetId} > - 天鳳牌譜 - ソロプレイ牌譜 + {datasets?.map((dataset) => ( + {dataset.friendly_name} + ))} { + const { data: datasets } = useDatasets() + const [startDate, setStartDate] = useState( + dayjs().subtract(1, 'day') + ) + const [endDate, setEndDate] = useState( + dayjs().subtract(1, 'day') + ) + const [datasetId, setDatasetId] = useState('') + + const handleChangeDatasetId = (event: SelectChangeEvent) => { + setDatasetId(event.target.value as string) + } + + const [result, setResult] = useState(null) + + const handleGetAverageScoreByPlayer = async () => { + const response = await getAverageScoreByPlayer( + datasetId, + startDate?.format('YYYY-MM-DD') ?? '', + endDate?.format('YYYY-MM-DD') ?? '' + ) + setResult(response) + } + + const handleGetYakuCount = async () => { + const response = await getYakuCount( + datasetId, + startDate?.format('YYYY-MM-DD') ?? '', + endDate?.format('YYYY-MM-DD') ?? '' + ) + setResult(response) + } + + const handleGetNagareCount = async () => { + const response = await getNagareCount( + datasetId, + startDate?.format('YYYY-MM-DD') ?? '', + endDate?.format('YYYY-MM-DD') ?? '' + ) + setResult(response) + } + + return ( + + + {/* フォームをいれる(のちのちcomponent化) */} + + + + + + + + + + + + + {/* APIの結果表示 */} + + + + {result?.map((r) => ( + + + + ))} + +
+
+
+
+ ) +}