Пример #1
0
        public GlobalHistoryDTO GetHistoryFrom(int year, int month, int day)
        {
            List <string> data;

            if (serviceUri != null)
            {
                var response = GetResponse(year, month, day);
                data = ExtractData(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                data = ExtractData(File.ReadAllText(fileName));
            }
            var parsedData = ParseData(data);
            var result     = new GlobalHistoryDTO();

            foreach (var row in parsedData.OrderBy(item => item.Date))
            {
                result.Station.Add(new AverageValue {
                    Hour = row.Date.ToLocalTime(), Value = row.EffectiveTemperature
                });
                result.Overcast.Add(new AverageValue {
                    Hour = row.Date.ToLocalTime(), Value = row.Overcast
                });
                result.Wind.Add(new AverageValue {
                    Hour = row.Date.ToLocalTime(), Value = row.WindSpeed
                });
            }
            return(result);
        }
Пример #2
0
 public Form1(LocalHistoryDTO localHistoryData, GlobalHistoryDTO globalHistoryData)
 {
     InitializeComponent();
     localHistoryData.Indoor.ForEach(item => chart1.Series[0].Points.AddXY(item.Hour, item.Value));
     localHistoryData.Outdoor.ForEach(item => chart1.Series[1].Points.AddXY(item.Hour, item.Value));
     localHistoryData.Boiler.ForEach(item => chart1.Series[2].Points.AddXY(item.Hour, item.Value));
     if (globalHistoryData != null)
     {
         globalHistoryData.Station.ForEach(item => chart1.Series[3].Points.AddXY(item.Hour, item.Value));
         globalHistoryData.Overcast.ForEach(item => chart1.Series[4].Points.AddXY(item.Hour,
                                                                                  item.Hour.TimeOfDay.Hours > 8 && item.Hour.TimeOfDay.Hours < 16 ? 10 - item.Value : 0));
         globalHistoryData.Wind.ForEach(item => chart1.Series[5].Points.AddXY(item.Hour, item.Value));
     }
     chart1.Titles[0].Text    = $"Всего записей: {localHistoryData.Count}. Последняя: {localHistoryData.Last}. ";
     chart1.Series[3].Enabled = false;
     //chart1.Series[4].Enabled = false;
     //chart1.Series[4].Enabled = false;
     //chart1.Series[5].Enabled = false;
 }
Пример #3
0
        public static void OutToCSVFile(LocalHistoryDTO localHistoryData, GlobalHistoryDTO globalHistoryData)
        {
            var indoor   = new List <AverageValue>();
            var outdoor  = new List <AverageValue>();
            var boiler   = new List <AverageValue>();
            var overcast = new List <AverageValue>();
            var wind     = new List <AverageValue>();

            DateTime[] ignoredDates = new DateTime[] { new DateTime(2018, 11, 03), new DateTime(2018, 11, 11),
                                                       new DateTime(2018, 11, 14), new DateTime(2019, 01, 02), new DateTime(2019, 01, 03), new DateTime(2019, 01, 04),
                                                       new DateTime(2019, 01, 05), new DateTime(2019, 01, 06), new DateTime(2019, 01, 07) };
            foreach (var item in globalHistoryData.Wind)
            {
                if (ignoredDates.Contains(item.Hour.Date))
                {
                    continue;
                }
                wind.Add(new AverageValue {
                    Hour  = item.Hour,
                    Value = globalHistoryData.Wind.First(x => x.Hour == item.Hour).Value
                });
                overcast.Add(new AverageValue {
                    Hour  = item.Hour,
                    Value = globalHistoryData.Overcast.First(x => x.Hour == item.Hour).Value
                });
                boiler.Add(new AverageValue {
                    Hour  = item.Hour,
                    Value = localHistoryData.Boiler
                            .Where(x => x.Hour <= item.Hour.AddHours(2) && x.Hour >= item.Hour.AddHours(-2))
                            .Average(x => x.Value)
                });
                outdoor.Add(new AverageValue {
                    Hour  = item.Hour,
                    Value = localHistoryData.Outdoor
                            .Where(x => x.Hour <= item.Hour.AddHours(2) && x.Hour >= item.Hour.AddHours(-2))
                            .Average(x => x.Value)
                });
                indoor.Add(new AverageValue {
                    Hour  = item.Hour,
                    Value = localHistoryData.Indoor
                            .Where(x => x.Hour <= item.Hour.AddHours(2) && x.Hour >= item.Hour.AddHours(-2))
                            .Average(x => x.Value)
                });
            }
            var result = new double[wind.Count, 5];

            for (int i = 0; i < wind.Count; i++)
            {
                result[i, 0] = (outdoor[i].Value - OutdoorLover) / (OutdoorHight - OutdoorLover);
                result[i, 1] = (indoor[i].Value - IndoorLover) / (IndoorHight - IndoorLover);
                result[i, 2] = ((overcast[i].Hour.TimeOfDay.Hours > 8 && overcast[i].Hour.TimeOfDay.Hours < 16 ? SunHihg - overcast[i].Value : 0) - SunLover) / (SunHihg - SunLover);
                result[i, 3] = (wind[i].Value - WindLover) / (WindHigh - WindLover);
                result[i, 4] = (boiler[i].Value - BoilerLover) / (BoilerHight - BoilerLover);
            }
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Улица; Дом; Солнце; Ветер; Котел");
            for (int i = 0; i < wind.Count; i++)
            {
                sb.AppendLine($"{result[i, 0]};{result[i, 1]};{result[i, 2]};{result[i, 3]};{result[i, 4]}");
            }
            File.WriteAllText(@"d:\out.csv", sb.ToString());
        }