-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bruteforce save roundtrips transit-json
- Loading branch information
awb99
committed
Oct 11, 2024
1 parent
7dc2b47
commit 66c6509
Showing
5 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(ns dev.lib.dataset | ||
(:require | ||
[tablecloth.api :as tc] | ||
[quanta.trade.backtest.store :refer [save-ds-transit-safe]] | ||
) | ||
|
||
) | ||
|
||
|
||
(def ds (tc/dataset {:a [1 2 3] | ||
:b [:a :b :C] | ||
})) | ||
|
||
ds | ||
|
||
(save-ds-transit-safe ds ".data/test.transit-json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(ns quanta.trade.backtest.store | ||
(:require | ||
[nano-id.core :refer [nano-id]] | ||
[tech.v3.libs.clj-transit :as tech-transit] | ||
[tech.v3.io :as io])) | ||
|
||
(defn ds->transit-json-file | ||
[fname ds] | ||
(with-open [outs (io/output-stream! fname)] | ||
(tech-transit/dataset->transit ds outs :json tech-transit/java-time-write-handlers))) | ||
|
||
(defn transit-json-file->ds | ||
[fname] | ||
(with-open [ins (io/input-stream fname)] | ||
(tech-transit/transit->dataset ins :json tech-transit/java-time-write-handlers))) | ||
|
||
(defn ds->nippy [filename ds] | ||
(let [s (io/gzip-output-stream! filename)] | ||
(io/put-nippy! s ds))) | ||
|
||
(defn nippy->ds [filename] | ||
(let [s (io/gzip-input-stream filename) | ||
ds (io/get-nippy s)] | ||
ds)) | ||
|
||
(defn save-ds-transit-safe [fname ds] | ||
(let [fname-tmp "/tmp/ds.nippy.gz" | ||
_ (ds->nippy fname-tmp ds) | ||
ds-safe (nippy->ds fname-tmp) | ||
] | ||
(ds->transit-json-file fname ds-safe))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters