Skip to content

Instantly share code, notes, and snippets.

@zs40x
Last active June 14, 2016 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zs40x/f9ebde9357d27bbb443e879922f42257 to your computer and use it in GitHub Desktop.
Save zs40x/f9ebde9357d27bbb443e879922f42257 to your computer and use it in GitHub Desktop.
public class Sensor
{
public string Name { get; }
public List<double> MeasuredValues { get; }
public double AverageValue
=> MeasuredValues.Average();
public double MinimumValue
=> MeasuredValues.Min();
public double MaximumValue
=> MeasuredValues.Max();
public Sensor(string name, IEnumerable<double> measuredValues)
{
Name = name;
MeasuredValues = new List<double>(measuredValues);
}
public void SaveToReportFile(string reportFile)
=> SaveReportToFile(reportFile, ToFileContent());
private void SaveReportToFile(string reportFile, string fileContent)
{
using (var fileStream = new FileStream(reportFile, FileMode.OpenOrCreate, FileAccess.Write))
{
using (var streamWriter = new StreamWriter(fileStream))
{
streamWriter.Write(fileContent);
}
}
}
private string ToFileContent()
{
var fileContent =
$"#SensorInfo#Name:{Name};Average:{AverageValue};"
+ $"Minimum:{MinimumValue};Maximum:{MaximumValue}";
MeasuredValues.ForEach(
value => fileContent += $@"{Environment.NewLine}##{value}"
);
return fileContent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment