Browse Source

threaded profile and new tops

master
gsd 1 year ago
parent
commit
96d7ce46cc
  1. 16
      src/main/java/app/controllers/user/KillFeedController.java
  2. 155
      src/main/java/app/services/ProfileService.java
  3. 56
      src/main/java/app/services/db/KillfeedService.java

16
src/main/java/app/controllers/user/KillFeedController.java

@ -37,6 +37,14 @@ public class KillFeedController {
return new ResponseEntity(killfeedService.getPopulateWeapons(steamID, srv, offset, limit), HttpStatus.OK); return new ResponseEntity(killfeedService.getPopulateWeapons(steamID, srv, offset, limit), HttpStatus.OK);
} }
@GetMapping("/top")
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "top")
public ResponseEntity getTopKills(HttpServletRequest request,
@RequestParam(required = false) String srv) {
return new ResponseEntity(killfeedService.getTopKills(srv), HttpStatus.OK);
}
@GetMapping @GetMapping
@CheckWebAccess(auth_method = AuthMethod.STEAM64) @CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "kills") @WaitAfterNext(order = "kills")
@ -81,4 +89,12 @@ public class KillFeedController {
if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE); if (limit > 20) return new ResponseEntity(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity(killfeedService.getDeads(steamID, srv, offset, limit), HttpStatus.OK); return new ResponseEntity(killfeedService.getDeads(steamID, srv, offset, limit), HttpStatus.OK);
} }
@DeleteMapping("/top")
@CheckWebAccess(auth_method = AuthMethod.STEAM64)
@WaitAfterNext(order = "top")
public ResponseEntity getTopDeads(HttpServletRequest request,
@RequestParam(required = false) String srv) {
return new ResponseEntity(killfeedService.getTopDeads(srv), HttpStatus.OK);
}
} }

155
src/main/java/app/services/ProfileService.java

@ -14,7 +14,15 @@ import org.springframework.stereotype.Service;
import java.time.Instant; import java.time.Instant;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.function.Supplier;
@Service @Service
public class ProfileService { public class ProfileService {
@ -61,97 +69,136 @@ public class ProfileService {
} }
public PlayerProfile GetProfile(String steam64, List<String> requests) { public PlayerProfile GetProfile(String steam64, List<String> requests) {
final int requests_pool = 16;
ExecutorService executor = Executors.newFixedThreadPool(requests_pool);
Set<Callable<Supplier>> callables = new HashSet<>(requests_pool);
PlayerProfile profile = new PlayerProfile(); PlayerProfile profile = new PlayerProfile();
profile.setResponse_time(new HashMap<>()); profile.setResponse_time(new HashMap<>());
SteamID steamID = SteamIDConverter.getSteamID(steam64); SteamID steamID = SteamIDConverter.getSteamID(steam64);
profile.setSteamids(steamID); profile.setSteamids(steamID);
Long start_time, end_time; Long start_time_total = Instant.now().toEpochMilli();
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setPlay_on(statsService.searchPlayer(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setPlay_on(statsService.searchPlayer(steamID));
profile.getResponse_time().put("play_on", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("play_on", (double) end_time / 1000);
return null;
});
if(requests.contains("steam_data")){ if(requests.contains("steam_data")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64));
profile.getResponse_time().put("steam_data", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("steam_data", (double) end_time / 1000);
return null;
});
} }
if(requests.contains("lastplay")){ if(requests.contains("lastplay")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setLastplay(usertimeService.getPlayerLastplay(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setLastplay(usertimeService.getPlayerLastplay(steamID));
profile.getResponse_time().put("lastplay", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("lastplay", (double) end_time / 1000);
return null;
});
} }
if(requests.contains("usertime")){ if(requests.contains("usertime")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setGametime(usertimeService.getPlayerUsertime(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setGametime(usertimeService.getPlayerUsertime(steamID));
profile.getResponse_time().put("usertime", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("usertime", (double) end_time / 1000);
return null;
});
} }
//if(requests.contains("permition")){ //if(requests.contains("permition")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setPermition(permitionService.getPermition(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setPermition(permitionService.getPermition(steamID));
profile.getResponse_time().put("permition", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("permition", (double) end_time / 1000);
return null;
});
//} //}
//if(requests.contains("ban")){ //if(requests.contains("ban")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setBan(banService.getBan(steamID)); long start_time = Instant.now().toEpochMilli();
/*if(profile.getBan() != null) { profile.setBan(banService.getBan(steamID));
profile.getBan().setAdmin_info( long end_time = Instant.now().toEpochMilli() - start_time;
permitionService.getAdminInfo(SteamIDConverter.getSteamID(profile.getBan().getBanned_by_id())) profile.getResponse_time().put("ban", (double) end_time / 1000);
); return null;
}*/ });
end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban", Double.valueOf(end_time) / 1000);
//} //}
if(requests.contains("attached_discord")){ if(requests.contains("attached_discord")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID));
profile.getResponse_time().put("attached_discord", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("attached_discord", (double) end_time / 1000);
return null;
});
} }
if(requests.contains("donates")){ if(requests.contains("donates")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setDonates(donateService.getDonateStatistic(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setDonates(donateService.getDonateStatistic(steamID));
profile.getResponse_time().put("donates", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("donates", (double) end_time / 1000);
return null;
});
} }
if(requests.contains("ban_list")){ if(requests.contains("ban_list")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setBan_list(banService.getBans(steamID)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setBan_list(banService.getBans(steamID));
profile.getResponse_time().put("ban_list", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("ban_list", (double) end_time / 1000);
return null;
});
} }
//if(requests.contains("killfeed")){ //if(requests.contains("killfeed")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setKillfeed((new Killfeed()) long start_time = Instant.now().toEpochMilli();
.setKills(killfeedService.getKills(steamID, null)) profile.setKillfeed((new Killfeed())
.setDeads(killfeedService.getDeads(steamID, null)) .setKills(killfeedService.getKills(steamID, null))
.setAssists(killfeedService.getAssists(steamID, null)) .setDeads(killfeedService.getDeads(steamID, null))
.setSuicides(killfeedService.getSuicides(steamID, null))); .setAssists(killfeedService.getAssists(steamID, null))
end_time = Instant.now().toEpochMilli() - start_time; .setSuicides(killfeedService.getSuicides(steamID, null)));
profile.getResponse_time().put("killfeed", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("killfeed", (double) end_time / 1000);
return null;
});
//} //}
//if(requests.contains("messages")){ //if(requests.contains("messages")){
start_time = Instant.now().toEpochMilli(); callables.add(() -> {
profile.setMessages(messageService.getMessageCount(steamID, null)); long start_time = Instant.now().toEpochMilli();
end_time = Instant.now().toEpochMilli() - start_time; profile.setMessages(messageService.getMessageCount(steamID, null));
profile.getResponse_time().put("messages", Double.valueOf(end_time) / 1000); long end_time = Instant.now().toEpochMilli() - start_time;
profile.getResponse_time().put("messages", (double) end_time / 1000);
return null;
});
//} //}
try {
executor.invokeAll(callables);
} catch (InterruptedException ie) {}
finally {
profile.getResponse_time().put("total", (double) (Instant.now().toEpochMilli() - start_time_total) / 1000);
executor.shutdown();
}
return profile; return profile;
} }

56
src/main/java/app/services/db/KillfeedService.java

@ -37,6 +37,13 @@ public class KillfeedService {
.getSingleResult(); .getSingleResult();
} }
public List<TopInFeed> getTopKills(String server_id) {
List<TopInFeed> result = entityManager.createNativeQuery("SELECT `attacker_id`, count(*) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `attacker_id` != 0 AND `server_id` LIKE ?1 GROUP BY `attacker_id` ORDER BY `c` DESC LIMIT 10")
.setParameter(1, server_id==null||server_id.isEmpty()?'%':server_id)
.getResultStream().map(obj -> new TopInFeed(obj)).toList();
return result.stream().peek(kif -> kif.setNicknames(nicknameService)).toList();
}
public Long getDeads(SteamID steamID, String server_id) { public Long getDeads(SteamID steamID, String server_id) {
return (Long) entityManager.createNativeQuery("SELECT COUNT(*) FROM `user_killfeed` WHERE `victim_id` = ?1 AND `attacker_id` != `victim_id` AND `server_id` like ?2") return (Long) entityManager.createNativeQuery("SELECT COUNT(*) FROM `user_killfeed` WHERE `victim_id` = ?1 AND `attacker_id` != `victim_id` AND `server_id` like ?2")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
@ -44,6 +51,13 @@ public class KillfeedService {
.getSingleResult(); .getSingleResult();
} }
public List<TopInFeed> getTopDeads(String server_id) {
List<TopInFeed> result = entityManager.createNativeQuery("SELECT `attacker_id`, count(*) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `victim_id` != 0 AND `server_id` LIKE ?1 GROUP BY `victim_id` ORDER BY `c` DESC LIMIT 10")
.setParameter(1, server_id==null||server_id.isEmpty()?'%':server_id)
.getResultStream().map(obj -> new TopInFeed(obj)).toList();
return result.stream().peek(kif -> kif.setNicknames(nicknameService)).toList();
}
public Long getSuicides(SteamID steamID, String server_id) { public Long getSuicides(SteamID steamID, String server_id) {
return (Long) entityManager.createNativeQuery("SELECT COUNT(*) FROM `user_killfeed` WHERE `victim_id` = ?1 AND `attacker_id` = `victim_id` AND `server_id` like ?2") return (Long) entityManager.createNativeQuery("SELECT COUNT(*) FROM `user_killfeed` WHERE `victim_id` = ?1 AND `attacker_id` = `victim_id` AND `server_id` like ?2")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
@ -59,7 +73,7 @@ public class KillfeedService {
} }
public Map getPopulateWeapons(SteamID steamID, String server_id, int offset, int limit) { public Map getPopulateWeapons(SteamID steamID, String server_id, int offset, int limit) {
List<HypeWeapons> result = entityManager.createNativeQuery("SELECT COUNT(u.`weapon_index`) as c, i.`name`, u.`server_id` FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ?1 AND `attacker_id` != `victim_id` AND u.server_id like ?2 GROUP BY u.`weapon_index` DESC ORDER BY `c` DESC LIMIT ?3 OFFSET ?4") List<HypeWeapons> result = entityManager.createNativeQuery("SELECT COUNT(u.`weapon_index`) as c, i.`name`, u.`server_id`, u.`weapon_classname` FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ?1 AND `attacker_id` != `victim_id` AND u.server_id like ?2 GROUP BY u.`weapon_index` DESC ORDER BY `c` DESC LIMIT ?3 OFFSET ?4")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id) .setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id)
.setParameter(3, limit) .setParameter(3, limit)
@ -73,7 +87,7 @@ public class KillfeedService {
} }
public Map getKills(SteamID steamID, String server_id, int offset, int limit) { public Map getKills(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> result = entityManager.createNativeQuery("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ?1 AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4") List<KillsInFeed> result = entityManager.createNativeQuery("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ?1 AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id) .setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id)
.setParameter(3, limit) .setParameter(3, limit)
@ -87,7 +101,7 @@ public class KillfeedService {
} }
public Map getDeads(SteamID steamID, String server_id, int offset, int limit) { public Map getDeads(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> result = entityManager.createNativeQuery("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`victim_id` = ?1 AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4") List<KillsInFeed> result = entityManager.createNativeQuery("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`victim_id` = ?1 AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id) .setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id)
.setParameter(3, limit) .setParameter(3, limit)
@ -101,7 +115,7 @@ public class KillfeedService {
} }
public Map getAssists(SteamID steamID, String server_id, int offset, int limit) { public Map getAssists(SteamID steamID, String server_id, int offset, int limit) {
List<KillsInFeed> result = entityManager.createNativeQuery("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`assister_id` = ?1 AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4") List<KillsInFeed> result = entityManager.createNativeQuery("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`assister_id` = ?1 AND u.`server_id` like ?2 ORDER BY u.`id` DESC LIMIT ?3 OFFSET ?4")
.setParameter(1, steamID.account_id) .setParameter(1, steamID.account_id)
.setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id) .setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id)
.setParameter(3, limit) .setParameter(3, limit)
@ -130,6 +144,23 @@ public class KillfeedService {
KILL, DEAD, ASSIST KILL, DEAD, ASSIST
} }
@Data
class TopInFeed {
int uid;
String name;
long count;
String server_id;
TopInFeed(Object obj) {
this.uid = (int) ((Object[]) obj) [0];
this.count = (long) ((Object[]) obj) [1];
this.server_id = (String) ((Object[]) obj) [2];
}
public void setNicknames(NicknameService nicknameService) {
this.name = uid <= 0 || server_id.isEmpty() || server_id == null ?"":nicknameService.grabNickname(uid, server_id);
}
}
@Data @Data
class KillsInFeed { class KillsInFeed {
int attacker_id; int attacker_id;
@ -139,7 +170,8 @@ public class KillfeedService {
int assister_id; int assister_id;
String assister_name; String assister_name;
long utime; long utime;
String weapon_name; private String weapon_name;
private String weapon_classname;
String server_id; String server_id;
KillsInFeed(Object obj) { KillsInFeed(Object obj) {
this.attacker_id = (int) ((Object[]) obj)[0]; this.attacker_id = (int) ((Object[]) obj)[0];
@ -148,12 +180,20 @@ public class KillfeedService {
this.utime = (long) ((Object[]) obj)[3]; this.utime = (long) ((Object[]) obj)[3];
this.weapon_name = (String) ((Object[]) obj)[4]; this.weapon_name = (String) ((Object[]) obj)[4];
this.server_id = (String) ((Object[]) obj)[5]; this.server_id = (String) ((Object[]) obj)[5];
this.weapon_classname = (String) ((Object[]) obj)[6];
} }
public void setNicknames(NicknameService nicknameService) { public void setNicknames(NicknameService nicknameService) {
this.attacker_name = attacker_id == -1?"":nicknameService.grabNickname(attacker_id, server_id); this.attacker_name = attacker_id == -1 || server_id.isEmpty() || server_id == null?"":nicknameService.grabNickname(attacker_id, server_id);
this.victim_name = victim_id == -1?"":nicknameService.grabNickname(victim_id, server_id); this.victim_name = victim_id == -1 || server_id.isEmpty() || server_id == null?"":nicknameService.grabNickname(victim_id, server_id);
this.assister_name = assister_id == -1?"":nicknameService.grabNickname(assister_id, server_id); this.assister_name = assister_id == -1 || server_id.isEmpty() || server_id == null?"":nicknameService.grabNickname(assister_id, server_id);
}
public String getWeapon_name(){
//obj_sentrygun
if (this.weapon_classname.contains("obj_sentrygun"))
return "Турель " + (this.weapon_classname.replace("obj_sentrygun", "").isEmpty()?"1":this.weapon_classname.replace("obj_sentrygun", "")) + " уровня";
return this.weapon_name;
} }
} }
} }

Loading…
Cancel
Save