commit 3cb70579932fefec85df2c9ad3affeb6fb376ef2
Author: kacerekz <zuzana.kacerekova@gmail.com>
Date:   Sat May 15 15:03:32 2021 +0200

    Added communication model and XML serialization

diff --git a/Client/Client/Assets/NetworkingTest.cs b/Client/Client/Assets/NetworkingTest.cs
new file mode 100644
index 0000000..632bc51
--- /dev/null
+++ b/Client/Client/Assets/NetworkingTest.cs
@@ -0,0 +1,19 @@
+﻿using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class NetworkingTest : MonoBehaviour
+{
+    // Start is called before the first frame update
+    void Start()
+    {
+        Response response = Response.Randomize();
+        var xml = XmlCommunication.Serialize(response);
+        Debug.Log(xml);
+
+        Request request = Request.Randomize();
+        xml = XmlCommunication.Serialize(request);
+        Debug.Log(xml);
+    }
+
+}
diff --git a/Client/Client/Assets/NetworkingTest.cs.meta b/Client/Client/Assets/NetworkingTest.cs.meta
new file mode 100644
index 0000000..633fb32
--- /dev/null
+++ b/Client/Client/Assets/NetworkingTest.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 660804ddf1eaa76418a412f568b07b8c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
diff --git a/Client/Client/Assets/Scenes/WebGL.unity b/Client/Client/Assets/Scenes/WebGL.unity
index 1298bcf..4a3cd68 100644
--- a/Client/Client/Assets/Scenes/WebGL.unity
+++ b/Client/Client/Assets/Scenes/WebGL.unity
@@ -9971,7 +9971,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: ac0fb3ff0286f974397f0b6b2c3c10ac, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  buildings: []
 --- !u!114 &1446501681
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -10309,13 +10308,14 @@ GameObject:
   serializedVersion: 6
   m_Component:
   - component: {fileID: 1478102839}
+  - component: {fileID: 1478102840}
   m_Layer: 0
   m_Name: NetworkManager
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!4 &1478102839
 Transform:
   m_ObjectHideFlags: 0
@@ -10330,6 +10330,18 @@ Transform:
   m_Father: {fileID: 0}
   m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!114 &1478102840
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1478102838}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 660804ddf1eaa76418a412f568b07b8c, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1 &1483322681
 GameObject:
   m_ObjectHideFlags: 0
diff --git a/Client/Client/Assets/Scripts/Model/Buildings.cs b/Client/Client/Assets/Scripts/Model/Buildings.cs
index cc03684..898dc1f 100644
--- a/Client/Client/Assets/Scripts/Model/Buildings.cs
+++ b/Client/Client/Assets/Scripts/Model/Buildings.cs
@@ -4,22 +4,26 @@ using UnityEngine;
 
 public class Buildings : MonoBehaviour
 {
-    public string[] buildings;
+    public static string[] buildings = new string[] { 
+        "FST+FEK", "FDU", "FAV", "FEL", "REK", "MENZA", "LIB", "CIV", "UNI14", 
+        "DOM", "HUS", "CHOD", "JUNG", "KLAT", "KOLL", "RIEG", "SADY", "SED+VEL", 
+        "TES", "TYL", "KARMA", "KBORY", "KLOCH", "KKLAT" };
+
 
     // Start is called before the first frame update
     void Start()
     {
-        TextAsset file = Resources.Load<TextAsset>("buildings");
-        string[] split = file.ToString().Split('\n');
-        List<string> buildingsTMP = new List<string>();
-
-        foreach (string s in split)
-        {
-            string trimmed = s.Trim();
-            if (trimmed.Length > 0)
-                buildingsTMP.Add(trimmed);
-        }
-
-        buildings = buildingsTMP.ToArray();
+        // TextAsset file = Resources.Load<TextAsset>("buildings");
+        // string[] split = file.ToString().Split('\n');
+        // List<string> buildingsTMP = new List<string>();
+        // 
+        // foreach (string s in split)
+        // {
+        //     string trimmed = s.Trim();
+        //     if (trimmed.Length > 0)
+        //         buildingsTMP.Add(trimmed);
+        // }
+        // 
+        // buildings = buildingsTMP.ToArray();
     }
 }
diff --git a/Client/Client/Assets/Scripts/Model/Date.cs b/Client/Client/Assets/Scripts/Model/Date.cs
index cefbc16..d047af9 100644
--- a/Client/Client/Assets/Scripts/Model/Date.cs
+++ b/Client/Client/Assets/Scripts/Model/Date.cs
@@ -1,11 +1,64 @@
 ﻿using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Xml.Serialization;
+using System;
 
-public class Date
+public class Date : IComparable<Date>
 {
+    [XmlIgnore]
+    public static int MIN_HOUR = 7;
+    [XmlIgnore]
+    public static int MAX_HOUR = 18;
+
+    [XmlElement]
     public int day;
+    
+    [XmlElement]
     public int month;
+    
+    [XmlElement]
     public int year;
+
+    [XmlElement]
     public int hour;
+
+    public static Date Randomize()
+    {
+        Date d = new Date();
+
+        d.day = DateTime.Now.Day;
+        d.month = DateTime.Now.Month;
+        d.year = DateTime.Now.Year;
+        d.hour = UnityEngine.Random.Range(7, 18);
+
+        return d;
+    }
+
+    public Date Clone()
+    {
+        Date clone = new Date();
+        clone.day = day;
+        clone.month = month;
+        clone.year = year;
+        clone.hour = hour;
+        return clone;
+    }
+
+    public int CompareTo(Date other)
+    {
+        if (year < other.year) return -1;
+        if (year > other.year) return 1;
+
+        if (month < other.month) return -1;
+        if (month > other.month) return 1;
+
+        if (day < other.day) return -1;
+        if (day > other.day) return 1;
+
+        if (hour < other.hour) return -1;
+        if (hour > other.hour) return 1;
+
+        return 0;
+    }
 }
diff --git a/Client/Client/Assets/Scripts/Model/DateTimeManager.cs b/Client/Client/Assets/Scripts/Model/DateTimeManager.cs
index 84ee758..fd9ba0a 100644
--- a/Client/Client/Assets/Scripts/Model/DateTimeManager.cs
+++ b/Client/Client/Assets/Scripts/Model/DateTimeManager.cs
@@ -36,6 +36,9 @@ public class DateTimeManager : MonoBehaviour, DateTimeObserver
         currentDate.hour = DateTime.Now.Hour;
         day = DateTime.Now.DayOfWeek;
 
+        if (startDate == null) startDate = currentDate;
+        if (endDate == null) endDate = startDate;
+
         foreach (var observer in observers)
             observer.Notify(startDate, endDate);
     }
diff --git a/Client/Client/Assets/Scripts/Model/Prediction.cs b/Client/Client/Assets/Scripts/Model/Prediction.cs
index 4edfd2e..8559a1c 100644
--- a/Client/Client/Assets/Scripts/Model/Prediction.cs
+++ b/Client/Client/Assets/Scripts/Model/Prediction.cs
@@ -1,9 +1,14 @@
 ﻿using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Xml.Serialization;
 
 public class Prediction
 {
+    [XmlElement]
     public Date dateTime;
+
+    [XmlArray("rushLevels")]
+    [XmlArrayItem("rushLevel")]
     public double[] predictions;
 }
diff --git a/Client/Client/Assets/Scripts/Model/Request.cs b/Client/Client/Assets/Scripts/Model/Request.cs
index 2e3ee2c..0491a76 100644
--- a/Client/Client/Assets/Scripts/Model/Request.cs
+++ b/Client/Client/Assets/Scripts/Model/Request.cs
@@ -1,18 +1,74 @@
 ﻿using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Xml.Serialization;
+using System;
 
+[XmlRoot("Request")]
 public class Request
 {
+    [XmlElement]
     public bool useWeather;
 
+
+    [XmlElement]
     public double temperature;
+    
+    [XmlElement]
     public double wind;
+    
+    [XmlElement]
     public double rain;
+
+    [XmlElement]
     public WeatherCondition weather;
 
+
+    [XmlElement]
     public bool useEndDate;
 
+
+    [XmlElement]
     public Date start;
+
+    [XmlElement]
     public Date end;
+
+
+    public static Request Randomize()
+    {
+        Request r = new Request();
+
+        r.useWeather = (UnityEngine.Random.Range(0f, 1f) < 0.5f) ? true : false;
+
+        if (r.useWeather)
+        {
+            r.temperature = UnityEngine.Random.Range(0f, 40f);
+            r.wind = UnityEngine.Random.Range(0f, 100f);
+            r.rain = UnityEngine.Random.Range(0f, 100f);
+            r.weather = (WeatherCondition)UnityEngine.Random.Range(0, 3);
+        }
+
+        r.start = Date.Randomize();
+
+        r.useEndDate = (UnityEngine.Random.Range(0f, 1f) < 0.5f) ? true : false;
+
+        if (r.useEndDate)
+        {
+            r.end = Date.Randomize();
+            if (r.start.CompareTo(r.end) < 0)
+            {
+                Date tmp = r.start;
+                r.start = r.end;
+                r.end = tmp;
+            }
+            else if (r.start.CompareTo(r.end) == 0) 
+            { 
+                r.useEndDate = false;
+            }
+        }
+
+        return r;
+    }
+
 }
diff --git a/Client/Client/Assets/Scripts/Model/Response.cs b/Client/Client/Assets/Scripts/Model/Response.cs
index 75b39c8..d391ced 100644
--- a/Client/Client/Assets/Scripts/Model/Response.cs
+++ b/Client/Client/Assets/Scripts/Model/Response.cs
@@ -1,9 +1,69 @@
 ﻿using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using System.Xml.Serialization;
+using System.IO;
 
+[XmlRoot("Response")]
 public class Response
 {
+    [XmlElement]
     public int hoursPerSegment;
+
+    [XmlArray("predictions")]
+    [XmlArrayItem("prediction")]
     public Prediction[] predicitons;
+
+    public static Response Randomize()
+    {
+        Response r = new Response();
+
+        r.hoursPerSegment = 3;
+
+        Date start = Date.Randomize();
+        Date end = start.Clone();
+
+        end.day += Random.Range(0, 2);
+        end.hour += Random.Range(0, 18);
+
+        // If end gets generated before start, swap them
+        if (start.day == end.day && start.hour > end.hour)
+        {
+            Date tmp = start;
+            start = end;
+            end = tmp;
+        }
+
+        List<Prediction> predictionList = new List<Prediction>();
+        Date curr = start;
+
+        while (curr.CompareTo(end) <= 0)
+        {
+            Prediction p = new Prediction();
+
+            p.dateTime = curr;
+            p.predictions = new double[Buildings.buildings.Length];
+
+            for (int i = 0; i < p.predictions.Length; i++)
+                p.predictions[i] = Random.Range(-1, 100);
+
+            predictionList.Add(p);
+
+            Date next = curr.Clone();
+            next.hour += r.hoursPerSegment;
+
+            if (next.hour > 18)
+            {
+                next.day++;
+                next.hour = 7;
+            }
+
+            curr = next;
+        }
+
+        r.predicitons = predictionList.ToArray();
+
+        return r;
+    }
+
 }
diff --git a/Client/Client/Assets/Scripts/Model/XmlCommunication.cs b/Client/Client/Assets/Scripts/Model/XmlCommunication.cs
new file mode 100644
index 0000000..62ace79
--- /dev/null
+++ b/Client/Client/Assets/Scripts/Model/XmlCommunication.cs
@@ -0,0 +1,29 @@
+﻿using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using System.Xml.Serialization;
+using System.IO;
+
+public class XmlCommunication
+{
+    public static string Serialize<T>(T toSerialize)
+    {
+        var xml = new XmlSerializer(toSerialize.GetType());
+
+        using (var stream = new StringWriter())
+        {
+            xml.Serialize(stream, toSerialize);
+            return stream.ToString();
+        }
+    }
+
+    public static T Deserialize<T>(T toDeserialize, string xmlString)
+    {
+        using (var stream = new StringReader(xmlString))
+        {
+            var xml = new XmlSerializer(toDeserialize.GetType());
+            T deserialized = (T)xml.Deserialize(stream);
+            return deserialized;
+        }
+    }
+}
diff --git a/Client/Client/Assets/Scripts/Model/XmlCommunication.cs.meta b/Client/Client/Assets/Scripts/Model/XmlCommunication.cs.meta
new file mode 100644
index 0000000..e1c1305
--- /dev/null
+++ b/Client/Client/Assets/Scripts/Model/XmlCommunication.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 88ce9ea0438c02546acb5bc75651adb1
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 
