예제 #1
0
        private void btnDraw_Click(object sender, EventArgs e)
        {
            var times = cmbAggregation.SelectedItem;

            timespan ts = (timespan)Enum.Parse(typeof(timespan), times.ToString());

            string query = baza.CreateSelectQuery(ts, (int)nmrUnits.Value, false);

            List <string>[] result = new List <string> [4];
            result = baza.Select(query);


            chart1.Series[0].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
            chart1.Series[1].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
            chart1.Series[2].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.DateTime;
            chart1.ChartAreas[0].AxisX.LabelStyle.Format = "g";
            chart1.ChartAreas[1].AxisX.LabelStyle.Format = "g";
            chart1.ChartAreas[2].AxisX.LabelStyle.Format = "g";


            DrawChart(result[0], result[1], result[2], result[3]);
        }
예제 #2
0
        private MyResponse SendWeatherInfo(timespan ts, int count)
        {
            MyResponse resp;

            if (ts == timespan.sample)
            {
                lock (sampleMutex)
                {
                    if (count < dataReceiveds.Count)
                    {
                        DataReceived temp = dataReceiveds[(dataReceiveds.Count - count)];
                        resp = new MyResponse()
                        {
                            Time = (int)temp.timestamp.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, Temperature = temp.temperature, Humidity = temp.humidity, Pressure = temp.pressure
                        };
                    }
                    else
                    {
                        if (dataReceiveds.Count > 0)
                        {
                            DataReceived temp = dataReceiveds[0];
                            resp = new MyResponse()
                            {
                                Time = (int)temp.timestamp.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, Temperature = temp.temperature, Humidity = temp.humidity, Pressure = temp.pressure
                            };
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                return(resp);
            }
            else
            {
                string query = Baza.CreateSelectQuery(ts, count, true);

                List <string>[] result = new List <string> [4];
                result = Baza.Select(query);


                try
                {
                    DateTime lol = DateTime.Parse(result[0][0]);
                    resp             = new MyResponse();
                    resp.Temperature = Convert.ToSingle((result[1][0]));
                    resp.Pressure    = Convert.ToSingle(result[2][0]);
                    resp.Humidity    = Convert.ToSingle(result[3][0]);
                    resp.Time        = (Int32)(lol.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                    return(resp);
                }
                catch (ArgumentNullException ex)
                {
                    return(null);
                    //MessageBox.Show("Brak argumentu " + ex);
                }
                catch (FormatException ex)
                {
                    return(null);
                    //MessageBox.Show("Błąd formatu: " + ex);
                }
                catch (OverflowException ex)
                {
                    return(null);
                    //MessageBox.Show("Błąd przepełnienia " + ex);
                }
            }
        }