userAgent = escapeHtml(userAgent);
List<CommunityAccount> listCommunityAccount = new ArrayList<CommunityAccount>();
AllCommunityAccount myAllCommunityAccount = new AllCommunityAccount ();
myAllCommunityAccount.setListCommunityAccount(listCommunityAccount);
PersistenceManager pm =null;
try {
pm = PMF.get().getPersistenceManager();
String AllIdUser ="";
for(String idUser :listIdUser) {
log.warning("Request stat for user : " + hMapIdUserName.get(idUser));
if("".equalsIgnoreCase(AllIdUser))
AllIdUser = idUser;
else
AllIdUser = AllIdUser + "," + idUser;
}
URL url = null ;
//http://api.worldoftanks.eu/wot/account/info/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=506486576
String urlServer = urlServerEU +"/wot/account/info/?application_id=" + applicationIdEU + "&account_id=";
if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
url = new URL(proxy + urlServer + AllIdUser);
}
else {
url = new URL(urlServer + AllIdUser);
}
HttpURLConnection conn2 = (HttpURLConnection)url.openConnection();
conn2.setReadTimeout(20000);
conn2.setConnectTimeout(20000);
conn2.getInputStream();
BufferedReader readerUser = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
//BufferedReader readerUser = new BufferedReader(new InputStreamReader(url.openStream()));
String lineUser = "";
;
String AllLinesUser = "";
while ((lineUser = readerUser.readLine()) != null) {
AllLinesUser = AllLinesUser + lineUser;
}
readerUser.close();
Gson gsonUser = new Gson();
PlayersInfos playersInfos = gsonUser.fromJson(AllLinesUser, PlayersInfos.class);
//Transform playerRatings en communityAccount (pour utiliser des types compatibles avec la sérialisation (pas de MAP !!))
List<CommunityAccount> listCommunityAccount1 = TransformDtoObject.TransformPlayersInfosToListCommunityAccount(playersInfos);
//////////////////////////////////
// ==API encyclopédie des tanks - Pour obtenir le level des char (on doit calculier le tier moyen joué)
// Dans les stats des joueurs nous avons le tank-id mais pas son level
//on requete notre base les averageLevel y ont été stockés par le cron dans la table community Account
Map <String, CommunityAccount> mapHistStatsUsers = getMapHistorizedStatsUsers(listIdUser, 6);
//make some calculation of stats
for(CommunityAccount communityAccount : listCommunityAccount1) {
String user_id = communityAccount.getIdUser();
//setData.
CommunityAccount histStatUser= mapHistStatsUsers.get(user_id);
//calcul du tier moyen
//Double nbBattles = 0.0;
//Double levelByBattles = 0.0 ;
//log.warning("histStatUser " + histStatUser);
//log.warning("histStatUser.getData() " + histStatUser.getData());
///log.warning("commAcc.getData().getAverageLevel " + commAcc.getData().getAverageLevel);
Double averageLevelTank =histStatUser.getData().getStatistics().getAllStatistics().getAverageLevelTankCalc();
Double wn8 =histStatUser.getData().getStatistics().getAllStatistics().getWn8();
DataPlayerInfos myDataCommunityAccountRatings = communityAccount.getData();
//average level tank
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setAverageLevelTankCalc(averageLevelTank);
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setWn8(wn8);
//== WR calculated
int battles = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getBattles();
int battlesWin = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getWins();
Double wrCal = (double) ((double)battlesWin/(double)battles);
//on ne conserve que 2 digits après la virgule
wrCal = wrCal * 100; //ex : 51,844444
int intWrCal = (int) (wrCal * 100); //ex : 5184
wrCal = (double)intWrCal / 100 ; //ex : 51,84
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setBattle_avg_performanceCalc(wrCal);
//== Ratio capture points calculated
int ctfPoints = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getCapture_points();
Double ctfPointsCal = (double) ((double)ctfPoints/(double)battles);// 1,28 :1 = 1.28
//on ne conserve que 2 digits après la virgule
//ctfPointsCal = ctfPointsCal * 100; //ex : 1,2827
int intCtfPointsCal = (int) (ctfPointsCal * 100); //ex intCtfPointsCal : 128,27 ctfPointsCal = 1.28
ctfPointsCal = (double)intCtfPointsCal / 100 ; //ex ctfPointsCal : 1,28 intCtfPointsCal = 128
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setRatioCtfPoints(ctfPointsCal);
//==Damage Ration calculated
int damagePoints = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getDamage_dealt();
Double ratioDamagePoints = (double) ((double)damagePoints/(double)battles);
//on ne conserve que 2 digits après la virgule
//ctfPointsCal = ctfPointsCal * 100; //ex : 1,2827
int intRatioDamagePoints = (int) (ratioDamagePoints * 100); //ex : 128,27
ratioDamagePoints = (double)intRatioDamagePoints / 100 ; //ex : 1,28
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setRatioDamagePoints(ratioDamagePoints);
//==Ratio Defense calculated
int droppedCtfPoints = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getDropped_capture_points();
Double ratioDroppedCtfPoints = (double) ((double)droppedCtfPoints/(double)battles);
//on ne conserve que 2 digits après la virgule
//ctfPointsCal = ctfPointsCal * 100; //ex : 1,2827
int intRatioDroppedCtfPoints = (int) (ratioDroppedCtfPoints * 100); //ex : 128,27
ratioDroppedCtfPoints = (double)intRatioDroppedCtfPoints / 100 ; //ex : 1,28
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setRatioDroppedCtfPoints(ratioDroppedCtfPoints);
//==Ratio Destroyed calculated
int destroyedPoints = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getFrags();
Double ratiodestroyedPoints = (double) ((double)destroyedPoints/(double)battles);
//on ne conserve que 2 digits après la virgule
//ctfPointsCal = ctfPointsCal * 100; //ex : 1,2827
int intRatiodestroyedPoints = (int) (ratiodestroyedPoints * 100); //ex : 128,27
ratiodestroyedPoints = (double)intRatiodestroyedPoints / 100 ; //ex : 1,28
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setRatioDestroyedPoints(ratiodestroyedPoints);
//==Ratio Detected calculated
int detectedPoints = myDataCommunityAccountRatings.getStatistics().getAllStatistics().getSpotted();
Double ratioDetectedPoints = (double) ((double)detectedPoints/(double)battles);
//on ne conserve que 2 digits après la virgule
//ctfPointsCal = ctfPointsCal * 100; //ex : 1,2827
int intRatioDetectedPoints = (int) (ratioDetectedPoints * 100); //ex : 128,27
ratioDetectedPoints = (double)intRatioDetectedPoints / 100 ; //ex : 1,28
myDataCommunityAccountRatings.getStatistics().getAllStatistics().setRatioDetectedPoints(ratioDetectedPoints);
}
//add account
listCommunityAccount.addAll(listCommunityAccount1);
} catch (MalformedURLException e) {
// ...
e.printStackTrace();
} catch (IOException e) {
// ...
e.printStackTrace();
}
finally {
pm.close();
}
return myAllCommunityAccount;
}