wxr
2022-06-30 af0269cf1d551fb799784df233d8d9c388c6b18b
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class CacDayHistoryPage : FrameLayout
    {
        CacDayHistoryPage bodyView;
        EchartsOption_BrokenLine brokenLine;
        MyEchartsViewOn myEchartsView_Line;
        string curQueryType = "hour";
        string queryTime;
        string functionId;
        string time;
        public CacDayHistoryPage(string functionId,string queryType, string time)
        {
            this.time = time;
            this.functionId = functionId;
            curQueryType = queryType;
            bodyView = this;
            queryTime = time;
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        public void InitView()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.StatisticalChart24Hour)).LoadTopView();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
 
            var contentView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(603),
            };
            bodyView.AddChidren(contentView);
 
            var btnTitle = new Button()
            {
                Height = Application.GetRealHeight(60),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            if(curQueryType == "room_temp")
            {
                btnTitle.Text = queryTime + "室内温度历史数据";
            }
            else
            {
                btnTitle.Text = queryTime + "室内湿度历史数据";
            }
            contentView.AddChidren(btnTitle);
 
 
            var historyDataView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealWidth(52),
                Height = Application.GetRealWidth(350),
            };
            contentView.AddChidren(historyDataView);
 
 
            brokenLine = new EchartsOption_BrokenLine();
 
            myEchartsView_Line = new MyEchartsViewOn()
            {
                Y = Application.GetRealWidth(10),
                Height = Application.GetRealWidth(338),
            };
            historyDataView.AddChidren(myEchartsView_Line);
 
 
#if DEBUG
 
            //List<string> vs = new List<string>() {
            //            "1","2","3","4","5","6","7","8","9","10","11","12","13","14"
            //        };
            //brokenLine.InitXdataText(vs);
            //brokenLine.InitYdataText("yData", new List<EnvironmentalSensorHistor>() {
            //    new EnvironmentalSensorHistor{ fieldName = "1", fieldValue= "23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "2", fieldValue= "22"  },
            //    new EnvironmentalSensorHistor{ fieldName = "3", fieldValue= "-11"  },
            //    new EnvironmentalSensorHistor{ fieldName = "4", fieldValue= "21"  },
            //    new EnvironmentalSensorHistor{ fieldName = "5", fieldValue= "-41"  },
            //    new EnvironmentalSensorHistor{ fieldName = "6", fieldValue= "23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "7", fieldValue= "-31"  },
            //    new EnvironmentalSensorHistor{ fieldName = "8", fieldValue= "-23"  },
            //    new EnvironmentalSensorHistor{ fieldName = "9", fieldValue= "-11"  },
            //    new EnvironmentalSensorHistor{ fieldName = "10", fieldValue= "-21"  },
            //    new EnvironmentalSensorHistor{ fieldName = "11", fieldValue= "24"  },
            //    new EnvironmentalSensorHistor{ fieldName = "12", fieldValue= "41"  },
            //    new EnvironmentalSensorHistor{ fieldName = "13", fieldValue= "32"  },
            //    new EnvironmentalSensorHistor{ fieldName = "14", fieldValue= "23"  }
            //}, "#FF9D54");
            //brokenLine.yTitle = "(℃)";
            //brokenLine.xTitle = "";
            ////if (curQueryType != "hour")
            ////{
            ////    brokenLine.xTitle = Language.StringByID(StringId.Date);
            ////}
            //var opString = brokenLine.InitOption();
 
            //    myEchartsView_Line.ShowWithOption(opString);
 
#endif
            LoadMothed_GetHistoryData();
        }
 
        /// <summary>
        /// 读取历史数据
        /// </summary>
        void LoadMothed_GetHistoryData()
        {
 
            var loadPage = new Loading()
            {
                LodingBackgroundColor = 0x88888888,
            };
            bodyView.AddChidren(loadPage);
 
            new System.Threading.Thread(() =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Start(Language.StringByID(StringId.PleaseWait));
                    });
 
                    var revertObj = new HttpServerRequest().GetSensorHistory("day_hour", functionId, curQueryType,time);
                    if (revertObj != null)
                    {
                        if (revertObj.Code == StateCode.SUCCESS)
                        {
                            var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EnvironmentalSensorHistor>>(revertObj.Data.ToString());
 
                            List<string> vs = new List<string>();
                            if (brokenLine.YvalueText == "")
                            {
                                foreach (var data in revertData)
                                {
                                    vs.Add(data.fieldName);
                                }
                                brokenLine.InitXdataText(vs);
                            }
                            //if (sr.GetAttribute("ydata") == null)
                            //{
                            //    sr.attributes.Add(new FunctionAttributes() { key = "ydata" });
                            //}
                            //sr.SetAttrState("ydata",
                            brokenLine.InitYdataText("", revertData, "#FF9D54");// + ",");
                        }
                    }
                    brokenLine.yTitle = Language.StringByID(StringId.Uint);
                    if(curQueryType == "room_temp")
                    {
                        brokenLine.yTitle += ":°C";
                    }
                    else
                    {
                        brokenLine.yTitle += ":%";
                    }
                    brokenLine.xTitle = Language.StringByID(StringId.timeMode);
                    //if (curQueryType != "hour")
                    //{
                    //    brokenLine.xTitle = Language.StringByID(StringId.Date);
                    //}
                    var opString = brokenLine.InitOption();
 
                    Application.RunOnMainThread(() =>
                    {
                        myEchartsView_Line.ShowWithOption(opString);
                    });
                }
                catch (Exception ex)
                {
                    MainPage.Log($"sensor history error : {ex.Message}");
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loadPage.Hide();
                    });
                }
            })
            { IsBackground = true }.Start();
        }
 
    }
}