1
|
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
|
Console.WriteLine(values);
|
69
|
Console.WriteLine(recordedAmount[0]);
|
70
|
|
71
|
WeatherInfo dayInfo = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range);
|
72
|
weatherInfo.Add(dayInfo);
|
73
|
|
74
|
recordedAmount = new double[4];
|
75
|
lastStartDay = date;
|
76
|
values = 0;
|
77
|
}
|
78
|
|
79
|
// tady nasčítávát data
|
80
|
recordedAmount[0] += list[i].temp;
|
81
|
recordedAmount[1] += list[i].rain;
|
82
|
recordedAmount[2] += list[i].wind;
|
83
|
recordedAmount[3] += list[i].lum * 1000;
|
84
|
values++;
|
85
|
}
|
86
|
|
87
|
WeatherInfo dayInfo2 = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range);
|
88
|
weatherInfo.Add(dayInfo2);
|
89
|
|
90
|
return weatherInfo;
|
91
|
}
|
92
|
|
93
|
private static List<JisInfo> ProcessOneWeatherFileAsIntervals(string path, int interval)
|
94
|
{
|
95
|
throw new NotImplementedException();
|
96
|
}
|
97
|
}
|
98
|
}
|