From 2cbcaf7b47c724077078698f22646fdab68b9511 Mon Sep 17 00:00:00 2001 From: gsd Date: Tue, 7 Feb 2023 20:34:45 +0300 Subject: [PATCH] response time --- src/main/java/app/entities/PlayerProfile.java | 2 +- src/main/java/app/services/ProfileService.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/app/entities/PlayerProfile.java b/src/main/java/app/entities/PlayerProfile.java index 3d2453f..cd0d8d4 100644 --- a/src/main/java/app/entities/PlayerProfile.java +++ b/src/main/java/app/entities/PlayerProfile.java @@ -14,7 +14,7 @@ public class PlayerProfile { HashMap> gametime; HashMap> lastplay; Object permition; - HashMap response_time; + HashMap response_time; SteamData steam_data; SteamID steamids; } diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 35ac4d7..d9fc63d 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -8,7 +8,9 @@ import app.utils.SteamIDConverter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.Instant; import java.util.Arrays; +import java.util.HashMap; import java.util.List; @Service @@ -24,19 +26,30 @@ public class ProfileService { public PlayerProfile GetProfile(String steam64, List requests) { PlayerProfile profile = new PlayerProfile(); + profile.setResponse_time(new HashMap<>()); SteamID steamID = SteamIDConverter.getSteamID(steam64); profile.setSteamids(steamID); + Long start_time, end_time; if(requests.contains("steam_data")){ + start_time = Instant.now().toEpochMilli(); profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64)); + end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("steam_data", Double.valueOf(end_time) / 1000); } if(requests.contains("lastplay")){ + start_time = Instant.now().toEpochMilli(); profile.setLastplay(usertimeService.getPlayerLastplay(profile.getSteamids())); + end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("lastplay", Double.valueOf(end_time) / 1000); } if(requests.contains("usertime")){ + start_time = Instant.now().toEpochMilli(); profile.setGametime(usertimeService.getPlayerUsertime(profile.getSteamids())); + end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("usertime", Double.valueOf(end_time) / 1000); } return profile;