Projekt

Obecné

Profil

Stáhnout (1.82 KB) Statistiky
| Větev: | Tag: | Revize:
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Xml.Serialization;
7

    
8
namespace ServerApp.Connection.XMLProtocolHandler
9
{
10
    [XmlRoot("Response")]
11
    public class Response
12
    {
13
        [XmlElement]
14
        public int hoursPerSegment;
15

    
16
        [XmlArray("predictions")]
17
        [XmlArrayItem("prediction")]
18
        public Prediction[] predicitons;
19

    
20
        public static Response Randomize()
21
        {
22
            Response r = new Response();
23
            Random rand = new Random();
24

    
25
            r.hoursPerSegment = 3;
26

    
27
            Date start = Date.Randomize();
28
            Date end = start.Clone();
29

    
30
            end.day += rand.Next(0, 2);
31
            end.hour += rand.Next(0, 18);
32

    
33
            // If end gets generated before start, swap them
34
            if (start.day == end.day && start.hour > end.hour)
35
            {
36
                Date tmp = start;
37
                start = end;
38
                end = tmp;
39
            }
40

    
41
            List<Prediction> predictionList = new List<Prediction>();
42
            Date curr = start;
43

    
44
            while (curr.CompareTo(end) <= 0)
45
            {
46
                Prediction p = new Prediction();
47

    
48
                p.dateTime = curr;
49
                p.predictions = new double[Buildings.buildings.Length];
50

    
51
                for (int i = 0; i < p.predictions.Length; i++)
52
                    p.predictions[i] = rand.Next(-1, 100);
53

    
54
                predictionList.Add(p);
55

    
56
                Date next = curr.Clone();
57
                next.hour += r.hoursPerSegment;
58

    
59
                if (next.hour > 18)
60
                {
61
                    next.day++;
62
                    next.hour = 7;
63
                }
64

    
65
                curr = next;
66
            }
67

    
68
            r.predicitons = predictionList.ToArray();
69

    
70
            return r;
71
        }
72

    
73
    }
74

    
75
}
(5-5/7)