Merge pull request 'Improved ontime loading & added game ontime #446' (#449) from #446 into dev
All checks were successful
Deploy dev on push / on-push-deploy_sh-edraft (push) Successful in 4m58s

Reviewed-on: #449
This commit is contained in:
Sven Heidemann 2023-12-03 16:06:50 +01:00
commit 898e005978
11 changed files with 86 additions and 58 deletions

View File

@ -2,6 +2,7 @@ from datetime import datetime, date
from typing import Optional from typing import Optional
from cpl_core.database import TableABC from cpl_core.database import TableABC
from cpl_core.database.context import DatabaseContextABC
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List from cpl_query.extension import List
@ -92,10 +93,32 @@ class User(TableABC):
@property @property
@ServiceProviderABC.inject @ServiceProviderABC.inject
def ontime(self, services: ServiceProviderABC) -> float: def ontime(self, services: ServiceProviderABC) -> float:
from bot_core.abc.client_utils_abc import ClientUtilsABC db: DatabaseContextABC = services.get_service(DatabaseContextABC)
result = db.select(
f"""
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedVoiceChannel.LeavedOn, UserJoinedVoiceChannel.JoinedOn)) / 3600),2)
FROM UserJoinedVoiceChannel
WHERE UserId = {self._user_id};
"""
)[0][0]
if result is None:
return 0
return float(result)
client_utils: ClientUtilsABC = services.get_service(ClientUtilsABC) @property
return client_utils.get_ontime_for_user(self) @ServiceProviderABC.inject
def game_ontime(self, services: ServiceProviderABC) -> float:
db: DatabaseContextABC = services.get_service(DatabaseContextABC)
result = db.select(
f"""
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600),2)
FROM UserJoinedGameServer
WHERE UserId = {self._user_id};
"""
)[0][0]
if result is None:
return 0
return float(result)
@property @property
@ServiceProviderABC.inject @ServiceProviderABC.inject

View File

@ -7,6 +7,7 @@ type User implements TableWithHistoryQuery {
reactionCount: Int reactionCount: Int
birthday: String birthday: String
ontime: Float ontime: Float
gameOntime: Float
level: Level level: Level
joinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer] joinedServers(filter: UserJoinedServerFilter, page: Page, sort: Sort): [UserJoinedServer]

View File

@ -132,7 +132,7 @@ class ServerStatisticQuery(QueryABC):
def _resolve_game_server_ontime(self, server, *_): def _resolve_game_server_ontime(self, server, *_):
query = f""" query = f"""
SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600),{server.server.id}) FROM UserJoinedGameServer SELECT ROUND(SUM(TIME_TO_SEC(TIMEDIFF(UserJoinedGameServer.LeavedOn, UserJoinedGameServer.JoinedOn)) / 3600),2) FROM UserJoinedGameServer
INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId INNER JOIN Users ON UserJoinedGameServer.UserId = Users.UserId
WHERE Users.ServerId = {server.server.id} WHERE Users.ServerId = {server.server.id}
AND UserJoinedGameServer.CreatedAt >= "{self._get_date(**server.kwargs)}"; AND UserJoinedGameServer.CreatedAt >= "{self._get_date(**server.kwargs)}";

View File

@ -2,6 +2,7 @@ from cpl_core.database.context import DatabaseContextABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.abc.permission_service_abc import PermissionServiceABC
from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC
from bot_data.abc.user_joined_game_server_repository_abc import ( from bot_data.abc.user_joined_game_server_repository_abc import (
UserJoinedGameServerRepositoryABC, UserJoinedGameServerRepositoryABC,
@ -11,7 +12,6 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryABC,
) )
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
from bot_data.model.user import User
from bot_data.model.user_history import UserHistory from bot_data.model.user_history import UserHistory
from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC from bot_graphql.abc.data_query_with_history_abc import DataQueryWithHistoryABC
from bot_graphql.filter.achievement_filter import AchievementFilter from bot_graphql.filter.achievement_filter import AchievementFilter
@ -22,7 +22,6 @@ from bot_graphql.filter.user_joined_voice_channel_filter import (
) )
from bot_graphql.filter.user_warning_filter import UserWarningFilter from bot_graphql.filter.user_warning_filter import UserWarningFilter
from modules.level.service.level_service import LevelService from modules.level.service.level_service import LevelService
from bot_core.abc.permission_service_abc import PermissionServiceABC
class UserQuery(DataQueryWithHistoryABC): class UserQuery(DataQueryWithHistoryABC):
@ -50,15 +49,16 @@ class UserQuery(DataQueryWithHistoryABC):
self._permissions = permissions self._permissions = permissions
self._achievements = achievements self._achievements = achievements
self.set_field("id", self.resolve_id) self.set_field("id", lambda user, *_: user.id)
self.set_field("discordId", self.resolve_discord_id) self.set_field("discordId", lambda user, *_: user.discord_id)
self.set_field("name", self.resolve_name) self.set_field("name", lambda user, *_: user.name)
self.set_field("xp", self.resolve_xp) self.set_field("xp", lambda user, *_: user.xp)
self.set_field("messageCount", lambda x, *_: x.message_count) self.set_field("messageCount", lambda x, *_: x.message_count)
self.set_field("reactionCount", lambda x, *_: x.reaction_count) self.set_field("reactionCount", lambda x, *_: x.reaction_count)
self.set_field("birthday", lambda x, *_: None if x.birthday is None else x.birthday.strftime("%d.%m.%Y")) self.set_field("birthday", lambda x, *_: None if x.birthday is None else x.birthday.strftime("%d.%m.%Y"))
self.set_field("ontime", self.resolve_ontime) self.set_field("ontime", lambda user, *_: user.ontime)
self.set_field("level", self.resolve_level) self.set_field("gameOntime", lambda user, *_: user.game_ontime)
self.set_field("level", lambda user, *_: user.level)
self.add_collection( self.add_collection(
"joinedServer", "joinedServer",
lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.id), lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.id),
@ -85,37 +85,5 @@ class UserQuery(DataQueryWithHistoryABC):
UserWarningFilter, UserWarningFilter,
) )
self.set_field("server", self.resolve_server) self.set_field("server", lambda user, *_: user.server)
self.set_field("leftServer", self.resolve_left_server) self.set_field("leftServer", lambda user, *_: user.left_server)
@staticmethod
def resolve_id(user: User, *_):
return user.id
@staticmethod
def resolve_discord_id(user: User, *_):
return user.discord_id
@staticmethod
def resolve_name(user: User, *_):
return user.name
@staticmethod
def resolve_xp(user: User, *_):
return user.xp
@staticmethod
def resolve_ontime(user: User, *_):
return user.ontime
@staticmethod
def resolve_level(user: User, *_):
return user.level
@staticmethod
def resolve_server(user: User, *_):
return user.server
@staticmethod
def resolve_left_server(user: User, *_):
return user.left_server

View File

@ -16,6 +16,7 @@ export interface User extends DataWithHistory {
reactionCount?: number; reactionCount?: number;
birthday?: string; birthday?: string;
ontime?: number; ontime?: number;
gameOntime?: number;
level?: Level; level?: Level;
server?: Server; server?: Server;
leftServer?: boolean; leftServer?: boolean;

View File

@ -361,6 +361,7 @@ export class Queries {
name name
xp xp
ontime ontime
gameOntime
level { level {
id id
name name
@ -386,6 +387,7 @@ export class Queries {
reactionCount reactionCount
birthday birthday
ontime ontime
gameOntime
level { level {
id id
name name

View File

@ -3,7 +3,8 @@
</h1> </h1>
<div class="content-wrapper"> <div class="content-wrapper">
<div class="content"> <div class="content">
<p-table #dt [value]="members" [responsive]="true" responsiveLayout="stack" [breakpoint]="'720px'" dataKey="id" editMode="row" [rowHover]="true" [rows]="10" <p-table #dt [value]="members" [responsive]="true" responsiveLayout="stack" [breakpoint]="'720px'" dataKey="id"
editMode="row" [rowHover]="true" [rows]="10"
[rowsPerPageOptions]="[10,25,50]" [paginator]="true" [loading]="loading" [totalRecords]="totalRecords" [rowsPerPageOptions]="[10,25,50]" [paginator]="true" [loading]="loading" [totalRecords]="totalRecords"
[lazy]="true" (onLazyLoad)="nextPage($event)"> [lazy]="true" (onLazyLoad)="nextPage($event)">
@ -17,7 +18,8 @@
{{'view.server.members.members' | translate}} {{'view.server.members.members' | translate}}
</div> </div>
<app-multi-select-columns [table]="name" [columns]="columns" [(hiddenColumns)]="hiddenColumns"></app-multi-select-columns> <app-multi-select-columns [table]="name" [columns]="columns"
[(hiddenColumns)]="hiddenColumns"></app-multi-select-columns>
</div> </div>
<div class="table-caption-btn-wrapper btn-wrapper"> <div class="table-caption-btn-wrapper btn-wrapper">
@ -65,6 +67,13 @@
</div> </div>
</th> </th>
<th hideable-th="game_ontime" [parent]="this" [sortable]="true">
<div class="table-header-label">
<div class="table-header-text">{{'common.game_ontime' | translate}}</div>
<p-sortIcon field="game_ontime" class="table-header-icon"></p-sortIcon>
</div>
</th>
<th hideable-th="left_server" [parent]="this" [sortable]="true"> <th hideable-th="left_server" [parent]="this" [sortable]="true">
<div class="table-header-label"> <div class="table-header-label">
<div class="table-header-text">{{'common.left_server' | translate}}</div> <div class="table-header-text">{{'common.left_server' | translate}}</div>
@ -106,7 +115,8 @@
</th> </th>
<th hideable-th="discord_id" [parent]="this" class="table-header-medium"> <th hideable-th="discord_id" [parent]="this" class="table-header-medium">
<form [formGroup]="filterForm"> <form [formGroup]="filterForm">
<input type="text" pInputText formControlName="discordId" placeholder="{{'common.discord_id' | translate}}"> <input type="text" pInputText formControlName="discordId"
placeholder="{{'common.discord_id' | translate}}">
</form> </form>
</th> </th>
<th hideable-th="name" [parent]="this"> <th hideable-th="name" [parent]="this">
@ -116,14 +126,17 @@
</th> </th>
<th hideable-th="xp" [parent]="this"></th> <th hideable-th="xp" [parent]="this"></th>
<th hideable-th="ontime" [parent]="this"></th> <th hideable-th="ontime" [parent]="this"></th>
<th hideable-th="game_ontime" [parent]="this"></th>
<th hideable-th="left_server" [parent]="this" class="table-header-small-dropdown"> <th hideable-th="left_server" [parent]="this" class="table-header-small-dropdown">
<form [formGroup]="filterForm"> <form [formGroup]="filterForm">
<p-dropdown formControlName="leftServer" [options]="leftServerOptions" placeholder="{{'common.left_server' | translate}}"></p-dropdown> <p-dropdown formControlName="leftServer" [options]="leftServerOptions"
placeholder="{{'common.left_server' | translate}}"></p-dropdown>
</form> </form>
</th> </th>
<th hideable-th="level" [parent]="this" class="table-header-small-dropdown"> <th hideable-th="level" [parent]="this" class="table-header-small-dropdown">
<form [formGroup]="filterForm"> <form [formGroup]="filterForm">
<p-dropdown formControlName="level" [options]="levels" placeholder="{{'common.level' | translate}}"></p-dropdown> <p-dropdown formControlName="level" [options]="levels"
placeholder="{{'common.level' | translate}}"></p-dropdown>
</form> </form>
</th> </th>
<th></th> <th></th>
@ -189,6 +202,17 @@
</ng-template> </ng-template>
</p-cellEditor> </p-cellEditor>
</td> </td>
<td hideable-th="game_ontime" [parent]="this">
<span class="p-column-title">{{'common.game_ontime' | translate}}:</span>
<p-cellEditor>
<ng-template pTemplate="input">
{{member.gameOntime}}
</ng-template>
<ng-template pTemplate="output">
{{member.gameOntime}}
</ng-template>
</p-cellEditor>
</td>
<td hideable-th="left_server" [parent]="this"> <td hideable-th="left_server" [parent]="this">
<span class="p-column-title">{{'common.left_server' | translate}}:</span> <span class="p-column-title">{{'common.left_server' | translate}}:</span>
<p-cellEditor> <p-cellEditor>
@ -204,7 +228,8 @@
<span class="p-column-title">{{'common.level' | translate}}:</span> <span class="p-column-title">{{'common.level' | translate}}:</span>
<p-cellEditor> <p-cellEditor>
<ng-template pTemplate="input"> <ng-template pTemplate="input">
<p-dropdown [options]="levels" [(ngModel)]="member.level" dataKey="id" placeholder="{{'common.level' | translate}}"></p-dropdown> <p-dropdown [options]="levels" [(ngModel)]="member.level" dataKey="id"
placeholder="{{'common.level' | translate}}"></p-dropdown>
</ng-template> </ng-template>
<ng-template pTemplate="output"> <ng-template pTemplate="output">
{{member.level.name}} {{member.level.name}}
@ -235,7 +260,8 @@
</td> </td>
<td> <td>
<div class="btn-wrapper"> <div class="btn-wrapper">
<app-history-btn *ngIf="!isEditingNew" [id]="member.id" [query]="query" translationKey="view.server.members.header"></app-history-btn> <app-history-btn *ngIf="!isEditingNew" [id]="member.id" [query]="query"
translationKey="view.server.members.header"></app-history-btn>
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil" <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-pencil"
(click)="onRowEditInit(dt, member, ri)"></button> (click)="onRowEditInit(dt, member, ri)"></button>
<button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-user" <button *ngIf="!editing" pButton pInitEditableRow class="btn icon-btn" icon="pi pi-user"

View File

@ -89,7 +89,7 @@ export class MembersComponent extends ComponentWithTable implements OnInit, OnDe
private data: DataService, private data: DataService,
private route: ActivatedRoute private route: ActivatedRoute
) { ) {
super("member", ["id", "discord_id", "name", "xp", "ontime", "left_server", "level"]); super("member", ["id", "discord_id", "name", "xp", "ontime", "game_ontime", "left_server", "level"]);
} }
ngOnInit(): void { ngOnInit(): void {

View File

@ -63,11 +63,18 @@
<div class="content-row"> <div class="content-row">
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'view.server.profile.ontime' | translate}}:</div> <div class="content-data-name">{{'common.ontime' | translate}}:</div>
<div class="content-data-value">{{user.ontime}}</div> <div class="content-data-value">{{user.ontime}}</div>
</div> </div>
</div> </div>
<div class="content-row">
<div class="content-column">
<div class="content-data-name">{{'common.game_ontime' | translate}}:</div>
<div class="content-data-value">{{user.gameOntime}}</div>
</div>
</div>
<div class="content-row"> <div class="content-row">
<div class="content-column"> <div class="content-column">
<div class="content-data-name">{{'view.server.profile.level' | translate}}:</div> <div class="content-data-name">{{'view.server.profile.level' | translate}}:</div>

View File

@ -154,6 +154,7 @@
"uploaded": "Daten wurden erfolgreich importiert." "uploaded": "Daten wurden erfolgreich importiert."
}, },
"first_name": "Vorname", "first_name": "Vorname",
"game_ontime": "Spiel Ontime",
"hidden_columns": "Ausgeblendete Spalten", "hidden_columns": "Ausgeblendete Spalten",
"history": { "history": {
"attribute": "Attribut", "attribute": "Attribut",
@ -542,7 +543,6 @@
"message_count": "Anzahl Nachrichten", "message_count": "Anzahl Nachrichten",
"minecraft_id": "Minecraft Id", "minecraft_id": "Minecraft Id",
"name": "Name", "name": "Name",
"ontime": "Ontime",
"permission_denied": "Zugriff verweigert!", "permission_denied": "Zugriff verweigert!",
"permission_denied_d": "Du musst Moderator sein, um andere Profile sehen zu können!", "permission_denied_d": "Du musst Moderator sein, um andere Profile sehen zu können!",
"reaction_count": "Anzahl Reaktionen", "reaction_count": "Anzahl Reaktionen",

View File

@ -154,6 +154,7 @@
"uploaded": "Data was imported successfully." "uploaded": "Data was imported successfully."
}, },
"first_name": "First name", "first_name": "First name",
"game_ontime": "Game ontime",
"hidden_columns": "Hidden columns", "hidden_columns": "Hidden columns",
"history": { "history": {
"attribute": "Attribute", "attribute": "Attribute",
@ -542,7 +543,6 @@
"message_count": "Message count", "message_count": "Message count",
"minecraft_id": "Minecraft Id", "minecraft_id": "Minecraft Id",
"name": "Name", "name": "Name",
"ontime": "Ontime",
"permission_denied": "Access denied!", "permission_denied": "Access denied!",
"permission_denied_d": "You have to be moderator to see other profiles!", "permission_denied_d": "You have to be moderator to see other profiles!",
"reaction_count": "Reaction count", "reaction_count": "Reaction count",