Package javax.jdo

Examples of javax.jdo.PersistenceManager


        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) {
            AllIdUser = AllIdUser + "," + idUser;
          }
         
     
               
          URL url = null ;
         
          String urlServer = urlServerEU +"/2.0/account/ratings/?application_id=" + applicationIdEU + "&account_id=";
          //http://api.worldoftanks.ru/2.0/account/ratings/?application_id=171745d21f7f98fd8878771da1000a31&account_id=461
         
          if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
            url = new URL("https://pedro-proxy.appspot.com/"+urlServer.replaceAll("http://", "") + 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;
          }
          //System.out.println(AllLinesUser);
         
          readerUser.close();
 
          Gson gsonUser = new Gson();
          //log.info(AllLinesUser.substring(0, 200));
          PlayerRatings playerRatings = gsonUser.fromJson(AllLinesUser, PlayerRatings.class);
          //playerRatings.setIdUser(idUser);
         
          //Transform playerRatings en communityAccount (pour utiliser des types compatibles avec la sérialisation (pas de MAP !!))
          List<CommunityAccount> listCommunityAccount1 =  TransformDtoObject.TransformPlayerRatingsToListCommunityAccount(playerRatings);
         
         
          //////////////////////////////////
          // ==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
         
          //http://api.worldoftanks.eu/2.0/encyclopedia/tanks/?application_id=d0a293dc77667c9328783d489c8cef73
          /*
           * {"status":"ok",
           * "count":336,
           * "data":{
            "3073":{
            "nation_i18n":"U.S.S.R.","name":"#ussr_vehicles:T-46","level":3,"nation":"ussr","is_premium":false,"name_i18n":"T-46","type":"lightTank","tank_id":3073}
            ,"6417":{
            "nation_i18n":"Germany","name":"#germany_vehicles:PzIII_IV","level":5,"nation":"germany","is_premium":false,"name_i18n":"Pz.Kpfw. III\/IV","type":"mediumTank","tank_id":6417}
          */
         
         
          //=======================
//          if (tankEncyclopedia == null) {
//            urlServer = urlServerEU +"/2.0/encyclopedia/tanks/?application_id=" + applicationIdEU ;
//            url = new URL(urlServer);
//           
//            conn2 = (HttpURLConnection)url.openConnection();
//            conn2.setReadTimeout(20000);
//            conn2.setConnectTimeout(20000);
//            conn2.getInputStream();
//            readerUser = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
//   
//            lineUser = "";
//            AllLinesUser = "";
//   
//            while ((lineUser = readerUser.readLine()) != null) {
//              AllLinesUser = AllLinesUser + lineUser;
//            }
//            readerUser.close();
//   
//            gsonUser = new Gson();
//            tankEncyclopedia = gsonUser.fromJson(AllLinesUser, TankEncyclopedia.class);
//          }
//          if (tankEncyclopedia == null) {
//            log.severe("tankEncyclopedia is null" );
//           
//          }
//          else {
//            log.warning("tankEncyclopedia is good" );
//            if (tankEncyclopedia.getData() ==null ) {
//              log.severe("tankEncyclopedia data is null" );
//            }
//            else {
//               Set<Entry<String, DataTankEncyclopedia>>  set = tankEncyclopedia.getData().entrySet();
//             
//  //            for(Entry<String, DataTankEncyclopedia> entry : set) {
//  //              log.warning(entry.getValue().getName());
//  //              log.warning(entry.getKey());
//  //            }
//              if (tankEncyclopedia.getData().get("6417") == null ){
//                log.severe("tankEncyclopedia data get tank id 1 is null" );
//              }
//            }
//               
//          }
          //=========================
         
         
//          //API stats des joueurs ========================
//          //PB access denied sometimes
//          //http://api.worldoftanks.eu/2.0/stats/accountbytime/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=500423304&hours_ago=24
//          //http://api.worldoftanks.ru/2.0/account/ratings/?application_id=171745d21f7f98fd8878771da1000a31&account_id=461
//         
//          // ==API stats des véhicules ==
//          //http://api.worldoftanks.eu/2.0/account/tanks/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=506486576,502674600
//          urlServer = urlServerEU +"/2.0/account/tanks/?application_id=" + applicationIdEU + "&account_id=";
//          if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
//            url = new URL("https://pedro-proxy.appspot.com/"+urlServer.replaceAll("http://", "") + AllIdUser);
//          }
//          else {
//            url = new URL(urlServer + AllIdUser);
//          }
//          //
//          conn2 = (HttpURLConnection)url.openConnection();
//          conn2.setReadTimeout(20000);
//          conn2.setConnectTimeout(20000);
//          conn2.getInputStream();
//          readerUser = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
//          lineUser = "";
//          AllLinesUser = "";
//          while ((lineUser = readerUser.readLine()) != null) {
//            AllLinesUser = AllLinesUser + lineUser;
//          }
//          readerUser.close();
//          gsonUser = new Gson();
//          PlayerTankRatings playerTankRatings = gsonUser.fromJson(AllLinesUser, PlayerTankRatings.class);
          //=========================
         
         
          //on requete notre base les averageLevel y ont été stockés par le cron dans la table community Account
          Map <String, CommunityAccount> mapCommAcc = getMapHistorizedStatsUsers(listIdUser, 2);
         
       

         
         
          /////////////////////////////////
         
          //make some calculation of stats
          for(CommunityAccount communityAccount : listCommunityAccount1) {
            String user_id = communityAccount.getIdUser();
  //         
  //          if(playerVehicles != null) {
  //            if (playerVehicles.getData() != null ) {
  //              for (DataPlayerVehicles myDataPlayerVehicles : playerVehicles.getData()) {
  //                if ( user_id == myDataPlayerVehicles.getStat().getAccount_id() ) {
  //                  for (DataStatVehicle myDataStatVehicle : myDataPlayerVehicles.getStat().getVehicles() ) {
  //                    log.info(""+ myDataStatVehicle.getTank_id());
  //                  }
  //                }
  //              }
  //            }else {
  //              log.severe("playerVehicles.getData() is null ");
  //            }
  //          } else {
  //            log.severe("playerVehicles is null ");
  //          }
           
            //Rechercher dans playerTankRatings, les batailles sur tous les char du joueur ( pour caluler son tier moyen)
           
            //
            //Map<String,List<DataPlayerTankRatings>> mapDataPlayerTankRatings = playerTankRatings.getData();
           
           
            //Set<Entry<String, List<DataPlayerTankRatings>>>  setData = mapDataPlayerTankRatings.entrySet();
            //setData.
            log.warning("mapCommAcc " + mapCommAcc);
            CommunityAccount  commAcc= mapCommAcc.get(user_id);
           
            //calcul du tier moyen
            //Double nbBattles = 0.0;
            //Double levelByBattles = 0.0 ;
            log.warning("commAcc " + commAcc);
            log.warning("commAcc.getData() " + commAcc.getData());
            ///log.warning("commAcc.getData().getAverageLevel " + commAcc.getData().getAverageLevel);
           
            Double averageLevelTank =commAcc.getData().getAverageLevel();
           
//            for (DataPlayerTankRatings dataPlayerTankRatings : listPlayerTanksRatings) {
//              int tankId= dataPlayerTankRatings.getTank_id() ;
//              int battles = dataPlayerTankRatings.getStatistics().getAll().getBattles();
//              //int wins = dataPlayerTankRatings.getStatistics().getAll().getWins();
//              //
//              //log.warning("tankId :" + tankId );
//              if (tankEncyclopedia.getData().get(String.valueOf(tankId)) == null )
//                log.severe ("tankEncyclopedia.getData().get(tankId) is null ");
//             
//              int levelTank = tankEncyclopedia.getData().get(String.valueOf(tankId)).getLevel();
//              //
//              nbBattles = nbBattles + battles;
//              levelByBattles =levelByBattles + levelTank * battles;
//            }
//            averageLevelTank = levelByBattles/nbBattles;
           
            DataCommunityAccountRatings myDataCommunityAccountRatings = communityAccount.getData();
           
            //average level tank
            myDataCommunityAccountRatings.setAverageLevel(averageLevelTank);
           
            //log.info("averageLevelTank" + averageLevelTank);
           
            //== WR calculated
            int battles = myDataCommunityAccountRatings.getBattles();
            int battlesWin = myDataCommunityAccountRatings.getBattle_wins();
            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.setBattle_avg_performanceCalc(wrCal);
           
            //== Ratio capture points calculated
            int ctfPoints = myDataCommunityAccountRatings.getCtf_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.setRatioCtfPoints(ctfPointsCal);
           
            //==Damage Ration calculated
            int damagePoints = myDataCommunityAccountRatings.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.setRatioDamagePoints(ratioDamagePoints);
           
           
            //==Ratio Defense calculated
            int droppedCtfPoints = myDataCommunityAccountRatings.getDropped_ctf_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.setRatioDroppedCtfPoints(ratioDroppedCtfPoints);
           
           
            //==Ratio Destroyed calculated
            int destroyedPoints = myDataCommunityAccountRatings.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.setRatioDestroyedPoints(ratiodestroyedPoints);
           
            //==Ratio Detected calculated
            int detectedPoints = myDataCommunityAccountRatings.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.setRatioDetectedPoints(ratioDetectedPoints);
         
          }
          //add account
          listCommunityAccount.addAll(listCommunityAccount1);
   
 
        } catch (MalformedURLException e) {
          // ...
          e.printStackTrace();
        } catch (IOException e) {
          // ...
          e.printStackTrace();
        }
        finally {
          pm.close();
        }
     
        return myAllCommunityAccount;
     
      }
View Full Code Here


    }
   
    List<CommunityAccount> resultsFinal = new ArrayList<CommunityAccount>();
   

    PersistenceManager pm =null;
   
    try {
      pm = PMF.get().getPersistenceManager();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd hh:mm");

       
          try {
            for (String user  : listIdUsers) {
            /// query
          Query query = pm.newQuery(DaoCommunityAccount2.class);
            query.setFilter("idUser == nameParam");
            query.setOrdering("name desc");
            query.setOrdering("dateCommunityAccount desc");
            query.setRange(0, range); //only 6 results
            //query.setOrdering("hireDate desc");
            query.declareParameters("String nameParam");
            List<DaoCommunityAccount2> resultsTmp = (List<DaoCommunityAccount2>) query.execute(user);
           
            if(resultsTmp.size() != 0 )
            {
              DaoCommunityAccount2 daoComAcc = resultsTmp.get(0);
              CommunityAccount comAcc=  TransformDtoObject.TransformDaoCommunityAccountToCommunityAccount(daoComAcc);
              String previousDate = "";
              for (DaoCommunityAccount2 myDaoCommunityAccount : resultsTmp ) {
                //si 2 dates identiques se suivent on ne prend la deuxième
                String dateCurrent = "";
                if (myDaoCommunityAccount.getDateCommunityAccount() != null) {
                  dateCurrent = sdf.format(myDaoCommunityAccount.getDateCommunityAccount());
                  if (!dateCurrent.equalsIgnoreCase(previousDate)) {
                    comAcc.listDates.add(dateCurrent);
                    comAcc.listbattles.add(myDaoCommunityAccount.getData().getStats().getBattles());
                   
                    comAcc.listBattlesWins.add(myDaoCommunityAccount.getData().getStats().getBattle_wins());
                  }
                }
                previousDate = dateCurrent;
              }
              resultsFinal.add(comAcc);
            }
            query.closeAll();
         
            }
         
         
          }
        catch(Exception e){
          log.severe(e.getLocalizedMessage());
            //pm.currentTransaction().rollback();
          }
    } catch (Exception e) {
      e.printStackTrace();
      log.severe(e.getLocalizedMessage());
    }
    finally {
      if(pm != null)
        pm.close();
    }
 
    return resultsFinal;
 
  }
View Full Code Here

    }
   
    List<CommunityAccount> resultsFinal = new ArrayList<CommunityAccount>();
   

    PersistenceManager pm =null;
   
    try {
      pm = PMF.get().getPersistenceManager();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd hh:mm");

       
          try {
            for (String user  : listIdUsers) {
            /// query
          Query query = pm.newQuery(DaoCommunityAccount2.class);
            query.setFilter("idUser == nameParam");
            query.setOrdering("name desc");
            query.setOrdering("dateCommunityAccount desc");
            query.setRange(0, range); //only a few results
            //query.setOrdering("hireDate desc");
            query.declareParameters("String nameParam");
            List<DaoCommunityAccount2> resultsTmp = (List<DaoCommunityAccount2>) query.execute(user);
           
            if(resultsTmp.size() != 0 )
            {
              DaoCommunityAccount2 daoComAcc = resultsTmp.get(0);
              CommunityAccount comAcc=  TransformDtoObject.TransformDaoCommunityAccountToCommunityAccount(daoComAcc);
              String previousDate = "";
              for (DaoCommunityAccount2 myDaoCommunityAccount : resultsTmp ) {
                //si 2 dates identiques se suivent on ne prend pas la deuxième
                String dateCurrent = "";
                if (myDaoCommunityAccount.getDateCommunityAccount() != null) {
                  dateCurrent = sdf.format(myDaoCommunityAccount.getDateCommunityAccount());
                  if (!dateCurrent.equalsIgnoreCase(previousDate)) {
                    comAcc.listDates.add(dateCurrent);
                    //comAcc.listbattles.add(myDaoCommunityAccount.getData().getStats().getBattles());
                   
                    //comAcc.listBattlesWins.add(myDaoCommunityAccount.getData().getStats().getBattle_wins());
                    comAcc.listDataDaoCommunityAccount.add(myDaoCommunityAccount.getData().stats);
                  }
                }
                previousDate = dateCurrent;
              }
              resultsFinal.add(comAcc);
            }
            query.closeAll();
         
            }
         
         
          }
        catch(Exception e){
          log.severe(e.getLocalizedMessage());
            //pm.currentTransaction().rollback();
          }
    } catch (Exception e) {
      e.printStackTrace();
      log.severe(e.getLocalizedMessage());
    }
    finally {
      if(pm != null)
        pm.close();
    }
 
    return resultsFinal;
 
  }
View Full Code Here

    }
   
    Map<String, CommunityAccount> resultsFinal = new HashMap<String, CommunityAccount>();
   

    PersistenceManager pm =null;
   
    try {
      pm = PMF.get().getPersistenceManager();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd hh:mm");

       
          try {
            for (String user  : listIdUsers) {
            /// query
          Query query = pm.newQuery(DaoCommunityAccount2.class);
            query.setFilter("idUser == nameParam");
            query.setOrdering("name desc");
            query.setOrdering("dateCommunityAccount desc");
            query.setRange(0, range); //only 6 results
            //query.setOrdering("hireDate desc");
            query.declareParameters("String nameParam");
            List<DaoCommunityAccount2> resultsTmp = (List<DaoCommunityAccount2>) query.execute(user);
           
            if(resultsTmp.size() != 0 )
            {
              DaoCommunityAccount2 daoComAcc = resultsTmp.get(0);
              CommunityAccount comAcc=  TransformDtoObject.TransformDaoCommunityAccountToCommunityAccount(daoComAcc);
              String previousDate = "";
              for (DaoCommunityAccount2 myDaoCommunityAccount : resultsTmp ) {
                //si 2 dates identiques se suivent on ne prend la deuxième
                String dateCurrent = "";
                if (myDaoCommunityAccount.getDateCommunityAccount() != null) {
                  dateCurrent = sdf.format(myDaoCommunityAccount.getDateCommunityAccount());
                  if (!dateCurrent.equalsIgnoreCase(previousDate)) {
                    comAcc.listDates.add(dateCurrent);
                    comAcc.listbattles.add(myDaoCommunityAccount.getData().getStats().getBattles());
                   
                    comAcc.listBattlesWins.add(myDaoCommunityAccount.getData().getStats().getBattle_wins());
                  }
                }
                previousDate = dateCurrent;
              }
              resultsFinal.put(user, comAcc);
            }
            query.closeAll();
         
            }
         
         
          }
        catch(Exception e){
          log.severe(e.getLocalizedMessage());
            //pm.currentTransaction().rollback();
          }
    } catch (Exception e) {
      e.printStackTrace();
      log.severe(e.getLocalizedMessage());
    }
    finally {
      if(pm != null)
        pm.close();
    }
 
    return resultsFinal;
 
  }
View Full Code Here

  public static final String SYSTEM_USER_EMAIL = "system@bookings";
  public static final User SYSTEM_USER = new User(SYSTEM_USER_EMAIL, "System User", "", Accesslevel.NO_LOGIN);
 
  public static void createCoreData()
  {
    PersistenceManager pm = PMF.get().getPersistenceManager();
   
    // Annoyingly datanucleus won't let us use the copy up above...
    pm.makePersistent(new User(SYSTEM_USER_EMAIL, "System User", "", Accesslevel.NO_LOGIN));
   
    pm.close();
  }
View Full Code Here

   
    log.warning("getHistorizedStatsTanksUsers for " + listIdUsers.size() + " users");
    List<CommunityAccount> resultsFinal = new ArrayList<CommunityAccount>();
   

    PersistenceManager pm =null;
   
    try {
      pm = PMF.get().getPersistenceManager();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd hh:mm");

       
          try {
            for (String user  : listIdUsers) {
            /// query
          Query query = pm.newQuery(DaoCommunityAccount2.class);
            query.setFilter("idUser == nameParam");
            query.setOrdering("name desc");
            query.setOrdering("dateCommunityAccount desc");
            query.setRange(0, 6); //only 6 results
            //query.setOrdering("hireDate desc");
            query.declareParameters("String nameParam");
            List<DaoCommunityAccount2> resultsTmp = (List<DaoCommunityAccount2>) query.execute(user);
           
            if(resultsTmp.size() != 0 )
            {
              DaoCommunityAccount2 daoComAcc = resultsTmp.get(0);
              CommunityAccount comAcc=  TransformDtoObject.TransformDaoCommunityAccountToCommunityAccount(daoComAcc);
              String previousDate = "";
              for (DaoCommunityAccount2 myDaoCommunityAccount : resultsTmp ) {
                //si 2 dates identiques se suivent on ne prend la deuxième
                String dateCurrent = "";
                if (myDaoCommunityAccount.getDateCommunityAccount() != null) {
                  dateCurrent = sdf.format(myDaoCommunityAccount.getDateCommunityAccount());
                  if (!dateCurrent.equalsIgnoreCase(previousDate)) {
                    CommunityAccount comAccForList=  TransformDtoObject.TransformDaoCommunityAccountToCommunityAccount(myDaoCommunityAccount);
                    comAcc.listDates.add(dateCurrent);
                    //comAcc.listBattlesTanks.add(comAccForList.g);  //bug now !!!!
                   
                    //comAcc.listBattlesTanksWins.add(myDaoCommunityAccount.getData().getStatsVehicules().getBattle_wins());
                  }
                }
                previousDate = dateCurrent;
              }
              resultsFinal.add(comAcc);
            }
            query.closeAll();
         
            }
         
         
          }
        catch(Exception e){
          log.severe(e.getLocalizedMessage());
            //pm.currentTransaction().rollback();
          }
    } catch (Exception e) {
      e.printStackTrace();
      log.severe(e.getLocalizedMessage());
    }
    finally {
      if(pm != null)
        pm.close();
    }
 
    return resultsFinal;
 
  }
View Full Code Here

      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) {
          AllIdUser = AllIdUser + "," + idUser;
        }
       
   
             
        URL url = null ;
       
        String urlServer = urlServerEU +"/2.0/account/ratings/?application_id=" + applicationIdEU + "&account_id=";
        //http://api.worldoftanks.ru/2.0/account/ratings/?application_id=171745d21f7f98fd8878771da1000a31&account_id=461
       
        if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
          url = new URL("https://pedro-proxy.appspot.com/"+urlServer.replaceAll("http://", "") + 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;
        }
        //System.out.println(AllLinesUser);
       
        readerUser.close();

        Gson gsonUser = new Gson();
        //log.info(AllLinesUser.substring(0, 200));
        PlayerRatings playerRatings = gsonUser.fromJson(AllLinesUser, PlayerRatings.class);
        //playerRatings.setIdUser(idUser);
       
        //Transform playerRatings en communityAccount (pour utiliser des types compatibles avec la sérialisation (pas de MAP !!))
        List<CommunityAccount> listCommunityAccount1 =  TransformDtoObject.TransformPlayerRatingsToListCommunityAccount(playerRatings);
       
       
        //////////////////////////////////
        // ==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
       
        //http://api.worldoftanks.eu/2.0/encyclopedia/tanks/?application_id=d0a293dc77667c9328783d489c8cef73
        /*
         * {"status":"ok",
         * "count":336,
         * "data":{
          "3073":{
          "nation_i18n":"U.S.S.R.","name":"#ussr_vehicles:T-46","level":3,"nation":"ussr","is_premium":false,"name_i18n":"T-46","type":"lightTank","tank_id":3073}
          ,"6417":{
          "nation_i18n":"Germany","name":"#germany_vehicles:PzIII_IV","level":5,"nation":"germany","is_premium":false,"name_i18n":"Pz.Kpfw. III\/IV","type":"mediumTank","tank_id":6417}
        */
        //=======================
        if (tankEncyclopedia == null) {
          urlServer = urlServerEU +"/2.0/encyclopedia/tanks/?application_id=" + applicationIdEU ;
          url = new URL(urlServer);
         
          conn2 = (HttpURLConnection)url.openConnection();
          conn2.setReadTimeout(20000);
          conn2.setConnectTimeout(20000);
          conn2.getInputStream();
          readerUser = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
 
          lineUser = "";
          AllLinesUser = "";
 
          while ((lineUser = readerUser.readLine()) != null) {
            AllLinesUser = AllLinesUser + lineUser;
          }
          readerUser.close();
 
          gsonUser = new Gson();
          tankEncyclopedia = gsonUser.fromJson(AllLinesUser, TankEncyclopedia.class);
        }
        if (tankEncyclopedia == null) {
          log.severe("tankEncyclopedia is null" );
         
        }
        else {
          log.warning("tankEncyclopedia is good" );
          if (tankEncyclopedia.getData() ==null ) {
            log.severe("tankEncyclopedia data is null" );
          }
          else {
             Set<Entry<String, DataTankEncyclopedia>>  set = tankEncyclopedia.getData().entrySet();
           
//            for(Entry<String, DataTankEncyclopedia> entry : set) {
//              log.warning(entry.getValue().getName());
//              log.warning(entry.getKey());
//            }
            if (tankEncyclopedia.getData().get("6417") == null ){
              log.severe("tankEncyclopedia data get tank id 1 is null" );
            }
          }
             
        }
       
        //API stats des joueurs ========================
        //PB access denied sometimes
        //http://api.worldoftanks.eu/2.0/stats/accountbytime/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=500423304&hours_ago=24
        //http://api.worldoftanks.ru/2.0/account/ratings/?application_id=171745d21f7f98fd8878771da1000a31&account_id=461
       
        // ==API stats des véhicules ==
        //http://api.worldoftanks.eu/2.0/account/tanks/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=506486576,502674600
        urlServer = urlServerEU +"/2.0/account/tanks/?application_id=" + applicationIdEU + "&account_id=";
        if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
          url = new URL("https://pedro-proxy.appspot.com/"+urlServer.replaceAll("http://", "") + AllIdUser);
        }
        else {
          url = new URL(urlServer + AllIdUser);
        }
        //
        conn2 = (HttpURLConnection)url.openConnection();
        conn2.setReadTimeout(20000);
        conn2.setConnectTimeout(20000);
        conn2.getInputStream();
        readerUser = new BufferedReader(new InputStreamReader(conn2.getInputStream()));
        lineUser = "";
        AllLinesUser = "";
        while ((lineUser = readerUser.readLine()) != null) {
          AllLinesUser = AllLinesUser + lineUser;
        }
        readerUser.close();
        gsonUser = new Gson();
        PlayerTankRatings playerTankRatings = gsonUser.fromJson(AllLinesUser, PlayerTankRatings.class);
       
       
        /////////////////////////////////
       
        //make some calculation of stats
        for(CommunityAccount communityAccount : listCommunityAccount1) {
          String user_id = communityAccount.getIdUser();
//         
//          if(playerVehicles != null) {
//            if (playerVehicles.getData() != null ) {
//              for (DataPlayerVehicles myDataPlayerVehicles : playerVehicles.getData()) {
//                if ( user_id == myDataPlayerVehicles.getStat().getAccount_id() ) {
//                  for (DataStatVehicle myDataStatVehicle : myDataPlayerVehicles.getStat().getVehicles() ) {
//                    log.info(""+ myDataStatVehicle.getTank_id());
//                  }
//                }
//              }
//            }else {
//              log.severe("playerVehicles.getData() is null ");
//            }
//          } else {
//            log.severe("playerVehicles is null ");
//          }
         
          //Rechercher dans playerTankRatings, les batailles sur tous les char du joueur ( pour caluler son tier moyen)
         
          //
          Map<String,List<DataPlayerTankRatings>> mapDataPlayerTankRatings = playerTankRatings.getData();
          //Set<Entry<String, List<DataPlayerTankRatings>>>  setData = mapDataPlayerTankRatings.entrySet();
          //setData.
          List<DataPlayerTankRatings> listPlayerTanksRatings = mapDataPlayerTankRatings.get(user_id);
         
          //calcul du tier moyen
          Double nbBattles = 0.0;
          Double levelByBattles = 0.0 ;
          Double averageLevelTank =0.0;
         
          for (DataPlayerTankRatings dataPlayerTankRatings : listPlayerTanksRatings) {
            int tankId= dataPlayerTankRatings.getTank_id() ;
            int battles = dataPlayerTankRatings.getStatistics().getAll().getBattles();
            //int wins = dataPlayerTankRatings.getStatistics().getAll().getWins();
            //
            //log.warning("tankId :" + tankId );
            if (tankEncyclopedia.getData().get(String.valueOf(tankId)) == null )
              log.severe ("tankEncyclopedia.getData().get(tankId) is null ");
           
            int levelTank = tankEncyclopedia.getData().get(String.valueOf(tankId)).getLevel();
            //
            nbBattles = nbBattles + battles;
            levelByBattles =levelByBattles + levelTank * battles;
          }
          averageLevelTank = levelByBattles/nbBattles;
         
          DataCommunityAccountRatings myDataCommunityAccountRatings = communityAccount.getData();
         
          //average level tank
          myDataCommunityAccountRatings.setAverageLevel(averageLevelTank);
         
          //log.info("averageLevelTank" + averageLevelTank);
         
          //== WR calculated
          int battles = myDataCommunityAccountRatings.getBattles();
          int battlesWin = myDataCommunityAccountRatings.getBattle_wins();
          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.setBattle_avg_performanceCalc(wrCal);
         
          //== Ratio capture points calculated
          int ctfPoints = myDataCommunityAccountRatings.getCtf_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.setRatioCtfPoints(ctfPointsCal);
         
          //==Damage Ration calculated
          int damagePoints = myDataCommunityAccountRatings.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.setRatioDamagePoints(ratioDamagePoints);
         
         
          //==Ratio Defense calculated
          int droppedCtfPoints = myDataCommunityAccountRatings.getDropped_ctf_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.setRatioDroppedCtfPoints(ratioDroppedCtfPoints);
         
         
          //==Ratio Destroyed calculated
          int destroyedPoints = myDataCommunityAccountRatings.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.setRatioDestroyedPoints(ratiodestroyedPoints);
         
          //==Ratio Detected calculated
          int detectedPoints = myDataCommunityAccountRatings.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.setRatioDetectedPoints(ratioDetectedPoints);
       
        }
        //add account
        listCommunityAccount.addAll(listCommunityAccount1);
 

      } catch (MalformedURLException e) {
        // ...
        e.printStackTrace();
      } catch (IOException e) {
        // ...
        e.printStackTrace();
      }
      finally {
        pm.close();
      }
   
      return myAllCommunityAccount;
   
    }
View Full Code Here

    }

    List<CommunityAccount> listCommunityAccount = new ArrayList<CommunityAccount>();
    AllCommunityAccount myAllCommunityAccount = new AllCommunityAccount ();
    myAllCommunityAccount.setListCommunityAccount(listCommunityAccount);
    PersistenceManager pm =null;
    pm = PMF.get().getPersistenceManager();
    try {
      String AllIdUser ="";
      for(String idUser :listIdUser) {
        AllIdUser = AllIdUser + "," + idUser;
      }
           
      URL url = null ;
      //http://wotachievement.appspot.com/cronPersistPlayersStats?clanId=500006074
      String urlServer = urlServerEU +"/2.0/account/ratings/?application_id=" + applicationIdEU + "&account_id=";
      //http://api.worldoftanks.ru/2.0/account/ratings/?application_id=171745d21f7f98fd8878771da1000a31&account_id=461
     
      if(lieu.equalsIgnoreCase("boulot")){ //on passe par 1 proxy
        url = new URL("https://pedro-proxy.appspot.com/"+urlServer.replaceAll("http://", "") + 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();
      PlayerRatings playerRatings = gsonUser.fromJson(AllLinesUser, PlayerRatings.class);
      //Transform playerRatings en communityAccount (pour utiliser des types compatibles avec la sérialisation (pas de MAP !!))
      List<CommunityAccount> listCommunityAccount1 =  TransformDtoObject.TransformPlayerRatingsToListCommunityAccount(playerRatings);
     
     
      /////////////////////
      for(CommunityAccount communityAccount : listCommunityAccount1) {
       
          //Transform playerRatings en communityAccount (pour utiliser des types compatibles avec la sérialisation (pas de MAP !!))
          //communityAccount =  TransformDtoObject.TransformPlayerRatingsToCommunityAccount(playerRatings);
         
          //make some calculation of stats
          DataCommunityAccountRatings myDataCommunityAccountStats = communityAccount.getData();
          myDataCommunityAccountStats.setAverageLevel(5.5);
//             
          int battles = myDataCommunityAccountStats.getBattles();
          log.warning("userId :" + communityAccount.getIdUser() + " battles : " + battles);

          if (saveDataPlayer){
            //pm = PMF.get().getPersistenceManager();
                try {
                  //must transform before persist the objet clan
                  pm.currentTransaction().begin();
                  DaoCommunityAccount2 daoCommunityAccount = TransformDtoObject.TransformCommunityAccountToDaoCommunityAccount(communityAccount);
                 
                  //pour eviter trop de données en base 60 write OP
                  //daoCommunityAccount.getData().setAchievements(null);
                  daoCommunityAccount.setDateCommunityAccount(date);
                  //
                  pm.makePersistent(daoCommunityAccount);
                  pm.currentTransaction().commit();
                  //log.warning("vehicules daoCommunityAccount " + daoCommunityAccount.getData().statsVehicules.get(0).getName() + ":"+  daoCommunityAccount.getData().statsVehicules.get(0).getBattle_count() + ":"+  daoCommunityAccount.getData().statsVehicules.get(0).getWin_count());
                  listUsersPersisted.add(communityAccount.getIdUser());
                 
                }
              catch(Exception e){
                log.log(Level.SEVERE, "Exception while saving daoCommunityAccount", e);
                  pm.currentTransaction().rollback();
                }
                finally {
                    //pm.close();
                }
          }
      }
//            }//for (DataCommunityClanMembers

    } catch (MalformedURLException e) {
      // ...
      log.throwing("Persist stats", "", e);
      log.severe(e.getLocalizedMessage());
    } catch (IOException e) {
      // ...
      log.throwing("Persist stats", "", e);
      e.printStackTrace();
    } catch (Exception e) {
        // ...
      log.throwing("Persist stats", "", e);
      log.severe(e.getLocalizedMessage());
    }
    finally {
      if (pm != null)
        pm.close();
    }
 
    return listUsersPersisted;
 
  }
View Full Code Here

@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(CannedQueries.class.getName());

  public static Collection<Event> allEvents(boolean showNonOpenEvents)
  { 
    PersistenceManager pm = PMF.get().getPersistenceManager();
   
    Query query = pm.newQuery(Event.class);
    query.setOrdering("name");
   
    if(!showNonOpenEvents) query.setFilter("isCurrentlyOpen == true");
   
    return queryDetachAndClose(Event.class, query, true);
View Full Code Here

   * @param eventName The event name
   * @return The event, or null if nothing matched
   */
  public static Event eventByName(String eventName)
  {
    PersistenceManager pm = PMF.get().getPersistenceManager();
   
    Query query = pm.newQuery(Event.class);
    query.setFilter("name == nameParam");
    query.declareParameters("String nameParam");
   
    return querySingleDetachAndClose(Event.class, query, false, eventName);
  }
View Full Code Here

TOP

Related Classes of javax.jdo.PersistenceManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.