tailwind ready
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
(ns ingest-ml
|
||||
(:require [datomic.client.api :as dc]
|
||||
(:require [datomic.api :as dc]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.data.csv :as csv]
|
||||
[iol-ion.tx :refer [upsert-entity]]
|
||||
#_[iol-ion.tx :refer [upsert-entity]]
|
||||
[auto-ap.datomic :refer [conn]]))
|
||||
|
||||
(println "hi")
|
||||
@@ -13,23 +13,22 @@
|
||||
|
||||
|
||||
(defn reset-inference []
|
||||
(doseq [p (->>
|
||||
(dc/q '[:find ?t
|
||||
:where [?t :transaction/recommended-account]]
|
||||
(dc/db conn))
|
||||
(map (fn [[t]]
|
||||
`(upsert-entity
|
||||
~{:db/id t
|
||||
:transaction/recommended-account nil
|
||||
:tranasction/vendor-confidence nil
|
||||
:transaction/account-confidence nil
|
||||
:transaction/recommended-vendor nil})))
|
||||
|
||||
(partition-all 100))]
|
||||
(dc/transact conn {:tx-data p})))
|
||||
(doseq [p (->>
|
||||
(dc/q '[:find ?t
|
||||
:where [?t :transaction/recommended-account]]
|
||||
(dc/db conn))
|
||||
(map (fn [[t]]
|
||||
[:upsert-entity {:db/id t
|
||||
:transaction/recommended-account nil
|
||||
:tranasction/vendor-confidence nil
|
||||
:transaction/account-confidence nil
|
||||
:transaction/recommended-vendor nil}]))
|
||||
|
||||
(partition-all 100))]
|
||||
@(dc/transact conn p)))
|
||||
|
||||
(defn read-inference []
|
||||
(with-open [reader (io/reader "/mnt/data/dev2/ml-test/inference-outcome.csv")]
|
||||
(with-open [reader (io/reader "data/inference-outcome.csv")]
|
||||
(->> (csv/read-csv reader)
|
||||
(into []
|
||||
(comp
|
||||
@@ -43,7 +42,7 @@
|
||||
|
||||
(defn apply-inference [inference]
|
||||
(doseq [p (->> inference (partition-all 100))]
|
||||
(dc/transact conn {:tx-data p})))
|
||||
@(dc/transact conn p)))
|
||||
|
||||
|
||||
(defn check-applied-inference []
|
||||
@@ -69,3 +68,20 @@
|
||||
(dc/db conn))
|
||||
(shuffle)
|
||||
(take 10))))
|
||||
|
||||
|
||||
(defn random-infer []
|
||||
(let [n (rand-int 1000)
|
||||
vs (into [] (map first (dc/q '[:find ?v :in $ :where [?v :vendor/name]] (dc/db conn))))
|
||||
as (into [] (map first (dc/q '[:find ?v :in $ :where [?v :account/name]] (dc/db conn))))]
|
||||
(->>
|
||||
(dc/qseq {:query '[:find ?t
|
||||
:where [?t :transaction/client]]
|
||||
:args [(dc/db conn)]})
|
||||
(map first)
|
||||
(take n)
|
||||
(map (fn [t]
|
||||
{:db/id t
|
||||
:transaction/recommended-account (rand-nth as)
|
||||
:transaction/account-confidence (double (/ (double (rand-int 100)) 100.0))
|
||||
:transaction/recommended-vendor (rand-nth vs)})))))
|
||||
|
||||
83
scratch-sessions/pnl-export.repl
Normal file
83
scratch-sessions/pnl-export.repl
Normal file
@@ -0,0 +1,83 @@
|
||||
;; This buffer is for Clojure experiments and evaluation.
|
||||
|
||||
;; Press C-j to evaluate the last expression.
|
||||
|
||||
;; You can also press C-u C-j to evaluate the expression and pretty-print its result.
|
||||
(dc/pull (dc/db conn) [:db/id] [:client/code "NGAK"])
|
||||
|
||||
(user/init-repl)
|
||||
|
||||
(require '[auto-ap.datomic :refer [pull-attr pull-many]])
|
||||
|
||||
(csv/write-csv *out*
|
||||
(let [clients (pull-many (dc/db conn) '[:db/id :client/code :client/locations] [[:client/code "NGAK"] [:client/code "NGOP"] #_#_[:client/code "NGRV"] [:client/code "NGE1"]])
|
||||
account->numeric-code (into {} (seq (dc/q '[:find ?i ?n
|
||||
:in $ [?a ...]
|
||||
:where [?i ?a ?n]]
|
||||
(dc/db conn) [:account/numeric-code :bank-account/numeric-code])))
|
||||
account->name (let [lookup (into {} (seq (dc/q '[:find ?i ?n
|
||||
:in $
|
||||
:where [?i :account/name ?n]]
|
||||
(dc/db conn))))]
|
||||
(fn [x]
|
||||
(or (lookup x) "Bank Account")))
|
||||
account->location (into {} (seq (dc/q '[:find ?i ?l
|
||||
:in $
|
||||
:where [?i :account/location ?l]]
|
||||
(dc/db conn))))
|
||||
used-accounts (into #{} (for [c clients
|
||||
d (dc/index-range (dc/db conn)
|
||||
:journal-entry-line/client+account+location+date
|
||||
[(:db/id c)]
|
||||
[(inc (:db/id c))])
|
||||
:let [[_ account] (:v d)]]
|
||||
account))]
|
||||
(for [client clients
|
||||
:let [all-entries (->> (dc/index-pull (dc/db conn)
|
||||
{:index :avet
|
||||
:selector [:db/id :journal-entry-line/running-balance :journal-entry-line/client+account+location+date]
|
||||
:start [:journal-entry-line/client+account+location+date [(:db/id client)]]
|
||||
:reverse false
|
||||
:limit 1})
|
||||
(take-while (fn [curr]
|
||||
(= (first (:journal-entry-line/client+account+location+date curr))
|
||||
(:db/id client)))))
|
||||
account-lookup (->> all-entries
|
||||
(reduce
|
||||
(fn [acc curr]
|
||||
(let [[client account location date] (:journal-entry-line/client+account+location+date curr)
|
||||
numeric-code (account->numeric-code account)]
|
||||
(assoc acc (format "%d-%d-%s-%s" client numeric-code location (atime/unparse-local (clj-time.coerce/to-date-time date) atime/iso-date)) (:journal-entry-line/running-balance curr))))
|
||||
(sorted-map)))]
|
||||
a (sort-by account->numeric-code used-accounts)
|
||||
:let [numeric-code (account->numeric-code a)]
|
||||
l (or (account->location a) (:client/locations client))
|
||||
delta (range -60 0)
|
||||
:let [date (t/plus (c/to-date-time #inst "2023-06-12T08:00:00") (t/days delta))
|
||||
date-str (atime/unparse-local date atime/iso-date)]
|
||||
:when (and numeric-code (>= numeric-code 40000))]
|
||||
(conj [(:client/code client) l numeric-code (account->name a) date-str] (with-precision 2
|
||||
(double (.setScale (bigdec (or
|
||||
(some->> (subseq account-lookup >= (format "%d-%d-%s-%s" (:db/id client) numeric-code l "2000-01-01") <= (format "%d-%d-%s-%s" (:db/id client) numeric-code l date-str))
|
||||
last
|
||||
last)
|
||||
0.0))
|
||||
2 java.math.RoundingMode/HALF_UP))))))
|
||||
)
|
||||
|
||||
(dc/q '[:find (count ?x)
|
||||
:where [?x :journal-entry-line/dirty true]]
|
||||
(dc/db conn))
|
||||
|
||||
(let [clients (map first
|
||||
(dc/q '[:find (pull ?c [:client/code :db/id])
|
||||
:where [?c :client/code]]
|
||||
(dc/db conn)))]
|
||||
(doseq [[c i] (map vector clients (range))]
|
||||
(let [db (dc/db conn)
|
||||
accounts-needing-rebuild (auto-ap.ledger/accounts-needing-rebuild db (:db/id c))]
|
||||
(when (seq accounts-needing-rebuild)
|
||||
(println "C" c "needs" (count accounts-needing-rebuild) "built")
|
||||
#_(refresh-running-balance-accounts accounts-needing-rebuild clients c i db)
|
||||
#_(mu/log ::client-completed)))))
|
||||
,
|
||||
Reference in New Issue
Block a user