(with-let [_ (dispatch [::events/api-fetch :from-date #inst…
- User
(with-let [_ (dispatch [::events/api-fetch :from-date #inst "2020-01-02T00:00:00.000-00:00" :to-date #inst "2024-04-05T00:00:00.000-00:00"]) dashboard (subscribe [::events/dashboard]) jobs (subscribe [::events/jobs])] (def foo @jobs))
I'm trying to make the following code return the api call below with the dates included:
(rf/reg-event-fx ::api-fetch (fn [{:keys [db]} _] (let [{:keys [from-date to-date tags]} (:dashboard db)] {:call-api {:operation [:job :fetch-dashboard-info] :params {:pre-filter :open :filter { :from-date from-date :to-date to-date :quote-sent? :off :has-approved-invoice? :off :approved-for-purchasing? :off :locations `() :has-purchase-order? :off :show-dnc? true :show-fp? true :show-pos? true} :page-idx 0 :page-size 20 :sort-config {:sort-key :update-ts, :direction "DESC"} :search-query nil} :success-args [::fetch-feedback-success]}})))
So it would look like the following:
{:pre-filter :open, :filter {:from-date "2020-01-02", :to-date "2024-04-05", ...}
- Assistant
- User
Here is some job data:
[{:wip-journaled nil, :wip-expensed nil, :job-id "58b04b8b-e481-459d-88a6-96525edd3262", :uses-wip false, :total-draft-invoice-amount 0, :completed false, :total-approved-invoice-amount 0, :customer "City Limousines", :actual-cost {:profession-cost 8684, :inventory-cost 1496, :asset-cost 1875}, :reference "J00001", :update-ts #inst "2024-03-25T01:23:40.178-00:00", :quote {:approved? false, :job-id "58b04b8b-e481-459d-88a6-96525edd3262", :org-id "fc3433bb-c881-493c-89b2-dc36e7a5f6cc", :currency-code "AUD", :reference "1 - J00001 - Quote 1", :total 58300, :id "597a798d-8f16-49ba-87df-a1f9a1b605bc", :create-ts #inst "2024-03-25T00:41:32.285-00:00", :sent? false}, :create-ts #inst "2024-03-25T01:23:40.178-00:00", :estimated-cost 27251, :latest-invoice-ts nil} {:wip-journaled nil, :wip-expensed nil, :job-id "3e6e6c76-7dfd-48eb-afdc-6f496906a929", :uses-wip false, :total-draft-invoice-amount 0, :completed false, :total-approved-invoice-amount 33000, :customer "Bayside Club", :actual-cost {:profession-cost 0, :inventory-cost 8000, :asset-cost 2500}, :reference "J00002", :update-ts #inst "2024-04-05T03:08:56.065-00:00", :quote {:approved? false, :job-id "3e6e6c76-7dfd-48eb-afdc-6f496906a929", :org-id "fc3433bb-c881-493c-89b2-dc36e7a5f6cc", :currency-code "AUD", :reference "3 - J00002", :total 59520, :id "335193f9-b433-4231-ba5e-833d0614c391", :create-ts #inst "2024-04-05T00:55:44.673-00:00", :sent? false}, :create-ts #inst "2024-04-03T23:05:44.656-00:00", :estimated-cost 28380, :latest-invoice-ts #inst "2024-04-05T00:59:53.357-00:00"} {:wip-journaled nil, :wip-expensed nil, :job-id "a743e4c6-23a6-4c6f-b827-c972bd9df5c2", :uses-wip false, :total-draft-invoice-amount 70548, :completed false, :total-approved-invoice-amount 0, :customer "Abby & Wells", :actual-cost {:profession-cost 0, :inventory-cost 8000, :asset-cost 0}, :reference "J00006", :update-ts #inst "2024-04-05T03:15:25.939-00:00", :quote nil, :create-ts #inst "2024-04-05T03:15:07.994-00:00", :estimated-cost 22800, :latest-invoice-ts #inst "2024-04-05T03:18:30.983-00:00"}]
- Assistant
- User
Here's some more context:
I'm retrieving this data from the backend.
Here is the code I am working with:
(def month-labels ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"])
(defn get-current-month-index "Gets the current month (0-based index) using cljs-time" [] (time/month (time/now)))
(defn rotate-vector [v n] (let [split-index (mod n (count v))] (concat (subvec v split-index (count v)) (subvec v 0 split-index))))
(defn get-month-labels-relative [] (vec (rotate-vector month-labels (get-current-month-index))))
(defn get-month [timestamp] (comp time/month coerce/to-date-time timestamp))
(defn job-month-numbers [job-list] (map (get-month :update-ts) job-list))
(defn jobs-per-month [job-list] (frequencies (job-month-numbers job-list)))
(defn to-apex-bar-chart-quantities [job-list] (let [job-frequencies (jobs-per-month job-list) job-quantity [0 0 0 0 0 0 0 0 0 0 0 0]] (rotate-vector (reduce (fn [job-quantity [month quantity]] (assoc job-quantity (dec month) quantity)) job-quantity job-frequencies) (get-current-month-index))))
- Assistant
- User
(map :wip-journaled (:jobs foo)) gives me this:
cljs꞉dashboard.events꞉> (nil nil ({:id "48eed22b-e5fe-4a93-bd9a-f948663c76bd", :job-id "1130baf8-4e2f-4dbe-b1b1-e5f31b9e68e3", :amount 748, :account :wip, :sku nil, :create-ts #inst "2024-04-05T06:22:38.516-00:00"} {:id "8a865c7c-7eee-434f-bfa9-c66a4e9df722", :job-id "1130baf8-4e2f-4dbe-b1b1-e5f31b9e68e3", :amount -748, :account :wip, :sku nil, :create-ts #inst "2024-04-05T06:24:22.307-00:00"} {:id "3db0d18f-127d-4150-8ed9-f2e34577842f", :job-id "1130baf8-4e2f-4dbe-b1b1-e5f31b9e68e3", :amount 2500, :account :wip, :sku nil, :create-ts #inst "2024-04-07T22:47:33.282-00:00"}) nil nil)
I want to do the following: For each non-nil result, get the month of the transaction and get the sum of the :amount field for every timestamp with a matching month. Which job it is doesn't matter, only the timestamps.
- Assistant