/src/Curba/WeatherBundle/Entity/StationData.php

https://github.com/jordidh/urvangreen-web · PHP · 382 lines · 158 code · 44 blank · 180 comment · 4 complexity · fcca6b55cf5d956550e07aad3e457c4d MD5 · raw file

  1. <?php
  2. namespace Curba\WeatherBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6. * Curba\WeatherBundle\Entity\StationData
  7. *
  8. * @ORM\Table()
  9. * @ORM\Entity
  10. * @ORM\Entity(repositoryClass="Curba\WeatherBundle\Entity\StationDataRepository")
  11. */
  12. class StationData
  13. {
  14. /**
  15. * @var integer $id
  16. *
  17. * @ORM\Column(name="id", type="integer")
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="AUTO")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\ManyToOne(targetEntity="Station")
  24. * @ORM\JoinColumn(name="station_id", referencedColumnName="id")
  25. */
  26. private $station;
  27. /**
  28. * @ORM\Column(type="datetime")
  29. */
  30. private $data_time;
  31. /**
  32. * @ORM\Column(type="decimal", scale=2)
  33. */
  34. private $wind_direction;
  35. /**
  36. * @ORM\Column(type="decimal", scale=2)
  37. */
  38. private $wind_speed;
  39. /**
  40. * @ORM\Column(type="decimal", scale=2)
  41. */
  42. private $wind_gust;
  43. /**
  44. * @ORM\Column(type="decimal", scale=2)
  45. */
  46. private $humidity_in;
  47. /**
  48. * @ORM\Column(type="decimal", scale=2)
  49. */
  50. private $humidity_out;
  51. /**
  52. * @ORM\Column(type="decimal", scale=2)
  53. */
  54. private $temperature_in;
  55. /**
  56. * @ORM\Column(type="decimal", scale=2)
  57. */
  58. private $temperature_out;
  59. /**
  60. * @ORM\Column(type="decimal", scale=2)
  61. */
  62. private $bar;
  63. /**
  64. * @ORM\Column(type="decimal", scale=2)
  65. */
  66. private $rain;
  67. /**
  68. * Get id
  69. *
  70. * @return integer
  71. */
  72. public function getId()
  73. {
  74. return $this->id;
  75. }
  76. /**
  77. * Set data_time
  78. *
  79. * @param datetime $dataTime
  80. */
  81. public function setDataTime($dataTime)
  82. {
  83. $this->data_time = $dataTime;
  84. }
  85. /**
  86. * Get data_time
  87. *
  88. * @return datetime
  89. */
  90. public function getDataTime()
  91. {
  92. return $this->data_time;
  93. }
  94. /**
  95. * Set wind_direction
  96. *
  97. * @param decimal $windDirection
  98. */
  99. public function setWindDirection($windDirection)
  100. {
  101. $this->wind_direction = $windDirection;
  102. }
  103. /**
  104. * Get wind_direction
  105. *
  106. * @return decimal
  107. */
  108. public function getWindDirection()
  109. {
  110. return $this->wind_direction;
  111. }
  112. /**
  113. * Set wind_speed
  114. *
  115. * @param decimal $windSpeed
  116. */
  117. public function setWindSpeed($windSpeed)
  118. {
  119. $this->wind_speed = $windSpeed;
  120. }
  121. /**
  122. * Get wind_speed
  123. *
  124. * @return decimal
  125. */
  126. public function getWindSpeed()
  127. {
  128. return $this->wind_speed;
  129. }
  130. /**
  131. * Set wind_gust
  132. *
  133. * @param decimal $windGust
  134. */
  135. public function setWindGust($windGust)
  136. {
  137. $this->wind_gust = $windGust;
  138. }
  139. /**
  140. * Get wind_gust
  141. *
  142. * @return decimal
  143. */
  144. public function getWindGust()
  145. {
  146. return $this->wind_gust;
  147. }
  148. /**
  149. * Set humidity_in
  150. *
  151. * @param decimal $humidityIn
  152. */
  153. public function setHumidityIn($humidityIn)
  154. {
  155. $this->humidity_in = $humidityIn;
  156. }
  157. /**
  158. * Get humidity_in
  159. *
  160. * @return decimal
  161. */
  162. public function getHumidityIn()
  163. {
  164. return $this->humidity_in;
  165. }
  166. /**
  167. * Set humidity_out
  168. *
  169. * @param decimal $humidityOut
  170. */
  171. public function setHumidityOut($humidityOut)
  172. {
  173. $this->humidity_out = $humidityOut;
  174. }
  175. /**
  176. * Get humidity_out
  177. *
  178. * @return decimal
  179. */
  180. public function getHumidityOut()
  181. {
  182. return $this->humidity_out;
  183. }
  184. /**
  185. * Set temperature_in
  186. *
  187. * @param decimal $temperatureIn
  188. */
  189. public function setTemperatureIn($temperatureIn)
  190. {
  191. $this->temperature_in = $temperatureIn;
  192. }
  193. /**
  194. * Get temperature_in
  195. *
  196. * @return decimal
  197. */
  198. public function getTemperatureIn()
  199. {
  200. return $this->temperature_in;
  201. }
  202. /**
  203. * Set temperature_out
  204. *
  205. * @param decimal $temperatureOut
  206. */
  207. public function setTemperatureOut($temperatureOut)
  208. {
  209. $this->temperature_out = $temperatureOut;
  210. }
  211. /**
  212. * Get temperature_out
  213. *
  214. * @return decimal
  215. */
  216. public function getTemperatureOut()
  217. {
  218. return $this->temperature_out;
  219. }
  220. /**
  221. * Set bar
  222. *
  223. * @param decimal $bar
  224. */
  225. public function setBar($bar)
  226. {
  227. $this->bar = $bar;
  228. }
  229. /**
  230. * Get bar
  231. *
  232. * @return decimal
  233. */
  234. public function getBar()
  235. {
  236. return $this->bar;
  237. }
  238. /**
  239. * Set rain
  240. *
  241. * @param decimal $rain
  242. */
  243. public function setRain($rain)
  244. {
  245. $this->rain = $rain;
  246. }
  247. /**
  248. * Get rain
  249. *
  250. * @return decimal
  251. */
  252. public function getRain()
  253. {
  254. return $this->rain;
  255. }
  256. /**
  257. * Set station
  258. *
  259. * @param Curba\WeatherBundle\Entity\Station $station
  260. */
  261. public function setStation(\Curba\WeatherBundle\Entity\Station $station)
  262. {
  263. $this->station = $station;
  264. }
  265. /**
  266. * Get station
  267. *
  268. * @return Curba\WeatherBundle\Entity\Station
  269. */
  270. public function getStation()
  271. {
  272. return $this->station;
  273. }
  274. public function __toString()
  275. {
  276. return $this->getDataTime()->format('Y-m-d H:i:s');
  277. }
  278. public function LoadFromString($data, $station)
  279. {
  280. // Temp Hi Low Out Dew Wind Wind
  281. //Date Time Out Temp Temp Hum Pt. Speed Dir
  282. //0 1 2 3 4 5 6 7 8
  283. //28/11/10 13:30 13.6 13.6 12.9 34 -2.0 1.6 SW
  284. //
  285. //Wind Hi Hi Wind Heat THW Rain
  286. //Run Speed Dir Chill Index Index Bar Rain Rate
  287. //9 10 11 12 13 14 15 16 17
  288. //0.27 4.8 WSW 13.6 11.9 11.9 1000.0 0.00 0.0
  289. //
  290. //Heat Cool In In In In In In Air Wind Wind ISS Arc.
  291. //D-D D-D Temp Hum Dew Heat EMC Density Samp Tx Recept Int.
  292. //18 19 20 21 22 23 24 25 26 27 28 29
  293. //0.033 0.000 16.2 56 7.4 15.4 10.45 .0744 222 1 97.4 10
  294. //
  295. if (strlen(trim($data)) <= 0) return 0;
  296. $dataValues = explode("\t", $data);
  297. if (is_null($dataValues[0])) return 0;
  298. if (count($dataValues) == 30)
  299. {
  300. $date = explode("/", $dataValues[0]);
  301. $time = explode(":", $dataValues[1]);
  302. //$this->setDataTime(mktime($time[0], $time[1], '0', $date[1], $date[0], '20'.$date[2]));
  303. //$this->setDataTime(date('c', mktime(12,0,0,2,1,2011)));
  304. $this->setDataTime(new \DateTime('20'.$date[2].'-'.$date[1].'-'.$date[0].' '.$dataValues[1].':00'));
  305. $this->setStation($station);
  306. $this->setTemperatureIn($dataValues[20]);
  307. $this->setTemperatureOut($dataValues[2]);
  308. $this->setHumidityIn($dataValues[21]);
  309. $this->setHumidityOut($dataValues[5]);
  310. $this->setRain($dataValues[16]);
  311. $this->setBar($dataValues[15]);
  312. switch($dataValues[8])
  313. {
  314. case 'N': $this->setWindDirection(0); break;
  315. case 'NNE': $this->setWindDirection(23); break;
  316. case 'NE': $this->setWindDirection(45); break;
  317. case 'ENE': $this->setWindDirection(67); break;
  318. case 'E': $this->setWindDirection(90); break;
  319. case 'ESE': $this->setWindDirection(113); break;
  320. case 'SE': $this->setWindDirection(135); break;
  321. case 'SSE': $this->setWindDirection(157); break;
  322. case 'S': $this->setWindDirection(180); break;
  323. case 'SSW': $this->setWindDirection(203); break;
  324. case 'SW': $this->setWindDirection(225); break;
  325. case 'WSW': $this->setWindDirection(247); break;
  326. case 'W': $this->setWindDirection(270); break;
  327. case 'WNW': $this->setWindDirection(293); break;
  328. case 'NW': $this->setWindDirection(315); break;
  329. case 'NNW': $this->setWindDirection(337); break;
  330. default:
  331. $this->setWindDirection(0);
  332. }
  333. $this->setWindSpeed($dataValues[7]);
  334. $this->setWindGust($dataValues[12]);
  335. }
  336. return count($dataValues);
  337. }
  338. }