e7c9784cced1e103c63495825e0988933cccb119
1
module ParasitemiaUI.Utils
9 let inline listAsStr
(s
: 'a seq) =
10 s |> Seq.fold (fun acc obj -> acc + (if acc = "" then "" else ", ") + string obj) ""
12 let percentText (nbTotal : int, nb : int) : string =
16 let percent = 100. * (float nb) / (float nbTotal)
17 sprintf "%.1f %% (%d / %d)" percent nb nbTotal
20 Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.ApplicationData), "Parasitemia")
22 let predefinedPPIFilename = "predefined-ppi.json"
23 let predefinedPPIFilepath = Path.Combine (roamingDir, predefinedPPIFilename)
25 let sensorSizesFilename = "sensor-sizes.json"
26 let sensorSizesFilepath = Path.Combine (roamingDir, sensorSizesFilename)
28 let private savePredefinedPPIToFile (predefinedPPI : PredefinedPPI list) =
30 Directory.CreateDirectory roamingDir |> ignore
31 use file = new StreamWriter (predefinedPPIFilepath)
32 file.Write (JsonConvert.SerializeObject (predefinedPPI, JsonSerializerSettings (Formatting = Formatting.Indented)))
35 Logger.Log.Error "Unable to save predefined PPI to file \"%s\": %O" predefinedPPIFilepath ex
37 let private saveSensorSizesToFile (sensorSizes : SensorSize list) =
39 Directory.CreateDirectory roamingDir |> ignore
40 use file = new StreamWriter (sensorSizesFilepath)
41 file.Write (JsonConvert.SerializeObject (sensorSizes, JsonSerializerSettings (Formatting = Formatting.Indented)))
44 Logger.Log.Error "Unable to save sensor sizes to file \"%s\": %O" sensorSizesFilepath ex
46 let predefinedPPI : PredefinedPPI list =
48 use file = new StreamReader (predefinedPPIFilepath)
49 JsonConvert.DeserializeObject<PredefinedPPI list> (file.ReadToEnd ())
52 savePredefinedPPIToFile defaultPredefinedPPI
55 let sensorSizes : SensorSize list =
57 use file = new StreamReader (sensorSizesFilepath)
58 JsonConvert.DeserializeObject<SensorSize list> (file.ReadToEnd ())
61 saveSensorSizesToFile defaultSensorSizes
65 let programName = System.AppDomain.CurrentDomain.FriendlyName
66 "Usage of Parasitemia:\n" +
67 "Non-interactive mode:\n" +
68 (sprintf " %s (--folder <folder>|--file <file>) --output <folder> [--debug]\n" programName) +
69 " --folder <folder> : an input folder containing images to analyze\n" +
70 " --file <file> : an image file to be analyzed\n" +
71 " --output <folder> : a folder to put the results\n" +
72 " --debug : output more information like intermediate images (it takes more CPU and memory)\n" +
74 "Interactive mode:\n" +
75 (sprintf " %s [<document-file>] [--debug]\n" programName) +
76 " <document-file> : a PIAZ file to automatically open at startup\n" +
77 " --debug : output information like intermediate images in the current directory (it takes more CPU and memory)"