-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamPrediction.cs
More file actions
95 lines (77 loc) · 2.44 KB
/
StreamPrediction.cs
File metadata and controls
95 lines (77 loc) · 2.44 KB
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
95
using System;
namespace LiveSplit.TwitchPredictions
{
internal class StreamPrediction
{
public enum PredictionStatus
{
RESOLVED,
ACTIVE,
CANCELED,
LOCKED
}
internal class StreamPredictionOutcome
{
public string ID { get; private set; }
public string Title { get; private set; }
internal StreamPredictionOutcome()
{
ID = "";
Title = "";
}
public static StreamPredictionOutcome[] Convert(object nodeRef)
{
var node = (dynamic)nodeRef;
var returnNode1 = new StreamPredictionOutcome();
var returnNode2 = new StreamPredictionOutcome();
var subNode1 = node[0];
var subNode2 = node[1];
returnNode1.ID = subNode1["id"];
returnNode1.Title = subNode1["title"];
returnNode2.ID = subNode2["id"];
returnNode2.Title = subNode2["title"];
return new StreamPredictionOutcome[] { returnNode1, returnNode2 };
}
}
internal string ID { get; private set; }
internal PredictionStatus Status { get; private set; }
internal string Title { get; private set; }
internal StreamPredictionOutcome FirstOutcome { get; private set; }
internal StreamPredictionOutcome SecondOutcome { get; private set; }
internal DateTime CreateAt { get; private set; }
internal DateTime? LockedAt { get; private set; }
internal DateTime? EndedAt { get; private set; }
internal int PredictionWindow { get; private set; }
internal StreamPrediction()
{
ID = "";
Status = PredictionStatus.RESOLVED;
Title = "";
FirstOutcome = new StreamPredictionOutcome();
SecondOutcome = new StreamPredictionOutcome();
CreateAt = DateTime.MinValue;
LockedAt = null;
EndedAt = null;
PredictionWindow = 120;
}
public static StreamPrediction ConvertNode(object nodeRef)
{
var node = (dynamic)nodeRef;
var obj = new StreamPrediction();
obj.ID = node["id"];
obj.Status = Enum.Parse(typeof(PredictionStatus), node["status"]);
obj.Title = node["title"];
if (DateTime.TryParse(node["created_at"], out DateTime output1))
obj.CreateAt = output1;
if (DateTime.TryParse(node["ended_at"], out DateTime output2))
obj.EndedAt = output2;
if (DateTime.TryParse(node["locked_at"], out DateTime output3))
obj.LockedAt = output3;
obj.PredictionWindow = node["prediction_window"];
var predictionResults = StreamPredictionOutcome.Convert(node["outcomes"]);
obj.FirstOutcome = predictionResults[0];
obj.SecondOutcome = predictionResults[1];
return obj;
}
}
}