1
0
Fork 0

Spreadsheet standardDeviation done.

pull/1/head
selim 2023-12-26 05:46:30 +01:00
parent c059a4289a
commit cc351b4395
1 changed files with 65 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner; import java.util.Scanner;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -195,7 +196,18 @@ public class Spreadsheet {
else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung else if (formula.startsWith("STABW(")) // e.g. STABW(C6:D8) -> Standardabweichung
result = "TODO"; // TODO if(formula.length()<13)
result = "" + standardDeviation(substringStartCell1, substringEndCell);
else if(formula.length()<14&&substringStart2.contains(":"))
result = "" + standardDeviation(substringStartCell1, substringEndCell);
else if(formula.length()<14&&!substringStart2.contains(":"))
result = "" + standardDeviation(substringStart2, substringEndCell);
else if(formula.length()<15)
result = "" + standardDeviation(substringStart2, substringEndCell);
else
result = "0";
else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert else if (formula.startsWith("MIN(")) // e.g. MIN(C13:H13) -> größter Wert
result = "TODO"; // TODO result = "TODO"; // TODO
else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung
@ -265,7 +277,58 @@ public class Spreadsheet {
cellNames.add(getCellName(r, c)); cellNames.add(getCellName(r, c));
} catch (NumberFormatException n){} } catch (NumberFormatException n){}
avg /= counter; avg /= counter;
return 0; //average
ArrayList<String> copyCellNames = new ArrayList<>(cellNames);
double[] frequency = new double[cellNames.size()];
Arrays.fill(frequency,1);
ArrayList<Double> relativeFrequency = new ArrayList<>();
double mem = 0;
for(int i = 0; i< cellNames.size(); i++) {
for(int t = 0; t<cellNames.size(); t++){
if(((get(cellNames.get(i)).isEmpty())&&!(get(cellNames.get(t)).isEmpty()))&&(Double.parseDouble(get(cellNames.get(t)))==0)&&(t!=i)){
cellNames.remove(t);
frequency[i]++;
t = 0;
}else if((!(get(cellNames.get(i)).isEmpty())&&(get(cellNames.get(t)).isEmpty()))&&(Double.parseDouble(get(cellNames.get(i)))==0)&&(t!=i)){
cellNames.remove(t);
frequency[i]++;
t = 0;
}else if((get(cellNames.get(i)).isEmpty())&&(get(cellNames.get(t)).isEmpty())&&(t!=i)){
cellNames.remove(t);
frequency[i]++;
t = 0;
}else if((t!=i)&&(Double.parseDouble(get(cellNames.get(i))))==(Double.parseDouble(get(cellNames.get(t))))){
cellNames.remove(t);
frequency[i] ++;
t = 0;
}
}
}
//delete all duplicates
for(int i = 0; i< cellNames.size(); i++)
relativeFrequency.add(i,frequency[i]/copyCellNames.size());
if(get(cellNames.get(0)).isEmpty())
mem = ((0 - avg)*(0 - avg))
* relativeFrequency.get(0);
else
mem = ((Double.parseDouble(get(cellNames.get(0))) - avg)*(Double.parseDouble(get(cellNames.get(0))) - avg))
* relativeFrequency.get(0);
for(int i = 1; i<cellNames.size(); i++)
if(get(cellNames.get(i)).isEmpty())
mem += ((0 - avg)*(0 - avg))
* relativeFrequency.get(i);
else
mem += ((Double.parseDouble(get(cellNames.get(i))) - avg)*(Double.parseDouble(get(cellNames.get(i))) - avg))
* relativeFrequency.get(i);
return Math.sqrt(mem);
//standardDeviation formula
} }
/** /**