Use a maybe monad to be able abort an analysis.
[master-thesis.git] / Parasitemia / ParasitemiaUI / Program.fs
index 74f0d35..24e33cd 100644 (file)
@@ -74,12 +74,15 @@ let main args =
                     let images = [ for file in files -> Path.GetFileNameWithoutExtension(FileInfo(file).Name), config.Copy(), new Image<Bgr, byte>(file) ]
 
                     Log.LogWithTime("Whole analyze", Severity.USER, (fun () ->
-                        let results = ParasitemiaCore.Analysis.doMultipleAnalysis images None
-
-                        for id, cells in results do
-                            let config = images |> List.pick (fun (id', config', _) -> if id' = id then Some config' else None)
-                            let total, infected = countCells cells
-                            fprintf resultFile "File: %s %d %d %.2f (diameter: %A)\n" id total infected (100. * (float infected) / (float total)) config.RBCRadius))
+                        match ParasitemiaCore.Analysis.doMultipleAnalysis images None with
+                        | Some results ->
+                            for id, cells in results do
+                                let config = images |> List.pick (fun (id', config', _) -> if id' = id then Some config' else None)
+                                let total, infected = countCells cells
+                                fprintf resultFile "File: %s %d %d %.2f (diameter: %A)\n" id total infected (100. * (float infected) / (float total)) config.RBCRadius
+                        | None ->
+                            fprintf resultFile "Analysis aborted"
+                        Some ())) |> ignore
 
                     Log.RmListener(listener)
                     0