1
module ParasitemiaUI.Main
12 open ParasitemiaCore.Utils
13 open ParasitemiaCore.Config
15 [<System.Runtime.InteropServices.DllImport "kernel32.dll">]
16 extern
bool AttachConsole (int dwProcessId)
21 // To redirect stdout to the attached console.
22 AttachConsole -1 |> ignore
// -1 to attach to the parent process.
24 Log.LogDirectory <- Constants.USER_DIRECTORY_LOG
30 Log.AvoidRepeatingIdenticalMessages <- true
32 if Array.exists
(fun e
-> e
= "--help" || e = "-h") args
then
37 Log.Info ">>>>> Starting of Parasitemia UI ..."
38 // Log.Info "UI Version: %s" Utils.UIVersion TODO
41 match Args.parse
args with
43 let config = Config defaultParameters
46 Log.DebugLoggingEnabled <- true
48 Log.DebugLoggingEnabled <- debug
51 Log.Info "Command line arguments: %s" (args |> String.concat
" ")
52 Log.Info "Configuration: %O" config
53 // Log.Info "Settings from %s:\n%s" Settings.Instance.Path Settings.Instance.AsJson TODO
56 | Args.CmdLine (input
, output
) ->
58 config.Debug <- DebugOn output
60 Directory.CreateDirectory output
|> ignore
62 use logFile = new StreamWriter (new FileStream (Path.Combine(output
, "log.txt"), FileMode.Append, FileAccess.Write))
63 let listener = { new IListener with member this
.NewEntry severity header mess
= logFile.WriteLine (header
+ " : " + mess
) }
64 Log.AddListener listener
66 Log.Info "=== New run : %O %s ===" DateTime.Now (if debug
then "[DEBUG]" else "[RELEASE]")
70 | Args.File file -> [ file ]
71 | Args.Dir dir
-> Directory.EnumerateFiles dir |> List.ofSeq
73 use resultFile = new StreamWriter (new FileStream (Path.Combine (output
, "results.txt"), FileMode.Append, FileAccess.Write))
75 let images = [ for file in files -> Path.GetFileNameWithoutExtension (FileInfo(file).Name), config.Copy (), new Image<Bgr, byte
> (file) ]
77 Log.LogWithTime Types.Severity.INFO (
79 match ParasitemiaCore.Analysis.doMultipleAnalysis
images None with
81 for id
, result in results
do
82 let config, img
= images |> List.pick
(fun (id
', config', img
') -> if id' = id
then Some (config', img') else None)
84 let total, infected
= countCells
result.Cells
85 fprintf
resultFile "File: %s %d %d %.2f (diameter: %O)\n" id
total infected (100. * (float infected) / (float total)) config.RBCRadius
87 fprintf
resultFile "Analysis aborted"
89 ) "Whole analyze" |> ignore
91 Log.RemoveListener listener
94 | Args.Window fileToOpen
->
95 if debug
then config.Debug <- DebugOn "."
96 GUI.run
config fileToOpen
98 Log.Info "<<<<< Parasitemia UI closed"
104 Log.Fatal "Error: %A" ex