-
Notifications
You must be signed in to change notification settings - Fork 0
/
KP7DayConverter.cs
89 lines (81 loc) · 2.11 KB
/
KP7DayConverter.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeslaInstituteSpaceWeather
{
public class KP7DatConverter : JsonConverter
{
//private readonly Type[] _types;
//public JsonExponentialConverter(params Type[] types)
//{
// _types = types;
//}
public override bool CanRead { get { return true; } }
public override bool CanConvert(Type objectType)
{
return true;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
/*
* time_tag : 20.5.2022. 23:00:00
dst : 0
*/
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
List<Form1.KP7day> list = new List<Form1.KP7day>();
Form1.KP7day item = new Form1.KP7day();
int i = -1;
//while (reader.TokenType != JsonToken.EndObject)
while (reader.Read())
{
//reader.Read();
if (reader.Value != null)
{
string key = reader.Value.ToString();
//Console.Write(key);
// ------------------
//Console.Write(" : ");
reader.Read();
float amount = 0;
string val = "";
if (reader.Value == null)
{
amount = 0;
}
else
{
val = reader.Value.ToString();
//Console.WriteLine(val);
}
//if (float.TryParse(reader.Value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out amount))
{
}
if (reader.Value == null)
{
amount = 0;
}
else
float.TryParse(reader.Value.ToString(), out amount);
if (i % 5 == 0) item.model_prediction_time = DateTime.Parse(val);
if (i % 5 == 1) item.k = amount;
} // end if
//if (i % 5 == 0) list.Add(item);
if (reader.TokenType == JsonToken.EndObject)
{
list.Add(item);
item = new Form1.KP7day();
i = -2;
}
i++;
} // end while
return list;
}
}
}