just some more updates

This commit is contained in:
jenzur 2019-07-18 20:26:33 +02:00
parent 01405d0532
commit cf49e6546d
8 changed files with 139 additions and 86 deletions

View File

@ -20,6 +20,70 @@ public class PlayerDTO {
private String steamID64;
private String steamID;
private String name;
public String getSteamID64() {
return steamID64;
}
public void setSteamID64(String steamID64) {
this.steamID64 = steamID64;
}
public String getSteamID() {
return steamID;
}
public void setSteamID(String steamID) {
this.steamID = steamID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAvatar() {
return Avatar;
}
public void setAvatar(String Avatar) {
this.Avatar = Avatar;
}
public int getRank() {
return Rank;
}
public void setRank(int Rank) {
this.Rank = Rank;
}
public int getPlayerPoints() {
return PlayerPoints;
}
public void setPlayerPoints(int PlayerPoints) {
this.PlayerPoints = PlayerPoints;
}
public int getTimes() {
return Times;
}
public void setTimes(int Times) {
this.Times = Times;
}
public List<String> getUrlBanners() {
return UrlBanners;
}
public void setUrlBanners(List<String> UrlBanners) {
this.UrlBanners = UrlBanners;
}
private String Avatar;
private int Rank;
private int PlayerPoints;

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -46,12 +47,11 @@ import utils.PuSelector;
public class Facade {
private ConcurrentMap<String, Player> playerCache = new MapMaker().concurrencyLevel(4).makeMap();
private ConcurrentMap<String, MapBoard> mapBoardCache = new MapMaker().concurrencyLevel(4).makeMap();
private ConcurrentMap<String, ConcurrentMap<String, MapValues>> playerRelatedMapValuesCache = new MapMaker().concurrencyLevel(6).makeMap();
private final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(30, TimeUnit.MINUTES);
private Instant elapsedTime;
private int initSetup = 0;
private static Map<String, Player> playerCache = new LinkedHashMap();
private static ConcurrentMap<String, MapBoard> mapBoardCache = new MapMaker().concurrencyLevel(4).makeMap();
private static ConcurrentMap<String, ConcurrentMap<String, MapValues>> playerRelatedMapValuesCache = new MapMaker().concurrencyLevel(6).makeMap();
private static final long EXPIRE_TIME_IN_SECONDS = TimeUnit.SECONDS.convert(30, TimeUnit.MINUTES);
private static Instant elapsedTime = Instant.now();
private static final ForkJoinPool executor = instantiateExecutor();
private static ForkJoinPool instantiateExecutor() {
@ -60,11 +60,6 @@ public class Facade {
null, false);
}
public Facade() {
elapsedTime = Instant.now();
initSetup = 1;
}
private boolean getMap(String map, String Identifier) {
boolean identified = Pattern.compile(Pattern.quote(Identifier), Pattern.CASE_INSENSITIVE).matcher(map).find();
return identified;
@ -236,24 +231,24 @@ public class Facade {
public Collection<PlayerDTO> getleaderBoard(int iterator) {
int playerAddiditionCap = 99;
Collection<Player> playerAvatarsCaching = new ArrayList();
List<Player> players = new ArrayList(playerCache.values());
Collection<PlayerDTO> playersDTO = new ArrayList();
players.sort(Comparator.comparing(Player::getRank));
int counter = 0;
for (Player player : players) {
if (counter >= iterator && counter <= iterator + playerAddiditionCap && player.getAvatar() == null) {
playerAvatarsCaching.add(player);
for (Player player : playerCache.values()) {
if (counter >= iterator && counter <= iterator + playerAddiditionCap) {
if (player.getAvatar() == null || player.getAvatar().isEmpty()) {
playerAvatarsCaching.add(player);
}
}
if (counter > iterator + playerAddiditionCap) {
break;
}
counter++;
}
updateAvatarsToCache(playerAvatarsCaching);
players = new ArrayList(playerCache.values());
players.sort(Comparator.comparing(Player::getRank));
if (!playerAvatarsCaching.isEmpty()) {
updateAvatarsToCache(playerAvatarsCaching);
}
counter = 0;
for (Player player : players) {
for (Player player : playerCache.values()) {
if (counter >= iterator && counter <= iterator + playerAddiditionCap) {
playersDTO.add(new PlayerDTO(player));
}
@ -265,9 +260,10 @@ public class Facade {
return playersDTO;
}
private void addNewPlayerValuesToCache(Collection<Player> keyCollection, ConcurrentMap<String, Collection<Integer>> playerUrlBanners) {
private ConcurrentMap<String, Player> addNewPlayerValuesToCache(Collection<Player> keyCollection, ConcurrentMap<String, Collection<Integer>> playerUrlBanners) {
//2 = user, 6 = mapper, 7 = admin, 8 = technical staff, 10 = leader, 12 = vip, 13 = trial admin, 15 = event winner, 19 = discord manager
// 20 NSFW, 21 = Retired admin, 25 = event manager, 11 = GA
ConcurrentMap<String, Player> playersConcurrentMap = new MapMaker().concurrencyLevel(6).makeMap();
for (Player player : keyCollection) {
Collection<Integer> banners = playerUrlBanners.getOrDefault(player.getSteamID(), null);
if (banners != null) {
@ -319,8 +315,9 @@ public class Facade {
}
player.setUrlBanners(urlBanners);
}
playerCache.put(player.getSteamID(), player);
playersConcurrentMap.put(player.getSteamID(), player);
}
return playersConcurrentMap;
}
private void retrieveAvatarFull(String avatarurl) {
@ -333,12 +330,17 @@ public class Facade {
JSONObject jsonObject = root.getJSONObject("response");
JSONArray jsonArray = jsonObject.getJSONArray("players");
for (int incrementer = 0; incrementer < jsonArray.length(); incrementer++) {
worker = new CallableJsonObject(jsonArray.getJSONObject(incrementer));
futures.put(incrementer, executor.submit(worker));
}
futures.values().parallelStream().forEach(future -> {
JSONObject jsonObjectPlayer = jsonArray.getJSONObject(incrementer);
try {
Entry<String, String> getEntry = future.get(3, TimeUnit.SECONDS);
worker = new CallableJsonObject(jsonObjectPlayer);
futures.put(incrementer, executor.submit(worker));
} catch (Exception ex) {
//some are simply nosteamers with no steam data
}
}
futures.values().forEach(future -> {
try {
Entry<String, String> getEntry = future.get(5, TimeUnit.SECONDS);
playerCache.get(getEntry.getKey()).setAvatar(getEntry.getValue());
} catch (InterruptedException | ExecutionException | TimeoutException ex) {
Logger.getLogger(Facade.class.getName()).log(Level.SEVERE, null, ex);
@ -355,37 +357,15 @@ public class Facade {
//http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=262F3F0C6B83E0F263C272C3762002F1&steamids=76561198029832363,76561198003907342
StringBuilder avatarURL = new StringBuilder();
avatarURL.append("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=262F3F0C6B83E0F263C272C3762002F1&steamids=");
int incrementer = 0;
int overallCounter = 0;
int fetchCapacity = players.size() > 5 ? players.size() / 5 : 6;
CountDownLatch cdl = new CountDownLatch(1);
boolean init = true;
for (Player player : players) {
if (incrementer > 0) {
if (!init) {
avatarURL.append(",");
}
incrementer++;
avatarURL.append(Long.toString(convertSteamIdToCommunityId(player.getSteamID())));
if (incrementer >= fetchCapacity || incrementer + overallCounter >= players.size()) {
final String fullUrl = avatarURL.toString();
final int overall = incrementer + overallCounter;
new Thread(() -> {
retrieveAvatarFull(fullUrl);
if (overall >= players.size()) {
cdl.countDown();
}
}).start();
overallCounter += incrementer;
incrementer = 0;
avatarURL = new StringBuilder();
avatarURL.append("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=262F3F0C6B83E0F263C272C3762002F1&steamids=");
}
}
try {
cdl.await();
} catch (InterruptedException ex) {
System.out.println("cdl await interrupted: " + ex.getLocalizedMessage() + "\n");
init = false;
}
retrieveAvatarFull(avatarURL.toString());
setNonExistingAvatarOnPlayers(players);
}
@ -439,23 +419,24 @@ public class Facade {
}
}
private void setPlayerPoints() {
private List<Player> setPlayerPoints(ConcurrentMap<String, Player> playersMap) {
for (MapBoard mapboard : mapBoardCache.values()) {
List<MapValues> mapvalues = mapboard.getMapvalues();
for (MapValues mapvalue : mapvalues) {
String steamID = mapvalue.getPlayerSteamID();
int mapPoints = mapvalue.getMapPoints();
playerCache.get(steamID).addPlayerPoints(mapPoints);
playersMap.get(steamID).addPlayerPoints(mapPoints);
}
}
return new ArrayList(playersMap.values());
}
private void updatePlayerRanks() {
List<Player> playerList = new ArrayList(playerCache.values());
playerList.sort(Comparator.comparing(Player::getPlayerPoints).reversed());
private void updatePlayerRanks(List<Player> playersConcurrentmap) {
int rank = 1;
for (Player player : playerList) {
playerCache.get(player.getSteamID()).setRank(rank);
playersConcurrentmap.sort(Comparator.comparing(Player::getPlayerPoints).reversed());
for (Player player : playersConcurrentmap) {
player.setRank(rank);
playerCache.put(player.getSteamID(), player);
rank++;
}
}
@ -478,13 +459,12 @@ public class Facade {
}
}
public void checkTimeElapse() {
public String checkTimeElapse() {
Instant current = Instant.now();
long timeElapsed = Duration.between(elapsedTime, current).toMillis();
//perharps 3 mins instead of 30?
if (timeElapsed >= EXPIRE_TIME_IN_SECONDS * 1000 || initSetup > 0) {
//System.out.println("went through \ntimeElapsed: " + timeElapsed + "\nEXPIRE_TIME_IN_SECONDS: " + EXPIRE_TIME_IN_SECONDS * 100);
initSetup = 0;
int cachesize = playerCache.size();
if (timeElapsed >= EXPIRE_TIME_IN_SECONDS * 1000 || playerCache.isEmpty()) {
String elapsed = String.valueOf(timeElapsed);
elapsedTime = Instant.now();
Entry<Collection<Player>, Collection<MapBoard>> playersMapBoards = DataMapperCalls.getAllValues();
Collection<MapBoard> mapBoardCollection = playersMapBoards.getValue();
@ -493,14 +473,16 @@ public class Facade {
mapBoardCache.clear();
playerRelatedMapValuesCache.clear();
addNewMapBoardValuesToCache(mapBoardCollection);
addNewPlayerValuesToCache(playersMapBoards.getKey(), playerRelatedUrlBanners);
ConcurrentMap<String, Player> playersConcurrentmap = addNewPlayerValuesToCache(playersMapBoards.getKey(), playerRelatedUrlBanners);
orderingMapBoardValuesByTime();
setPositionAndMapPoints();
setPlayerPoints();
updatePlayerRanks();
updatePlayerRanks(setPlayerPoints(playersConcurrentmap));
setTimesAsociatedToPeople();
//updateEntitiesPersistence();
//System.out.println("timeElapsed: " + elapsed + "\nEXPIRE_TIME_IN_SECONDS: " + EXPIRE_TIME_IN_SECONDS * 1000 + "cachesize: " + cachesize);
//return "timeElapsed: " + elapsed + "\nEXPIRE_TIME_IN_SECONDS: " + EXPIRE_TIME_IN_SECONDS * 1000 + "cachesize: " + cachesize;
}
return "";
}
public void updateEntitiesPersistence() {

View File

@ -84,15 +84,15 @@ public class TimerResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("searchplayers/{identifier}")
public String searchPlayers(@PathParam("identifier") String identifier){
public String searchPlayers(@PathParam("identifier") String identifier) {
facade.checkTimeElapse();
return gson.toJson(facade.getSearchPlayerResults(identifier));
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("searchmaps/{identifier}")
public String searchMaps(@PathParam("identifier") String identifier){
public String searchMaps(@PathParam("identifier") String identifier) {
facade.checkTimeElapse();
return gson.toJson(facade.getSearchMapsResults(identifier));
}

View File

@ -28,12 +28,15 @@ public class Initialization {
Facade facade = new Facade();
facade.checkTimeElapse();
System.out.println("finished first timeelapse");
List<Player> getAllPlayers = facade.getAllPlayersFromCache();
System.out.println("finished getAllPlayers");
facade.getleaderBoard(0);
System.out.println("finished retrieving leaderboard");
Collection<MapBoard> getAllMapBoards = facade.getAllMapBoardsFromCache();
//facade.getPlayerMaps("STEAM_0:0:33155716", 0);
/*
AdminEditor admin = new AdminEditor("jenz", "1234");
EntityManager em = PuSelector.getEntityManagerFactory("pu").createEntityManager();
//simply cant persist collections/list
@ -53,5 +56,9 @@ public class Initialization {
}
em.persist(admin);
em.getTransaction().commit();
*/
System.out.println("checktime second time");
facade.checkTimeElapse();
facade.getSpecificMap("ze_Ancient_wrath_v1_fix2", 1, 153);
}
}

View File

@ -1,13 +1,13 @@
import React from 'react';
import { trackPromise } from 'react-promise-tracker';
const URLleaderboard = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/leaderboard";
const URLPlayer = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/player/";
const URLPlayerMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/player/maps/";
const URLMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/map/";
const URLAllMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/allmaps";
const URLMapsSize = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/mapsizecache";
const URLSearchPlayers = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/searchplayers/";
const URLSearchMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/searchmaps/";
const URLleaderboard = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/leaderboard";
const URLPlayer = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/player/";
const URLPlayerMaps = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/player/maps/";
const URLMaps = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/map/";
const URLAllMaps = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/allmaps";
const URLMapsSize = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/mapsizecache";
const URLSearchPlayers = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/searchplayers/";
const URLSearchMaps = "http://163.172.84.14:8080/racetimer_endpoints-1.0/api/timers/searchmaps/";
function handleHttpErrors(res) {
if (!res.ok) {

View File

@ -128,7 +128,7 @@ class Leaderboard extends React.Component {
</div>
</div>
{!this.state.breakload ? <h1>
Loading Maps <br /> <br /> <br /> <LoadingIndicator />
Loading Players <br /> <br /> <br /> <LoadingIndicator />
</h1> : ""}
{this.state.searchBool ? ("") : (<PlayersSearch keyword={this.state.keyword} />)}
<div className="container mm">

View File

@ -52,13 +52,13 @@ class Maps extends React.Component {
window.removeEventListener("scroll", this.scrollListener);
}
findSecondLast(array) {
return array[array.length - 2];
findLateIndex(array) {
return array[array.length - 5];
}
handleScroll = () => {
if (this.state.breakload && this.state.fetchsize > this.state.mapTimes.length) {
const player = this.findSecondLast(this.state.mapTimes);
const player = this.findLateIndex(this.state.mapTimes);
var lastLi = document.getElementById('maps/' + player.steamID);
var lastLiOffset = lastLi.offsetTop + lastLi.clientHeight;
var pageOffset = window.pageYOffset + window.innerHeight;
@ -99,7 +99,7 @@ class Maps extends React.Component {
</p>
<p className="text-center ">
<NavLink to={'/leaderboard/'}>
<b>leaderboard</b>
<b>LeaderBoard</b>
</NavLink>
</p>
</div>

View File

@ -100,7 +100,7 @@ class Player extends React.Component {
</p>
<p className="text-center ">
<NavLink to={'/leaderboard/'}>
<b>leaderboard</b>
<b>LeaderBoard</b>
</NavLink>
</p>
</div>