Calculator.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. package weerstation1;
  2. import java.sql.Timestamp;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. public class Calculator {
  6. // Luchtdruk in hPa
  7. // Malek&Tom
  8. public static double luchtdruk(short mval)
  9. {
  10. double luchtdruk = (mval / 1000f) * 33.86389;
  11. return luchtdruk;
  12. }
  13. // Temperatuur in graden Celcius
  14. // Malek&Tom
  15. public static double temperatuur(short mval)
  16. {
  17. double temperatuur = (((double)mval / 10) -32) / 1.8;
  18. return temperatuur;
  19. }
  20. // Relatieve luchtvochtigheid in %
  21. // Malek&Tom
  22. public static double luchtVochtigheid(short mval)
  23. {
  24. double luchtvochtigheid = mval;
  25. return luchtvochtigheid;
  26. }
  27. // Windsnelheid in m/s
  28. // Janco&Tim
  29. public static double windSnelheid(short mval)
  30. {
  31. double windSpeed = mval * 0.44704;
  32. return windSpeed;
  33. }
  34. // Windrichting in noord, oost, zuid en west.
  35. // Kenneth&Daniël
  36. public static String windRichting(short mval)
  37. {
  38. String direction = "Error";
  39. if(mval < 12)
  40. {
  41. direction = "N";
  42. }
  43. else if(mval < 34)
  44. {
  45. direction = "NNO";
  46. }
  47. else if(mval < 57)
  48. {
  49. direction = "NO";
  50. }
  51. else if(mval < 79)
  52. {
  53. direction = "ONO";
  54. }
  55. else if(mval < 102)
  56. {
  57. direction = "O";
  58. }
  59. else if(mval < 124)
  60. {
  61. direction = "OZO";
  62. }
  63. else if(mval < 147)
  64. {
  65. direction = "ZO";
  66. }
  67. else if(mval < 169)
  68. {
  69. direction = "ZZO";
  70. }
  71. else if(mval < 192)
  72. {
  73. direction = "Z";
  74. }
  75. else if(mval < 214)
  76. {
  77. direction = "ZZW";
  78. }
  79. else if(mval < 237)
  80. {
  81. direction = "ZW";
  82. }
  83. else if(mval < 259)
  84. {
  85. direction = "WZW";
  86. }
  87. else if(mval < 282)
  88. {
  89. direction = "W";
  90. }
  91. else if(mval < 304)
  92. {
  93. direction = "WNW";
  94. }
  95. else if(mval < 327)
  96. {
  97. direction = "NW";
  98. }
  99. else if(mval < 349)
  100. {
  101. direction = "NNW";
  102. }
  103. else if(mval < 360)
  104. {
  105. direction = "N";
  106. }
  107. return direction;
  108. }
  109. // Regenmeter in mm
  110. // Kenneth&Daniël
  111. public static double regenmeter(short mval)
  112. {
  113. double rainAmount = (double)mval*0.2;
  114. return rainAmount;
  115. }
  116. // uvIndex in index
  117. // Kenneth&Daniël
  118. public static double uvIndex(short mval)
  119. {
  120. double index = (double) mval/10;
  121. return index;
  122. }
  123. // BatterySpanning in Volt
  124. // Janco&Tim
  125. public static double batterySpanning(short mval){
  126. double voltage = (((double)mval * 300)/512)/100;
  127. return voltage;
  128. }
  129. // sunRise en Sunset in tijdformaat hh:mm
  130. // Janco&Tim
  131. public static String sunRise(short mval){
  132. return sun(mval);
  133. }
  134. public static String sunSet(short mval){
  135. return sun(mval);
  136. }
  137. private static String sun(short sunRaw){
  138. String tijd = "";
  139. for(int i = 0; i <= 3; i++){
  140. tijd = sunRaw % 10 + tijd;
  141. sunRaw /= 10;
  142. if(i == 1){
  143. tijd = ":" + tijd;
  144. }
  145. }
  146. return tijd;
  147. }
  148. public static double solarRad(short mval){
  149. double zonSterkte = mval;
  150. return zonSterkte;
  151. }
  152. //windchill in graden Celcius
  153. //Janco en Keneth
  154. public static double windChill(short grdnFh, short mph)
  155. {
  156. double gradenFahrenheit = grdnFh;
  157. double mijlPerUur = mph;
  158. double windChill2 = (35.74 + (0.6215*gradenFahrenheit) - 35.75*Math.pow(mijlPerUur, 0.16) + 0.4275*gradenFahrenheit*Math.pow(mijlPerUur, 0.16));
  159. short windChill = (short) windChill2;
  160. return temperatuur(windChill);
  161. }
  162. //Heatindex in celcius
  163. //Tom met Malek
  164. public static double heatIndex(double RH, double T)
  165. {
  166. 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;
  167. double heatindex = Calculator.temperatuur( (short) (HI*10) );
  168. return heatindex;
  169. }
  170. //Dauwpunt in Celcius
  171. //Daniel en Tim
  172. public static double dewPoint(double omgevingsTemp, short luchtVochtigheid)
  173. {
  174. double hm = luchtVochtigheid/100f;
  175. double dauwpunt = Math.pow( hm, (1/8f)) * (112 + 0.9*omgevingsTemp) + (0.1*omgevingsTemp) - 112;
  176. return dauwpunt;
  177. }
  178. public static double cloudHeight(double temp, short luchtVochtigheid ){
  179. double wolkhoogte = 125 * (temp-dewPoint(temp, luchtVochtigheid));
  180. return wolkhoogte;
  181. }
  182. public static Periode timeStampToPeriode(Timestamp timeStamp1, Timestamp timeStamp2)
  183. {
  184. Periode periode = new Periode("-");
  185. int year,month,day;
  186. String[] ts1 = timeStamp1.toString().split(" ");
  187. ts1 = ts1[0].split("-");
  188. periode.setBeginPeriode(Integer.valueOf(ts1[0]), Integer.valueOf(ts1[1]), Integer.valueOf(ts1[2]));
  189. String[] ts2 = timeStamp2.toString().split(" ");
  190. ts2 = ts2[0].split("-");
  191. periode.setEindePeriode(Integer.valueOf(ts2[0]), Integer.valueOf(ts2[1]), Integer.valueOf(ts2[2]));
  192. return periode;
  193. }
  194. }