Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HOTSLogsDataParser;
- import java.util.*;
- import java.io.*;
- import java.awt.*;
- import javax.swing.*;
- public class Main {
- // Integer Values for Game Types
- public static final int QUICK_MATCH = 3;
- public static final int HERO_LEAGUE = 4;
- public static final int TEAM_LEAGUE = 5;
- public static final int UNRANKED_DRAFT = 6;
- // Integer Values for Game Types in Stats Array
- public static final int QM = 0;
- public static final int HL = 1;
- public static final int TL = 2;
- public static final int URD = 3;
- public static final int TOTAL = 4;
- // Integer Values for Positions in Data Stream
- public static final int MATCH_ID_POS = 0;
- public static final int GAME_TYPE_POS = 1;
- public static final int WINNER_POS = 4;
- public static final int MMR_POS = 5;
- public static final int TAKEDOWNS_POS = 7;
- public static final int DEATHS_POS = 10;
- public static void main(String[] args) throws IOException {
- HashMap<Integer, Match> matchCollection = new HashMap<Integer, Match>();
- gatherDataFromReplayCharacters(matchCollection);
- gatherDataFromReplays(matchCollection);
- analyzeStats(matchCollection);
- }
- public static void analyzeStats(HashMap<Integer, Match> matchCollection){
- Match workingMatchReference = null;
- int gameCount[] = {0,0,0,0,0};
- int biggerSpreadIsLoserCount[] = {0,0,0,0,0};
- int higherAverageMMRWinsCount[] = {0,0,0,0,0};
- int lowestMMRLosesCount[] = {0,0,0,0,0};
- int highestMMRWinsCount[] = {0,0,0,0,0};
- for (int key : matchCollection.keySet()){
- workingMatchReference = matchCollection.get(key);
- // Do not analyze unless all players are populated on both sides
- if (workingMatchReference.isMatchFull()){
- int gameModeValue = 0;
- int winningMMRSpread = 0;
- int losingMMRSpread = 0;
- int winningAverageMMR = 0;
- int losingAverageMMR = 0;
- int winningLowestMMR = 0;
- int losingLowestMMR = 0;
- int winningHighestMMR = 0;
- int losingHighestMMR = 0;
- // Set Game Mode Value
- switch (workingMatchReference.getGameType()){
- case QUICK_MATCH:
- gameModeValue = QM;
- break;
- case HERO_LEAGUE:
- gameModeValue = HL;
- break;
- case TEAM_LEAGUE:
- gameModeValue = TL;
- break;
- case UNRANKED_DRAFT:
- gameModeValue = URD;
- break;
- }
- // Gather data for analysis from match reference
- winningMMRSpread = workingMatchReference.getWinningTeam().getMMRSpread();
- losingMMRSpread = workingMatchReference.getLosingTeam().getMMRSpread();
- winningAverageMMR = workingMatchReference.getWinningTeam().getAverageTeamMMR();
- losingAverageMMR = workingMatchReference.getLosingTeam().getAverageTeamMMR();
- winningLowestMMR = workingMatchReference.getWinningTeam().getLowestMMR();
- losingLowestMMR = workingMatchReference.getLosingTeam().getLowestMMR();
- winningHighestMMR = workingMatchReference.getWinningTeam().getHighestMMR();
- losingHighestMMR = workingMatchReference.getLosingTeam().getHighestMMR();
- // Determine if the losing team had a larger MMR spread
- if (losingMMRSpread > winningMMRSpread){
- biggerSpreadIsLoserCount[gameModeValue]++;
- biggerSpreadIsLoserCount[TOTAL]++;
- }
- // Determine if the losing team had a lower average MMR
- if (losingAverageMMR < winningAverageMMR){
- higherAverageMMRWinsCount[gameModeValue]++;
- higherAverageMMRWinsCount[TOTAL]++;
- }
- // Determine if the lowest MMR player is on the losing team
- if (losingLowestMMR < winningLowestMMR){
- lowestMMRLosesCount[gameModeValue]++;
- lowestMMRLosesCount[TOTAL]++;
- }
- // Determine if the highest MMR player is on the winning team
- if (losingHighestMMR < winningHighestMMR){
- highestMMRWinsCount[gameModeValue]++;
- highestMMRWinsCount[TOTAL]++;
- }
- gameCount[gameModeValue]++;
- gameCount[TOTAL]++;
- }
- }
- // Print out results
- System.out.println();
- System.out.println("Stats Start ---------------------------");
- System.out.println("-- The number of games being analyzed in each mode --");
- System.out.println("QM Game Count: " + gameCount[QM]);
- System.out.println("HL Game Count: " + gameCount[HL]);
- System.out.println("TL Game Count: " + gameCount[TL]);
- System.out.println("URD Game Count: " + gameCount[URD]);
- System.out.println("Total Game Count: " + gameCount[TOTAL]);
- System.out.println();
- System.out.println("-- The number of games where the losing team had the biggest spread --");
- System.out.println("Biggest Spread is Loser QM: " + biggerSpreadIsLoserCount[QM]);
- System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[QM]/(float)gameCount[QM]));
- System.out.println("Biggest Spread is Loser HL: " + biggerSpreadIsLoserCount[HL]);
- System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[HL]/(float)gameCount[HL]));
- System.out.println("Biggest Spread is Loser TL: " + biggerSpreadIsLoserCount[TL]);
- System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[TL]/(float)gameCount[TL]));
- System.out.println("Biggest Spread is Loser URD: " + biggerSpreadIsLoserCount[URD]);
- System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[URD]/(float)gameCount[URD]));
- System.out.println("Biggest Spread is Loser TOTAL: " + biggerSpreadIsLoserCount[TOTAL]);
- System.out.println("Percentage of Games: " + ((float)biggerSpreadIsLoserCount[TOTAL]/(float)gameCount[TOTAL]));
- System.out.println();
- System.out.println("-- The number of games where the losing team had the lowest average MMR --");
- System.out.println("Lower Average MMR is Loser QM: " + higherAverageMMRWinsCount[QM]);
- System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[QM]/(float)gameCount[QM]));
- System.out.println("Lower Average MMR is Loser HL: " + higherAverageMMRWinsCount[HL]);
- System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[HL]/(float)gameCount[HL]));
- System.out.println("Lower Average MMR is Loser TL: " + higherAverageMMRWinsCount[TL]);
- System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[TL]/(float)gameCount[TL]));
- System.out.println("Lower Average MMR is Loser URD: " + higherAverageMMRWinsCount[URD]);
- System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[URD]/(float)gameCount[URD]));
- System.out.println("Lower Average MMR is Loser TOTAL: " + higherAverageMMRWinsCount[TOTAL]);
- System.out.println("Percentage of Games: " + ((float)higherAverageMMRWinsCount[TOTAL]/(float)gameCount[TOTAL]));
- System.out.println();
- System.out.println("-- The number of games where the losing team had the lowest MMR player --");
- System.out.println("Lowest MMR Player is Loser QM: " + lowestMMRLosesCount[QM]);
- System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[QM]/(float)gameCount[QM]));
- System.out.println("Lowest MMR Player is Loser HL: " + lowestMMRLosesCount[HL]);
- System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[HL]/(float)gameCount[HL]));
- System.out.println("Lowest MMR Player is Loser TL: " + lowestMMRLosesCount[TL]);
- System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[TL]/(float)gameCount[TL]));
- System.out.println("Lowest MMR Player is Loser URD: " + lowestMMRLosesCount[URD]);
- System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[URD]/(float)gameCount[URD]));
- System.out.println("Lowest MMR Player is Loser TOTAL: " + lowestMMRLosesCount[TOTAL]);
- System.out.println("Percentage of Games: " + ((float)lowestMMRLosesCount[TOTAL]/(float)gameCount[TOTAL]));
- System.out.println();
- System.out.println("-- The number of games where the winning team had the highest MMR player --");
- System.out.println("Highest MMR Player is Winner QM: " + highestMMRWinsCount[QM]);
- System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[QM]/(float)gameCount[QM]));
- System.out.println("Highest MMR Player is Winner HL: " + highestMMRWinsCount[HL]);
- System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[HL]/(float)gameCount[HL]));
- System.out.println("Highest MMR Player is Winner TL: " + highestMMRWinsCount[TL]);
- System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[TL]/(float)gameCount[TL]));
- System.out.println("Highest MMR Player is Winner URD: " + highestMMRWinsCount[URD]);
- System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[URD]/(float)gameCount[URD]));
- System.out.println("Highest MMR Player is Winner TOTAL: " + highestMMRWinsCount[TOTAL]);
- System.out.println("Percentage of Games: " + ((float)highestMMRWinsCount[TOTAL]/(float)gameCount[TOTAL]));
- System.out.println("Stats End -----------------------------");
- }
- public static void gatherDataFromReplayCharacters(HashMap<Integer, Match> matchCollection)
- throws IOException{
- BufferedReader bufferedReader = null;
- String readLine = null;
- String lineArray[] = null;
- String fileName = null;
- int matchID = 0;
- int MMR = 0;
- int takedowns = 0;
- int deaths = 0;
- int winnerValue = 0;
- boolean winningTeam = false;
- JOptionPane.showMessageDialog(null, "Please open 'ReplayCharacters.csv'");
- JFileChooser chooser = new JFileChooser();
- int returnVal = chooser.showOpenDialog(null);
- if(returnVal == JFileChooser.APPROVE_OPTION) {
- fileName = chooser.getSelectedFile().getPath();
- }
- try {
- // Create Buffered Reader
- bufferedReader = new BufferedReader(new FileReader(fileName));
- // Skip the first line
- bufferedReader.readLine();
- // Parse the file and create objects
- while ((readLine = bufferedReader.readLine()) != null){
- try {
- lineArray = readLine.split(",");
- matchID = Integer.parseInt(lineArray[MATCH_ID_POS]);
- MMR = Integer.parseInt(lineArray[MMR_POS]);
- takedowns = Integer.parseInt(lineArray[TAKEDOWNS_POS]);
- deaths = Integer.parseInt(lineArray[DEATHS_POS]);
- winnerValue = Integer.parseInt(lineArray[WINNER_POS]);
- if (winnerValue == 1){
- winningTeam = true;
- } else {
- winningTeam = false;
- }
- addPlayerToMatchID(matchCollection, matchID, MMR, takedowns, deaths, winningTeam);
- } catch (NumberFormatException ex){
- //System.out.println("Error: Line is missing data, skipping");
- //System.out.println("--- " + readLine);
- }
- }
- } catch (FileNotFoundException ex) {
- System.out.println("Error: Unable to open file " + fileName);
- } catch (IOException ex){
- System.out.println("Error: Unable to read file " + fileName);
- ex.printStackTrace();
- } finally {
- bufferedReader.close();
- }
- }
- public static void gatherDataFromReplays(HashMap<Integer, Match> matchCollection)
- throws IOException{
- BufferedReader bufferedReader = null;
- String readLine = null;
- String lineArray[] = null;
- String fileName = null;
- int matchID = 0;
- int gameType = 0;
- JOptionPane.showMessageDialog(null, "Please open 'Replays.csv'");
- JFileChooser chooser = new JFileChooser();
- int returnVal = chooser.showOpenDialog(null);
- if(returnVal == JFileChooser.APPROVE_OPTION) {
- fileName = chooser.getSelectedFile().getPath();
- }
- try {
- // Create Buffered Reader
- bufferedReader = new BufferedReader(new FileReader(fileName));
- // Skip the first line
- bufferedReader.readLine();
- // Parse the file and create objects
- while ((readLine = bufferedReader.readLine()) != null){
- try {
- lineArray = readLine.split(",");
- matchID = Integer.parseInt(lineArray[MATCH_ID_POS]);
- gameType = Integer.parseInt(lineArray[GAME_TYPE_POS]);
- updateGameType(matchCollection, matchID, gameType);
- } catch (NumberFormatException ex){
- //System.out.println("Error: Line is missing data, skipping");
- //System.out.println("--- " + readLine);
- }
- }
- } catch (FileNotFoundException ex) {
- System.out.println("Error: Unable to open file " + fileName);
- } catch (IOException ex){
- System.out.println("Error: Unable to read file " + fileName);
- ex.printStackTrace();
- } finally {
- bufferedReader.close();
- }
- }
- public static void updateGameType(HashMap<Integer, Match> matchCollection, int matchID, int gameType){
- Match workingMatchReference = null;
- // Grab MatchID reference, returns null if not found.
- workingMatchReference = matchCollection.get(matchID);
- // If Match Reference found, update Game Type; Prints Error Log otherwise
- if (workingMatchReference != null){
- workingMatchReference.setGameType(gameType);
- } else {
- System.out.print("Error: Match ID " + matchID + " not found in Match Collection");
- }
- }
- public static void addPlayerToMatchID(HashMap<Integer, Match> matchCollection, int matchID, int MMR,
- int takedowns, int deaths, boolean winningTeam){
- Match workingMatchReference = null;
- // Grab MatchID reference, returns null if not found.
- workingMatchReference = matchCollection.get(matchID);
- // If MatchID reference not found, create a new Match using MatchID
- if (workingMatchReference == null){
- workingMatchReference = new Match(matchID);
- matchCollection.put(matchID, workingMatchReference);
- }
- // Add new player to existing MatchID
- if(winningTeam){
- workingMatchReference.addPlayerToWinningTeam(MMR, takedowns, deaths);
- } else {
- workingMatchReference.addPlayerToLosingTeam(MMR, takedowns, deaths);
- }
- }
- }
- package HOTSLogsDataParser;
- public class Match {
- private int matchID;
- private int gameType;
- private Team winningTeam;
- private Team losingTeam;
- public Match(int matchID){
- this.matchID = matchID;
- this.winningTeam = new Team(true);
- this.losingTeam = new Team(false);
- }
- public void addPlayerToWinningTeam(int MMR, int takedowns, int deaths){
- this.winningTeam.addPlayer(MMR, takedowns, deaths);
- }
- public void addPlayerToLosingTeam(int MMR, int takedowns, int deaths){
- this.losingTeam.addPlayer(MMR, takedowns, deaths);
- }
- public void setGameType(int gameType){
- this.gameType = gameType;
- }
- public int getMatchID(){
- return this.matchID;
- }
- public int getGameType(){
- return this.gameType;
- }
- public Team getWinningTeam(){
- return this.winningTeam;
- }
- public Team getLosingTeam(){
- return this.losingTeam;
- }
- public boolean isMatchFull(){
- return (this.losingTeam.isTeamFull() && this.winningTeam.isTeamFull());
- }
- }
- package HOTSLogsDataParser;
- public class Team {
- private Player[] players;
- private boolean winner;
- public Team(boolean winner){
- this.players = new Player[5];
- this.winner = winner;
- }
- public void addPlayer(int MMR, int takedowns, int deaths){
- for (int i = 0; i < 5; i++){
- if (players[i] == null){
- this.players[i] = new Player(MMR, takedowns, deaths);
- break;
- }
- }
- }
- public boolean isWinner(){
- return this.winner;
- }
- public int getAverageTeamMMR(){
- int teamAverage = 0;
- for (int i = 0; i < 5; i++){
- if (players[i] != null){
- teamAverage += players[i].getMMR();
- }
- }
- return teamAverage / 5;
- }
- public int getMMRSpread(){
- int lowestMMR = 10000;
- int highestMMR = 0;
- for (int i = 0; i < 5; i++){
- if (players[i] != null){
- if (players[i].getMMR() > highestMMR){
- highestMMR = players[i].getMMR();
- }
- if (players[i].getMMR() < lowestMMR){
- lowestMMR = players[i].getMMR();
- }
- }
- }
- return highestMMR - lowestMMR;
- }
- public int getLowestMMR(){
- int lowestMMR = 10000;
- for (int i = 0; i < 5; i++){
- if (players[i] != null){
- if (players[i].getMMR() < lowestMMR){
- lowestMMR = players[i].getMMR();
- }
- }
- }
- return lowestMMR;
- }
- public int getHighestMMR(){
- int highestMMR = 0;
- for (int i = 0; i < 5; i++){
- if (players[i] != null){
- if (players[i].getMMR() > highestMMR){
- highestMMR = players[i].getMMR();
- }
- }
- }
- return highestMMR;
- }
- public boolean isTeamFull(){
- boolean isFull = true;
- for (int i = 0; i < 5; i++){
- if (players[i] == null){
- isFull = false;
- }
- }
- return isFull;
- }
- }
- package HOTSLogsDataParser;
- public class Player {
- private int MMR;
- private int takedowns;
- private int deaths;
- public Player(int MMR, int takedowns, int deaths){
- this.MMR = MMR;
- this.takedowns = takedowns;
- this.deaths = deaths;
- }
- public int getMMR(){
- return this.MMR;
- }
- public float getKDA(){
- return (float)this.takedowns / (float)this.deaths;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement