public static object Interpolate(TimeSpan time, TimeNode currentNode, TimeNode nextNode, string propertyName) { var currentProperty = currentNode.Properties.First(prop => prop.Name == propertyName); var nextProperty = nextNode.Properties.First(prop => prop.Name == propertyName); var currentValue = currentProperty.Value; var nextValue = nextProperty.Value; if (currentValue == null) { return(null); } if (nextValue == null) { return(null); } if (currentValue.GetType() != nextValue.GetType()) { return(null); } var percentage = GetRelTimePercentage(time, currentNode.TimeOfDay, nextNode.TimeOfDay); return(Interpolate(currentValue, nextValue, percentage)); }
public static TimeProfile Create() { Log.Info("Creating default time profile"); var result = new TimeProfile(); var wakeUpTime = new TimeNode(TimeSpan.FromHours(7)); wakeUpTime.Properties.Add(new NodeProperty(NodeProperty.Brightness, 20)); wakeUpTime.Properties.Add(new NodeProperty(NodeProperty.ColorTemperature, 3300)); result.AddNode(wakeUpTime); var morning = new TimeNode(TimeSpan.FromHours(8)); morning.Properties.Add(new NodeProperty(NodeProperty.Brightness, 80)); morning.Properties.Add(new NodeProperty(NodeProperty.ColorTemperature, 6500)); result.AddNode(morning); var srsModeOver = new TimeNode(TimeSpan.FromHours(17)); srsModeOver.Properties.Add(new NodeProperty(NodeProperty.Brightness, 80)); srsModeOver.Properties.Add(new NodeProperty(NodeProperty.ColorTemperature, 6500)); result.AddNode(srsModeOver); var afterDinner = new TimeNode(TimeSpan.FromHours(19)); afterDinner.Properties.Add(new NodeProperty(NodeProperty.Brightness, 40)); afterDinner.Properties.Add(new NodeProperty(NodeProperty.ColorTemperature, 5000)); result.AddNode(afterDinner); var bedTime = new TimeNode(TimeSpan.FromHours(22)); bedTime.Properties.Add(new NodeProperty(NodeProperty.Brightness, 20)); bedTime.Properties.Add(new NodeProperty(NodeProperty.ColorTemperature, 3300)); result.AddNode(bedTime); return(result); }
public void AddNode(TimeNode node) { Nodes.Add(node); NodeAdded?.Invoke(this, new TimeProfileNodeAddedEvent(node)); }
public TimeProfileNodeAddedEvent(TimeNode node) { Node = node; }