package mapreduce;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.util.Tool;

public class RegressionMapper extends Mapper<LongWritable, Text, Text, CompositeWritable> {
	private Text word = new Text();
	private CompositeWritable parXY = null;
	
	@Override
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
		word.set("FUNCTION");
		Configuration conf = context.getConfiguration();
		String estatistica = conf.get("estatistica");
		String x = "";
		double y = 0.0;
		
		int iniChave = 0;
		
		String balde = value.toString();
		
		int iniEstat = 0;
		int fimEstat = 0;
		
		if(estatistica.equals("MEDIA")){
			iniEstat = 4;
			fimEstat = 9;
		}
		
		if(!balde.isEmpty() && balde.charAt(0) != 'S'){
			String valor = "";
			
			while(balde.charAt(iniChave) != '\t' && balde.charAt(iniChave) != ' '){
				valor += balde.charAt(iniChave);
				iniChave++;
			}
			System.out.println(valor);
			x = valor;

			valor = "";
			while(iniEstat < fimEstat){
				if(balde.charAt(iniEstat) != '\t' && balde.charAt(iniEstat) != ' '){
					valor += balde.charAt(iniEstat);
				}
				iniEstat++;
			}
			System.out.println(valor);
			y = Double.parseDouble(valor);
			
			Text xWritable = new Text();
			xWritable.set(x);
			
			DoubleWritable yWritable = new DoubleWritable();
			yWritable.set(y);
			
			System.out.println("X: "+xWritable+" Y: "+yWritable);
			try {
				parXY = new CompositeWritable(xWritable, yWritable);
				context.write(word, parXY);
			} 
			catch (NumberFormatException e) {
			}
		}
	}
}
@@ -546,17 +546,16 @@
 = null;%0A
-%09
 %0A%09@Overr
@@ -829,33 +829,8 @@
 .0;%0A
-%09%09%0A%09%09int iniChave = 0;%0A%09%09
 %0A%09%09S
@@ -834,16 +834,18 @@
 %09%09String
+%5B%5D
  balde =
@@ -865,44 +865,37 @@
 ng()
-;%0A%09%09%0A%09%09int iniEstat = 0;
+.split(%22/t/t%22);%0A
 %0A%09%09int 
-fimEs
+indexS
 tat 
@@ -899,18 +899,16 @@
 at = 0;%0A
-%09%09
 %0A%09%09if(es
@@ -944,513 +944,171 @@
 %09%09in
-iEs
+dexS
 tat = 
-4
+1
 ;%0A%09%09
-%09fimEstat = 9;%0A%09%09%7D%0A%09%09%0A%09%09if(!balde.isEmpty() && balde.charAt(0) != 'S')%7B%0A%09%09%09String valor = %22%22;%0A%09%09%09%0A%09%09%09while(balde.charAt(iniChave) != '%5Ct' && balde.charAt(iniChave) != ' ')%7B%0A%09%09%09%09valor += balde.charAt(iniChave);%0A%09%09%09%09iniChave++;%0A%09%09%09%7D%0A%09%09%09System.out.println(valor);%0A%09%09%09x = valor;%0A%0A%09%09%09valor = %22%22;%0A%09%09%09while(iniEstat %3C fimEstat)%7B%0A%09%09%09%09if(balde.charAt(iniEstat) != '%5Ct' && balde.charAt(iniEstat) != ' ')%7B%0A%09%09%09%09%09valor += balde.charAt(iniEstat);%0A%09%09%09%09%7D%0A%09%09%09%09iniEstat++;%0A%09%09%09%7D%0A%09%09%09System.out.println(valor)
+%7Delse if(estatistica.equals(%22DESVIOPADRAO%22))%7B%0A%09%09%09indexStat = 2;%0A%09%09%7Delse if(estatistica.equals(%22VARIANCIA%22))%7B%0A%09%09%09indexStat = 3;%0A%09%09%7D%0A%0A%09%09x = balde%5B0%5D
 ;%0A
-%09
 %09%09y 
@@ -1132,21 +1132,28 @@
 ble(
-valor);%0A%09%09%09%0A%09
+balde%5BindexStat%5D);%0A%0A
 %09%09Te
@@ -1179,17 +1179,16 @@
 Text();%0A
-%09
 %09%09xWrita
@@ -1199,21 +1199,17 @@
 set(x);%0A
-%09%09%09%0A%09
+%0A
 %09%09Double
@@ -1253,17 +1253,16 @@
 le();%0A%09%09
-%09
 yWritabl
@@ -1275,13 +1275,9 @@
 y);%0A
-%09%09%09%0A%09
+%0A
 %09%09Sy
@@ -1334,16 +1334,14 @@
 ;%0A%09%09
-%09
 try %7B%0A
-%09
 %09%09%09p
@@ -1395,17 +1395,16 @@
 le);%0A%09%09%09
-%09
 context.
@@ -1429,13 +1429,11 @@
 ;%0A%09%09
-%09
 %7D %0A
-%09
 %09%09ca
@@ -1470,14 +1470,10 @@
 %7B%0A%09%09
-%09
 %7D%0A
-%09%09%7D
 %0A%09%7D%0A

Pega todas as estatisticas