public Records Load() { if (File.Exists(fileName)) { var document = XDocument.Load(fileName); var data = new Records(); var records = document.Root.Elements("record"); foreach (var element in records) { data.Add( new Record( DateTime.Parse( element.Attribute("datetime").Value, CultureInfo.InvariantCulture), float.Parse( element.Attribute("amount").Value, CultureInfo.InvariantCulture))); } return(data); } return(new Records()); }
public double Sum(Records records) => records.Sum(record => record.Amount);
public double Rate(Records records) => records.Count() > 1 ? (Duration(records).TotalSeconds > 0 ? Sum(records) / Duration(records).TotalSeconds : 0.0f) : 0.0f;