Skip to content

Commit

Permalink
Merge pull request #28 from linomp/feat/leaderboard
Browse files Browse the repository at this point in the history
Add leaderboard functionality
  • Loading branch information
linomp authored Apr 22, 2024
2 parents 56a1c14 + 7bc0416 commit c81011a
Show file tree
Hide file tree
Showing 32 changed files with 662 additions and 332 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ venv
.idea
*.xml
*.iml
*.pyc
*.pyc
**/data/
10 changes: 6 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
version: "3.8"

networks:
my-network:

services:
mvp-api:
build:
Expand All @@ -13,6 +10,8 @@ services:
networks:
- my-network
restart: always
volumes:
- ./mvp/data:/code/mvp/data

mvp-client:
build:
Expand All @@ -22,4 +21,7 @@ services:
- "8080:80"
networks:
- my-network
restart: always
restart: always

networks:
my-network:
Binary file added media/22_04_2024.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 34 additions & 36 deletions mvp/client/ui/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
<script lang="ts">
import { onMount } from "svelte";
import { Route, Router } from "svelte-navigator";
import { GameParametersService, OpenAPI } from "./api/generated/";
import { globalSettings } from "src/stores/stores";
import { isUndefinedOrNull } from "src/shared/utils";
import HomePage from "src/pages/HomePage.svelte";
import Spinner from "src/components/graphical/Spinner.svelte";
import Preloader from "src/components/Preloader.svelte";
import {onMount} from "svelte";
import {Route, Router} from "svelte-navigator";
import {GameParametersService} from "./api/generated/";
import {globalSettings} from "src/stores/stores";
import {isUndefinedOrNull} from "src/shared/utils";
import HomePage from "src/pages/HomePage.svelte";
import Spinner from "src/components/graphical/Spinner.svelte";
import Preloader from "src/components/Preloader.svelte";
OpenAPI.BASE = import.meta.env.VITE_API_BASE;
onMount(async () => {
try {
globalSettings.set(
await GameParametersService.getParametersGameParametersGet(),
);
} catch (error) {
alert(
"Error fetching game settings or connecting to MQTT broker. Please refresh the page.",
);
}
});
onMount(() => {
GameParametersService.getParametersGameParametersGet()
.then((response) => {
globalSettings.set(response);
})
.catch((error) => {
alert(
"Error fetching game settings or connecting to MQTT broker. Please refresh the page.",
);
});
});
</script>

<svelte:head>
<title>The Predictive Maintenance Game</title>
<title>The Predictive Maintenance Game</title>
</svelte:head>

<Router primary={false}>
<Preloader />
{#if isUndefinedOrNull($globalSettings)}
<div class="spinner-container">
<Spinner />
</div>
{:else}
<div>
<Route path="/" component={HomePage} />
</div>
{/if}
<Preloader/>
{#if isUndefinedOrNull($globalSettings)}
<div class="spinner-container">
<Spinner/>
</div>
{:else}
<div>
<Route path="/" component={HomePage}/>
</div>
{/if}
</Router>

<style>
.spinner-container {
width: 5%;
margin: 0 auto;
}
.spinner-container {
width: 5%;
margin: 0 auto;
}
</style>
3 changes: 3 additions & 0 deletions mvp/client/ui/src/api/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export type { OpenAPIConfig } from './core/OpenAPI';
export type { GameMetrics } from './models/GameMetrics';
export type { GameParametersDTO } from './models/GameParametersDTO';
export type { GameSessionDTO } from './models/GameSessionDTO';
export type { HighScoreDTO } from './models/HighScoreDTO';
export type { HTTPValidationError } from './models/HTTPValidationError';
export type { MachineStateDTO } from './models/MachineStateDTO';
export type { MqttFrontendConnectionDetails } from './models/MqttFrontendConnectionDetails';
export type { OperationalParameters } from './models/OperationalParameters';
export type { ScoreCreateRequest } from './models/ScoreCreateRequest';
export type { ValidationError } from './models/ValidationError';

export { GameParametersService } from './services/GameParametersService';
export { LeaderboardService } from './services/LeaderboardService';
export { PlayerActionsService } from './services/PlayerActionsService';
export { SessionsService } from './services/SessionsService';
1 change: 1 addition & 0 deletions mvp/client/ui/src/api/generated/models/GameSessionDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export type GameSessionDTO = {
available_funds: number;
is_game_over: boolean;
game_over_reason?: (string | null);
final_score?: (number | null);
};
10 changes: 10 additions & 0 deletions mvp/client/ui/src/api/generated/models/HighScoreDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type HighScoreDTO = {
nickname: string;
score: number;
timestamp: string;
};
8 changes: 8 additions & 0 deletions mvp/client/ui/src/api/generated/models/ScoreCreateRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type ScoreCreateRequest = {
nickname: string;
};
85 changes: 85 additions & 0 deletions mvp/client/ui/src/api/generated/services/LeaderboardService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { HighScoreDTO } from '../models/HighScoreDTO';
import type { ScoreCreateRequest } from '../models/ScoreCreateRequest';

import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';

export class LeaderboardService {

/**
* Get Leaderboard
* @returns HighScoreDTO Successful Response
* @throws ApiError
*/
public static getLeaderboardLeaderboardGet(): CancelablePromise<Array<HighScoreDTO>> {
return __request(OpenAPI, {
method: 'GET',
url: '/leaderboard/',
errors: {
404: `Not found`,
},
});
}

/**
* Post Score
* @param sessionId
* @param requestBody
* @returns any Successful Response
* @throws ApiError
*/
public static postScoreLeaderboardScorePost(
sessionId: string,
requestBody: ScoreCreateRequest,
): CancelablePromise<any> {
return __request(OpenAPI, {
method: 'POST',
url: '/leaderboard/score',
query: {
'session_id': sessionId,
},
body: requestBody,
mediaType: 'application/json',
errors: {
404: `Not found`,
422: `Validation Error`,
},
});
}

/**
* Test Leaderboard Post
* @returns any Successful Response
* @throws ApiError
*/
public static testLeaderboardPostLeaderboardTestPost(): CancelablePromise<any> {
return __request(OpenAPI, {
method: 'POST',
url: '/leaderboard/test',
errors: {
404: `Not found`,
},
});
}

/**
* Test Leaderboard Delete
* @returns any Successful Response
* @throws ApiError
*/
public static testLeaderboardDeleteLeaderboardTestDelete(): CancelablePromise<any> {
return __request(OpenAPI, {
method: 'DELETE',
url: '/leaderboard/test',
errors: {
404: `Not found`,
},
});
}

}
40 changes: 20 additions & 20 deletions mvp/client/ui/src/api/generated/services/SessionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import { request as __request } from '../core/request';
export class SessionsService {

/**
* Get Mqtt Connection Details
* Get Session
* @param sessionId
* @returns MqttFrontendConnectionDetails Successful Response
* @returns GameSessionDTO Successful Response
* @throws ApiError
*/
public static getMqttConnectionDetailsSessionsMqttConnectionDetailsGet(
public static getSessionSessionsGet(
sessionId: string,
): CancelablePromise<MqttFrontendConnectionDetails> {
): CancelablePromise<GameSessionDTO> {
return __request(OpenAPI, {
method: 'GET',
url: '/sessions/mqtt-connection-details',
url: '/sessions/',
query: {
'session_id': sessionId,
},
Expand All @@ -50,38 +50,38 @@ sessionId: string,
}

/**
* Get Session
* @param sessionId
* @returns GameSessionDTO Successful Response
* Get Metrics
* @returns GameMetrics Successful Response
* @throws ApiError
*/
public static getSessionSessionsGet(
sessionId: string,
): CancelablePromise<GameSessionDTO> {
public static getMetricsSessionsMetricsGet(): CancelablePromise<GameMetrics> {
return __request(OpenAPI, {
method: 'GET',
url: '/sessions/',
query: {
'session_id': sessionId,
},
url: '/sessions/metrics',
errors: {
404: `Not found`,
422: `Validation Error`,
},
});
}

/**
* Get Metrics
* @returns GameMetrics Successful Response
* Get Mqtt Connection Details
* @param sessionId
* @returns MqttFrontendConnectionDetails Successful Response
* @throws ApiError
*/
public static getMetricsSessionsMetricsGet(): CancelablePromise<GameMetrics> {
public static getMqttConnectionDetailsSessionsMqttConnectionDetailsGet(
sessionId: string,
): CancelablePromise<MqttFrontendConnectionDetails> {
return __request(OpenAPI, {
method: 'GET',
url: '/sessions/metrics',
url: '/sessions/mqtt-connection-details',
query: {
'session_id': sessionId,
},
errors: {
404: `Not found`,
422: `Validation Error`,
},
});
}
Expand Down
Loading

0 comments on commit c81011a

Please sign in to comment.