Calculator.java 6.4 KB

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