Skip to content

Commit

Permalink
Merge pull request #136 from MastodonC/fix/errors-in-headers
Browse files Browse the repository at this point in the history
Error field now correctly reset in forecast headers
  • Loading branch information
acron0 committed Jan 15, 2016
2 parents 6db2f3b + 2bc7d01 commit 76d16b9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/witan/app/forecast.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
(hayt/set-columns {:current_version_id version-id
:version version
:in_progress in-progress?
:created (tf/unparse (tf/formatters :date-time) (t/now))})
:created (tf/unparse (tf/formatters :date-time) (t/now))
:error nil})
(hayt/where {:forecast_id forecast-id})))

(defn update-forecast-outputs
Expand Down Expand Up @@ -322,7 +323,7 @@
[{:keys [forecast-id version version-id]} error]
(let [error (or error "No error message was provided.")]
(c/exec (update-forecast-error {:forecast-id forecast-id :version version :error error}))
(when (or (<= version 1) (= (-> forecast-id (get-most-recent-version) :version-id) version-id))
(when (or (<= version 1) (= (-> forecast-id (get-most-recent-version) :version_id) version-id))
(c/exec (update-forecast-header-error {:forecast-id forecast-id :version version :error error})))))


Expand Down Expand Up @@ -354,7 +355,7 @@
uuid-model-id (util/to-uuid model-id)
checked-property-values (check-property-values uuid-model-id model-properties)]
(if (-> checked-property-values :errors empty?)
(let [ owner-name (-> owner u/retrieve-user :name)
(let [owner-name (-> owner u/retrieve-user :name)
new-forecast (assoc forecast :forecast-id id
:version-id version-id
:model-id uuid-model-id
Expand Down Expand Up @@ -399,17 +400,18 @@
new-version (inc old-version)
new-version-id (uuid/random)
owner-name (-> owner u/retrieve-user :name) ;; TODO should check for nil
new-forecast (assoc latest-forecast
:version new-version
:version-id new-version-id
:owner owner
:owner-name owner-name
:in-progress? true
:public? (:public latest-forecast)
:forecast-id forecast-id
:model-id (:model_id latest-forecast)
:model-property-values (into {} (for [[k v] (:model_property_values latest-forecast)] [k (hayt/user-type v)]))
:inputs (into {} (for [[k v] inputs] [(name k) (hayt/user-type v)])))]
new-forecast (-> latest-forecast
(dissoc :error)
(assoc :version new-version
:version-id new-version-id
:owner owner
:owner-name owner-name
:in-progress? true
:public? (:public latest-forecast)
:forecast-id forecast-id
:model-id (:model_id latest-forecast)
:model-property-values (into {} (for [[k v] (:model_property_values latest-forecast)] [k (hayt/user-type v)]))
:inputs (into {} (for [[k v] inputs] [(name k) (hayt/user-type v)]))))]
(create-new-forecast-version! new-forecast old-version)
(run-model! (assoc new-forecast :inputs inputs) model) ;; assoc to use the original inputs (not UDT'd)
(get-forecast-version forecast-id new-version))
Expand Down

0 comments on commit 76d16b9

Please sign in to comment.