ArrayList loadTransactions() { //Raw list of each of the checkouts for the year. To be sorted into totals for each catorgory on a daily basis. datapoints = new ArrayList(); //NOAA file // File weather = new File("/Users/balunjones/Documents/Work/UCSB/MAT 259/Week 3/DeweyRain_Project1/data/SortedWeather.txt"); //Load weather data into an array first of all the days in the year. String[] lines = loadStrings("SortedWeather.txt"); for (int i = 0; i < lines.length; i++){ parseWeather(lines[i]); } //Sort the transactions TransactionUtils sorter = new TransactionUtils(); sorter.sortTransactionsByWeather(datapoints); //update the everyDay array //println("made it here"); datapoints = removeDuplicates(datapoints); data = assign2array(datapoints); //data = interpolate(data); return datapoints; } //create a new transaction obejct from a comma separated line. public WetDay parseWeather(String line) { String sections[] = split(line, ","); WetDay d = new WetDay(); //store all fields and initialise entries d.date = sections[0]; d.precip = Double.parseDouble(sections[1]); // print(d.precip); d.europe = Integer.parseInt(sections[2].trim()); d.asia = Integer.parseInt(sections[3].trim()); d.africa = Integer.parseInt(sections[4].trim()); d.northam = Integer.parseInt(sections[5].trim()); d.southam = Integer.parseInt(sections[6].trim()); d.other = Integer.parseInt(sections[7].trim()); if(!(d.europe < 1 && d.asia < 1 && d.africa < 1 && d.northam < 1 && d.southam < 1 && d.other < 1)){ datapoints.add(d); } return d; } ArrayList removeDuplicates(ArrayList datapoints){ //Assumes sorted data //does basic averaging of duplicate points ArrayList result = new ArrayList(); int index = 0; result.add((WetDay)datapoints.get(0)); for (int i = 1; i < datapoints.size(); i++){ WetDay before = (WetDay)datapoints.get(i-1); WetDay tmp = (WetDay)datapoints.get(i); float subs = (float)(tmp.precip - before.precip); if(abs(subs) <0.008){ WetDay new_day = average(before,tmp); result.remove(index); //println("removed : "+index); result.add(index,new_day); } else{ index = index+1; result.add(tmp); } } Arraysize = datapoints.size(); return result; } WetDay average(WetDay a, WetDay b){ WetDay res = new WetDay(); //println("averaged!"); //not important res.date = a.date; //should be same; res.precip = a.precip; //naive interpolation res.europe = int((a.europe+b.europe)/2); res.asia = int((a.asia+b.asia)/2); res.africa = int((a.africa+b.africa)/2); res.northam = int((a.northam+b.northam)/2); res.southam = int((a.southam+b.southam)/2); res.other = int((a.other+b.other)/2); return res; } double[][] assign2array(ArrayList datapoints){ Arraysize = datapoints.size(); double raindata[][] = new double[datapoints.size()][8]; for(int i = 0 ; i< Arraysize;i++){ WetDay temp = (WetDay)datapoints.get(i); raindata[i][0] = temp.precip; raindata[i][1] = temp.europe; raindata[i][2] = temp.asia; raindata[i][3] = temp.africa; raindata[i][4] = temp.northam; raindata[i][5] = temp.southam; raindata[i][6] = temp.other; raindata[i][7] = temp.other + temp.southam + temp.northam + temp.africa + temp.asia + temp.europe; } return raindata; } // //double[][] interpolate(double[][] data){ // // Integrator interppy = new Integrator[; // // for(int i = 0 ; i< datapoints.size();i++){ // //}