1
module ParasitemiaUI.Utils
6 open Newtonsoft.Json.Converters
10 let inline listAsStr
(s
: 'a seq) =
11 s |> Seq.fold (fun acc obj -> acc + (if acc = "" then "" else ", ") + string obj) ""
13 let percentText (nbTotal : int, nb : int) : string =
17 let percent = 100. * (float nb) / (float nbTotal)
18 sprintf "%.1f %% (%d / %d)" percent nb nbTotal
21 Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.ApplicationData), "Parasitemia")
23 let predefinedPPIFilename = "predefined-ppi.json"
24 let predefinedPPIFilepath = Path.Combine (roamingDir, predefinedPPIFilename)
26 let sensorSizesFilename = "sensor-sizes.json"
27 let sensorSizesFilepath = Path.Combine (roamingDir, sensorSizesFilename)
29 let private savePredefinedPPIToFile (predefinedPPI : PredefinedPPI list) =
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 use file = new StreamWriter (sensorSizesFilepath)
40 file.Write (JsonConvert.SerializeObject (sensorSizes, JsonSerializerSettings (Formatting = Formatting.Indented)))
43 Logger.Log.Error "Unable to save sensor sizes to file \"%s\": %O" sensorSizesFilepath ex
45 let predefinedPPI : PredefinedPPI list =
47 use file = new StreamReader (predefinedPPIFilepath)
48 JsonConvert.DeserializeObject<PredefinedPPI list> (file.ReadToEnd ())
51 savePredefinedPPIToFile defaultPredefinedPPI
54 let sensorSizes : SensorSize list =
56 use file = new StreamReader (sensorSizesFilepath)
57 JsonConvert.DeserializeObject<SensorSize list> (file.ReadToEnd ())
60 saveSensorSizesToFile defaultSensorSizes