Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 8a243ab2

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

re #8962 Fixing bugs in JsonParser.EncompassSunriseSetTimes

Zobrazit rozdíly:

Server/ServerApp/WeatherPredictionParser/JsonParser.cs
189 189
            {
190 190
                WeatherInfo w = Predictions[i];
191 191
                WeatherInfo wNext = Predictions[i + 1];
192
                DateTime sunrise = sunriseTime[index];
193
                DateTime sunset = sunsetTime[index];
194

  
192 195

  
193 196
                // if wNext time < than w time then it is prediction from the next day -> add 24 to correctly calculate timespan
194 197
                int timespan = wNext.startTime.Hour - w.startTime.Hour;
198
                bool intoTwo = false;
195 199
                if (wNext.startTime.Hour < w.startTime.Hour)
196 200
                {
201
                    intoTwo = true;
197 202
                    timespan = (wNext.startTime.Hour + 24) - w.startTime.Hour;
198 203
                }
199 204
                
200 205
                w.intervalLength = timespan;
206
                TimeSpan endTime = new TimeSpan(w.startTime.TimeOfDay.Hours + timespan, w.startTime.TimeOfDay.Minutes, 0);
201 207

  
202 208
                // if start under sunset
203 209
                if (w.startTime.TimeOfDay > sunsetTime[index].TimeOfDay)
204
                    w.condition = WeatherConditions.Dark;
210
                {
211
                    // when is end - if end after next sunrise need to compute the extent of dark
212
                    if (intoTwo && endTime > sunriseTime[index+1].TimeOfDay)
213
                    {
214
                        double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunriseTime[index + 1].Hour * 60 + sunriseTime[index + 1].Minute)) / 60.0;
215
                        howMuch = w.intervalLength - howMuch;
216

  
217
                        if (howMuch >= timespan / 2.0)
218
                            w.condition = WeatherConditions.Dark;
219
                    }
220
                    else
221
                        w.condition = WeatherConditions.Dark;
222
                }
205 223

  
206 224
                // if start under sunrise
207 225
                if (w.startTime.TimeOfDay < sunriseTime[index].TimeOfDay)
208 226
                {
209 227
                    double howMuch = ((sunriseTime[index].Hour * 60 + sunriseTime[index].Minute) - (w.startTime.Hour * 60 + w.startTime.Minute)) / 60.0;
228
                    if (endTime > sunset.TimeOfDay)
229
                        howMuch += ((w.startTime.Hour * 60 + w.startTime.Minute) - (sunset.Hour * 60 + sunset.Minute)) / 60.0;
210 230

  
211 231
                    if (howMuch >= timespan / 2.0)
212 232
                        w.condition = WeatherConditions.Dark;
213 233
                }
214 234

  
215
                // if start under sunrise
216
                TimeSpan endTime = new TimeSpan(w.startTime.TimeOfDay.Hours + timespan, w.startTime.TimeOfDay.Minutes, 0);
217
                if (endTime > sunsetTime[index].TimeOfDay)
235
                // if end over sunset
236
                else if (endTime > sunsetTime[index].TimeOfDay)
218 237
                {
219 238
                    double howMuch = ((endTime.Hours * 60 + endTime.Minutes) - (sunsetTime[index].Hour * 60 + sunsetTime[index].Minute)) / 60.0;
220 239

  
......
228 247

  
229 248
            // last prediction
230 249
            WeatherInfo wLast = Predictions[Predictions.Count - 1];
231
            TimeSpan endTimeW = new TimeSpan(24, 0, 0);
250
            TimeSpan endTimeW = new TimeSpan(23, 59, 59);
232 251
            int timespanLast = 24 - wLast.startTime.Hour;
233 252
            wLast.intervalLength = timespanLast;
234 253

  
......
240 259
            if (wLast.startTime.TimeOfDay < sunriseTime[sunriseTime.Count - 1].TimeOfDay)
241 260
            {
242 261
                double howMuch = ((sunriseTime[sunriseTime.Count - 1].Hour * 60 + sunriseTime[sunriseTime.Count - 1].Minute) - (wLast.startTime.Hour * 60 + wLast.startTime.Minute)) / 60.0;
262
                if (endTimeW > sunsetTime[sunriseTime.Count - 1].TimeOfDay)
263
                    howMuch += ((wLast.startTime.Hour * 60 + wLast.startTime.Minute) - (sunsetTime[sunriseTime.Count - 1].Hour * 60 + sunsetTime[sunriseTime.Count - 1].Minute)) / 60.0;
243 264

  
244 265
                if (howMuch >= timespanLast / 2.0)
245 266
                    wLast.condition = WeatherConditions.Dark;

Také k dispozici: Unified diff