Added code for StatisticsCalculator, Periode.. etc

Added a lot of code. Currently not functioning for Periode is acting
strange.
Not tested...
This commit is contained in:
Kenneth van Ewijk
2014-10-19 14:38:43 +02:00
parent cbd4ef9077
commit ab4df98479
7 changed files with 363 additions and 84 deletions
+79 -52
View File
@@ -1,23 +1,25 @@
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
public class Calculator {
// Luchtdruk in hPa
// Malek&Tom
public static double luchtdruk(short mval)
// Luchtdruk in hPa
// Malek&Tom
public static double luchtdruk(short mval)
{
double luchtdruk = (mval / 1000f) * 33.86389;
return luchtdruk;
}
// Temperatuur in graden Celcius
// Temperatuur in graden Celcius
// Malek&Tom
public static double temperatuur(short mval)
{
double temperatuur = (((double)mval / 10) -32) / 1.8;
return temperatuur;
}
// Relatieve luchtvochtigheid in %
// Malek&Tom
public static double luchtVochtigheid(short mval)
@@ -27,15 +29,15 @@ public class Calculator {
}
// Windsnelheid in m/s
// Janco&Tim
public static double windSnelheid(short mval)
{
double windSpeed = mval * 0.44704;
return windSpeed;
}
// Windrichting in noord, oost, zuid en west.
// Kenneth&Daniël
// Janco&Tim
public static double windSnelheid(short mval)
{
double windSpeed = mval * 0.44704;
return windSpeed;
}
// Windrichting in noord, oost, zuid en west.
// Kenneth&Daniël
public static String windRichting(short mval)
{
String direction = "Error";
@@ -111,16 +113,16 @@ public class Calculator {
return direction;
}
// Regenmeter in mm
// Kenneth&Daniël
public static double regenmeter(short mval)
{
double rainAmount = (double)mval*0.2;
return rainAmount;
}
{
double rainAmount = (double)mval*0.2;
return rainAmount;
}
// uvIndex in index
// uvIndex in index
// Kenneth&Daniël
public static double uvIndex(short mval)
{
@@ -131,37 +133,37 @@ public class Calculator {
// BatterySpanning in Volt
// Janco&Tim
public static double batterySpanning(short mval){
double voltage = (((double)mval * 300)/512)/100;
return voltage;
}
double voltage = (((double)mval * 300)/512)/100;
return voltage;
}
// sunRise en Sunset in tijdformaat hh:mm
// Janco&Tim
// Janco&Tim
public static String sunRise(short mval){
return sun(mval);
return sun(mval);
}
public static String sunSet(short mval){
return sun(mval);
return sun(mval);
}
private static String sun(short sunRaw){
String tijd = "";
for(int i = 0; i <= 3; i++){
tijd = sunRaw % 10 + tijd;
sunRaw /= 10;
if(i == 1){
tijd = ":" + tijd;
}
}
return tijd;
}
public static double solarRad(short mval){
double zonSterkte = mval;
return zonSterkte;
private static String sun(short sunRaw){
String tijd = "";
for(int i = 0; i <= 3; i++){
tijd = sunRaw % 10 + tijd;
sunRaw /= 10;
if(i == 1){
tijd = ":" + tijd;
}
}
return tijd;
}
public static double solarRad(short mval){
double zonSterkte = mval;
return zonSterkte;
}
//windchill in graden Celcius
//Janco en Keneth
//Janco en Keneth
public static double windChill(short grdnFh, short mph)
{
double gradenFahrenheit = grdnFh;
@@ -172,7 +174,7 @@ public class Calculator {
}
//Heatindex in celcius
//Tom met Malek
//Tom met Malek
public static double heatIndex(double RH, double T)
{
double HI = -42.379 + 2.04901523*T + 10.14333127*RH - .22475541*T*RH - .00683783*T*T - .05481717*RH*RH + .00122874*T*T*RH + .00085282*T*RH*RH - .00000199*T*T*RH*RH;
@@ -188,11 +190,36 @@ public class Calculator {
double dauwpunt = Math.pow( hm, (1/8f)) * (112 + 0.9*omgevingsTemp) + (0.1*omgevingsTemp) - 112;
return dauwpunt;
}
public static double cloudHeight(double temp, short luchtVochtigheid ){
double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
return wolkhoogte;
}
double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
return wolkhoogte;
}
public static Periode timeStampToPeriode(Timestamp timeStamp1, Timestamp timeStamp2)
{
Periode periode = new Periode();
Calendar cal = Calendar.getInstance();
int year,month,day;
//Zet de eerste TimeStamp om
cal.setTime(new Date(timeStamp1.getTime()));
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH+1);
day = cal.get(Calendar.DAY_OF_MONTH);
periode.setBeginPeriode(year,month, day);
//Zet de tweede TimeStamp om
cal.setTime(new Date(timeStamp2.getTime()));
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH+1);
day = cal.get(Calendar.DAY_OF_MONTH);
periode.setEindePeriode(year,month, day);
return periode;
}
}
+48
View File
@@ -0,0 +1,48 @@
import java.util.ArrayList;
public class LangsteZomerPeriode extends Grootheid{
private ArrayList<Double> list;
private Periode zomerPeriode;
//constructor
public LangsteZomerPeriode(Measurement measurement1, ArrayList<Measurement> measurement2, Periode totalePeriode){
list = new ArrayList<Double>();
zomerPeriode = new Periode();
updateRecent(measurement1);
update24Hour(measurement2);
}
public void updateRecent(Measurement measurement1){
setCurrent(measurement1.getOutsideTemp());
}
public void update24Hour(ArrayList<Measurement> measurement2){
createList(measurement2);
calculateMaxMinAvg(list);
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(), "");
}
public void displayGraph()
{
display();
}
private void createList(ArrayList<Measurement> measurement2)
{
if(!list.isEmpty())
{
list.clear();
}
for(Measurement ms : measurement2)
{
list.add(ms.getOutsideTemp());
}
}
}
+43
View File
@@ -0,0 +1,43 @@
import java.util.ArrayList;
public class MaximaleRegenPeriode extends Grootheid{
private ArrayList<Double> list;
//constructor
public MaximaleRegenPeriode(Measurement measurement1, ArrayList<Measurement> measurement2){
list = new ArrayList<Double>();
updateRecent(measurement1);
update24Hour(measurement2);
}
public void updateRecent(Measurement measurement1){
setCurrent(measurement1.getRainRate());
}
public void update24Hour(ArrayList<Measurement> measurement2){
createList(measurement2);
calculateMaxMinAvg(list);
}
public void display(){
GUIboard.writePageToMatrix("Periode met meeste regen", StatisticsCalculator.maximaleRegenPeriode(list) + "", "");
}
public void displayGraph()
{
display();
}
private void createList(ArrayList<Measurement> measurement2)
{
if(!list.isEmpty())
{
list.clear();
}
for(Measurement ms : measurement2)
{
list.add(ms.getRainRate());
}
}
}
+4 -4
View File
@@ -1,12 +1,12 @@
import java.sql.Timestamp;
import java.math.BigDecimal;
public class Measurement
{
private String stationId;
private java.sql.Timestamp dateStamp;
private Timestamp dateStamp;
private short barometer;
private short insideTemp;
private short insideHum;
@@ -32,8 +32,8 @@ public class Measurement
public String getStationId () { return stationId; };
// dateStamp
public void setDateStamp (java.sql.Timestamp ts) { this.dateStamp = ts;};
public java.sql.Timestamp getDateStamp () { return dateStamp; };
public void setDateStamp (Timestamp ts) { this.dateStamp = ts;};
public Timestamp getDateStamp () { return dateStamp; };
// barometer
public void setRawBarometer (short val) { this.barometer = val;};
+52 -7
View File
@@ -1,20 +1,34 @@
import java.util.GregorianCalendar;
import java.util.Calendar;
public class Periode
{
public GregorianCalendar beginPeriode;
public GregorianCalendar eindePeriode;
private GregorianCalendar beginPeriode;
private GregorianCalendar eindePeriode;
public Periode()
{
beginPeriode = new GregorianCalendar();
eindePeriode = new GregorianCalendar();
}
public Periode(int jaar, int maand, int dag, int eindjaar, int eindmaand, int einddag)
{
beginPeriode = new GregorianCalendar();
eindePeriode = new GregorianCalendar();
beginPeriode.set(jaar, maand, dag,0,0,0);
eindePeriode.set(eindjaar, eindmaand, einddag,23,59,59);
beginPeriode = new GregorianCalendar(jaar, maand, dag);
eindePeriode = new GregorianCalendar(eindjaar, eindmaand, einddag);
/*
if(eindjaar > jaar && eindmaand > maand && einddag > dag)
{
beginPeriode.set(eindjaar, eindmaand, einddag);
eindePeriode.set(jaar, maand, dag);
}
else
{
beginPeriode.set(jaar, maand, dag);
eindePeriode.set(eindjaar, eindmaand, einddag);
}
*/
}
public GregorianCalendar getBeginPeriode()
@@ -26,4 +40,35 @@ public class Periode
{
return eindePeriode;
}
}
public void setBeginPeriode(int jaar, int maand, int dag)
{
beginPeriode.set(jaar, maand, dag);
}
public void setEindePeriode(int jaar, int maand, int dag)
{
eindePeriode.set(jaar, maand, dag);
}
public String toString()
{
Calendar cal = getBeginPeriode().getInstance();
Calendar cal2 = getEindePeriode().getInstance();
String returnString = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)+1) + "-" + cal.get(Calendar.DATE);
returnString += " | ";
returnString += cal2.get(Calendar.YEAR) + "-" + (cal2.get(Calendar.MONTH)+1) + "-" + cal2.get(Calendar.DATE);
return returnString;
}
}
+128 -18
View File
@@ -1,6 +1,5 @@
package weerstation1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Collections;
public class StatisticsCalculator {
@@ -41,7 +40,7 @@ public class StatisticsCalculator {
return avg;
}
public static double median(ArrayList<Double> array){
public static double median(ArrayList<Double> array){
Collections.sort(array); //sort the array
double median = 0;
@@ -86,36 +85,147 @@ public class StatisticsCalculator {
}
public static Periode langsteDroogstePeriode(ArrayList<Double> array)
public static double graagDagen(ArrayList<Double> array)
{
Periode periode = new Periode();
int graaddagen = 0;
//Code
return periode;
return graaddagen;
}
public static Periode langsteDroogstePeriodeMetMax(ArrayList<Double> array, int maxNeerslag)
public static int[] langsteDroogstePeriode(ArrayList<Double> array)
{
Periode periode = new Periode();
return periode;
return langsteDroogstePeriodeMetMax(array, 0);
}
public static Periode langsteRegenPeriode(ArrayList<Double> array)
public static int[] langsteDroogstePeriodeMetMax(ArrayList<Double> array, int maxNeerslag)
{
Periode periode = new Periode();
int[] index = new int[2];
int index1 = 0;
int index2 = 0;
//Code
return periode;
index[0] = index1;
index[1] = index2;
return index;
}
public static double meesteRegenAchterElkaar(ArrayList<Double> array)
public static int[] langsteRegenPeriode(ArrayList<Double> array)
{
double regenHoeveelheid = 0;
int[] index = new int[2];
int index1 = 0;
int index2 = 0;
//Code
return regenHoeveelheid;
index[0] = index1;
index[1] = index2;
return index;
}
public static double maximaleRegenPeriode(ArrayList<Double> array)
{
double totaleRegen = 0;
for(double db : array)
{
totaleRegen += db;
}
return totaleRegen;
}
public static int[] langsteZomersePeriode(ArrayList<Double> array)
{
ArrayList<Double> maxTempDag = new ArrayList<Double>();
int i = 0;
double maxTemp = 0;
//Bereken de maximale temperatuur per dag.
for(double db : array)
{
i++;
if(i%1440==0)
{
maxTempDag.add(maxTemp);
maxTemp = 0;
}
if(db > maxTemp)
{
maxTemp = db;
}
}
//Creer een array met twee indexen
int[] index = new int[2];
int index1 = 0;
int index2 = 0;
//Een tijdelijke index om bij te houden wat de index was in het geval dat de vorige groter was.
int index1_1 = 0;
//Een boolean
boolean zomers = false;
int p = 0;
int maxDays = 0;
//Doorloop je maximale temperaturen en zoek de langste periode
for(int t=0; t<maxTempDag.size(); t++) {
if(maxTempDag.get(t) > 25) {
p++;
if(!zomers)
{
zomers = true;
index1_1 = t;
}
}
else {
if(p > maxDays) {
maxDays = p;
index1 = index1_1;
index2 = t-1;
zomers=false;
}
p=0;
}
}
//Het terugsturen van de gevonden indexen. Je doet ze keer 1440 omdat je bij het berekenen van
//de temperatuur per dag je het in stukken van 1440 samenvoegde.
index[0] = index1*1440;
index[1] = index2*1440;
return index;
}
public static int[] langsteHitteGolfPeriode(ArrayList<Double> array)
{
int[] index = new int[2];
int index1 = 0;
int index2 = 0;
//Code
index[0] = index1;
index[1] = index2;
return index;
}
public static int[] langsteTempStijgingPeriode(ArrayList<Double> array)
{
int[] index = new int[2];
int index1 = 0;
int index2 = 0;
//Code
index[0] = index1;
index[1] = index2;
return index;
}
}
+9 -3
View File
@@ -1,5 +1,5 @@
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@@ -8,9 +8,11 @@ import java.util.Calendar;
public class Weerstation {
WeerstationConnector weerstation1;
Calendar now;
Measurement meting1;
Periode periodeDag;
Measurement meting1;
ArrayList<Measurement> meting2;
Timer starter;
int currentScreen;
@@ -22,7 +24,8 @@ public class Weerstation {
weerstation1 = new WeerstationConnector();
now = Calendar.getInstance();
periodeDag = new Periode(Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH,Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH);
periodeDag = new Periode(2013,12,25,2014,1,5);
System.out.println(periodeDag);
GUIboard.init();
starter = new Timer();
@@ -30,6 +33,7 @@ public class Weerstation {
meting1 = weerstation1.getMostRecentMeasurement();
meting2 = weerstation1.getAllMeasurementsBetween(periodeDag.getBeginPeriode(), periodeDag.getEindePeriode());
System.out.println(meting2.size());
stopAnimatie();
while(startup)
@@ -53,6 +57,8 @@ public class Weerstation {
//All the different screen classes
final List<Grootheid> lstScreens = new ArrayList<Grootheid>();
lstScreens.add(new LangsteZomerPeriode(meting1, meting2, periodeDag));
lstScreens.add(new MaximaleRegenPeriode(meting1, meting2));
lstScreens.add(new WindDirection(meting1, meting2));
lstScreens.add(new OutsideTemp(meting1, meting2));
lstScreens.add(new WindChill(meting1, meting2));