From 7f1f9d337345635db96fb96286bd975d7a45fcd4 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Wed, 22 Oct 2014 16:22:02 +0200 Subject: [PATCH] Better performance --- LangsteZomerPeriode.java | 7 ++-- MaximaleRegenPeriode.java | 9 +++-- StatisticsCalculator.java | 76 ++++++++------------------------------- 3 files changed, 21 insertions(+), 71 deletions(-) diff --git a/LangsteZomerPeriode.java b/LangsteZomerPeriode.java index 8a3c35c..18217a0 100644 --- a/LangsteZomerPeriode.java +++ b/LangsteZomerPeriode.java @@ -2,12 +2,12 @@ import java.util.ArrayList; public class LangsteZomerPeriode extends Grootheid{ - private ArrayList list; + private ArrayList list; private Periode zomerPeriode; //constructor public LangsteZomerPeriode(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); + list = new ArrayList(); zomerPeriode = new Periode("Zomer"); updateRecent(measurement1); updatePeriod(measurement2); @@ -19,7 +19,6 @@ public class LangsteZomerPeriode extends Grootheid{ } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); int[] index = StatisticsCalculator.langsteZomersePeriode(list); zomerPeriode = Calculator.timeStampToPeriode( measurement2.get(index[0]).getDateStamp(), measurement2.get(index[1]).getDateStamp()); @@ -43,7 +42,7 @@ public class LangsteZomerPeriode extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getOutsideTemp()); + list.add(ms.getRawOutsideTemp()); } } } diff --git a/MaximaleRegenPeriode.java b/MaximaleRegenPeriode.java index e6b2ea8..a416d6f 100644 --- a/MaximaleRegenPeriode.java +++ b/MaximaleRegenPeriode.java @@ -2,11 +2,11 @@ import java.util.ArrayList; public class MaximaleRegenPeriode extends Grootheid{ - private ArrayList list; + private ArrayList list; //constructor public MaximaleRegenPeriode(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); + list = new ArrayList(); updateRecent(measurement1); updatePeriod(measurement2); } @@ -17,11 +17,10 @@ public class MaximaleRegenPeriode extends Grootheid{ } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); } public void display(){ - GUIboard.writePageToMatrix("Totale regenval", StatisticsCalculator.maximaleRegenPeriode(list) + "", ""); + GUIboard.writePageToMatrix("Totale regenval", Calculator.regenmeter(StatisticsCalculator.maximaleRegenPeriode(list)) + "", ""); } public void displayGraph() @@ -38,7 +37,7 @@ public class MaximaleRegenPeriode extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getRainRate()); + list.add(ms.getRawRainRate()); } } } diff --git a/StatisticsCalculator.java b/StatisticsCalculator.java index ac5b20f..33d1a57 100644 --- a/StatisticsCalculator.java +++ b/StatisticsCalculator.java @@ -216,11 +216,12 @@ public class StatisticsCalculator { index[1] = index2*1440; return index; } - public static double maximaleRegenPeriode(ArrayList array) + + public static short maximaleRegenPeriode(ArrayList array) { - double totaleRegen = 0; + short totaleRegen = 0; - for(double db : array) + for(short db : array) { totaleRegen += db; } @@ -228,20 +229,20 @@ public class StatisticsCalculator { return totaleRegen; } - public static int[] langsteZomersePeriode(ArrayList array) + public static int[] langsteZomersePeriode(ArrayList array) { ArrayList maxTempDag = new ArrayList(); int i = 0; - double maxTemp = 0; + short maxTemp = 0; //Bereken de maximale temperatuur per dag. - for(double db : array) + for(short db : array) { i++; if(i%1440==0) { - maxTempDag.add(maxTemp); + maxTempDag.add( (double) maxTemp); maxTemp = 0; } @@ -310,64 +311,15 @@ public class StatisticsCalculator { public static int[] langsteTempStijgingPeriode(ArrayList array) { - ArrayList maxTempDag = new ArrayList(); - ArrayList periodeLengteList = new ArrayList(); - ArrayList periodeStartList = new ArrayList(); - int[] index = new int[2]; int index1 = 0; int index2 = 0; - int indexStart = 0; - int indexEind = 1; - int periodeLengte = 0; - int i = 0; - double maxTemp = 0; - //berekent maximale temp. per dag - for(double db : array) - { - i ++; - if(i % 1440 == 0) - { - maxTempDag.add(maxTemp); - maxTemp = 0; - } - - if(db > maxTemp) - { - maxTemp = db; - } - } + //Code - for(int t = 1; t < maxTempDag.size(); t ++) //zoekt naar periodes van temp.stijgingen - { - if (maxTempDag.get(t) > maxTempDag.get(t - 1)) - { - indexEind ++; - } - - if (maxTempDag.get(t) <= maxTempDag.get(t - 1)) - { - periodeLengte = indexEind - indexStart; - periodeLengteList.add(periodeLengte); - periodeStartList.add(indexStart); - indexStart = indexEind; - } - } - - Integer tempMax = Collections.max(periodeLengteList); //onthoudt de grootste periode van een temp.stijging - - for (int u = 0; u < periodeLengteList.size(); u ++) //pakt de index van de grootste periode - { - if (tempMax == periodeLengteList.get(u)) - { - index1 = u; - index2 = tempMax - u; - } - } - - index[0] = index1 * 1440; - index[1] = index2 * 1440; - return index; - } + index[0] = index1; + index[1] = index2; + return index; + } + }