Currently temp basal is calculated by:
var rate = profile_data.current_basal - (2 * insulinReq);
profile_data.current_basal should be substituted by variable - calculation of predicted (30-min) basal.
Calculation of predicted 30-min basal is essential, because temp basal could be applied on top of two different basals.
For example:
1.00 - 2.00 - basal 0,9
2.00 - 3.00 - basal 1,2
When we apply temp basal at 1:59, temp basal will be calculated by adding/substracting insulinReq from "0,9" basal in spite that 30-temp basal mainly acts over the "1,2" basal.