HK data calculation

HK data calculation. Due to data quality issue its disabled by default.

Write data only when needed. Extremely improve performance of history
data calculation.