-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubmissionData.cs
94 lines (84 loc) · 3.39 KB
/
SubmissionData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace IndoorCO2App_Multiplatform
{
public class SubmissionData
{
internal string SensorType { get; set; }
internal string SensorID { get; set; }
internal string NwrType { get; set; }
internal long NwrID { get; set; }
internal string NwrName { get; set; }
internal double NwrLatitude { get; set; }
internal double NwrLongitude { get; set; }
internal long StartTime { get; set; }
internal List<SensorData> SensorData { get; set; }
internal bool OpenWindowsDoors { get; set; }
internal bool VentilationSystem { get; set; }
internal string OccupancyLevel { get; set; }
internal string AdditionalNotes { get; set; }
public SubmissionData(string sensorType, string sensorID, string nwrType, long nwrID, string nwrName, double nwrLat, double nwrLon, long startTime)
{
SensorType = sensorType;
SensorID = sensorID;
NwrType = nwrType;
NwrID = nwrID;
NwrName = nwrName;
StartTime = startTime;
NwrLatitude = nwrLat;
NwrLongitude = nwrLon;
OccupancyLevel = "undefined";
AdditionalNotes = String.Empty;
SensorData = new List<SensorData>();
}
public string ToJson(int rangeSliderMin, int rangeSliderMax)
{
JObject json = new JObject();
int arraySize = ((rangeSliderMax+1) - rangeSliderMin);
string[] ppmArray = new string[arraySize];
string[] timestampArray = new string[arraySize];
if (rangeSliderMin + 1 > SensorData.Count)
{
throw new IndexOutOfRangeException("RangeSliderMin +1 > SensorData Array - this should not happen");
}
if (rangeSliderMax > SensorData.Count)
{
throw new IndexOutOfRangeException("RangeSliderMax +1 > SensorData Array - this should not happen");
}
int arrayIndex = 0;
for (int i = rangeSliderMin; i <= rangeSliderMax; i++)
{
SensorData data = SensorData[i];
ppmArray[arrayIndex] = data.CO2ppm.ToString();
timestampArray[arrayIndex] = data.timeStamp.ToString();
arrayIndex++;
}
OpenWindowsDoors = MainPage.hasOpenWindowsDoors;
VentilationSystem = MainPage.hasVentilationSystem;
AdditionalNotes = MainPage.MainPageSingleton.GetNotesEditorText();
//TODO: =
json["d"] = SensorType.ToString() +"_"+ SensorID;
json["p"] = NwrType;
json["i"] = NwrID;
json["n"] = NwrName;
json["b"] = StartTime;
json["x"] = NwrLongitude; // x = lon
json["y"] = NwrLatitude; // y = lat
json["w"] = OpenWindowsDoors;
json["v"] = VentilationSystem;
json["o"] = OccupancyLevel;
json["a"] = AdditionalNotes;
json["c"] = string.Join(";", ppmArray);
json["t"] = string.Join(";", timestampArray);
return json.ToString();
}
}
public static class Converter
{
public static string ArrayToString(string[] array, string separator)
{
return string.Join(separator, array);
}
}
}