Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- public class Data {
- String[] roles = {"RB/FB","OL","WR","TE","DB","QB","LB","DL"};
- ArrayList<Player> playerList = new ArrayList<Player>();
- HashMap<String,LinkedList<Double>> means = new HashMap<>();
- HashMap<String,LinkedList<Double>> deviance = new HashMap<>();
- public static void main(String[] main){
- System.out.println("Main");
- Data kilmar = new Data();
- kilmar.cleanData(readFile());
- kilmar.loopLists(kilmar);
- }
- private double calculateProability(double x, double mean, double stdev){
- double exponent = Math.exp( -(Math.pow(x - mean, 2)) / (2 * Math.pow(stdev, 2)));
- return (1 / ( 2*Math.PI ) *stdev ) * exponent;
- }
- private double calculateClassProb(){
- }
- private double predict(){
- }
- private double getPredictions(){
- }
- private void loopLists(Data d){
- for(String s:roles){
- ArrayList<Integer>age=new ArrayList<Integer>();
- ArrayList<Integer>height=new ArrayList<Integer>();
- ArrayList<Integer>weight=new ArrayList<Integer>();
- for(Player p:d.playerList){
- if(p.position.equals(s)){
- age.add(p.age);
- weight.add(p.weight);
- height.add(p.height);
- }
- }
- d.getMean(age, s);
- d.getDeviation(age, 0, s);
- d.getMean(height, s);
- d.getDeviation(height, 1, s);
- d.getMean(weight, s);
- d.getDeviation(weight, 2, s);
- }
- System.out.println(d.deviance);
- }
- private void getDeviation(List<Integer> value, int y, String x){
- double devi;
- double totalSum=0;
- double mean = means.get(x).get(y);
- for(int i =0; i < value.size(); i++) {
- double sqrVal = value.get(i) - mean;
- totalSum = totalSum + Math.pow(sqrVal, 2);
- }
- if(deviance.get(x)==null) {
- deviance.put(x, new LinkedList<Double>());
- }
- devi = Math.sqrt(totalSum / value.size());
- deviance.get(x).add(devi);
- }
- private void getMean(List<Integer> value,String x){
- int total = 0;
- for(int i = 0; i < value.size(); i++) { // get first value
- total += (int) value.get(i);
- }
- double average = total / (value.size()-1);
- if(means.get(x)==null){
- means.put(x,new LinkedList<Double>());
- }
- means.get(x).add(average);
- }
- private static List<String[]> readFile(){
- List<String[]> masterList = new ArrayList<>();
- String filename= "src/DataSet_DEADNFLPLAYERS.txt";
- try {
- BufferedReader br = new BufferedReader(new FileReader(filename));
- String line;
- String[] lineArray;
- while ((line = br.readLine()) != null) {
- lineArray = line.split(",");
- masterList.add(lineArray);
- }
- }
- catch(IOException e){e.printStackTrace();}
- return masterList;
- }
- private void cleanData(List<String[]> masterList){
- int deathYear;
- int birthYear;
- int age; // deathYear - birthYear
- int weight;
- int height;
- String heightHolder;
- String position;
- String birthLocation;
- for(int i=1; i< masterList.size(); i++ ){ //starts at 1 to avoid headers
- String[] currentLine = masterList.get(i);
- deathYear = Integer.parseInt(currentLine[10].replace("\"", "")); //10th element
- birthYear = Integer.parseInt(currentLine[masterList.get(i).length-1].replace("\"", "")); //last element
- age = deathYear - birthYear; // determines the age at death
- if(currentLine[16].length() == 5 && currentLine[17].length() == 5 ) {
- heightHolder = currentLine[16].replace("\"", "");
- weight = Integer.parseInt(currentLine[17].replace("\"", ""));
- position = currentLine[8].replace("\"", "");
- birthLocation = currentLine[masterList.get(i).length - 2].replace("\"", "");
- birthLocation = birthLocation.replace(" ", "");
- height = Character.getNumericValue(heightHolder.charAt(0)) * 30;
- height = height + (Character.getNumericValue(heightHolder.charAt(2)) * 2);
- Player temp = new Player(age, weight, height, position, birthLocation );
- playerList.add(temp);
- }
- }
- }
- }
- class Player{
- int age;
- int weight;
- int height;
- String position;
- String birthLocation;
- Player(int age, int weight, int height, String position, String birthLocation) {
- this.age =age;
- this.weight =weight;
- this.height =height;
- this.position =position;
- this.birthLocation =birthLocation;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement