Builds client SSR approach, sunsets old cljs.
This commit is contained in:
344
src/clj/user.clj
344
src/clj/user.clj
@@ -1,10 +1,13 @@
|
||||
(ns user
|
||||
(ns user
|
||||
(:require
|
||||
[amazonica.aws.s3 :as s3]
|
||||
[clojure.tools.namespace.repl :refer [set-refresh-dirs refresh]]
|
||||
[auto-ap.datomic :refer [conn pull-attr random-tempid]]
|
||||
[auto-ap.ledger :as l ]
|
||||
[auto-ap.ledger :as l]
|
||||
[clj-http.core :as http]
|
||||
[clj-http.client :as client]
|
||||
[figwheel.main.api]
|
||||
[hawk.core]
|
||||
[auto-ap.server]
|
||||
[auto-ap.time :as atime]
|
||||
[auto-ap.utils :refer [by]]
|
||||
@@ -29,6 +32,7 @@
|
||||
(:import
|
||||
(org.apache.commons.io.input BOMInputStream)))
|
||||
|
||||
|
||||
(defn println-event [item]
|
||||
(printf "%s: %s - %s:%s by %s\n"
|
||||
(str (c/to-date-time (:mulog/timestamp item)))
|
||||
@@ -36,23 +40,22 @@
|
||||
(if (:mulog/duration item)
|
||||
(str " " (int (/ (:mulog/duration item) 1000000)) "ms")
|
||||
"")
|
||||
(:user-name item)
|
||||
)
|
||||
(:user-name item))
|
||||
(println (reduce
|
||||
(fn [acc [k v]]
|
||||
(assoc acc k v))
|
||||
{}
|
||||
(dissoc
|
||||
item
|
||||
:user)))
|
||||
#_(puget/cprint (reduce
|
||||
(fn [acc [k v]]
|
||||
(assoc acc k v))
|
||||
{}
|
||||
(dissoc
|
||||
item
|
||||
:user))
|
||||
{:seq-limit 10})
|
||||
(dissoc
|
||||
item
|
||||
:user)))
|
||||
#_(puget/cprint (reduce
|
||||
(fn [acc [k v]]
|
||||
(assoc acc k v))
|
||||
{}
|
||||
(dissoc
|
||||
item
|
||||
:user))
|
||||
{:seq-limit 10})
|
||||
(println))
|
||||
|
||||
|
||||
@@ -70,8 +73,7 @@
|
||||
(publish [_ buffer]
|
||||
;; items are pairs [offset <item>]
|
||||
(doseq [item (transform (map second (rb/items buffer)))]
|
||||
(println-event item)
|
||||
)
|
||||
(println-event item))
|
||||
(flush)
|
||||
(rb/clear buffer)))
|
||||
|
||||
@@ -91,23 +93,23 @@
|
||||
(defn load-accounts [conn]
|
||||
(let [[header & rows] (-> "master-account-list.csv" (io/resource) io/input-stream (BOMInputStream.) (io/reader) csv/read-csv)
|
||||
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
|
||||
:db/id])]
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
:where ['[?e :account/name]]}
|
||||
(dc/db conn))))
|
||||
(dc/db conn))))
|
||||
|
||||
also-merge-txes (fn [also-merge old-account-id]
|
||||
(if old-account-id
|
||||
(if old-account-id
|
||||
(let [[sunset-account]
|
||||
(first (dc/q {:find ['?a ]
|
||||
:in ['$ '?ac ]
|
||||
(first (dc/q {:find ['?a]
|
||||
:in ['$ '?ac]
|
||||
:where ['[?a :account/numeric-code ?ac]]}
|
||||
(dc/db conn) also-merge))]
|
||||
(into (mapv
|
||||
(fn [[entity id _]]
|
||||
[:db/add entity id old-account-id])
|
||||
(dc/q {:find ['?e '?id '?a ]
|
||||
:in ['$ '?ac ]
|
||||
(dc/q {:find ['?e '?id '?a]
|
||||
:in ['$ '?ac]
|
||||
:where ['[?a :account/numeric-code ?ac]
|
||||
'[?e ?at ?a]
|
||||
'[?at :db/ident ?id]]}
|
||||
@@ -122,7 +124,7 @@
|
||||
(into {} (map vector header r))))
|
||||
(map (fn parse-map [r]
|
||||
{:old-account-id (:db/id (code->existing-account
|
||||
(or
|
||||
(or
|
||||
(if (= (get r "IOL Account #")
|
||||
"NEW")
|
||||
nil
|
||||
@@ -157,8 +159,7 @@
|
||||
(if also-merge
|
||||
(into tx
|
||||
(also-merge-txes also-merge old-account-id))
|
||||
tx)
|
||||
))))
|
||||
tx)))))
|
||||
|
||||
|
||||
conj
|
||||
@@ -168,7 +169,7 @@
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-bad-accounts []
|
||||
(set (map second (dc/q {:find ['(pull ?x [*]) '?z]
|
||||
(set (map second (dc/q {:find ['(pull ?x [*]) '?z]
|
||||
:in ['$]
|
||||
:where ['[?e :account/numeric-code ?z]
|
||||
'[(<= ?z 9999)]
|
||||
@@ -177,32 +178,31 @@
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn delete-4-digit-accounts []
|
||||
@(dc/transact conn
|
||||
(transduce
|
||||
@(dc/transact conn
|
||||
(transduce
|
||||
(comp
|
||||
(map first)
|
||||
(map (fn [old-account-id]
|
||||
[:db/retractEntity old-account-id])))
|
||||
(map first)
|
||||
(map (fn [old-account-id]
|
||||
[:db/retractEntity old-account-id])))
|
||||
conj
|
||||
[]
|
||||
(dc/q {:find ['?e]
|
||||
(dc/q {:find ['?e]
|
||||
:in ['$]
|
||||
:where ['[?e :account/numeric-code ?z]
|
||||
'[(<= ?z 9999)]]}
|
||||
(dc/db conn))))
|
||||
)
|
||||
(dc/db conn)))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-conflicting-accounts []
|
||||
(filter
|
||||
(filter
|
||||
(fn [[_ v]]
|
||||
(> (count v) 1))
|
||||
(reduce
|
||||
(reduce
|
||||
(fn [acc [e z]]
|
||||
(update acc z conj e))
|
||||
{}
|
||||
(dc/q {:find ['?e '?z]
|
||||
(dc/q {:find ['?e '?z]
|
||||
:in ['$]
|
||||
:where ['[?e :account/numeric-code ?z]]}
|
||||
(dc/db conn)))))
|
||||
@@ -214,31 +214,29 @@
|
||||
:in ['$ '?z]
|
||||
:where [['?e :client/code '?z]]}
|
||||
(dc/db conn) customer)))
|
||||
_ (println client-id)
|
||||
code->existing-account (by :account/numeric-code (map first (dc/q {:find ['(pull ?e [:account/numeric-code
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id])]
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
:where ['[?e :account/name]]}
|
||||
(dc/db conn))))
|
||||
(dc/db conn))))
|
||||
|
||||
existing-account-overrides (dc/q {:find ['?e]
|
||||
:in ['$ '?client-id]
|
||||
:where [['?e :account-client-override/client '?client-id]]}
|
||||
(dc/db conn) client-id)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_ (when-let [bad-rows (seq (->> rows
|
||||
(group-by (fn [[_ account]]
|
||||
account))
|
||||
vals
|
||||
(filter #(> (count %) 1))
|
||||
(filter (fn [duplicates]
|
||||
(apply not= (map rest duplicates))))
|
||||
#_(map (fn [[[_ account]]]
|
||||
account))
|
||||
))]
|
||||
(group-by (fn [[_ account]]
|
||||
account))
|
||||
vals
|
||||
(filter #(> (count %) 1))
|
||||
(filter (fn [duplicates]
|
||||
(apply not= (map rest duplicates))))
|
||||
#_(map (fn [[[_ account]]]
|
||||
account))))]
|
||||
(throw (Exception. (str "These accounts are duplicated:" (str bad-rows)))))
|
||||
rows (vec (set (map rest rows)))
|
||||
|
||||
@@ -256,8 +254,7 @@
|
||||
(:db/ident (:account/applicability existing)))
|
||||
(and (not-empty override-name)
|
||||
(not-empty account-name)
|
||||
(not= override-name account-name)
|
||||
)))
|
||||
(not= override-name account-name))))
|
||||
[{:db/id (:db/id existing)
|
||||
:account/client-overrides [{:account-client-override/client client-id
|
||||
:account-client-override/name (or (not-empty override-name)
|
||||
@@ -284,34 +281,30 @@
|
||||
[:db/retractEntity x])
|
||||
existing-account-overrides)
|
||||
rows)]
|
||||
|
||||
|
||||
txes
|
||||
#_@(d/transact conn txes)))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn fix-transactions-without-locations [client-code location]
|
||||
(->>
|
||||
(dc/q {:find ['(pull ?e [*])]
|
||||
:in ['$ '?client-code]
|
||||
:where ['[?e :transaction/accounts ?ta]
|
||||
'[?e :transaction/matched-rule]
|
||||
'[?e :transaction/approval-status :transaction-approval-status/approved]
|
||||
'(not [?ta :transaction-account/location])
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/code ?client-code]
|
||||
]}
|
||||
(dc/db conn) client-code)
|
||||
(->>
|
||||
(dc/q {:find ['(pull ?e [*])]
|
||||
:in ['$ '?client-code]
|
||||
:where ['[?e :transaction/accounts ?ta]
|
||||
'[?e :transaction/matched-rule]
|
||||
'[?e :transaction/approval-status :transaction-approval-status/approved]
|
||||
'(not [?ta :transaction-account/location])
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/code ?client-code]]}
|
||||
(dc/db conn) client-code)
|
||||
(mapcat
|
||||
(fn [[{:transaction/keys [accounts]}]]
|
||||
(mapv
|
||||
(fn [a]
|
||||
{:db/id (:db/id a)
|
||||
:transaction-account/location location}
|
||||
)
|
||||
accounts)
|
||||
)
|
||||
)
|
||||
:transaction-account/location location})
|
||||
accounts)))
|
||||
vec))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
@@ -323,21 +316,21 @@
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn entity-history [i]
|
||||
(vec (sort-by first (dc/q
|
||||
{:find ['?tx '?z '?v ]
|
||||
:in ['?i '$]
|
||||
:where ['[?i ?a ?v ?tx ?ad]
|
||||
'[?a :db/ident ?z]
|
||||
'[(= ?ad true)]]}
|
||||
i (dc/history (dc/db conn))))))
|
||||
{:find ['?tx '?z '?v]
|
||||
:in ['?i '$]
|
||||
:where ['[?i ?a ?v ?tx ?ad]
|
||||
'[?a :db/ident ?z]
|
||||
'[(= ?ad true)]]}
|
||||
i (dc/history (dc/db conn))))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn entity-history-with-revert [i]
|
||||
(vec (sort-by first (dc/q
|
||||
{:find ['?tx '?z '?v '?ad ]
|
||||
:in ['?i '$]
|
||||
:where ['[?i ?a ?v ?tx ?ad]
|
||||
'[?a :db/ident ?z]]}
|
||||
i (dc/history (dc/db conn))))))
|
||||
{:find ['?tx '?z '?v '?ad]
|
||||
:in ['?i '$]
|
||||
:where ['[?i ?a ?v ?tx ?ad]
|
||||
'[?a :db/ident ?z]]}
|
||||
i (dc/history (dc/db conn))))))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn tx-detail [i]
|
||||
@@ -357,47 +350,71 @@
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn start-db []
|
||||
(mu/start-publisher! {:type :dev})
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.datomic/conn })))
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.datomic/conn})))
|
||||
|
||||
|
||||
(defn- auto-reset-handler [ctx event]
|
||||
(require 'figwheel.main.api)
|
||||
(binding [*ns* *ns*]
|
||||
(clojure.tools.namespace.repl/refresh)
|
||||
ctx))
|
||||
|
||||
(defn auto-reset
|
||||
"Automatically reset the system when a Clojure or edn file is changed in
|
||||
`src` or `resources`."
|
||||
[]
|
||||
(println "starting auto reset")
|
||||
(hawk.core/watch! [{:paths ["src/"]
|
||||
:handler auto-reset-handler}]))
|
||||
|
||||
(defn start-http []
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.server/port #'auto-ap.server/jetty})))
|
||||
|
||||
|
||||
(defn start-dev []
|
||||
(set-refresh-dirs "src")
|
||||
(start-db)
|
||||
(start-http)
|
||||
(auto-reset))
|
||||
|
||||
#_(defn start-search []
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.graphql.vendors/indexer #'auto-ap.graphql.accounts/indexer})))
|
||||
(mount.core/start (mount.core/only #{#'auto-ap.graphql.vendors/indexer #'auto-ap.graphql.accounts/indexer})))
|
||||
|
||||
(defn restart-db []
|
||||
#_(require 'datomic.dev-local)
|
||||
#_(datomic.dev-local/release-db {:system "dev" :db-name "prod-migration"})
|
||||
(mount.core/stop (mount.core/only #{#'auto-ap.datomic/conn }))
|
||||
(mount.core/stop (mount.core/only #{#'auto-ap.datomic/conn}))
|
||||
(start-db))
|
||||
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn spit-csv [columns data ]
|
||||
(defn spit-csv [columns data]
|
||||
(csv/write-csv *out*
|
||||
(into [(map name columns)]
|
||||
(for [r data]
|
||||
((apply juxt columns) r )))))
|
||||
((apply juxt columns) r)))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn find-queries [words]
|
||||
(let [obj (s3/list-objects-v2 :bucket-name (:data-bucket env)
|
||||
:prefix (str "queries/"))
|
||||
:prefix (str "queries/"))
|
||||
concurrent 30
|
||||
output-chan (async/chan)]
|
||||
(async/pipeline-blocking concurrent
|
||||
output-chan
|
||||
(comp
|
||||
(map #(do
|
||||
[(:key %)
|
||||
(str (slurp (:object-content (s3/get-object
|
||||
:bucket-name (:data-bucket env)
|
||||
:key (:key %)))))]))
|
||||
|
||||
(filter #(->> words
|
||||
(every? (fn [w] (str/includes? (second %) w)))))
|
||||
(map first)
|
||||
(map #(str/replace % #"queries/" ""))
|
||||
)
|
||||
(comp
|
||||
(map #(do
|
||||
[(:key %)
|
||||
(str (slurp (:object-content (s3/get-object
|
||||
:bucket-name (:data-bucket env)
|
||||
:key (:key %)))))]))
|
||||
|
||||
(filter #(->> words
|
||||
(every? (fn [w] (str/includes? (second %) w)))))
|
||||
(map first)
|
||||
(map #(str/replace % #"queries/" "")))
|
||||
(async/to-chan! (:object-summaries obj))
|
||||
true
|
||||
(fn [e]
|
||||
@@ -408,13 +425,13 @@
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn upsert-invoice-amounts [tsv]
|
||||
(let [data (with-open [reader (io/reader (char-array tsv))]
|
||||
(doall (csv/read-csv reader :separator \tab)))
|
||||
(doall (csv/read-csv reader :separator \tab)))
|
||||
db (dc/db conn)
|
||||
i->invoice-id (fn [i]
|
||||
(try (Long/parseLong i)
|
||||
(catch Exception e
|
||||
(:db/id (dc/pull db '[:db/id]
|
||||
[:invoice/original-id (Long/parseLong (first (str/split i #"-")))])))))
|
||||
i->invoice-id (fn [i]
|
||||
(try (Long/parseLong i)
|
||||
(catch Exception e
|
||||
(:db/id (dc/pull db '[:db/id]
|
||||
[:invoice/original-id (Long/parseLong (first (str/split i #"-")))])))))
|
||||
invoice-totals (->> data
|
||||
(drop 1)
|
||||
(group-by first)
|
||||
@@ -423,13 +440,11 @@
|
||||
(reduce + 0.0
|
||||
(->> values
|
||||
(map (fn [[_ _ _ _ amount]]
|
||||
(- (Double/parseDouble amount))))))
|
||||
]))
|
||||
(- (Double/parseDouble amount))))))]))
|
||||
(into {}))]
|
||||
(->>
|
||||
(->>
|
||||
(for [[i invoice-expense-account-id target-account target-date amount _ location] (drop 1 data)
|
||||
:let [
|
||||
invoice-id (i->invoice-id i)
|
||||
:let [invoice-id (i->invoice-id i)
|
||||
|
||||
invoice (dc/pull db '[FILL_IN] invoice-id)
|
||||
current-total (:invoice/total invoice)
|
||||
@@ -441,34 +456,32 @@
|
||||
(:db/id (first (:invoice/expense-accounts invoice)))
|
||||
(random-tempid))
|
||||
invoice-expense-account (when-not new-account?
|
||||
(dc/pull db '[FILL_IN]invoice-expense-account-id))
|
||||
current-account-id (:db/id (:invoice-expense-account/account invoice-expense-account))
|
||||
(dc/pull db '[FILL_IN] invoice-expense-account-id))
|
||||
current-account-id (:db/id (:invoice-expense-account/account invoice-expense-account))
|
||||
target-account-id (Long/parseLong (str/trim target-account))
|
||||
|
||||
target-date (clj-time.coerce/to-date (atime/parse target-date atime/normal-date))
|
||||
current-date (:invoice/date invoice)
|
||||
|
||||
|
||||
current-expense-account-amount (:invoice-expense-account/amount invoice-expense-account 0.0)
|
||||
|
||||
current-expense-account-amount (:invoice-expense-account/amount invoice-expense-account 0.0)
|
||||
target-expense-account-amount (- (Double/parseDouble amount))
|
||||
|
||||
|
||||
current-expense-account-location (:invoice-expense-account/location invoice-expense-account)
|
||||
current-expense-account-location (:invoice-expense-account/location invoice-expense-account)
|
||||
target-expense-account-location location
|
||||
|
||||
|
||||
[[_ _ invoice-payment]] (vec (dc/q
|
||||
'[:find ?p ?a ?ip
|
||||
:in $ ?i
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/amount ?a]
|
||||
[?ip :invoice-payment/payment ?p]
|
||||
]
|
||||
db invoice-id))]
|
||||
'[:find ?p ?a ?ip
|
||||
:in $ ?i
|
||||
:where [?ip :invoice-payment/invoice ?i]
|
||||
[?ip :invoice-payment/amount ?a]
|
||||
[?ip :invoice-payment/payment ?p]]
|
||||
db invoice-id))]
|
||||
:when current-total]
|
||||
|
||||
[
|
||||
(when (not (auto-ap.utils/dollars= current-total target-total))
|
||||
[(when (not (auto-ap.utils/dollars= current-total target-total))
|
||||
{:db/id invoice-id
|
||||
:invoice/total target-total})
|
||||
|
||||
@@ -486,7 +499,7 @@
|
||||
[:db/retractEntity invoice-payment])
|
||||
|
||||
(when (or new-account?
|
||||
(not (auto-ap.utils/dollars= current-expense-account-amount target-expense-account-amount)))
|
||||
(not (auto-ap.utils/dollars= current-expense-account-amount target-expense-account-amount)))
|
||||
{:db/id invoice-expense-account-id
|
||||
:invoice-expense-account/amount target-expense-account-amount})
|
||||
|
||||
@@ -495,7 +508,7 @@
|
||||
{:db/id invoice-expense-account-id
|
||||
:invoice-expense-account/location target-expense-account-location})
|
||||
|
||||
(when (not= current-account-id target-account-id )
|
||||
(when (not= current-account-id target-account-id)
|
||||
{:db/id invoice-expense-account-id
|
||||
:invoice-expense-account/account target-account-id})])
|
||||
(mapcat identity)
|
||||
@@ -506,18 +519,18 @@
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-schema [prefix]
|
||||
(->> (dc/q '[:find ?i
|
||||
:in $ ?p
|
||||
:where [_ :db/ident ?i]
|
||||
[(namespace ?i) ?p]] (dc/db auto-ap.datomic/conn) prefix)
|
||||
:in $ ?p
|
||||
:where [_ :db/ident ?i]
|
||||
[(namespace ?i) ?p]] (dc/db auto-ap.datomic/conn) prefix)
|
||||
(mapcat identity)
|
||||
vec))
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn get-idents []
|
||||
(->> (dc/q '[:find ?i
|
||||
:in $
|
||||
:where [_ :db/ident ?i]]
|
||||
(dc/db conn) )
|
||||
:in $
|
||||
:where [_ :db/ident ?i]]
|
||||
(dc/db conn))
|
||||
(mapcat identity)
|
||||
(map str)
|
||||
(sort)
|
||||
@@ -532,45 +545,45 @@
|
||||
(defn sample-ledger-import
|
||||
([client-code]
|
||||
(sample-ledger-import client-code 10))
|
||||
([client-code n]
|
||||
([client-code n]
|
||||
(let [client-location (ffirst (d/q '[:find ?l :in $ ?c :where [?c :client/locations ?l]] (dc/db conn) [:client/code client-code]))]
|
||||
(clojure.data.csv/write-csv
|
||||
*out*
|
||||
(for [n (range n)
|
||||
:let [v (rand-nth (map first (d/q '[:find ?vn :where [_ :vendor/name ?vn]] (dc/db conn))))
|
||||
[{a-1 :account/numeric-code a-1-location :account/location}
|
||||
{a-2 :account/numeric-code a-2-location :account/location}] (->> (d/q '[:find (pull ?a [:account/numeric-code :account/location]) :where [?a :account/numeric-code]]
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(shuffle)
|
||||
(take 2))
|
||||
amount (rand-int 2000)
|
||||
d (-> (t/now)
|
||||
(t/minus (t/days (rand-int 60)))
|
||||
(atime/unparse atime/normal-date))
|
||||
id (rand-int 100000)]
|
||||
a [[(str id) client-code "synthetic" v d a-1 (or a-1-location client-location) 0 amount ]
|
||||
[(str id) client-code "synthetic" v d a-2 (or a-2-location client-location) amount 0]]]
|
||||
a)
|
||||
:separator \tab))))
|
||||
*out*
|
||||
(for [n (range n)
|
||||
:let [v (rand-nth (map first (d/q '[:find ?vn :where [_ :vendor/name ?vn]] (dc/db conn))))
|
||||
[{a-1 :account/numeric-code a-1-location :account/location}
|
||||
{a-2 :account/numeric-code a-2-location :account/location}] (->> (d/q '[:find (pull ?a [:account/numeric-code :account/location]) :where [?a :account/numeric-code]]
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(shuffle)
|
||||
(take 2))
|
||||
amount (rand-int 2000)
|
||||
d (-> (t/now)
|
||||
(t/minus (t/days (rand-int 60)))
|
||||
(atime/unparse atime/normal-date))
|
||||
id (rand-int 100000)]
|
||||
a [[(str id) client-code "synthetic" v d a-1 (or a-1-location client-location) 0 amount]
|
||||
[(str id) client-code "synthetic" v d a-2 (or a-2-location client-location) amount 0]]]
|
||||
a)
|
||||
:separator \tab))))
|
||||
|
||||
|
||||
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
|
||||
(defn sample-manual-yodlee
|
||||
([client-code]
|
||||
(sample-ledger-import client-code 10))
|
||||
([client-code n]
|
||||
([client-code n]
|
||||
(let [bank-accounts (map first (d/q '[:find ?bac :in $ ?c :where [?c :client/bank-accounts ?b] [?b :bank-account/code ?bac]] (dc/db conn) [:client/code client-code]))]
|
||||
(clojure.data.csv/write-csv
|
||||
*out*
|
||||
(for [n (range n)
|
||||
:let [amount (rand-int 2000)
|
||||
d (-> (t/now)
|
||||
(t/minus (t/days (rand-int 60)))
|
||||
(atime/unparse atime/normal-date))
|
||||
id (rand-int 100000)]]
|
||||
["posted" d (str "Random Description - " id) "Travel" nil nil (- amount) nil nil nil nil nil (rand-nth bank-accounts) client-code])
|
||||
:separator \tab))))
|
||||
*out*
|
||||
(for [n (range n)
|
||||
:let [amount (rand-int 2000)
|
||||
d (-> (t/now)
|
||||
(t/minus (t/days (rand-int 60)))
|
||||
(atime/unparse atime/normal-date))
|
||||
id (rand-int 100000)]]
|
||||
["posted" d (str "Random Description - " id) "Travel" nil nil (- amount) nil nil nil nil nil (rand-nth bank-accounts) client-code])
|
||||
:separator \tab))))
|
||||
|
||||
|
||||
|
||||
@@ -580,8 +593,7 @@
|
||||
:in $
|
||||
:where [?i :invoice/invoice-number]
|
||||
(not [?i :invoice/status :invoice-status/voided])]
|
||||
:args [
|
||||
(dc/db conn)]})
|
||||
:args [(dc/db conn)]})
|
||||
(map first)
|
||||
(partition-all 1000))]
|
||||
(print ".")
|
||||
@@ -627,4 +639,4 @@
|
||||
(print ".")
|
||||
@(dc/transact auto-ap.datomic/conn n)))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user