Growing Degree Day

From HiveTool
Revision as of 18:54, 29 April 2018 by Paul (talk | contribs)
Jump to: navigation, search

Calculate Growing Degree Day (GDD) for each hive and add to database.

SET @gdd_total:=0;
SELECT
  q1.doy,
  q1.gdd,
  round(@gdd_total := @gdd_total + q1.gdd) as gdd_tot
FROM
 (SELECT DAYOFYEAR(DATE_FORMAT(`hive_observation_time_local`, '%Y-%m-%d')) AS doy,
  (least(greatest(max(wx_temp_c),10),30) - least(greatest(min(wx_temp_c),10),30))/2 AS gdd
  from HIVE_DATA 
  where hive_id=10 group by DATE_FORMAT(`hive_observation_time_local`, '%Y-%m-%d') ) AS q1



SELECT hive_id, DAYOFYEAR(DATE_FORMAT(`hive_observation_time_local`, '%Y-%m-%d')) AS doy,
  (least(greatest(max(wx_temp_c),10),30) - least(greatest(min(wx_temp_c),10),30))/2 AS gdd
  from HIVE_DATA group by DATE_FORMAT(`hive_observation_time_local`, '%Y-%m-%d'), hive_id