From eda9bffd6818fd5f81de8029874c2a6e359a22df Mon Sep 17 00:00:00 2001 From: dazering Date: Thu, 11 Jun 2026 12:52:38 +0300 Subject: [PATCH 1/2] Add inp statistic --- .../Inpx/InpxGenerator.fs | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs index 0052e5d..cfcc5a3 100644 --- a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs +++ b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs @@ -28,6 +28,11 @@ type InpxGeneratorParameters = ErrorReport: string -> unit DoInTransactionAsync: DbConnection * (DbConnection -> Task) -> Task } +type private InpStat = + { Processed: uint + Skipped: uint + Added: uint } + let private authorInpxInfoToAuthorsName (author: AuthorInpxInfo) : InpLine.AuthorName = { First = author.FirstName Middle = author.MiddleName @@ -69,16 +74,22 @@ let private getInpLinesAsync (bookId: int64) (extension: string) (size: string) + (inpStat: InpStat) (reportError: string -> unit) (connection: DbConnection) - : Task = + : Task = task { let! bookInfo = Books.GetBookInpxInfosByIdAsync(connection, bookId) match bookInfo with | [||] -> reportError $"Not found any information in database for Book Id: {bookId}" - return [||] + + return + [||], + { inpStat with + Processed = inpStat.Processed + 1u + Skipped = inpStat.Skipped + 1u } | bf -> let! authors = Authors.GetAuthorInpxInfosByBookIdAsync(connection, bookId) let! genres = Genres.GetGenreKeysByBookIdAsync(connection, bookId) @@ -89,24 +100,33 @@ let private getInpLinesAsync bf |> Array.map (fun bi -> bookAttributesToInpRecord (bookId.ToString()) extension size rate bi authors genres keywords - |> InpLine.makeLine) + |> InpLine.makeLine), + { inpStat with + Processed = inpStat.Processed + 1u + Added = inpStat.Added + 1u } } let private tryToGetInpLinesAsync (reportError: string -> unit) (entry: ZipArchiveEntry) + (inpStat: InpStat) (connection: DbConnection) - : Task = + : Task = task { match Int64.TryParse(entry.Name |> Path.GetFileNameWithoutExtension) with | true, bookId -> let extension = (entry.Name |> Path.GetExtension).Replace(".", String.Empty) let size = entry.Length.ToString() - let! lines = getInpLinesAsync bookId extension size reportError connection + let! lines, stat = getInpLinesAsync bookId extension size inpStat reportError connection - return Some lines - | false, _ -> return None + return Some lines, stat + | false, _ -> + return + None, + { inpStat with + Processed = inpStat.Processed + 1u + Skipped = inpStat.Skipped + 1u } } let private createInp (inpx: ZipArchive) (name: string) : ZipArchiveEntry = inpx.CreateEntry name @@ -118,22 +138,31 @@ let private createInpFromLibraryArchive (reportError: string -> unit) (connection: DbConnection) (libraryArchive: ZipArchive) - : Task = + : Task = task { let inp = Path.ChangeExtension(archiveName, "inp") |> createInp inpx use fs = inp.Open() use sw = new StreamWriter(fs) + let mutable inpStat = + { Processed = 0u + Skipped = 0u + Added = 0u } + for entry in libraryArchive.Entries do - let! linesResult = tryToGetInpLinesAsync reportError entry connection + let! linesResult, stat = tryToGetInpLinesAsync reportError entry inpStat connection + + inpStat <- stat match linesResult with | Some lines -> for line in lines do do! sw.WriteLineAsync line | None -> () + + return inpStat } let private genreInpxEntityToString (genre: GenreInpxEntity) : string = @@ -214,14 +243,15 @@ let private fillInpxAsync for archive in zipArchives do let archiveName = Path.GetFileName archive - reportProgress $"Generating inp for {archiveName}" - try - do! + let! inpStat = ArchiveUtils.DoWithArchiveAsync( archive, createInpFromLibraryArchive archiveName inpx reportProgress reportError connection ) + + reportProgress + $"Generated inp for {archiveName}. Processed: {inpStat.Processed}, Added: {inpStat.Added}, Skipped: {inpStat.Skipped}" with :? InvalidDataException as _ -> reportError $"Invalid archive {archiveName}" } From cd11eafe1533e789088e6c1608e2fbe7c981a2c1 Mon Sep 17 00:00:00 2001 From: dazering Date: Thu, 11 Jun 2026 13:07:08 +0300 Subject: [PATCH 2/2] Add inpx statistic --- .../Inpx/InpxGenerator.fs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs index cfcc5a3..ea9ca00 100644 --- a/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs +++ b/HomeLibProt.CollectionManager/Inpx/InpxGenerator.fs @@ -33,6 +33,11 @@ type private InpStat = Skipped: uint Added: uint } +type private InpxStat = + { Processed: uint + Skipped: uint + Added: uint } + let private authorInpxInfoToAuthorsName (author: AuthorInpxInfo) : InpLine.AuthorName = { First = author.FirstName Middle = author.MiddleName @@ -145,7 +150,7 @@ let private createInpFromLibraryArchive use fs = inp.Open() use sw = new StreamWriter(fs) - let mutable inpStat = + let mutable inpStat: InpStat = { Processed = 0u Skipped = 0u Added = 0u } @@ -240,6 +245,11 @@ let private fillInpxAsync let zipArchives = Directory.EnumerateFiles(pathToLibrary, "*.zip") + let mutable inpxStat: InpxStat = + { Processed = 0u + Skipped = 0u + Added = 0u } + for archive in zipArchives do let archiveName = Path.GetFileName archive @@ -250,10 +260,19 @@ let private fillInpxAsync createInpFromLibraryArchive archiveName inpx reportProgress reportError connection ) + inpxStat <- + { inpxStat with + Processed = inpxStat.Processed + inpStat.Processed + Added = inpxStat.Added + inpStat.Added + Skipped = inpxStat.Skipped + inpStat.Skipped } + reportProgress $"Generated inp for {archiveName}. Processed: {inpStat.Processed}, Added: {inpStat.Added}, Skipped: {inpStat.Skipped}" with :? InvalidDataException as _ -> reportError $"Invalid archive {archiveName}" + + reportProgress + $"Total books Processed: {inpxStat.Processed}, Added: {inpxStat.Added}, Skipped: {inpxStat.Skipped}" } let private createInpxAndFillAsync (path: string) (fillInpx: ZipArchive -> Task) : Task =