Projekt

Obecné

Profil

Stáhnout (3.5 KB) Statistiky
| Větev: | Tag: | Revize:
1 3811845f Alex Konig
using Parser.InputData;
2
using Parser.OutputInfo;
3
using System;
4
using System.Collections.Generic;
5
using System.IO;
6
7
namespace Parser.Parsers
8
{
9
    class WeatherParser
10
    {
11
        
12
        public List<WeatherInfo> ParseWeatherData(string folder, bool wholeDay = true, int interval = 1)
13
        {
14
            List<WeatherInfo> list = new List<WeatherInfo>();
15
16
            // najít složku, ve složce sou data co se budou parsovat
17
18
            if (!Directory.Exists(folder))
19
                return null;
20
21
            // když v jednej složce budou všechny jis data co chci zpracovat
22
            // pro každej soubor budu spouštět parsování
23
            string[] fileEntries = Directory.GetFiles(folder);
24
            foreach (string fileName in fileEntries)
25
            {
26
                List<WeatherInfo> loadedData = null;
27
                // pokud po jednom dni
28
                if (wholeDay)
29
                    loadedData = ProcessOneWeatherFileAsDays(fileName);
30
                // pokud po hodinách
31
                else
32
                {
33
                    // pokud: konec dne nebo konec aktuálního intervalu -> vemu to co sem nasčítal
34
                    throw new NotImplementedException();
35
                }
36
37
                list.AddRange(loadedData);
38
            }
39
40
            return list;
41
        }
42
43
        private static List<WeatherInfo> ProcessOneWeatherFileAsDays(string path)
44
        {
45
            List<WeatherInfo> weatherInfo = new List<WeatherInfo>();
46
47
            // načíst data ze souboru
48
            List<WeatherInstance> list = CsvDataLoader.LoadWeatherFile(path);
49
50
            //temp, rain, wind, lum
51
            double[] recordedAmount = new double[4];
52
            int[] minmaxHour = new int[] { 7, 18 };
53
            int range = minmaxHour[1] - minmaxHour[0];
54
55
            // procházet data ze souboru
56
            DateTime lastStartDay = new DateTime(list[0].dateTime.Year, list[0].dateTime.Month, list[0].dateTime.Day);
57
            int values = 0;
58
            for (int i = 0; i < list.Count; i++)
59
            {
60
                int currHour = list[i].dateTime.Hour;
61
                if (currHour < minmaxHour[0] || currHour > minmaxHour[1])
62
                    continue;
63
64
                // v každym dni agreguju
65
                DateTime date = new DateTime(list[i].dateTime.Year, list[i].dateTime.Month, list[i].dateTime.Day);
66
                if (!date.Equals(lastStartDay))
67
                {
68
                    WeatherInfo dayInfo = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range); 
69
                    weatherInfo.Add(dayInfo);
70
71
                    recordedAmount = new double[4];
72
                    lastStartDay = date;
73
                    values = 0;
74
                }
75
76
                // tady nasčítávát data
77
                recordedAmount[0] += list[i].temp;
78
                recordedAmount[1] += list[i].rain;
79
                recordedAmount[2] += list[i].wind;
80
                recordedAmount[3] += list[i].lum * 1000;
81
                values++;
82
            }
83
84
            WeatherInfo dayInfo2 = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range); 
85
            weatherInfo.Add(dayInfo2);
86
87
            return weatherInfo;
88
        }
89
90
        private static List<JisInfo> ProcessOneWeatherFileAsIntervals(string path, int interval)
91
        {
92
            throw new NotImplementedException();
93
        }
94
    }
95
}