From b4258909e3ea2bd291afa61b68a6c386aa854d31 Mon Sep 17 00:00:00 2001 From: jancoow Date: Wed, 22 Oct 2014 21:40:15 +0200 Subject: [PATCH] "Some" improvements --- AvgWindSpeed.java | 31 +++----- Barometer.java | 33 +++------ Calculator.java | 1 + CloudHeight.java | 28 ++------ DewPoint.java | 27 ++----- GUIboard.java | 1 + GraadDagen.java | 1 + Grootheid.java | 123 +++++++++++++++++++++++--------- HeatIndex.java | 26 ++----- IO.java | 1 + InsideHum.java | 28 +++----- InsideTemp.java | 30 +++----- LangsteRegenPeriode.java | 1 + LangsteTempStijgingPeriode.java | 3 +- LangsteZomerPeriode.java | 27 +++---- Main.java | 1 + MaximaleRegenPeriode.java | 20 ++---- Measurement.java | 1 + OutsideHum.java | 31 +++----- OutsideTemp.java | 32 ++++----- Periode.java | 5 +- RainRate.java | 30 +++----- StatisticsCalculator.java | 81 +++++++++++++++------ Sun.java | 22 ++---- UVLevel.java | 31 +++----- Voorspellingen.java | 84 +++++++++++----------- Weerstation.java | 30 ++++---- WeerstationConnector.java | 1 + WindChill.java | 26 ++----- WindDirection.java | 33 +++------ Zonsterkte.java | 29 ++------ 31 files changed, 374 insertions(+), 444 deletions(-) mode change 100755 => 100644 IO.java diff --git a/AvgWindSpeed.java b/AvgWindSpeed.java index 4f8b899..2bbbb8b 100644 --- a/AvgWindSpeed.java +++ b/AvgWindSpeed.java @@ -1,34 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class AvgWindSpeed extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public AvgWindSpeed(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Gem. Windsnelheid"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getAvgWindSpeed()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setDeviation(StatisticsCalculator.afwijking(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Gem. Windsnelheid", "Afwijking: " + getDeviation(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + afwijking(); } private void createList(ArrayList measurement2) @@ -40,7 +27,11 @@ public class AvgWindSpeed extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getAvgWindSpeed()); + list.add((double)ms.getRawAvgWindSpeed()); } } + + public double calculate(double value){ + return Calculator.windSnelheid((short)value); + } } diff --git a/Barometer.java b/Barometer.java index 20baf6b..d159a6f 100644 --- a/Barometer.java +++ b/Barometer.java @@ -1,35 +1,20 @@ - +package weerstation1; import java.util.ArrayList; public class Barometer extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public Barometer(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Luchtdruk"); + updateRecent(measurement1); updatePeriod(measurement2); } - + public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getBarometer()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setMode(StatisticsCalculator.modus(list)); - } - - public void display(){ - super.display(); - GUIboard.clearLeft(); - GUIboard.clearRight(); - GUIboard.writePageToMatrix("Luchtdruk", "Modus: " + getMode(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + modus(); } private void createList(ArrayList measurement2) @@ -41,7 +26,11 @@ public class Barometer extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getBarometer()); + list.add((double)ms.getRawBarometer()); } } + + public double calculate(double value){ + return Calculator.luchtdruk((short)value); + } } diff --git a/Calculator.java b/Calculator.java index fba52bf..cf9b0c6 100644 --- a/Calculator.java +++ b/Calculator.java @@ -1,3 +1,4 @@ +package weerstation1; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; diff --git a/CloudHeight.java b/CloudHeight.java index f383dcb..0a6baf6 100644 --- a/CloudHeight.java +++ b/CloudHeight.java @@ -1,36 +1,20 @@ - +package weerstation1; import java.util.ArrayList; public class CloudHeight extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public CloudHeight(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Wolkhoogte"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getCloudHeight()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.clearLeft(); - GUIboard.clearRight(); - GUIboard.writePageToMatrix("Wolkhoogte", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + modus(); } private void createList(ArrayList measurement2) @@ -42,7 +26,7 @@ public class CloudHeight extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getCloudHeight()); + list.add((double)ms.getCloudHeight()); } } } diff --git a/DewPoint.java b/DewPoint.java index 597db90..98ce9bd 100644 --- a/DewPoint.java +++ b/DewPoint.java @@ -1,35 +1,22 @@ - +package weerstation1; import java.util.ArrayList; public class DewPoint extends Grootheid { - public ArrayList list; - - //constructor + //constructor public DewPoint(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Dauwpunt"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getDewPoint()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setMedian(StatisticsCalculator.median(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Dauwpunt", "Mediaan: " + getMedian(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + median(); } private void createList(ArrayList measurement2) @@ -41,7 +28,7 @@ public class DewPoint extends Grootheid for(Measurement ms : measurement2) { - list.add(ms.getDewPoint()); + list.add((double)ms.getDewPoint()); } } } diff --git a/GUIboard.java b/GUIboard.java index e278515..c5dad11 100644 --- a/GUIboard.java +++ b/GUIboard.java @@ -1,3 +1,4 @@ +package weerstation1; import java.util.ArrayList; diff --git a/GraadDagen.java b/GraadDagen.java index 04f8ae4..a7a437c 100644 --- a/GraadDagen.java +++ b/GraadDagen.java @@ -1,3 +1,4 @@ +package weerstation1; import java.util.ArrayList; diff --git a/Grootheid.java b/Grootheid.java index 8d8f4c9..f926d92 100644 --- a/Grootheid.java +++ b/Grootheid.java @@ -1,17 +1,24 @@ - +package weerstation1; import java.util.ArrayList; public class Grootheid { // instance variables - replace the example below with your own - private double avg; + private double statics; private double max; private double min; - private double mode; - private double median; - private double deviation; private double current; - + private Periode period; + ArrayList list = new ArrayList(); + + //boolean to check if the variables are set + private boolean max_min_check = false; + private boolean current_check = false; + + private String statics_name = ""; + private String name = ""; + private String custom = ""; + //constructor public Grootheid(){ } @@ -22,7 +29,8 @@ public class Grootheid } public void setCurrent(double current) { - this.current = current; + current_check = true; + this.current = current; } public double getMax() { @@ -41,46 +49,68 @@ public class Grootheid this.min = Math.round(min * 100.0) / 100.0;; } - public double getAvg() { - return avg; - } - - public void setAvg(double avg) { - this.avg = Math.round(avg * 100.0) / 100.0; - } - - public double getMode() { - return mode; + public double getStatics() { + return statics; } - public void setMode(double mode) { - this.mode = Math.round(mode * 100.0) / 100.0; + public void setStatics(double statics) { + this.statics = Math.round(statics * 100.0) / 100.0; + } + + public String getName() { + return name; } - public double getMedian() { - return median; + public void setName(String name) { + this.name = name; } - public void setMedian(double median) { - this.median = Math.round(median * 100.0) / 100.0; + public Periode getPeriod() { + return period; } - public double getDeviation() { - return deviation; + public void setPeriod(Periode period) { + this.period = period; } - public void setDeviation(double deviation) { - this.deviation = Math.round(deviation * 100.0) / 100.0; + public void setStatics_name(String statics_name) { + this.statics_name = statics_name; + } + + public String getCustom() { + return custom; + } + + public void setCustom(String custom) { + this.custom = custom; } //Methods - public void calculateMaxMin(ArrayList array){ - setMax(StatisticsCalculator.max(array)); - setMin(StatisticsCalculator.min(array)); + public void maxMin(){ + max_min_check = true; + setMax(calculate(StatisticsCalculator.max(list))); + setMin(calculate(StatisticsCalculator.min(list))); + } + public void median(){ + setStatics_name("Mediaan: "); + setStatics(calculate(StatisticsCalculator.median(list))); + } + public void modus(){ + setStatics_name("Modus: "); + setStatics(calculate(StatisticsCalculator.modus(list))); + } + public void avg(){ + setStatics_name("Gemiddelde: "); + setStatics(calculate(StatisticsCalculator.avg(list))); + } + public void afwijking(){ + setStatics_name("Afwijking: "); + setStatics(calculate(StatisticsCalculator.afwijking(list))); } - public void updateRecent(Measurement measurement1){ + public void updateRecent(Measurement measurement1){ + } public void updatePeriod(ArrayList measurement2){ @@ -88,13 +118,36 @@ public class Grootheid } public void display(){ - GUIboard.writeUpperDigits(getCurrent()); - GUIboard.writeLeftDigits(getMax()); - GUIboard.writeRightDigits(getMin()); + GUIboard.clearLeft(); + GUIboard.clearRight(); + GUIboard.clearTop(); + GUIboard.clearBottom(); + + if(current_check){ + GUIboard.writeUpperDigits(getCurrent()); + } + if(max_min_check){ + GUIboard.writeLeftDigits(getMax()); + GUIboard.writeRightDigits(getMin()); + } + if(!(statics_name == "")){ + + GUIboard.writePageToMatrix(getName(), statics_name + getStatics(), ""); + }else if(!(custom == "")){ + + GUIboard.writePageToMatrix(getName(), custom, ""); + } + if(!(period == null)){ + GUIboard.writePageToMatrix(getName(), period.toString(), ""); + } } public void displayGraph() { - + GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + } + + public double calculate(double value){ + return value; } } diff --git a/HeatIndex.java b/HeatIndex.java index fc0ff52..21d5ce9 100644 --- a/HeatIndex.java +++ b/HeatIndex.java @@ -1,33 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class HeatIndex extends Grootheid{ - public ArrayList list; - //constructor + //constructor public HeatIndex(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("HeatIndex"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getHeatIndex()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setMedian(StatisticsCalculator.median(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Warmte indexcijfer", "Mediaan: " + getMedian(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + median(); } private void createList(ArrayList measurement2) @@ -39,7 +27,7 @@ public class HeatIndex extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getHeatIndex()); + list.add((double)ms.getHeatIndex()); } } } diff --git a/IO.java b/IO.java old mode 100755 new mode 100644 index c4a52ac..79c30ad --- a/IO.java +++ b/IO.java @@ -1,3 +1,4 @@ +package weerstation1; // // Port IO emulator class. All read/writes are send over TCP/IP to the host diff --git a/InsideHum.java b/InsideHum.java index e1c1759..3671a1e 100644 --- a/InsideHum.java +++ b/InsideHum.java @@ -1,34 +1,22 @@ - +package weerstation1; import java.util.ArrayList; public class InsideHum extends Grootheid{ - public ArrayList list; //constructor public InsideHum(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Luchtv. Binnen"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getInsideHum()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Luchtv. Binnen", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -40,7 +28,11 @@ public class InsideHum extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getInsideHum()); + list.add((double)ms.getRawInsideHum()); } } + + public double calculate(double value){ + return Calculator.luchtVochtigheid((short)value); + } } diff --git a/InsideTemp.java b/InsideTemp.java index 6062db1..2e224b9 100644 --- a/InsideTemp.java +++ b/InsideTemp.java @@ -1,34 +1,22 @@ - +package weerstation1; import java.util.ArrayList; public class InsideTemp extends Grootheid{ - public ArrayList list; - //constructor + //constructor public InsideTemp(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Binnentemperatuur"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getInsideTemp()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Binnentemperatuur", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -40,7 +28,11 @@ public class InsideTemp extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getInsideTemp()); + list.add((double)ms.getRawInsideTemp()); } } + + public double calculate(double value){ + return Calculator.temperatuur((short)value); + } } diff --git a/LangsteRegenPeriode.java b/LangsteRegenPeriode.java index 51705a8..8a469e3 100644 --- a/LangsteRegenPeriode.java +++ b/LangsteRegenPeriode.java @@ -1,3 +1,4 @@ +package weerstation1; import java.util.ArrayList; public class LangsteRegenPeriode extends Grootheid{ diff --git a/LangsteTempStijgingPeriode.java b/LangsteTempStijgingPeriode.java index 7064828..642564d 100644 --- a/LangsteTempStijgingPeriode.java +++ b/LangsteTempStijgingPeriode.java @@ -1,3 +1,4 @@ +package weerstation1; import java.util.ArrayList; public class LangsteTempStijgingPeriode extends Grootheid @@ -23,7 +24,7 @@ public class LangsteTempStijgingPeriode extends Grootheid public void updatePeriod(ArrayList measurement2) { createList(measurement2); - calculateMaxMin(list); + int[] index = StatisticsCalculator.langsteTempStijgingPeriode(list); StijgingPeriode= Calculator.timeStampToPeriode( measurement2.get(index[0]).getDateStamp(), measurement2.get(index[1]).getDateStamp()); diff --git a/LangsteZomerPeriode.java b/LangsteZomerPeriode.java index 18217a0..f82d09b 100644 --- a/LangsteZomerPeriode.java +++ b/LangsteZomerPeriode.java @@ -1,36 +1,25 @@ - +package weerstation1; import java.util.ArrayList; public class LangsteZomerPeriode extends Grootheid{ - private ArrayList list; - private Periode zomerPeriode; //constructor public LangsteZomerPeriode(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - zomerPeriode = new Periode("Zomer"); - updateRecent(measurement1); + setName("Langste zomerse periode"); updatePeriod(measurement2); } - - public void updateRecent(Measurement measurement1){ - setCurrent(measurement1.getOutsideTemp()); - } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - - int[] index = StatisticsCalculator.langsteZomersePeriode(list); - zomerPeriode = Calculator.timeStampToPeriode( measurement2.get(index[0]).getDateStamp(), measurement2.get(index[1]).getDateStamp()); - } - - public void display(){ - GUIboard.writePageToMatrix("Langste zomerse periode", zomerPeriode.toString(), ""); + int[] index = StatisticsCalculator.langsteDroogstePeriode(list); + System.out.println(list.size()); + System.out.println(index[0]); + System.out.println(index[1]); + setPeriod(Calculator.timeStampToPeriode( measurement2.get(index[0]).getDateStamp(), measurement2.get(index[1]).getDateStamp())); } public void displayGraph() { - display(); } private void createList(ArrayList measurement2) @@ -42,7 +31,7 @@ public class LangsteZomerPeriode extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getRawOutsideTemp()); + list.add((double)ms.getRawOutsideTemp()); } } } diff --git a/Main.java b/Main.java index 2e74ab0..0127476 100644 --- a/Main.java +++ b/Main.java @@ -1,3 +1,4 @@ +package weerstation1; public class Main { diff --git a/MaximaleRegenPeriode.java b/MaximaleRegenPeriode.java index a416d6f..5ff5d49 100644 --- a/MaximaleRegenPeriode.java +++ b/MaximaleRegenPeriode.java @@ -1,33 +1,25 @@ - +package weerstation1; import java.util.ArrayList; public class MaximaleRegenPeriode extends Grootheid{ - private ArrayList list; //constructor public MaximaleRegenPeriode(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Totale regenval"); updatePeriod(measurement2); } - - public void updateRecent(Measurement measurement1){ - setCurrent(measurement1.getRainRate()); - } public void updatePeriod(ArrayList measurement2){ createList(measurement2); + setCustom(StatisticsCalculator.maximaleRegenPeriode(list) + " "); } - public void display(){ - GUIboard.writePageToMatrix("Totale regenval", Calculator.regenmeter(StatisticsCalculator.maximaleRegenPeriode(list)) + "", ""); - } - + public void displayGraph() { - display(); } + private void createList(ArrayList measurement2) { if(!list.isEmpty()) @@ -37,7 +29,7 @@ public class MaximaleRegenPeriode extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getRawRainRate()); + list.add((double)ms.getRawRainRate()); } } } diff --git a/Measurement.java b/Measurement.java index 8c1548a..b8d412d 100644 --- a/Measurement.java +++ b/Measurement.java @@ -1,3 +1,4 @@ +package weerstation1; import java.sql.Timestamp; import java.math.BigDecimal; diff --git a/OutsideHum.java b/OutsideHum.java index b477781..1c5009b 100644 --- a/OutsideHum.java +++ b/OutsideHum.java @@ -1,34 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class OutsideHum extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public OutsideHum(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Luchtv. Buiten"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getOutsideHum()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Luchtv. Buiten", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -40,7 +27,11 @@ public class OutsideHum extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getOutsideHum()); + list.add((double)ms.getRawOutsideHum()); } } + + public double calculate(double value){ + return Calculator.luchtVochtigheid((short)value); + } } diff --git a/OutsideTemp.java b/OutsideTemp.java index eb385e4..fd4b996 100644 --- a/OutsideTemp.java +++ b/OutsideTemp.java @@ -1,34 +1,22 @@ - +package weerstation1; import java.util.ArrayList; public class OutsideTemp extends Grootheid{ - public ArrayList list; - - //constructor + + //constructor public OutsideTemp(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Buitentemperatuur"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getOutsideTemp()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Buitentemperatuur", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -40,7 +28,11 @@ public class OutsideTemp extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getOutsideTemp()); + list.add((double)ms.getRawOutsideTemp()); } } + + public double calculate(double value){ + return Calculator.temperatuur((short)value); + } } diff --git a/Periode.java b/Periode.java index c12f83d..ff97258 100644 --- a/Periode.java +++ b/Periode.java @@ -1,3 +1,4 @@ +package weerstation1; import java.util.GregorianCalendar; import java.util.Calendar; @@ -19,8 +20,8 @@ public class Periode { beginPeriode = new GregorianCalendar(); eindePeriode = new GregorianCalendar(); - setBeginPeriode(jaar, maand, dag); - setEindePeriode(eindjaar, eindmaand, einddag); + setBeginPeriode(jaar, maand-1, dag); + setEindePeriode(eindjaar, eindmaand-1, einddag); this.name = name; } diff --git a/RainRate.java b/RainRate.java index bb350a4..3c069f5 100644 --- a/RainRate.java +++ b/RainRate.java @@ -1,33 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class RainRate extends Grootheid{ - public ArrayList list; - //constructor + //constructor public RainRate(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Regenval in mm/h"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getRainRate()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Regenval in mm/h", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -39,7 +27,11 @@ public class RainRate extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getRainRate()); + list.add((double)ms.getRawRainRate()); } } + + public double calculate(double value){ + return Calculator.regenmeter((short)value); + } } diff --git a/StatisticsCalculator.java b/StatisticsCalculator.java index 213ec4a..adc2fe5 100644 --- a/StatisticsCalculator.java +++ b/StatisticsCalculator.java @@ -1,5 +1,7 @@ -import java.util.ArrayList; -import java.util.Collections; +package weerstation1; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; public class StatisticsCalculator { @@ -217,7 +219,7 @@ public class StatisticsCalculator { return index; } - public static short maximaleRegenPeriode(ArrayList array) + public static short maximaleRegenPeriode(ArrayList array) { short regen = 0; ArrayList regenPerUur = new ArrayList(); @@ -245,15 +247,15 @@ public class StatisticsCalculator { return totaleRegen; } - public static int[] langsteZomersePeriode(ArrayList array) + public static int[] langsteZomersePeriode(ArrayList array) { ArrayList maxTempDag = new ArrayList(); int i = 0; - short maxTemp = 0; + double maxTemp = 0; //Bereken de maximale temperatuur per dag. - for(short db : array) + for(double db : array) { i++; if(i%1440==0) @@ -284,7 +286,7 @@ public class StatisticsCalculator { //Doorloop je maximale temperaturen en zoek de langste periode for(int t=0; t 25) { + if(maxTempDag.get(t) > 770) { p++; if(!zomers) { @@ -312,19 +314,55 @@ public class StatisticsCalculator { return index; } - public static int[] langsteHitteGolfPeriode(ArrayList array) - { - int[] index = new int[2]; - int index1 = 0; - int index2 = 0; - - //Code - - index[0] = index1; - index[1] = index2; - return index; + + + public static Periode langsteHittegolfPeriode(ArrayList array){ + double maxDay = 0; + ArrayList maxTempPerDay = new ArrayList(); + + //calculate the max for every day + for(int i = 0; i < array.size(); i++){ + if((i % 1440) == 0){ + maxTempPerDay.add(maxDay); + maxDay = 0; + } + if(array.get(i).getRawOutsideTemp() > maxDay){ + maxDay = array.get(i).getRawOutsideTemp(); + } + } + + int periodLength = 0; + int maxPeriodLength = 5; + int numberOfTropicalDays = 0; + + Calendar begin = Calendar.getInstance(); + Calendar eind = Calendar.getInstance(); + Periode periode = new Periode(begin, eind, "Geen hittegolfperiode gevonden"); + + for(int i = 0; i < maxTempPerDay.size(); i++){ + if( maxTempPerDay.get(i) >= 770){ // If the temperature is bigger then 25 degree Celcius (770 degree Fahrenheit) the summer period will start + periodLength++; + if (maxTempPerDay.get(i) >= 860){ // If the temperature is bigger then 30 degree Celcius (860 degree Fahrenheit) it will add a tropical day + numberOfTropicalDays++; + } + }else if(periodLength > maxPeriodLength && numberOfTropicalDays >= 3){ //period has ended. If it is bigger then 5 days AND there are 3 or more tropical days, the period is a heat wave + maxPeriodLength = periodLength; + periodLength = 0; + numberOfTropicalDays = 0; + eind.setTimeInMillis(array.get((i-1)*1440).getDateStamp().getTime()); + periode = new Periode(eind, begin, "Langste hittegolf periode"); + }else{ + numberOfTropicalDays = 0; + periodLength = 0; + } + if(periodLength == 5){ + begin.setTimeInMillis(array.get((i-5)*1440).getDateStamp().getTime()); + } + } + return periode; } + public static int[] langsteTempStijgingPeriode(ArrayList array) { ArrayList maxTempDag = new ArrayList(); @@ -371,7 +409,7 @@ public class StatisticsCalculator { indexStart = indexEind; } } - } + Integer tempMax = Collections.max(periodeLengteList); //onthoudt de grootste periode van een temp.stijging @@ -390,4 +428,7 @@ public class StatisticsCalculator { } } -} + + + + diff --git a/Sun.java b/Sun.java index b4c2fc9..8409987 100644 --- a/Sun.java +++ b/Sun.java @@ -1,8 +1,5 @@ +package weerstation1; - - -import java.util.ArrayList; - public class Sun extends Grootheid{ //fields @@ -12,6 +9,8 @@ public class Sun extends Grootheid{ //constructor public Sun(Measurement measurement1){ updateRecent(measurement1); + setName("Zons opkomst: " + sunRise); + setCustom("Zons ondergang: " + sunSet); } //Getters and setters @@ -32,19 +31,12 @@ public class Sun extends Grootheid{ this.sunRise = sunRise; } + public void displayGraph() + { + } + public void updateRecent(Measurement measurement1){ setSunSet(measurement1.getSunset()); setSunRise(measurement1.getSunrise()); } - - public void updatePeriod(ArrayList measurement2){ - } - - public void display(){ - GUIboard.clearLeft(); - GUIboard.clearRight(); - GUIboard.clearTop(); - GUIboard.writePageToMatrix("Sunset: " + sunSet, "Sunrise: " + sunRise, ""); - } - } diff --git a/UVLevel.java b/UVLevel.java index f4ffb3b..d61d3a8 100644 --- a/UVLevel.java +++ b/UVLevel.java @@ -1,34 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class UVLevel extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public UVLevel(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("UVlevel"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getUVLevel()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("UV Level", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -40,7 +27,11 @@ public class UVLevel extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getUVLevel()); + list.add((double)ms.getRawUVLevel()); } } + + public double calculate(double value){ + return Calculator.uvIndex((short)value); + } } diff --git a/Voorspellingen.java b/Voorspellingen.java index 83a0453..09d0c91 100644 --- a/Voorspellingen.java +++ b/Voorspellingen.java @@ -1,89 +1,91 @@ -import java.util.ArrayList; +package weerstation1; public class Voorspellingen extends Grootheid{ - public ArrayList list; + private double barometer; + //constructor public Voorspellingen(Measurement measurement1){ - updateRecent(measurement1); + setName("Weersvoorspelling:"); + updateRecent(measurement1); } - public void updateRecent(Measurement measurement1){ - setCurrent(measurement1.getBarometer()); + barometer = measurement1.getBarometer(); } public void display() { - if (getCurrent() >= 1033 && getCurrent() <= 1084) + if (barometer >= 1033 && barometer <= 1084) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "mooi weer", ""); - GUIboard.writeUpperDigits(10); + setCustom("Mooi weer"); + setCurrent(10); } else - if (getCurrent() >= 1030 && getCurrent() <= 1033) + if (barometer >= 1030 && barometer <= 1033) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "mooi weer", ""); - GUIboard.writeUpperDigits(10); + setCustom("Mooi weer"); + setCurrent(10); } else - if (getCurrent() >= 1020 && getCurrent() <= 1030) + if (barometer >= 1020 && barometer <= 1030) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "goed weer", ""); - GUIboard.writeUpperDigits(20); + setCustom("Goed weer"); + setCurrent(20); } else - if (getCurrent() >= 1015 && getCurrent() <= 1020) + if (barometer >= 1015 && barometer <= 1020) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "wisselvallig weer", ""); - GUIboard.writeUpperDigits(30); + setCustom("Wisselvallig weer"); + setCurrent(30); } else - if (getCurrent() >= 1010 && getCurrent() <= 1015) + if (barometer >= 1010 && barometer <= 1015) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "wisselvallig weer", ""); - GUIboard.writeUpperDigits(40); + setCustom("Wisselvallig weer"); + setCurrent(40); } else - if (getCurrent() >= 1007 && getCurrent() <= 1010) + if (barometer >= 1007 && barometer <= 1010) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "wisselvallig weer", ""); - GUIboard.writeUpperDigits(50); + setCustom("Wisselvallig weer"); + setCurrent(50); } else - if (getCurrent() >= 1003 && getCurrent() <= 1007) + if (barometer >= 1003 && barometer <= 1007) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "regen of wind", ""); - GUIboard.writeUpperDigits(60); + setCustom("Regen of wind"); + setCurrent(60); } else - if (getCurrent() >= 1000 && getCurrent() <= 1003) + if (barometer >= 1000 && barometer <= 1003) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "regen of wind", ""); - GUIboard.writeUpperDigits(70); + setCustom("Regen of wind"); + setCurrent(70); } else - if (getCurrent() >= 990 && getCurrent() <= 1000) + if (barometer >= 990 && barometer <= 1000) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "regen of wind", ""); - GUIboard.writeUpperDigits(80); + setCustom("Regen of wind"); + setCurrent(80); } else - if (getCurrent() >= 980 && getCurrent() <= 990) + if (barometer >= 980 && barometer <= 990) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "veel regen", ""); - GUIboard.writeUpperDigits(90); + setCustom("Veel regen"); + setCurrent(90); } else - if (getCurrent() >= 970 && getCurrent() <= 980) + if (barometer >= 970 && barometer <= 980) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "storm", ""); - GUIboard.writeUpperDigits(90); + setCustom("Storm"); + setCurrent(90); } else - if (getCurrent() >= 870 && getCurrent() <= 970) + if (barometer >= 870 && barometer <= 970) { - GUIboard.writePageToMatrix("Weersvoorspelling:", "zware storm", ""); - GUIboard.writeUpperDigits(90); + setCustom("Zware storm"); + setCurrent(90); } + super.display(); } } diff --git a/Weerstation.java b/Weerstation.java index b998b93..aa302fd 100644 --- a/Weerstation.java +++ b/Weerstation.java @@ -1,3 +1,4 @@ +package weerstation1; @@ -29,7 +30,7 @@ public class Weerstation { public Weerstation(){ now = Calendar.getInstance(); calPeriod = Calendar.getInstance(); - ArrayList periods = new ArrayList(); + final ArrayList periods = new ArrayList(); GUIboard.init(); startupState = true; @@ -73,7 +74,7 @@ public class Weerstation { System.out.println("2 Years: " + periods.get(6)); //Kies hier welke periode je wil laden, hij veranderd in een keer alles: - int periodeNr = 1; + final int periodeNr = 2; weerstation1 = new WeerstationConnector(); meting1 = weerstation1.getMostRecentMeasurement(); @@ -90,25 +91,30 @@ public class Weerstation { final List lstScreens = new ArrayList(); lstScreens.add(new OutsideTemp(meting1, meting2)); //Buitentemperatuur - lstScreens.add(new WindDirection(meting1, meting2)); //Windrichting - lstScreens.add(new WindChill(meting1, meting2)); //Gevoelstemperatuur lstScreens.add(new OutsideHum(meting1, meting2)); //Luchtv. Buiten - lstScreens.add(new Barometer(meting1, meting2)); //Luchtdruk - lstScreens.add(new AvgWindSpeed(meting1, meting2)); //Gem. Windsnelheid - lstScreens.add(new RainRate(meting1, meting2)); //Regenval lstScreens.add(new InsideTemp(meting1, meting2)); //Binnentemperatuur lstScreens.add(new InsideHum(meting1, meting2)); //Luchtv. Binnen + lstScreens.add(new AvgWindSpeed(meting1, meting2)); //Gem. Windsnelheid + lstScreens.add(new WindDirection(meting1, meting2)); //Windrichting + lstScreens.add(new WindChill(meting1, meting2)); //Gevoelstemperatuur + lstScreens.add(new Barometer(meting1, meting2)); //Luchtdruk + lstScreens.add(new Voorspellingen(meting1)); //Weervoorspelling + lstScreens.add(new RainRate(meting1, meting2)); //Regenval lstScreens.add(new CloudHeight(meting1, meting2)); //Wolkhoogte lstScreens.add(new UVLevel(meting1, meting2)); //UV Level + lstScreens.add(new HeatIndex(meting1, meting2)); //Dauwpunt lstScreens.add(new Zonsterkte(meting1, meting2)); //Zonkracht lstScreens.add(new DewPoint(meting1, meting2)); //Dauwpunt lstScreens.add(new Sun(meting1)); //Sunrise en Sunset - lstScreens.add(new LangsteZomerPeriode(meting1, meting2));//Langste Zomerse Periode - lstScreens.add(new LangsteTempStijgingPeriode(meting1, meting2)); //Langste temperatuurstijging - lstScreens.add(new LangsteRegenPeriode(meting1, meting2)); //Langste Regen Periode - lstScreens.add(new MaximaleRegenPeriode(meting1, meting2)); //Totale regenval in een periode - lstScreens.add(new GraadDagen(meting1, meting2)); //Aantal graaddagen in een periode + lstScreens.add(new LangsteHittegolfPeriode(meting1, meting2)); + lstScreens.add(new LangsteZomerPeriode(meting1, meting2)); //Langste Zomerse Periode + // lstScreens.add(new LangsteTempStijgingPeriode(meting1, meting2)); //Langste temperatuurstijging + lstScreens.add(new LangsteRegenPeriode(meting1, meting2)); //Langste Regen Periode + lstScreens.add(new MaximaleRegenPeriode(meting1, meting2)); //Totale regenval in een periode + lstScreens.add(new GraadDagen(meting1, meting2)); //Aantal graaddagen in een periode + + stopStartupAnimatie(); while(startup) { diff --git a/WeerstationConnector.java b/WeerstationConnector.java index 6bd3df0..44a613c 100644 --- a/WeerstationConnector.java +++ b/WeerstationConnector.java @@ -1,3 +1,4 @@ +package weerstation1; import java.sql.Connection; import java.sql.DriverManager; diff --git a/WindChill.java b/WindChill.java index 166e5af..cd88eae 100644 --- a/WindChill.java +++ b/WindChill.java @@ -1,13 +1,11 @@ - +package weerstation1; import java.util.ArrayList; public class WindChill extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public WindChill(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("WindChill"); + updateRecent(measurement1); updatePeriod(measurement2); } @@ -16,18 +14,8 @@ public class WindChill extends Grootheid{ } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.writePageToMatrix("Gevoelstemp", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -39,7 +27,7 @@ public class WindChill extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getWindChill()); + list.add((double)ms.getWindChill()); } } } diff --git a/WindDirection.java b/WindDirection.java index 3edce7e..887975a 100644 --- a/WindDirection.java +++ b/WindDirection.java @@ -1,43 +1,26 @@ - +package weerstation1; import java.util.ArrayList; public class WindDirection extends Grootheid{ - public ArrayList list; - - //constructor - public WindDirection(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + + public WindDirection(Measurement measurement1, ArrayList measurement2){ + setName("Windrichting"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getRawWindDir()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - setMode(StatisticsCalculator.modus(list)); - } - - public void display(){ - super.display(); - GUIboard.clearLeft(); - GUIboard.clearRight(); - - GUIboard.writePageToMatrix("Windrichting", "Modus: " + getMode(), ""); + maxMin(); + //modus(); } public void displayGraph() { - GUIboard.clearBottom(); - char[] charray = " West East".toCharArray(); - - IO.writeShort(0x40, '\n'); - for(char ch : charray) - { - IO.writeShort(0x40, ch); - } + GUIboard.writePageToMatrix("", "West East", ""); int x,y; int radius = 15; diff --git a/Zonsterkte.java b/Zonsterkte.java index e41ee6b..a711292 100644 --- a/Zonsterkte.java +++ b/Zonsterkte.java @@ -1,36 +1,21 @@ - +package weerstation1; import java.util.ArrayList; public class Zonsterkte extends Grootheid{ - public ArrayList list; - - //constructor + //constructor public Zonsterkte(Measurement measurement1, ArrayList measurement2){ - list = new ArrayList(); - updateRecent(measurement1); + setName("Zonsterkte"); + updateRecent(measurement1); updatePeriod(measurement2); } - public void updateRecent(Measurement measurement1){ setCurrent(measurement1.getSolarRad()); } public void updatePeriod(ArrayList measurement2){ createList(measurement2); - calculateMaxMin(list); - setAvg(StatisticsCalculator.avg(list)); - } - - public void display(){ - super.display(); - GUIboard.clearLeft(); - GUIboard.clearRight(); - GUIboard.writePageToMatrix("Zonsterkte", "Gemiddelde: " + getAvg(), ""); - } - - public void displayGraph() - { - GUIboard.writeGraphToMatrix(list, getMin(), getMax()); + maxMin(); + avg(); } private void createList(ArrayList measurement2) @@ -42,7 +27,7 @@ public class Zonsterkte extends Grootheid{ for(Measurement ms : measurement2) { - list.add(ms.getSolarRad()); + list.add((double)ms.getRawSolarRad()); } } } \ No newline at end of file