Exemple #1
0
        private static IEnumerable <PumpCycle> GetNextPumpCycles(
            List <PumpCycleGroupSetting> settings,
            DateTime currentTime,
            double temperature,
            TimeSpan durationPerDay,
            int numberOfDays)
        {
            if (settings.Count != 0)
            {
                // Find the group
                var groups = settings.OrderBy(g => g.MinimumTemperature).ToList();
                PumpCycleGroupSetting group = groups.LastOrDefault(g => g.MinimumTemperature <= temperature);
                if (group == null)
                {
                    group = groups.First();
                }

                if (group != null)
                {
                    // Correct ratio if required
                    foreach (var cycle in group.PumpingCycles)
                    {
                        if (cycle.Ratio < 0.5 || cycle.Ratio > 4)
                        {
                            cycle.Ratio = 1;
                        }
                    }

                    double totalRatio = group.PumpingCycles.Sum(g => g.Ratio);

                    for (int i = 0; i < numberOfDays; i++)
                    {
                        var time = currentTime.Date.AddDays(i);

                        foreach (var cycle in group.PumpingCycles)
                        {
                            var duration = TimeSpan.FromMinutes(Math.Round(durationPerDay.TotalMinutes * cycle.Ratio / totalRatio));

                            DateTime startTime = cycle.PumpCycleType == PumpCycleType.StartAt
                                ? time.Add(cycle.DecisionTime)
                                : time.Add(cycle.DecisionTime - duration);

                            DateTime endTime = cycle.PumpCycleType == PumpCycleType.StartAt
                                ? time.Add(cycle.DecisionTime + duration)
                                : time.Add(cycle.DecisionTime);

                            if (endTime > currentTime)
                            {
                                yield return(new PumpCycle(
                                                 startTime,
                                                 endTime,
                                                 cycle.ChlorineInhibition,
                                                 cycle.PhRegulationInhibition));
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        public PoolSettings ReadPoolSettings(string fileName)
        {
            if (File.Exists(fileName))
            {
                return(JsonConvert.DeserializeObject <PoolSettings>(File.ReadAllText(fileName)));
            }
            else
            {
                var settings = new PoolSettings();

                var summerGroup1 = new PumpCycleGroupSetting()
                {
                    MinimumTemperature = 0
                };
                summerGroup1.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(13.3), PumpCycleType = PumpCycleType.StopAt
                });

                var summerGroup2 = new PumpCycleGroupSetting()
                {
                    MinimumTemperature = 17
                };
                summerGroup2.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(13.5), PumpCycleType = PumpCycleType.StartAt
                });
                summerGroup2.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(2), PumpCycleType = PumpCycleType.StartAt
                });

                var summerGroup3 = new PumpCycleGroupSetting()
                {
                    MinimumTemperature = 20
                };
                summerGroup3.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(5), PumpCycleType = PumpCycleType.StopAt
                });
                summerGroup3.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(13.5), PumpCycleType = PumpCycleType.StartAt
                });
                summerGroup3.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(20), PumpCycleType = PumpCycleType.StartAt
                });

                // > 23°
                var summerGroup4 = new PumpCycleGroupSetting()
                {
                    MinimumTemperature = 23
                };
                summerGroup4.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(5), PumpCycleType = PumpCycleType.StartAt
                });
                summerGroup4.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(11), PumpCycleType = PumpCycleType.StartAt
                });
                summerGroup4.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(17), PumpCycleType = PumpCycleType.StartAt
                });
                summerGroup4.PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(23), PumpCycleType = PumpCycleType.StartAt
                });

                settings.SummerPumpingCycles.Add(summerGroup1);
                settings.SummerPumpingCycles.Add(summerGroup2);
                settings.SummerPumpingCycles.Add(summerGroup3);
                settings.SummerPumpingCycles.Add(summerGroup4);

                settings.WinterPumpingCycles.Add(new PumpCycleGroupSetting()
                {
                    MinimumTemperature = 0
                });
                settings.WinterPumpingCycles[0].PumpingCycles.Add(new PumpCycleSetting()
                {
                    DecisionTime = TimeSpan.FromHours(5), PumpCycleType = PumpCycleType.StartAt
                });

                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 15, RunTimeHours = 1
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 18, RunTimeHours = 3
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 20, RunTimeHours = 4
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 21, RunTimeHours = 5
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 22, RunTimeHours = 6
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 23, RunTimeHours = 8
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 24, RunTimeHours = 9
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 25, RunTimeHours = 10
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 26, RunTimeHours = 12
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 28, RunTimeHours = 14
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 29, RunTimeHours = 16
                });
                settings.TemperatureRunTime.Add(new TemperatureRunTime()
                {
                    Temperature = 30, RunTimeHours = 20
                });

                return(settings);
            }
        }