Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.53 KB | None | 0 0
  1. package HOTSLogsDataParser;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5. import java.awt.*;
  6. import javax.swing.*;
  7.  
  8. public class Main {
  9.     // Integer Values for Game Types
  10.     public static final int QUICK_MATCH = 3;
  11.     public static final int HERO_LEAGUE = 4;
  12.     public static final int TEAM_LEAGUE = 5;
  13.     public static final int UNRANKED_DRAFT = 6;
  14.    
  15.     // Integer Values for Game Types in Stats Array
  16.     public static final int QM = 0;
  17.     public static final int HL = 1;
  18.     public static final int TL = 2;
  19.     public static final int URD = 3;
  20.     public static final int TOTAL = 4;
  21.    
  22.     // Integer Values for Positions in Data Stream
  23.     public static final int MATCH_ID_POS = 0;
  24.     public static final int GAME_TYPE_POS = 1;
  25.     public static final int WINNER_POS = 4;
  26.     public static final int MMR_POS = 5;
  27.     public static final int TAKEDOWNS_POS = 7;
  28.     public static final int DEATHS_POS = 10;
  29.    
  30.     public static void main(String[] args) throws IOException {
  31.         HashMap<Integer, Match> matchCollection = new HashMap<Integer, Match>();
  32.        
  33.         gatherDataFromReplayCharacters(matchCollection);
  34.         gatherDataFromReplays(matchCollection);
  35.         analyzeStats(matchCollection);
  36.     }
  37.    
  38.     public static void analyzeStats(HashMap<Integer, Match> matchCollection){
  39.         Match workingMatchReference = null;
  40.        
  41.         int gameCount[] = {0,0,0,0,0};
  42.         int biggerSpreadIsLoserCount[] = {0,0,0,0,0};
  43.         int higherAverageMMRWinsCount[] = {0,0,0,0,0};
  44.         int lowestMMRLosesCount[] = {0,0,0,0,0};
  45.         int highestMMRWinsCount[] = {0,0,0,0,0};
  46.        
  47.         for (int key : matchCollection.keySet()){
  48.             workingMatchReference = matchCollection.get(key);
  49.            
  50.             // Do not analyze unless all players are populated on both sides
  51.             if (workingMatchReference.isMatchFull()){
  52.                 int gameModeValue = 0;
  53.                 int winningMMRSpread = 0;
  54.                 int losingMMRSpread = 0;
  55.                 int winningAverageMMR = 0;
  56.                 int losingAverageMMR = 0;
  57.                 int winningLowestMMR = 0;
  58.                 int losingLowestMMR = 0;
  59.                 int winningHighestMMR = 0;
  60.                 int losingHighestMMR = 0;
  61.                
  62.                 // Set Game Mode Value
  63.                 switch (workingMatchReference.getGameType()){
  64.                 case QUICK_MATCH:
  65.                     gameModeValue = QM;
  66.                     break;
  67.                 case HERO_LEAGUE:
  68.                     gameModeValue = HL;
  69.                     break;
  70.                 case TEAM_LEAGUE:
  71.                     gameModeValue = TL;
  72.                     break;
  73.                 case UNRANKED_DRAFT:
  74.                     gameModeValue = URD;
  75.                     break;
  76.                 }
  77.                
  78.                 // Gather data for analysis from match reference
  79.                 winningMMRSpread = workingMatchReference.getWinningTeam().getMMRSpread();
  80.                 losingMMRSpread = workingMatchReference.getLosingTeam().getMMRSpread();
  81.                 winningAverageMMR = workingMatchReference.getWinningTeam().getAverageTeamMMR();
  82.                 losingAverageMMR = workingMatchReference.getLosingTeam().getAverageTeamMMR();
  83.                 winningLowestMMR = workingMatchReference.getWinningTeam().getLowestMMR();
  84.                 losingLowestMMR = workingMatchReference.getLosingTeam().getLowestMMR();
  85.                 winningHighestMMR = workingMatchReference.getWinningTeam().getHighestMMR();
  86.                 losingHighestMMR = workingMatchReference.getLosingTeam().getHighestMMR();
  87.                
  88.                 // Determine if the losing team had a larger MMR spread
  89.                 if (losingMMRSpread > winningMMRSpread){
  90.                     biggerSpreadIsLoserCount[gameModeValue]++;
  91.                     biggerSpreadIsLoserCount[TOTAL]++;
  92.                 }
  93.                
  94.                 // Determine if the losing team had a lower average MMR
  95.                 if (losingAverageMMR < winningAverageMMR){
  96.                     higherAverageMMRWinsCount[gameModeValue]++;
  97.                     higherAverageMMRWinsCount[TOTAL]++;
  98.                 }
  99.                
  100.                 // Determine if the lowest MMR player is on the losing team
  101.                 if (losingLowestMMR < winningLowestMMR){
  102.                     lowestMMRLosesCount[gameModeValue]++;
  103.                     lowestMMRLosesCount[TOTAL]++;
  104.                 }
  105.                
  106.                 // Determine if the highest MMR player is on the winning team
  107.                 if (losingHighestMMR < winningHighestMMR){
  108.                     highestMMRWinsCount[gameModeValue]++;
  109.                     highestMMRWinsCount[TOTAL]++;
  110.                 }
  111.                
  112.                 gameCount[gameModeValue]++;
  113.                 gameCount[TOTAL]++;
  114.             }
  115.         }
  116.        
  117.         // Print out results
  118.         System.out.println();
  119.         System.out.println("Stats Start ---------------------------");
  120.         System.out.println("-- The number of games being analyzed in each mode --");
  121.         System.out.println("QM Game Count: " + gameCount[QM]);
  122.         System.out.println("HL Game Count: " + gameCount[HL]);
  123.         System.out.println("TL Game Count: " + gameCount[TL]);
  124.         System.out.println("URD Game Count: " + gameCount[URD]);
  125.         System.out.println("Total Game Count: " + gameCount[TOTAL]);
  126.         System.out.println();
  127.         System.out.println("-- The number of games where the losing team had the biggest spread --");
  128.         System.out.println("Biggest Spread is Loser QM: " + biggerSpreadIsLoserCount[QM]);
  129.         System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[QM]/(float)gameCount[QM]));
  130.         System.out.println("Biggest Spread is Loser HL: " + biggerSpreadIsLoserCount[HL]);
  131.         System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[HL]/(float)gameCount[HL]));
  132.         System.out.println("Biggest Spread is Loser TL: " + biggerSpreadIsLoserCount[TL]);
  133.         System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[TL]/(float)gameCount[TL]));
  134.         System.out.println("Biggest Spread is Loser URD: " + biggerSpreadIsLoserCount[URD]);
  135.         System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[URD]/(float)gameCount[URD]));
  136.         System.out.println("Biggest Spread is Loser TOTAL: " + biggerSpreadIsLoserCount[TOTAL]);
  137.         System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[TOTAL]/(float)gameCount[TOTAL]));
  138.         System.out.println();
  139.         System.out.println("-- The number of games where the losing team had the lowest average MMR --");
  140.         System.out.println("Lower Average MMR is Loser QM: " + higherAverageMMRWinsCount[QM]);
  141.         System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[QM]/(float)gameCount[QM]));
  142.         System.out.println("Lower Average MMR is Loser HL: " + higherAverageMMRWinsCount[HL]);
  143.         System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[HL]/(float)gameCount[HL]));
  144.         System.out.println("Lower Average MMR is Loser TL: " + higherAverageMMRWinsCount[TL]);
  145.         System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[TL]/(float)gameCount[TL]));
  146.         System.out.println("Lower Average MMR is Loser URD: " + higherAverageMMRWinsCount[URD]);
  147.         System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[URD]/(float)gameCount[URD]));
  148.         System.out.println("Lower Average MMR is Loser TOTAL: " + higherAverageMMRWinsCount[TOTAL]);
  149.         System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[TOTAL]/(float)gameCount[TOTAL]));
  150.         System.out.println();
  151.         System.out.println("-- The number of games where the losing team had the lowest MMR player --");
  152.         System.out.println("Lowest MMR Player is Loser QM: " + lowestMMRLosesCount[QM]);
  153.         System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[QM]/(float)gameCount[QM]));
  154.         System.out.println("Lowest MMR Player is Loser HL: " + lowestMMRLosesCount[HL]);
  155.         System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[HL]/(float)gameCount[HL]));
  156.         System.out.println("Lowest MMR Player is Loser TL: " + lowestMMRLosesCount[TL]);
  157.         System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[TL]/(float)gameCount[TL]));
  158.         System.out.println("Lowest MMR Player is Loser URD: " + lowestMMRLosesCount[URD]);
  159.         System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[URD]/(float)gameCount[URD]));
  160.         System.out.println("Lowest MMR Player is Loser TOTAL: " + lowestMMRLosesCount[TOTAL]);
  161.         System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[TOTAL]/(float)gameCount[TOTAL]));
  162.         System.out.println();
  163.         System.out.println("-- The number of games where the winning team had the highest MMR player --");
  164.         System.out.println("Highest MMR Player is Winner QM: " + highestMMRWinsCount[QM]);
  165.         System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[QM]/(float)gameCount[QM]));
  166.         System.out.println("Highest MMR Player is Winner HL: " + highestMMRWinsCount[HL]);
  167.         System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[HL]/(float)gameCount[HL]));
  168.         System.out.println("Highest MMR Player is Winner TL: " + highestMMRWinsCount[TL]);
  169.         System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[TL]/(float)gameCount[TL]));
  170.         System.out.println("Highest MMR Player is Winner URD: " + highestMMRWinsCount[URD]);
  171.         System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[URD]/(float)gameCount[URD]));
  172.         System.out.println("Highest MMR Player is Winner TOTAL: " + highestMMRWinsCount[TOTAL]);
  173.         System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[TOTAL]/(float)gameCount[TOTAL]));
  174.         System.out.println("Stats End -----------------------------");
  175.     }
  176.    
  177.     public static void gatherDataFromReplayCharacters(HashMap<Integer, Match> matchCollection)
  178.             throws IOException{
  179.         BufferedReader bufferedReader = null;
  180.         String readLine = null;
  181.         String lineArray[] = null;
  182.         String fileName = null;
  183.         int matchID = 0;
  184.         int MMR = 0;
  185.         int takedowns = 0;
  186.         int deaths = 0;
  187.         int winnerValue = 0;
  188.         boolean winningTeam = false;
  189.        
  190.         JOptionPane.showMessageDialog(null, "Please open 'ReplayCharacters.csv'");
  191.        
  192.         JFileChooser chooser = new JFileChooser();
  193.         int returnVal = chooser.showOpenDialog(null);
  194.         if(returnVal == JFileChooser.APPROVE_OPTION) {
  195.             fileName = chooser.getSelectedFile().getPath();
  196.         }
  197.        
  198.         try {
  199.             // Create Buffered Reader
  200.             bufferedReader = new BufferedReader(new FileReader(fileName));
  201.            
  202.             // Skip the first line
  203.             bufferedReader.readLine();
  204.            
  205.             // Parse the file and create objects
  206.             while ((readLine = bufferedReader.readLine()) != null){
  207.                 try {
  208.                     lineArray = readLine.split(",");
  209.                     matchID = Integer.parseInt(lineArray[MATCH_ID_POS]);
  210.                     MMR = Integer.parseInt(lineArray[MMR_POS]);
  211.                     takedowns = Integer.parseInt(lineArray[TAKEDOWNS_POS]);
  212.                     deaths = Integer.parseInt(lineArray[DEATHS_POS]);
  213.                     winnerValue = Integer.parseInt(lineArray[WINNER_POS]);
  214.                    
  215.                     if (winnerValue == 1){
  216.                         winningTeam = true;
  217.                     } else {
  218.                         winningTeam = false;
  219.                     }
  220.                    
  221.                     addPlayerToMatchID(matchCollection, matchID, MMR, takedowns, deaths, winningTeam);
  222.                 } catch (NumberFormatException ex){
  223.                     //System.out.println("Error: Line is missing data, skipping");
  224.                     //System.out.println("--- " + readLine);
  225.                 }
  226.             }
  227.         } catch (FileNotFoundException ex) {
  228.             System.out.println("Error: Unable to open file " + fileName);
  229.         } catch (IOException ex){
  230.             System.out.println("Error: Unable to read file " + fileName);
  231.             ex.printStackTrace();
  232.         } finally {
  233.             bufferedReader.close();
  234.         }
  235.     }
  236.    
  237.     public static void gatherDataFromReplays(HashMap<Integer, Match> matchCollection)
  238.             throws IOException{
  239.         BufferedReader bufferedReader = null;
  240.         String readLine = null;
  241.         String lineArray[] = null;
  242.         String fileName = null;
  243.         int matchID = 0;
  244.         int gameType = 0;
  245.        
  246.         JOptionPane.showMessageDialog(null, "Please open 'Replays.csv'");
  247.        
  248.         JFileChooser chooser = new JFileChooser();
  249.         int returnVal = chooser.showOpenDialog(null);
  250.         if(returnVal == JFileChooser.APPROVE_OPTION) {
  251.             fileName = chooser.getSelectedFile().getPath();
  252.         }
  253.        
  254.         try {
  255.             // Create Buffered Reader
  256.             bufferedReader = new BufferedReader(new FileReader(fileName));
  257.            
  258.             // Skip the first line
  259.             bufferedReader.readLine();
  260.            
  261.             // Parse the file and create objects
  262.             while ((readLine = bufferedReader.readLine()) != null){
  263.                 try {
  264.                     lineArray = readLine.split(",");
  265.                     matchID = Integer.parseInt(lineArray[MATCH_ID_POS]);
  266.                     gameType = Integer.parseInt(lineArray[GAME_TYPE_POS]);
  267.                    
  268.                     updateGameType(matchCollection, matchID, gameType);
  269.                 } catch (NumberFormatException ex){
  270.                     //System.out.println("Error: Line is missing data, skipping");
  271.                     //System.out.println("--- " + readLine);
  272.                 }
  273.             }
  274.         } catch (FileNotFoundException ex) {
  275.             System.out.println("Error: Unable to open file " + fileName);
  276.         } catch (IOException ex){
  277.             System.out.println("Error: Unable to read file " + fileName);
  278.             ex.printStackTrace();
  279.         } finally {
  280.             bufferedReader.close();
  281.         }
  282.     }
  283.  
  284.     public static void updateGameType(HashMap<Integer, Match> matchCollection, int matchID, int gameType){
  285.         Match workingMatchReference = null;
  286.        
  287.         // Grab MatchID reference, returns null if not found.
  288.         workingMatchReference = matchCollection.get(matchID);
  289.        
  290.         // If Match Reference found, update Game Type; Prints Error Log otherwise
  291.         if (workingMatchReference != null){
  292.             workingMatchReference.setGameType(gameType);
  293.         } else {
  294.             System.out.print("Error: Match ID " + matchID + " not found in Match Collection");
  295.         }
  296.     }
  297.    
  298.     public static void addPlayerToMatchID(HashMap<Integer, Match> matchCollection, int matchID, int MMR,
  299.             int takedowns, int deaths, boolean winningTeam){
  300.         Match workingMatchReference = null;
  301.        
  302.         // Grab MatchID reference, returns null if not found.
  303.         workingMatchReference = matchCollection.get(matchID);
  304.        
  305.         // If MatchID reference not found, create a new Match using MatchID
  306.         if (workingMatchReference == null){
  307.             workingMatchReference = new Match(matchID);
  308.             matchCollection.put(matchID, workingMatchReference);
  309.         }
  310.        
  311.         // Add new player to existing MatchID
  312.         if(winningTeam){
  313.             workingMatchReference.addPlayerToWinningTeam(MMR, takedowns, deaths);
  314.         } else {
  315.             workingMatchReference.addPlayerToLosingTeam(MMR, takedowns, deaths);
  316.         }
  317.        
  318.     }
  319. }
  320.  
  321. package HOTSLogsDataParser;
  322.  
  323. public class Match {
  324.     private int matchID;
  325.     private int gameType;
  326.     private Team winningTeam;
  327.     private Team losingTeam;
  328.    
  329.     public Match(int matchID){
  330.         this.matchID = matchID;
  331.         this.winningTeam = new Team(true);
  332.         this.losingTeam = new Team(false);
  333.     }
  334.    
  335.     public void addPlayerToWinningTeam(int MMR, int takedowns, int deaths){
  336.         this.winningTeam.addPlayer(MMR, takedowns, deaths);
  337.     }
  338.    
  339.     public void addPlayerToLosingTeam(int MMR, int takedowns, int deaths){
  340.         this.losingTeam.addPlayer(MMR, takedowns, deaths);
  341.     }
  342.    
  343.     public void setGameType(int gameType){
  344.         this.gameType = gameType;
  345.     }
  346.    
  347.     public int getMatchID(){
  348.         return this.matchID;
  349.     }
  350.    
  351.     public int getGameType(){
  352.         return this.gameType;
  353.     }
  354.    
  355.     public Team getWinningTeam(){
  356.         return this.winningTeam;
  357.     }
  358.    
  359.     public Team getLosingTeam(){
  360.         return this.losingTeam;
  361.     }
  362.    
  363.     public boolean isMatchFull(){
  364.         return (this.losingTeam.isTeamFull() && this.winningTeam.isTeamFull());
  365.     }
  366. }
  367.  
  368. package HOTSLogsDataParser;
  369.  
  370. public class Team {
  371.     private Player[] players;
  372.     private boolean winner;
  373.    
  374.     public Team(boolean winner){
  375.         this.players = new Player[5];
  376.         this.winner = winner;
  377.     }
  378.    
  379.     public void addPlayer(int MMR, int takedowns, int deaths){
  380.         for (int i = 0; i < 5; i++){
  381.             if (players[i] == null){
  382.                 this.players[i] = new Player(MMR, takedowns, deaths);
  383.                 break;
  384.             }
  385.         }
  386.     }
  387.    
  388.     public boolean isWinner(){
  389.         return this.winner;
  390.     }
  391.    
  392.     public int getAverageTeamMMR(){
  393.         int teamAverage = 0;
  394.        
  395.         for (int i = 0; i < 5; i++){
  396.             if (players[i] != null){
  397.                 teamAverage += players[i].getMMR();
  398.             }
  399.         }
  400.        
  401.         return teamAverage / 5;
  402.     }
  403.    
  404.     public int getMMRSpread(){
  405.         int lowestMMR = 10000;
  406.         int highestMMR = 0;
  407.        
  408.         for (int i = 0; i < 5; i++){
  409.             if (players[i] != null){
  410.                 if (players[i].getMMR() > highestMMR){
  411.                     highestMMR = players[i].getMMR();
  412.                 }
  413.                 if (players[i].getMMR() < lowestMMR){
  414.                     lowestMMR = players[i].getMMR();
  415.                 }
  416.             }
  417.         }
  418.        
  419.         return highestMMR - lowestMMR;
  420.     }
  421.    
  422.     public int getLowestMMR(){
  423.         int lowestMMR = 10000;
  424.        
  425.         for (int i = 0; i < 5; i++){
  426.             if (players[i] != null){
  427.                 if (players[i].getMMR() < lowestMMR){
  428.                     lowestMMR = players[i].getMMR();
  429.                 }
  430.             }
  431.         }
  432.        
  433.         return lowestMMR;
  434.     }
  435.    
  436.     public int getHighestMMR(){
  437.         int highestMMR = 0;
  438.        
  439.         for (int i = 0; i < 5; i++){
  440.             if (players[i] != null){
  441.                 if (players[i].getMMR() > highestMMR){
  442.                     highestMMR = players[i].getMMR();
  443.                 }
  444.             }
  445.         }
  446.        
  447.         return highestMMR;
  448.     }
  449.    
  450.     public boolean isTeamFull(){
  451.         boolean isFull = true;
  452.        
  453.         for (int i = 0; i < 5; i++){
  454.             if (players[i] == null){
  455.                 isFull = false;
  456.             }
  457.         }
  458.        
  459.         return isFull;
  460.     }
  461. }
  462.  
  463. package HOTSLogsDataParser;
  464.  
  465. public class Player {
  466.     private int MMR;
  467.     private int takedowns;
  468.     private int deaths;
  469.    
  470.     public Player(int MMR, int takedowns, int deaths){
  471.         this.MMR = MMR;
  472.         this.takedowns = takedowns;
  473.         this.deaths = deaths;
  474.     }
  475.    
  476.     public int getMMR(){
  477.         return this.MMR;
  478.     }
  479.    
  480.     public float getKDA(){
  481.         return (float)this.takedowns / (float)this.deaths;
  482.     }
  483. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement