Last active
June 14, 2016 18:15
-
-
Save zs40x/6fa07cfe187dd2843ebdc82c852a31b4 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 class PlainTextSensorReportGenerator : ISensorReportGenerator | |
{ | |
private readonly IFilesystem _filesystem; | |
public PlainTextSensorReportGenerator(IFilesystem filesystem) | |
{ | |
_filesystem = filesystem; | |
} | |
public void GenerateReport(Sensor sensor, string reportFile) | |
=> _filesystem.WriteContentToFile(reportFile, ToFileContent(sensor)); | |
private string ToFileContent(Sensor sensor) | |
{ | |
var fileContent = | |
$"#SensorInfo#Name:{sensor.Name};Average:{sensor.AverageValue};" | |
+ $"Minimum:{sensor.MinimumValue};Maximum:{sensor.MaximumValue}"; | |
sensor.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