Skip to content

Commit

Permalink
#1 dayextremes implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeymolen committed Dec 27, 2016
1 parent 9fcd6b7 commit 57126e4
Show file tree
Hide file tree
Showing 17 changed files with 303 additions and 167 deletions.
9 changes: 4 additions & 5 deletions sample/DavisVantage.WeatherReader.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DavisVantage.WeatherReader.WeatherLinkIp;
using NLog;

Expand All @@ -12,14 +9,16 @@ public class Program
private static readonly Logger s_logger = LogManager.GetCurrentClassLogger();
public static void Main(string[] args)
{
var dataloggerSettings = new WeatherLinkIpSettings("192.168.1.140",22222);
var dataloggerSettings = new WeatherLinkIpSettings("192.168.1.140", 22222);
s_logger.Info("Started");
using (var datalogger = new WeatherLinkIpDataLogger())
using (var datalogger = new WeatherLinkIpDataLogger(new WeatherLinkIpByteReader()))
{
if (datalogger.Connect(dataloggerSettings))
{
var currentWeather = datalogger.ReadCurrentWeather(true);
s_logger.Info(currentWeather);
var weatherExtremes = datalogger.ReadWeatherExtremes(true);
s_logger.Info(weatherExtremes);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
40 changes: 40 additions & 0 deletions src/DavisVantage.WeatherReader/Extensions/PrintExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace DavisVantage.WeatherReader.Extensions
{
public static class PrintExtensions
{
public static string PrintAllProperties<T>(this T data) where T: class
{
var stringBuilder = new StringBuilder();
foreach (var property in typeof(T).GetRuntimeProperties())
{
if (property.PropertyType == typeof(List<decimal>))
{
var extraValues = (List<decimal>)property.GetValue(data);
PrintValues(property, ref stringBuilder, extraValues);
}
else if (property.PropertyType == typeof(List<int>))
{
var extraValues = (List<int>)property.GetValue(data);
PrintValues(property, ref stringBuilder, extraValues);
}
else
{
stringBuilder.Append($"\n{property.Name}: {property.GetValue(data)}");
}
}
return stringBuilder.ToString();
}

private static void PrintValues<T>(PropertyInfo propertyInfo, ref StringBuilder stringBuilder, List<T> extraValues)
{
for (var i = 0; i < extraValues.Count; i++)
{
stringBuilder.Append($"\n{propertyInfo.Name}[{i}]: {extraValues[i]}");
}
}
}
}
11 changes: 11 additions & 0 deletions src/DavisVantage.WeatherReader/IByteReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using DavisVantage.WeatherReader.Models;
using DavisVantage.WeatherReader.Models.Extremes;

namespace DavisVantage.WeatherReader
{
public interface IByteReader
{
CurrentWeather ReadCurrentWeatherFromByteArray(byte[] byteArray, bool valuesInMetric);
WeatherExtremes ReadWeatherExtremesFromByteArray(byte[] byteArray, bool valuesInMetric);
}
}
13 changes: 6 additions & 7 deletions src/DavisVantage.WeatherReader/IDataLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using DavisVantage.WeatherReader.Models;
using DavisVantage.WeatherReader.Models;
using DavisVantage.WeatherReader.Models.Extremes;

namespace DavisVantage.WeatherReader
Expand All @@ -15,19 +14,19 @@ public interface IDataLogger<in T> where T : IDataLoggerSettings
/// <summary>
/// WakeUp console. Not necessary to call this method seperately
/// </summary>
void WakeUp();
bool WakeUp();
/// <summary>
/// Read current weather data from console
/// </summary>
/// <param name="valueInMetric">Specify if returned values should be converted to metric or to keep imperial</param>
/// <param name="valuesInMetric">Specify if returned values should be converted to metric or to keep imperial</param>
/// <returns>CurrentWeather object with ConsoleInfo included</returns>
CurrentWeather ReadCurrentWeather(bool valueInMetric);
CurrentWeather ReadCurrentWeather(bool valuesInMetric);

/// <summary>
/// Read extremes from console
/// </summary>
/// <param name="valueInMetric">Specify if returned values should be converted to metric or to keep imperial</param>
/// <param name="valuesInMetric">Specify if returned values should be converted to metric or to keep imperial</param>
/// <returns>WeatherExtremes object that includes day, month and year data</returns>
WeatherExtremes ReadWeatherExtremes(bool valueInMetric);
WeatherExtremes ReadWeatherExtremes(bool valuesInMetric);
}
}
3 changes: 0 additions & 3 deletions src/DavisVantage.WeatherReader/MetricConversion.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DavisVantage.WeatherReader
{
Expand Down
14 changes: 2 additions & 12 deletions src/DavisVantage.WeatherReader/Models/ConsoleInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models
{
Expand All @@ -14,12 +9,7 @@ public class ConsoleInfo

public override string ToString()
{
var stringBuilder = new StringBuilder();
foreach (var property in typeof(ConsoleInfo).GetRuntimeProperties())
{
stringBuilder.Append($"\n{property.Name}: {property.GetValue(this)}");
}
return stringBuilder.ToString();
return this.PrintAllProperties();
}
}
}
32 changes: 2 additions & 30 deletions src/DavisVantage.WeatherReader/Models/CurrentWeather.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models
{
Expand Down Expand Up @@ -33,34 +32,7 @@ public class CurrentWeather

public override string ToString()
{
var stringBuilder = new StringBuilder();
foreach (var property in typeof(CurrentWeather).GetRuntimeProperties())
{
if (property.PropertyType == typeof(List<decimal>))
{
var extraValues = (List<decimal>)property.GetValue(this);
PrintValues(property, ref stringBuilder, extraValues);
}
else if (property.PropertyType == typeof(List<int>))
{
var extraValues = (List<int>)property.GetValue(this);
PrintValues(property, ref stringBuilder, extraValues);
}
else
{
stringBuilder.Append($"\n{property.Name}: {property.GetValue(this)}");
}

}
return stringBuilder.ToString();
}

private void PrintValues<T>(PropertyInfo propertyInfo, ref StringBuilder stringBuilder, List<T> extraValues)
{
for (var i = 0; i < extraValues.Count; i++)
{
stringBuilder.Append($"\n{propertyInfo.Name}[{i}]: {extraValues[i]}");
}
return this.PrintAllProperties();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
namespace DavisVantage.WeatherReader.Models.Extremes
using System;
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models.Extremes
{
public class WeatherDayExtremes
{
public int BarometerMax { get; set; }
public int BarometerMin { get; set; }
public DateTime BarometerMaxTime { get; set; }
public DateTime BarometerMinTime { get; set; }
public int MaxWindSpeed { get; set; }
public DateTime MaxWindSpeedTime { get; set; }
public decimal TempInsideMax { get; set; }
public DateTime TempInsideMaxTime { get; set; }
public decimal TempInsideMin { get; set; }
public DateTime TempInsideMinTime { get; set; }
public int HumidityInsideMax { get; set; }
public DateTime HumidityInsideMaxTime { get; set; }
public int HumidityInsideMin { get; set; }
public DateTime HumidityInsideMinTime { get; set; }
public decimal TempOutsideMax { get; set; }
public decimal TempOutsideMin { get; set; }
public DateTime TempOutsideMaxTime { get; set; }
public DateTime TempOutsideMinTime { get; set; }
public decimal WindChillMin { get; set; }
public DateTime WindChillMinTime { get; set; }
public decimal ThswMax { get; set; }
public DateTime ThswMaxTime { get; set; }

public override string ToString()
{
return this.PrintAllProperties();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
namespace DavisVantage.WeatherReader.Models.Extremes
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models.Extremes
{
public class WeatherExtremes
{
public WeatherDayExtremes WeatherDayExtremes { get; set; }
public WeatherMonthExtremes WeatherMonthExtremes { get; set; }
public WeatherYearExtremes WeatherYearExtremes { get; set; }
public override string ToString()
{
return this.PrintAllProperties();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models.Extremes
{
public class WeatherMonthExtremes
{
public override string ToString()
{
return this.PrintAllProperties();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DavisVantage.WeatherReader.Extensions;

namespace DavisVantage.WeatherReader.Models.Extremes
{
public class WeatherYearExtremes
{
public override string ToString()
{
return this.PrintAllProperties();
}
}
}
1 change: 0 additions & 1 deletion src/DavisVantage.WeatherReader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
3 changes: 0 additions & 3 deletions src/DavisVantage.WeatherReader/RetryPolicies.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Polly;
using Polly.Retry;

Expand Down
Loading

0 comments on commit 57126e4

Please sign in to comment.