Advertisement
KillianMills

Data.java

Dec 4th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.12 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8.  
  9. public class Data {
  10.     String[] roles = {"RB/FB","OL","WR","TE","DB","QB","LB","DL"};
  11.  
  12.     ArrayList<Player> playerList = new ArrayList<Player>();
  13.     HashMap<String,LinkedList<Double>> means = new HashMap<>();
  14.     HashMap<String,LinkedList<Double>> deviance = new HashMap<>();
  15.  
  16.     public static void main(String[] main){
  17.         System.out.println("Main");
  18.         Data kilmar = new Data();
  19.         kilmar.cleanData(readFile());
  20.         kilmar.loopLists(kilmar);
  21.     }
  22.  
  23.     private double calculateProability(double x, double mean, double stdev){
  24.         double exponent = Math.exp( -(Math.pow(x - mean, 2)) / (2 * Math.pow(stdev, 2)));
  25.         return (1 / ( 2*Math.PI ) *stdev ) * exponent;
  26.     }
  27.  
  28.     private double calculateClassProb(){
  29.  
  30.     }
  31.  
  32.     private double predict(){
  33.  
  34.     }
  35.     private double getPredictions(){
  36.  
  37.     }
  38.  
  39.     private void loopLists(Data d){
  40.  
  41.         for(String s:roles){
  42.  
  43.             ArrayList<Integer>age=new ArrayList<Integer>();
  44.             ArrayList<Integer>height=new ArrayList<Integer>();
  45.             ArrayList<Integer>weight=new ArrayList<Integer>();
  46.  
  47.             for(Player p:d.playerList){
  48.                 if(p.position.equals(s)){
  49.                     age.add(p.age);
  50.                     weight.add(p.weight);
  51.                     height.add(p.height);
  52.                 }
  53.             }
  54.             d.getMean(age, s);
  55.             d.getDeviation(age, 0, s);
  56.             d.getMean(height, s);
  57.  
  58.             d.getDeviation(height, 1, s);
  59.             d.getMean(weight, s);
  60.             d.getDeviation(weight, 2, s);
  61.         }
  62.  
  63.         System.out.println(d.deviance);
  64.     }
  65.  
  66.     private void getDeviation(List<Integer> value, int y, String x){
  67.  
  68.  
  69.         double devi;
  70.         double totalSum=0;
  71.         double mean = means.get(x).get(y);
  72.  
  73.         for(int i =0; i < value.size(); i++) {
  74.             double sqrVal = value.get(i) - mean;
  75.             totalSum = totalSum + Math.pow(sqrVal, 2);
  76.         }
  77.  
  78.         if(deviance.get(x)==null) {
  79.             deviance.put(x, new LinkedList<Double>());
  80.         }
  81.  
  82.         devi = Math.sqrt(totalSum / value.size());
  83.         deviance.get(x).add(devi);
  84.     }
  85.  
  86.     private void getMean(List<Integer> value,String x){
  87.  
  88.         int total = 0;
  89.  
  90.         for(int i = 0; i < value.size(); i++) { // get first value
  91.             total += (int) value.get(i);
  92.         }
  93.         double average = total / (value.size()-1);
  94.  
  95.         if(means.get(x)==null){
  96.             means.put(x,new LinkedList<Double>());
  97.         }
  98.         means.get(x).add(average);
  99.     }
  100.  
  101.     private static List<String[]> readFile(){
  102.         List<String[]> masterList = new ArrayList<>();
  103.         String filename= "src/DataSet_DEADNFLPLAYERS.txt";
  104.         try {
  105.             BufferedReader br = new BufferedReader(new FileReader(filename));
  106.             String line;
  107.             String[] lineArray;
  108.             while ((line = br.readLine()) != null) {
  109.                 lineArray = line.split(",");
  110.                 masterList.add(lineArray);
  111.             }
  112.         }
  113.         catch(IOException e){e.printStackTrace();}
  114.         return masterList;
  115.     }
  116.  
  117.     private void cleanData(List<String[]> masterList){
  118.         int deathYear;
  119.         int birthYear;
  120.         int age; // deathYear - birthYear
  121.         int weight;
  122.         int height;
  123.         String heightHolder;
  124.         String position;
  125.         String birthLocation;
  126.  
  127.         for(int i=1; i< masterList.size(); i++ ){ //starts at 1 to avoid headers
  128.             String[] currentLine = masterList.get(i);
  129.  
  130.             deathYear = Integer.parseInt(currentLine[10].replace("\"", "")); //10th element
  131.             birthYear = Integer.parseInt(currentLine[masterList.get(i).length-1].replace("\"", "")); //last element
  132.             age = deathYear - birthYear; // determines the age at death
  133.  
  134.             if(currentLine[16].length() == 5 && currentLine[17].length() == 5 ) {
  135.                 heightHolder = currentLine[16].replace("\"", "");
  136.                 weight = Integer.parseInt(currentLine[17].replace("\"", ""));
  137.                 position = currentLine[8].replace("\"", "");
  138.                 birthLocation = currentLine[masterList.get(i).length - 2].replace("\"", "");
  139.                 birthLocation = birthLocation.replace(" ", "");
  140.  
  141.                 height = Character.getNumericValue(heightHolder.charAt(0)) * 30;
  142.                 height = height + (Character.getNumericValue(heightHolder.charAt(2)) * 2);
  143.                 Player temp = new Player(age, weight, height, position, birthLocation );
  144.                 playerList.add(temp);
  145.             }
  146.         }
  147.     }
  148. }
  149.  
  150. class Player{
  151.     int age;
  152.     int weight;
  153.     int height;
  154.  
  155.     String position;
  156.     String birthLocation;
  157.  
  158.     Player(int age, int weight, int height, String position, String birthLocation) {
  159.         this.age =age;
  160.         this.weight =weight;
  161.         this.height =height;
  162.         this.position =position;
  163.         this.birthLocation =birthLocation;
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement