Calculator.java 5.7 KB

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