Last active
June 14, 2016 18:23
-
-
Save zs40x/f9ebde9357d27bbb443e879922f42257 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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