                                       convert)
         page-size                10]
     (when calculated
-      (let [{:keys [min-date max-date]} (measurements/insert-measurements store
-                                                                          {:device_id device_id :type new-type}
+      (let [calculated-sensor {:device_id device_id :type new-type}
+            {:keys [min-date max-date]} (measurements/insert-measurements store
+                                                                          calculated-sensor
                                                                           page-size calculated)]
         (db/with-session [session (:hecuba-session store)]
-          (sensors/update-sensor-metadata session sensor min-date max-date))))))
+          (sensors/update-sensor-metadata session calculated-sensor (:start-date range) (:end-date range)))))))
 
 (defn gas-volume->kWh
   "Converts measurements from m^3 and ft^3 to kWh."

                 sensor                        {:device_id device_id :type new-type}
                 calculated                    (compute-datasets-using-field operation device_id new-type measurements field-value)
                 {:keys [start-date end-date]} range
                 page-size                     10
                 {:keys [min-date max-date]}   (measurements/insert-measurements store sensor page-size calculated)]

             (db/with-session [session (:hecuba-session store)]
               (sensors/update-sensor-metadata session sensor min-date max-date))
             (log/info "Finished calculation for operands: " operands "and operation: " operation))
           (log/info "There are not enough data to calculate.")))))
  ([store ds sensors range]

                                      convert)
        page-size                10]
    (when calculated
      (let [calculated-sensor {:device_id device_id :type new-type}]
        (measurements/insert-measurements store calculated-sensor page-size calculated)
        (db/with-session [session (:hecuba-session store)]
          (sensors/update-sensor-metadata session calculated-sensor (:start-date range) (:end-date range)))))))

;;;;;;;;;;; Rollups of measurements ;;;;;;;;;

