6579cd61dfc26bc772eaf43a23f90648f19a51da
1
module ParasitemiaUI.Utils
6 open Newtonsoft.Json.Converters
10 let listAsStr (s
: 'a seq) =
11 s |> Seq.fold (fun acc obj -> acc + (if acc = "" then "" else ", ") + obj.ToString()) ""
13 let percentText (nbTotal: int, nb: int) : string =
18 let percent = 100. * (float nb) / (float nbTotal)
19 sprintf "%.1f %% (%d / %d)" percent nb nbTotal
22 Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "Parasitemia")
24 let predefinedPPIFilename = "predefined-ppi.json"
25 let predefinedPPIFilepath = Path.Combine(roamingDir, predefinedPPIFilename)
27 let sensorSizesFilename = "sensor-sizes.json"
28 let sensorSizesFilepath = Path.Combine(roamingDir, sensorSizesFilename)
30 let private savePredefinedPPIToFile (predefinedPPI: PredefinedPPI list) =
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 \"{0}\": {1}", predefinedPPIFilepath, ex)
38 let private saveSensorSizesToFile (sensorSizes: SensorSize list) =
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 \"{0}\": {1}", 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