Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a53b1de8

Přidáno uživatelem Alex Konig před více než 3 roky(ů)

re #8933 Testing DataParser, JisParser and WeatherParser

Zobrazit rozdíly:

Server/ServerApp/Parser/Parsers/WeatherParser.cs
15 15
    /// Data parsed from 7am (included) to 18pm (included)
16 16
    /// </summary>
17 17
    /// <author>A. Konig</author>
18
    class WeatherParser
18
    public class WeatherParser
19 19
    {
20 20

  
21 21
        /// <summary> Datafile loader  </summary>
......
44 44
        {
45 45
            List<WeatherInfo> list = new List<WeatherInfo>();
46 46

  
47
            if (weatherFiles == null || startTime == null || endTime == null || interval <= 0)
47
            if (weatherFiles == null || interval <= 0)
48 48
                return list;
49 49

  
50 50
            // get all files in folder
......
80 80
        {
81 81
            List<WeatherInfo> weatherInfo = new List<WeatherInfo>();
82 82

  
83
            if (!File.Exists(path))
84
                return weatherInfo;
85

  
86 83
            List<WeatherInstance> list = loader.LoadWeatherFile(path);
84
            if (list == null)
85
                return weatherInfo;
87 86

  
88 87
            // array with data [temp, rain, wind, lum]
89 88
            double[] recordedAmount = new double[4];
......
116 115
                }
117 116

  
118 117
                // if not in allowed time window -> discard
119
                if (list[i].dateTime < startTime|| list[i].dateTime > endTime)
118
                if (list[i].dateTime < startTime || list[i].dateTime > endTime)
119
                {
120 120
                    continue;
121
                }
121 122

  
122 123
                // aggregate data
123 124
                recordedAmount[0] += list[i].temp;
......
125 126
                recordedAmount[2] += list[i].wind;
126 127

  
127 128
                if (ValueToConditions.TransferLuxToConditions(list[i].lum * 1000) != WeatherConditions.Dark)
129
                {
128 130
                    recordedAmount[3] += list[i].lum * 1000; weatherValues++;
131
                }
129 132

  
130 133
                values++;
131 134
            }
132 135

  
133 136
            // data from last day
134
            WeatherInfo dayInfo2 = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / values, range); 
135
            weatherInfo.Add(dayInfo2);
137
            if (values != 0)
138
            {
139
                WeatherInfo dayInfo2 = new WeatherInfo(lastStartDay, recordedAmount[0] / values, (int)(recordedAmount[1] / values * 100), recordedAmount[2] / values, recordedAmount[3] / weatherValues, range);
140
                weatherInfo.Add(dayInfo2);
141
            }
136 142

  
137 143
            return weatherInfo;
138 144
        }
......
149 155
        {
150 156
            List<WeatherInfo> weatherInfo = new List<WeatherInfo>();
151 157

  
152
            if (!File.Exists(path))
153
                return weatherInfo;
154

  
155 158
            List<WeatherInstance> list = loader.LoadWeatherFile(path);
159
            if (list == null)
160
                return weatherInfo;
156 161

  
157 162
            // min/max hour taken into account
158 163
            int[] minmaxHour = new int[] { 7, 18 };
......
169 174
            {
170 175
                to[i] = minmaxHour[0] + interval * (i + 1);
171 176
                data[i] = new double[4];
177
                count[i] = 0;
172 178
            }
173 179

  
174 180
            // first day
......
208 214
                    lastStartTime = date;
209 215
                    count = new int[indices];
210 216
                    for (int l = 0; l < data.Length; l++)
217
                    {
211 218
                        data[l] = new double[4];
219
                        count[l] = 0;
220
                    }
212 221
                }
213 222

  
214 223
                // if not in allowed time window -> discard

Také k dispozici: Unified diff