Generate SSD truth store storage summary from typed Jerboa
ober
63fb3d0bc20c5a4de1cdbdf517209cdaf6cfeaae
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -15538,10 +15538,12 @@ (export truthStoreSha256Hex truthStoreContainedLeaf truthStoreReadLocalText truthStoreTruthPath truthStoreLoadTruth truthStoreSaveSession - truthStoreAppendEvent truthStoreApplyTruth) + truthStoreAppendEvent truthStoreApplyTruth + truthStoreStorageSummaryLocal) (type Exception) (type File) (type InputStream) + (type Int32) (type LinkOption) (type MessageDigest) (type Path) @@ -15567,6 +15569,12 @@ (file : File) (json : JSONObject)) : Unit (kotlin-member-call appendJsonLine)) + (extern (truthStoreFileName + (file : File)) : String + (kotlin-member-get name)) + (extern (truthStoreListFiles + (file : File)) : (Nullable (Array File)) + (kotlin-member-call listFiles)) (extern (truthStoreFileInputStream (file : File)) : InputStream (kotlin-member-call inputStream)) @@ -15705,7 +15713,36 @@ (applyTruthJsonToSession session (truthJsonObjectOrEmpty truth)) - (begin)))))) + (begin)))) + (def (truthStoreCountMatchingFiles + (files : (Nullable (Array File))) + (accept : (-> File Bool))) : Int32 + (if (nullable-null? files) + (int32 0) + (for/fold ((count (int32 0))) + ((i (in-range + (int32 0) + (list-size (nullable-get files))))) + (if (invoke accept (list-ref (nullable-get files) i)) + (+ count (int32 1)) + count)))) + (def (truthStoreCountFiles + (files : (Nullable (Array File)))) : Int32 + (truthStoreCountMatchingFiles + files + (lambda ((file : File)) #t))) + (def (truthStoreCountTruthFiles + (files : (Nullable (Array File)))) : Int32 + (truthStoreCountMatchingFiles + files + (lambda ((file : File)) + (truthJsonFileName (truthStoreFileName file))))) + (def (truthStoreStorageSummaryLocal (store : TruthStore)) : String + (storageSummaryText + (truthStoreCountTruthFiles + (truthStoreListFiles (truthStoreGroundTruthDir store))) + (truthStoreCountFiles + (truthStoreListFiles (truthStoreEventsDir store))))))) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt" ( @@ -16254,11 +16291,8 @@ " }" " }" "" - " fun storageSummary(): String {" - " val truthCount = if (fileListFilesPresent(groundTruthDir)) checkNotNull(groundTruthDir.listFiles { f -> truthJsonFileName(f.name) }).size else 0" - " val eventCount = if (fileListFilesPresent(eventsDir)) checkNotNull(eventsDir.listFiles()).size else 0" - " return storageSummaryText(truthCount, eventCount)" - " }" + " fun storageSummary(): String =" + " truthStoreStorageSummaryLocal(this)" "" " fun seedBundledTruthAsync(done: (Int) -> Unit) {" " truthStoreSeedBundledTruthAsync(this, done)"