8635bcde813703bfc6e17ce2d48bdaab4aeba28e
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 Directory.CreateDirectory roamingDir |> ignore
32 use file = new StreamWriter (predefinedPPIFilepath)
33 file.Write (JsonConvert.SerializeObject (predefinedPPI, JsonSerializerSettings (Formatting = Formatting.Indented)))
36 Logger.Log.Error "Unable to save predefined PPI to file \"%s\": %O" predefinedPPIFilepath ex
38 let private saveSensorSizesToFile (sensorSizes : SensorSize list) =
40 Directory.CreateDirectory roamingDir |> ignore
41 use file = new StreamWriter (sensorSizesFilepath)
42 file.Write (JsonConvert.SerializeObject (sensorSizes, JsonSerializerSettings (Formatting = Formatting.Indented)))
45 Logger.Log.Error "Unable to save sensor sizes to file \"%s\": %O" sensorSizesFilepath ex
47 let predefinedPPI : PredefinedPPI list =
49 use file = new StreamReader (predefinedPPIFilepath)
50 JsonConvert.DeserializeObject<PredefinedPPI list> (file.ReadToEnd ())
53 savePredefinedPPIToFile defaultPredefinedPPI
56 let sensorSizes : SensorSize list =
58 use file = new StreamReader (sensorSizesFilepath)
59 JsonConvert.DeserializeObject<SensorSize list> (file.ReadToEnd ())
62 saveSensorSizesToFile defaultSensorSizes