Projekt

Obecné

Profil

Stáhnout (1.86 KB) Statistiky
| Větev: | Tag: | Revize:
1
using System.Collections;
2
using System.Collections.Generic;
3
using UnityEngine;
4
using System.Xml.Serialization;
5
using System.IO;
6

    
7
/// <summary>
8
/// Response data
9
/// 
10
/// Author: kacerekz
11
/// 
12
/// </summary>
13
[XmlRoot("Response")]
14
public class Response
15
{
16
    /// <summary>
17
    /// Hours per prediction segment
18
    /// </summary>
19
    [XmlElement]
20
    public int hoursPerSegment;
21

    
22
    /// <summary>
23
    /// Rush predictions
24
    /// </summary>
25
    [XmlArray("predictions")]
26
    [XmlArrayItem("prediction")]
27
    public Prediction[] predicitons;
28

    
29
    /// <summary>
30
    /// Creates a random response
31
    /// </summary>
32
    /// <returns>A random response</returns>
33
    public static Response Randomize()
34
    {
35
        Response r = new Response();
36

    
37
        r.hoursPerSegment = 3;
38

    
39
        Date start = Date.Randomize();
40
        Date end = start.Clone();
41

    
42
        end.day += Random.Range(0, 2);
43
        end.hour += Random.Range(0, 18);
44

    
45
        // If end gets generated before start, swap them
46
        if (start.day == end.day && start.hour > end.hour)
47
        {
48
            Date tmp = start;
49
            start = end;
50
            end = tmp;
51
        }
52

    
53
        List<Prediction> predictionList = new List<Prediction>();
54
        Date curr = start;
55

    
56
        while (curr.CompareTo(end) <= 0)
57
        {
58
            Prediction p = new Prediction();
59

    
60
            p.dateTime = curr;
61
            p.predictions = new double[Buildings.buildings.Length];
62

    
63
            for (int i = 0; i < p.predictions.Length; i++)
64
                p.predictions[i] = Random.Range(-1, 100);
65

    
66
            predictionList.Add(p);
67

    
68
            Date next = curr.Clone();
69
            next.hour += r.hoursPerSegment;
70

    
71
            if (next.hour > 18)
72
            {
73
                next.day++;
74
                next.hour = 7;
75
            }
76

    
77
            curr = next;
78
        }
79

    
80
        r.predicitons = predictionList.ToArray();
81

    
82
        return r;
83
    }
84

    
85
}
(13-13/16)