Beispiel #1
0
        private WindRecord[] InterpolateData(WindRecord[] src)
        {
            List <WindRecord> result = new List <WindRecord>();

            for (int c = 0; c < src.Length; c++)
            {
                var item = src[c];
                result.Add(item);
                if (c < src.Length - 1)
                {
                    var nextItem        = src[c + 1];
                    var intervalMinutes = (nextItem.Date - item.Date).TotalMinutes;
                    for (int i = 1; i < InterpolateMultiplier; i++)
                    {
                        double ratio          = (double)i / InterpolateMultiplier;
                        var    interDate      = item.Date.AddMinutes(intervalMinutes * ratio);
                        var    interDirection = item.Direction + (nextItem.Direction - item.Direction) * ratio;
                        var    interS         = item.Strength + (nextItem.Strength - item.Strength) * ratio;
                        var    iterpolated    = new WindRecord()
                        {
                            Date = interDate, Direction = interDirection, Strength = interS
                        };
                        result.Add(iterpolated);
                    }
                }
            }
            return(result.ToArray());
        }
Beispiel #2
0
        private bool Read(string fn)
        {
            ExcelTableReader reader = new ExcelTableReader();

            if (!reader.Read(fn))
            {
                MessageBox.Show("Не удалось прочитать файл " + fn);
                return(false);
            }

            int c = 0;

            if (reader.Pages.Count > 1)
            {
                string mes = string.Format("Файл '{0}' содержит более одной закладки. Прочитать данные из первой закладки='{1}'?", Path.GetFileName(fn), reader.Pages[0].Name);
                if (MessageBox.Show(mes, "", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return(false);
                }
            }
            c = 0;

            DataTable table = reader.Pages[c].Table;

            if (table.Columns.IndexOf("date") == -1)
            {
                MessageBox.Show("Не найдена колонка date");
                return(false);
            }
            if (table.Columns.IndexOf("direction") == -1)
            {
                MessageBox.Show("Не найдена колонка direction");
                return(false);
            }
            if (table.Columns.IndexOf("strength") == -1)
            {
                MessageBox.Show("Не найдена колонка strength");
                return(false);
            }

            List <WindRecord> data   = new List <WindRecord>();
            List <string>     errors = new List <string>();

            foreach (DataRow row in table.Rows)
            {
                var item = new WindRecord();
                if (!DateTime.TryParse(row["date"].ToString(), out DateTime dt))
                {
                    errors.Add("invalid date:" + row["date"].ToString());
                    continue;
                }
                item.Date = dt;

                if (!double.TryParse(row["direction"].ToString(), out double direction))
                {
                    errors.Add("invalid direction:" + row["direction"].ToString());
                    continue;
                }
                item.Direction = direction;

                if (!double.TryParse(row["strength"].ToString(), out double strength))
                {
                    errors.Add("invalid strength:" + row["strength"].ToString());
                    continue;
                }
                item.Strength = strength;
                data.Add(item);
            }

            Data = data.ToArray();


            return(true);
        }
Beispiel #3
0
    private void update(String location)
    {
        if (location == null)
        {
            // welcome page
            WelcomePage.Visible  = true;
            LocationPage.Visible = false;
            return;
        }

        String dbToUse = "";

        dbToUse = "Surfvind_data";

        WindData wd      = new WindData(true, dbToUse);
        bool     isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]);

        List <Location> loc = Helper.getLocations();

        String imei = location; // getLocation(location, loc).imei.ToString();

        if (imei == null)
        {
            /* Default to something */
            imei = "12345";
        }

        wd.SetImei(imei);

        /* Get pre-stored direction and speed arrows */
        imgSpeed.ImageUrl   = "http://www.surfvind.se/Images/" + imei + "_img_speed.png";
        imgCompass.ImageUrl = "http://www.surfvind.se/Images/" + imei + "_img_compass.png";

        // Set temp images
        //  water_temp.ImageUrl = "http://www.surfvind.se/Images/" + imei + "_img_water_temp.png";
        //  air_temp.ImageUrl = "http://www.surfvind.se/Images/" + imei + "_img_air_temp.png";

        int w_temp;
        int a_temp;

        WindRecord wr = wd.GetCurrentWind();

        w_temp = wr.AverageWaterTemp;
        a_temp = wr.AverageAirTemp;

        //   water_temp.ToolTip = "Water temperature: " + w_temp + " °C";
        //   air_temp.ToolTip = "Air temperature: " + a_temp + " °C";

        /* Set google map location */
        Location loca = getLocation(location, loc);

        setAppletLocation(imei);

        Title_loc.Text = loca.Name;

        Title = "Weather info - ";
        if (loca != null)
        {
            addGMap(loca);
            Title += loca;
        }

        WelcomePage.Visible  = false;
        LocationPage.Visible = true;
    }