public void ShowTrack(List<ProccessedTrack> pTracks, int start, int end, int skip)
        {
            this.skip = skip;
            this.start = start;
            this.end = end;
            Track track = new Track();
            foreach (ProccessedTrackItem pi in pTracks[0].ProccessedTrackItems)
            {
                track.AddTrackItem(new TrackItem(pi.OriginalLatitude, pi.OriginalLongitude, pi.MeasureDate));
            }
            FormRoutesInScreenSetting friss = new FormRoutesInScreenSetting(track, pTracks);
            friss.ShowDialog();
            RouteManager manager = friss.RouteManager;
            StringBuilder sb = new StringBuilder(File.ReadAllText(@"DisplayPlugins\HTML\start.txt"));
            foreach (Route route in manager.Routes)
            {
                sb.Append(CreateFragmentFromRoute(route));
            }
            sb.AppendLine("map.setView([" + pTracks[0].ProccessedTrackItems[start].OriginalLatitude.ToString().Replace(',', '.') + "," + pTracks[0].ProccessedTrackItems[start].OriginalLongitude.ToString().Replace(',','.') + "]);");
            sb.Append(File.ReadAllText(@"DisplayPlugins\HTML\end.txt"));
            String fileName = @"DisplayPlugins\HTML\temp.html";

            File.WriteAllText(fileName, sb.ToString().Replace("<title></title>","<title>Сравнение моделей</title>"));
            Process.Start(fileName);
        }
 public ProccessedTrack ProccessTrack(Track track)
 {
     ProccessedTrack pTrack = new ProccessedTrack("Фильтр Калмана",false);
     pTaL = new double[3];
     InitializeP();
     NormalRandom normRand = new NormalRandom();
     aX = Parameters[0].DoubleValue;
     aY = Parameters[1].DoubleValue;
     r = Parameters[2].DoubleValue;
     double predLatForAdd = 0;
     double predLonForAdd = 0;
     for (int i = 0; i < track.TrackItems.Length; i++)
     {
         DateTime date = track.TrackItems[i].Date;
         double[] kTal = new double[2];
         for (int j = 0; j < 2; j++)
         {
             kTal[j] = pTaL[j] / (pTaL[j] + r);
             /*pTaL[j] = (1 - kTal[j]) * pTaL[j];*/
             pTaL[j] -= (pTaL[j] > r) ? r : 0;
         }
         double predLat = predLatForAdd + aX * normRand.Next();
         double predLon = predLonForAdd + aY * normRand.Next();
         predLatForAdd = predLat + kTal[0] * (track.TrackItems[i].Latitude - predLat);
         predLonForAdd = predLon + kTal[1] * (track.TrackItems[i].Longitude - predLon);
         ProccessedTrackItem temp = new ProccessedTrackItem(track.TrackItems[i],predLatForAdd, predLonForAdd);
         pTrack.AddProccessedTrackItem(temp);
     }
     return pTrack;
 }
Пример #3
0
 /// <summary>
 /// получение обработанного трека
 /// </summary>
 /// <param name="track">Исходный трек</param>
 /// <returns>Обработанный трек</returns>
 public ProccessedTrack ProccessTrack(Track track)
 {
     ProccessedTrack pTrack = new ProccessedTrack(Message);
     avg = Parameters[0].IntegerValue;
     TrackItem[] trackItems = track.TrackItems;
     for (int i = 0; i < avg / 2; i++)
     {
         ProccessedTrackItem pItem = new ProccessedTrackItem(trackItems[i], trackItems[i].Latitude, trackItems[i].Longitude);
         pTrack.AddProccessedTrackItem(pItem);
     }
     for (int i = avg / 2; i < trackItems.Length - avg / 2; i++)
     {
         double sumLat = 0;
         double sumLon = 0;
         for (int j = i - avg / 2; j <= i + avg / 2; j++)
         {
             sumLat += trackItems[j].Latitude;
             sumLon += trackItems[j].Longitude;
         }
         sumLat /= avg + (avg + 1) % 2;
         sumLon /= avg + (avg + 1) % 2;
         ProccessedTrackItem pItem = new ProccessedTrackItem(trackItems[i], sumLat, sumLon);
         pTrack.AddProccessedTrackItem(pItem);
     }
     for (int i = trackItems.Length - avg / 2; i < trackItems.Length; i++)
     {
         ProccessedTrackItem pItem = new ProccessedTrackItem(trackItems[i], trackItems[i].Latitude, trackItems[i].Longitude);
         pTrack.AddProccessedTrackItem(pItem);
     }
     return pTrack;
 }
 public FormRoutesInScreenSetting(Track track, List<ProccessedTrack> pTracks)
 {
     this.track = track;
     this.pTracks = pTracks;
     InitializeComponent();
     InitSourceGrid();
     InitSelectedGrid();
 }
 public SequencedTrack SequenceTrack(Track track)
 {
     SequencedTrack seqTrack = new SequencedTrack(track,Message);
     String[] lines = File.ReadAllLines(@"SequencerPlugins\Models\Models.txt");
     String[] num = lines[3].Split(';');
     double numD = Convert.ToDouble(num[1]);
     List<List<double>> models = lines.ToList().ConvertAll(x => x.Split(';').ToList().ConvertAll(y => Convert.ToDouble(y)));
     models.ForEach(x => ApplyModel(x, seqTrack));
     return seqTrack;
 }
Пример #6
0
 public void LoadTrack(string fileName, ref Track track, ref List<ProccessedTrack> pTracks)
 {
     DataSet dataSet = ReadExcelFile(fileName);
     track = ParseDataTable(dataSet.Tables[0]);
     pTracks = new List<ProccessedTrack>();
     for (int i = 2; i < dataSet.Tables.Count; i++)
     {
         pTracks.Add(ParseProccessedDataTable(dataSet.Tables[i]));
     }
 }
 /// <summary>
 /// Создание трека по прогнозу
 /// </summary>
 /// <param name="track">Исходный трек</param>
 /// <returns>Прогнозируемый трек</returns>
 public ProccessedTrack ProccessTrack(Track track)
 {
     avg = Parameters[0].IntegerValue;
     ProccessedTrack res = GetDifferences(track);
     res = GetAvgDifferences(res, track);
     res = GetAverageFromDiffrences(res, track);
     ProccessedTrackItem[] pItems = res.ProccessedTrackItems;
     TrackItem[] trackItems = track.TrackItems;
     ProccessedTrack pTrack = new ProccessedTrack("ARIMAX");
     int vars = Parameters[1].IntegerValue;
     int eqCount = Parameters[2].IntegerValue;
     eqCount = eqCount < vars ? vars : eqCount;
     for (int i = 0; i < vars+eqCount;i++ )
     {
         pTrack.AddProccessedTrackItem(new ProccessedTrackItem(trackItems[i], trackItems[i].Latitude, trackItems[i].Longitude));
     }
     for (int i = vars+eqCount; i < pItems.Length;i++ )
     {
         double[,] mriLat = new double[eqCount, vars];
         double[,] mriLon = new double[eqCount, vars];
         double[] vecLat = new double[eqCount];
         double[] vecLon = new double[eqCount];
         for (int x = 0; x < eqCount; x++)
         {
             for (int y = 0; y < vars; y++)
             {
                 mriLat[x, y] = pItems[i - 2 - x - y].ProccessedLatitude;
                 mriLon[x, y] = pItems[i - 2 - x - y].ProccessedLongitude;
             }
             vecLat[x] = pItems[i - 1 - x].ProccessedLatitude;
             vecLon[x] = pItems[i - 1 - x].ProccessedLongitude;
         }
         double[] coefsLat = Solver.SolveLSM(mriLat, vecLat);
         double[] coefsLon = Solver.SolveLSM(mriLon, vecLon);
         double resLat = 0;
         double resLon = 0;
         if (double.IsNaN(coefsLat[0]) || double.IsNaN(coefsLon[0]))
         {
             resLat = trackItems[i].Latitude;
             resLon = trackItems[i].Longitude;
         }
         else
         {
             for (int count = 0; count < vars; count++)
             {
                 resLat += pItems[i - 1 - count].ProccessedLatitude * coefsLat[count];
                 resLon += pItems[i - 1 - count].ProccessedLongitude * coefsLon[count];
             }
         }
         pTrack.AddProccessedTrackItem(new ProccessedTrackItem(trackItems[i], resLat, resLon));
     }
     return pTrack;
 }
Пример #8
0
 public ProccessedTrack ProccessTrack(Track track)
 {
     ProccessedTrack pTrack = new ProccessedTrack(Message, false);
     foreach (TrackItem item in track.TrackItems)
     {
         double[] vec = new double[] {item.Longitude,item.Latitude };
         double[] newVec = CalcEstimation(vec);
         ProccessedTrackItem pItem = new ProccessedTrackItem(item, newVec[1], newVec[0]);
         pTrack.AddProccessedTrackItem(pItem);
     }
     return pTrack;
 }
 private bool Compare(Track track, int a, int b)
 {
     int i = 0;
     bool equal = true;
     while (equal && i < curLen)
     {
         TrackItem aTemp = track.TrackItems[a + i];
         TrackItem bTemp = track.TrackItems[b + i];
         TrackItem cTemp = track.TrackItems[b + i + 1];
         double dist = DataAnalyzer.GetPointToSegmentDist(aTemp.Latitude, aTemp.Longitude, bTemp.Latitude, bTemp.Longitude, cTemp.Latitude, cTemp.Longitude);
         equal = dist < minDist;
         i++;
     }
     return equal;
 }
 public FormRoutesInScreenSetting(SequencedTrack track, int pos)
 {
     this.track = track.Track;
     this.pTracks = new List<ProccessedTrack>();
     if (RMMap == null)
         RMMap = new RouteManager();
     Route rt = TrackToRoute(track.Track);
     InitializeComponent();
     InitSourceGrid();
     foreach (Sequence seq in track.GetSequence(pos))
     {
         RMMap.CreateAndRoute(rt, seq.Start - 1, seq.End - 1);
         int iRouteSector = dataGridViewSel.Rows.Add(rt.NameOfRoute);
     }
     InitSelectedGrid();
 }
 public SequencedTrack SequenceTrack(Track track)
 {
     curLen = Parameters[0].IntegerValue;
     minDist = Parameters[1].IntegerValue;
     List<MatchCount> seqList = new List<MatchCount>();
     SequencedTrack seqTrack = new SequencedTrack(track, "Прямой поиск");
     for (int i = 0; i < track.TrackItems.Length - curLen - 1; i++)
     {
         List<TrackItem> matches = new List<TrackItem>();
         for (int j = 0; j < track.TrackItems.Length - curLen; j++)
         {
             if (Compare(track, i, j))
                 seqTrack.AddSequence(i, j + 1, curLen);
         }
     }
     return seqTrack;
 }
 private Route TrackToRoute(Track track)
 {
     Route res = new Route("Исходный трек");
     TrackItem[] items = track.TrackItems;
     for (int i = 0; i < items.Length; i++)
     {
         RoutePoint rp = new RoutePoint(items[i].Latitude, items[i].Longitude, items[i].Date, i + 1);
         res.AddPoint(rp);
     }
     return res;
 }
 /// <summary>
 /// Получить трек с разностями
 /// </summary>
 /// <param name="track">Исходный трек</param>
 /// <returns>Трек с разносятми</returns>
 private ProccessedTrack GetDifferences(Track track)
 {
     ProccessedTrack res = new ProccessedTrack("Разности");
     if (track.TrackItems.Length>0)
     {
         res.AddProccessedTrackItem(new ProccessedTrackItem(track.TrackItems[0], track.TrackItems[0].Latitude, track.TrackItems[0].Longitude));
     }
     TrackItem[] trackItems = track.TrackItems;
     for (int i = 1; i < trackItems.Length; i++)
     {
         res.AddProccessedTrackItem(new ProccessedTrackItem(trackItems[i], trackItems[i].Latitude - trackItems[i - 1].Latitude, trackItems[i].Longitude - trackItems[i - 1].Longitude));
     }
     return res;
 }
Пример #14
0
 public SequencedTrack SequenceTrack(Track track)
 {
     SuffixTreeBuilder builder = new SuffixTreeBuilder(track);
     builder.Build();
     return null;
 }
Пример #15
0
 /// <summary>
 /// Загрузка трека по исходны данным
 /// </summary>
 /// <param name="sender">Кнопка</param>
 /// <param name="e">Параметры</param>
 private void loadTrackToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openRawFileDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             statusLabel.Text = "Загрузка...";
             track = RawXlsReader.ReadFromFile(openRawFileDialog.FileName);
             pTracks.Clear();
             showProccessedTrackToolStripMenuItem.DropDownItems.Clear();
             //MessageBox.Show(track.TrackItems.Length.ToString());
             FillTable();
             from = 1;
             to = track.TrackItems.Length;
             statusLabel.Text = "Готово";
             processTrackToolStripMenuItem.Enabled = true;
             foreach (ToolStripDropDownItem item in showOnMapToolStripMenuItem.DropDownItems)
             {
                 item.Enabled = true;
             }
             foreach (ToolStripDropDownItem item in saveFilteredTrackToolStripMenuItem.DropDownItems)
             {
                 item.Enabled = true;
             }
         }
         catch (Exception ex)
         {
             Logger.Error(this.GetType().FullName, ex);
             MessageBox.Show("Не удалось открыть файл, файл либо поврежден, либо неправильного формата");
             statusLabel.Text = "Ошибка";
         }
     }
 }
Пример #16
0
 public void SaveFilteredTrack(Track track, int from, int to, String fileName, bool isVector)
 {
     WriteExcelFile(track, new List<ProccessedTrack>(), fileName, from, to, isVector ? WriteMode.OnlyTrackVector : WriteMode.OnlyTrack);
 }
 private void loadTrackForOpt_Click(object sender, EventArgs e)
 {
     if (openOptimizeDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             track = RawXlsReader.ReadFromFile(openOptimizeDialog.FileName);
             MessageBox.Show("Данные загружены");
         }
         catch (Exception ex)
         {
             Logger.Error(this.GetType().FullName, ex);
             MessageBox.Show("Не удалось открыть файл, файл либо поврежден, либо неправильного формата");
         }
     }
 }
Пример #18
0
 public void SaveTrack(Track track, List<ProccessedTrack> pTracks, string fileName)
 {
     WriteExcelFile(track, pTracks, fileName, -1, -1, WriteMode.Full);
 }
        /// <summary>
        /// Нарисовать оригинаьный трек по датчику
        /// </summary>
        /// <param name="track">Исходный трек</param>
        /// <param name="color">Цвет</param>
        /// <returns>JavaScript код, рисующий линию</returns>
        private String CreateOriginal(Track track, String color)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder markersSB = new StringBuilder();
            sb.Append("L.polyline([");
            int endPos = this.end == 0 ? track.TrackItems.Length : this.end;
            for (int i = this.start-1; i < endPos - 1; i += this.skip)
            {
                TrackItem item = track.TrackItems[i];
                String popupHtml = "Исходный трек: <b>" + (i+1).ToString() + "</b><br/>Широта: <b>" + item.Latitude.ToString() + "</b><br/>Долгота: <b>" + item.Longitude.ToString() + "</b><br/>Время: <b>" + item.Date.ToString() + "</b>";
                markersSB.AppendLine("L.marker([" + item.Latitude.ToString().Replace(',', '.') + ", " + item.Longitude.ToString().Replace(',', '.') + "],{icon:L.divIcon({html:'<div style=\"width:2px;height:2px;font-size:6pt\">" + (i+1).ToString() + "</div>'})}).bindPopup('" + popupHtml + "').addTo(map);");

                sb.Append("[" + item.Latitude.ToString().Replace(',', '.') + ", " + item.Longitude.ToString().Replace(',', '.') + "], ");
            }
            String popupHtmlLast = "Исходный трек: <b>" + (endPos).ToString() + "</b><br/>Широта: <b>" + track.TrackItems[endPos - 1].Latitude.ToString() + "</b><br/>Долгота: <b>" + track.TrackItems[endPos - 1].Longitude.ToString() + "</b><br/>Время: <b>" + track.TrackItems[endPos - 1].Date.ToString() + "</b>";
            markersSB.AppendLine("L.marker([" + track.TrackItems[endPos - 1].Latitude.ToString().Replace(',', '.') + ", " + track.TrackItems[endPos - 1].Longitude.ToString().Replace(',', '.') + "],{icon:L.divIcon({html:'<div style=\"width:2px;height:2px;font-size:6pt\">" + (endPos).ToString() + "</div>'})}).bindPopup('" + popupHtmlLast + "').addTo(map);");
            sb.AppendLine("[" + track.TrackItems[endPos - 1].Latitude.ToString().Replace(',', '.') + ", " + track.TrackItems[endPos - 1].Longitude.ToString().Replace(',', '.') + "]],{color:'" + color + "'}).addTo(map);");
            sb.Append(markersSB.ToString());
            return sb.ToString();
        }
        public void ShowTrack(Track track, int start, int end, int skip)
        {
            this.skip = skip;
            this.start = start;
            this.end = end;
            FormRoutesInScreenSetting friss = new FormRoutesInScreenSetting(track, new List<ProccessedTrack>());
            friss.ShowDialog();
            RouteManager manager = friss.RouteManager;

            StringBuilder sb = new StringBuilder(File.ReadAllText(@"DisplayPlugins\HTML\start.txt"));
            foreach (Route route in manager.Routes)
            {
                sb.Append(CreateFragmentFromRoute(route));
            }
            sb.AppendLine("map.setView([" + track.TrackItems[start].Latitude.ToString().Replace(',', '.') + "," + track.TrackItems[start].Longitude.ToString().Replace(',', '.') + "]);");
            sb.Append(File.ReadAllText(@"DisplayPlugins\HTML\end.txt"));
            String fileName = @"DisplayPlugins\HTML\temp.html";
            File.WriteAllText(fileName, sb.ToString().Replace("<title></title>", "<title>Исходный трек</title>"));
            Process.Start(fileName);
        }
 /// <summary>
 /// Получить трек со средними разносятми
 /// </summary>
 /// <param name="pTrack">Трек с разносятми</param>
 /// <param name="track">Исходный трек</param>
 /// <returns>Трек со средними разносятми</returns>
 private ProccessedTrack GetAvgDifferences(ProccessedTrack pTrack, Track track)
 {
     ProccessedTrackItem[] pItems = pTrack.ProccessedTrackItems;
     ProccessedTrack res = new ProccessedTrack("Средние разности");
     for (int i = 0; i < avg / 2 + 1;i++ )
     {
         res.AddProccessedTrackItem(pItems[i]);
     }
     TrackItem[] trackItems = track.TrackItems;
     for (int i = avg / 2 + 1;i<pItems.Length-avg/2 ; i++)
     {
         double sumLat = 0;
         double sumLon = 0;
         for (int j = i - avg / 2; j <= i + avg / 2; j++)
         {
             sumLat += pItems[j].ProccessedLatitude;
             sumLon += pItems[j].ProccessedLongitude;
         }
         sumLat /= avg;
         sumLon /= avg;
         ProccessedTrackItem pItem = new ProccessedTrackItem(trackItems[i], sumLat, sumLon);
         res.AddProccessedTrackItem(pItem);
     }
     for (int i = trackItems.Length - avg / 2; i < trackItems.Length; i++)
     {
         res.AddProccessedTrackItem(pItems[i]);
     }
     return res;
 }
Пример #22
0
 public SequencedTrack(Track track, String mName)
 {
     this.track = track;
     sequences = track.TrackItems.ToList().ConvertAll(x=>new List<Sequence>());
     methodName = mName;
 }
Пример #23
0
 /// <summary>
 /// Обработать таблицу с треком
 /// </summary>
 /// <param name="dataTable">Таблица</param>
 /// <returns>Трек</returns>
 private Track ParseDataTable(DataTable dataTable)
 {
     DataRow[] dataRows = dataTable.Select();
     Track track = new Track();
     foreach (DataRow row in dataRows)
     {
         double lat = (double)row[1];
         double lon = (double)row[2];
         DateTime date = (DateTime)row[3];
         TrackItem temp = new TrackItem(lat, lon, date);
         track.AddTrackItem(temp);
     }
     track.CalculateVectors();
     return track;
 }
Пример #24
0
        /// <summary>
        /// Записать трек в файл
        /// </summary>
        /// <param name="track">Трек</param>
        /// <param name="pTracks">Обработанные треки</param>
        /// <param name="fileName">Имя файла</param>
        private void WriteExcelFile(Track track, List<ProccessedTrack> pTracks, string fileName, int from, int to, WriteMode wm)
        {
            bool useFilter = wm != WriteMode.Full;
            string connectionString = GetConnectionString(fileName);
            int start = 0;
            int finish = 0;
            int total = 0;
            if (track != null && wm != WriteMode.OnlyTrackVector && wm != WriteMode.OnlyProccessedTrack)
            {
                total += useFilter ? to - from + 1 : track.TrackItems.Length;
            }
            if (track != null && wm != WriteMode.OnlyTrack && wm != WriteMode.OnlyProccessedTrack)
            {
                total += useFilter ? to - from + 1 : track.TrackVectorItems.Length;
            }
            if (wm == WriteMode.Full || wm == WriteMode.OnlyProccessedTrack)
            {
                foreach (ProccessedTrack pTrack in pTracks)
                {
                    if (pTrack.IsVector)
                        total += useFilter ? to - from + 1 : pTrack.ProccessedTrackVectorItems.Length;
                    else
                        total += useFilter ? to - from + 1 : pTrack.ProccessedTrackItems.Length;
                }
            }
            int overAll = 0;
            progress = 0;
            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;
                if (track != null && wm != WriteMode.OnlyTrackVector && wm != WriteMode.OnlyProccessedTrack)
                {

                    cmd.CommandText = "CREATE TABLE [Базовые] (Номер INT, Широта FLOAT, Долгота FLOAT, Дата DATE );";
                    cmd.ExecuteNonQuery();
                    if (useFilter)
                    {
                        start = from - 1;
                        finish = to;
                    }
                    else
                    {
                        start = 0;
                        finish = track.TrackItems.Length;
                    }
                    for (int i = start; i < finish; i++)
                    {
                        TrackItem trackItem = track.TrackItems[i];
                        cmd.CommandText = "INSERT INTO [Базовые] VALUES(" + (i + 1).ToString() + "," + trackItem.Latitude.ToString().Replace(',', '.') + "," + trackItem.Longitude.ToString().Replace(',', '.') + ",'" + trackItem.Date.ToString() + "');";
                        //MessageBox.Show(cmd.CommandText);
                        cmd.ExecuteNonQuery();
                        overAll++;
                        progress = overAll * 100 / total;
                    }

                }
                if (track != null && wm != WriteMode.OnlyTrack && wm != WriteMode.OnlyProccessedTrack)
                {
                    cmd.CommandText = "CREATE TABLE [Вектора] (Номер INT, Широта_в_начале FLOAT, Долгота_в_начале FLOAT, Время_в_начале DATE, Широта_в_конце FLOAT, Долгота_в_конце FLOAT, Время_в_конце DATE, Скорость FLOAT, Продолжительность NVARCHAR(20), Расстояние FLOAT, Направление FLOAT );";
                    cmd.ExecuteNonQuery();
                    if (useFilter)
                    {
                        start = from - 1;
                        finish = to;
                        if (to > track.TrackVectorItems.Length)
                            finish = track.TrackVectorItems.Length;
                    }
                    else
                    {
                        start = 0;
                        finish = track.TrackVectorItems.Length;
                    }
                    for (int i = start; i < finish; i++)
                    {
                        TrackVectorItem trackVectorItem = track.TrackVectorItems[i];
                        cmd.CommandText = "INSERT INTO [Вектора] VALUES(" + (i + 1).ToString() + "," + trackVectorItem.Start.Latitude.ToString().Replace(',', '.') + "," + trackVectorItem.Start.Longitude.ToString().Replace(',', '.') + ",'" + trackVectorItem.Start.Date.ToString() + "'," + trackVectorItem.Finish.Latitude.ToString().Replace(',', '.') + "," + trackVectorItem.Finish.Longitude.ToString().Replace(',', '.') + ",'" + trackVectorItem.Finish.Date.ToString() + "'," + trackVectorItem.Speed.ToString().Replace(',', '.') + ", '" + trackVectorItem.Duration.ToString() + "', " + trackVectorItem.Distance.ToString().Replace(',', '.') + "," + trackVectorItem.Heading.ToString().Replace(',', '.') + ");";
                        //MessageBox.Show(cmd.CommandText);
                        cmd.ExecuteNonQuery();
                        overAll++;
                        progress = overAll * 100 / total;
                    }
                }
                if (wm == WriteMode.Full || wm == WriteMode.OnlyProccessedTrack)
                {
                    foreach (ProccessedTrack pTrack in pTracks)
                    {
                        int cnt = 0;
                        int repCount = 0;
                        while (pTracks[cnt] != pTrack)
                        {
                            repCount += pTracks[cnt].MethodName == pTrack.MethodName ? 1 : 0;
                            cnt++;
                        }
                        String pTrackName = pTrack.MethodName.Replace(' ', '_') + (repCount > 0 ? (repCount + 1).ToString() : "");
                        if (pTrack.IsVector)
                        {
                            cmd.CommandText = "CREATE TABLE [" + pTrackName + "] (Номер INT, Широта_в_начале FLOAT, Долгота_в_начале FLOAT, Время_в_начале DATE, Широта_в_конце FLOAT, Долгота_в_конце FLOAT, Время_в_конце DATE, Продолжительность NVARCHAR(20), Скорость_дачтика FLOAT, Скорость_рассчетная FLOAT, Расстояние_датчика FLOAT,Расстояние_рассчетное FLOAT, Направление_датчика FLOAT, Направление_рассчетное FLOAT );";
                            cmd.ExecuteNonQuery();
                            if (useFilter)
                            {
                                start = from - 1;
                                finish = to;
                                if (to > pTrack.ProccessedTrackVectorItems.Length)
                                    finish = pTrack.ProccessedTrackVectorItems.Length;
                            }
                            else
                            {
                                start = 0;
                                finish = pTrack.ProccessedTrackVectorItems.Length;
                            }
                            for (int i = from - 1; i < pTrack.ProccessedTrackVectorItems.Length; i++)
                            {
                                ProccessedTrackVectorItem pVec = pTrack.ProccessedTrackVectorItems[i];
                                cmd.CommandText = "INSERT INTO [" + pTrackName + "] VALUES(" + (i + 1).ToString() + "," + pVec.StartLatitude.ToString().Replace(',', '.') + "," + pVec.StartLongitude.ToString().Replace(',', '.') + ",'" + pVec.StartDate.ToString() + "'," + pVec.EndLatitude.ToString().Replace(',', '.') + "," + pVec.EndLongitude.ToString().Replace(',', '.') + ",'" + pVec.EndDate.ToString() + "', '" + pVec.Lapse.ToString() + "', " + pVec.OriginalSpeed.ToString().Replace(',', '.') + ", " + pVec.ProccessedSpeed.ToString().Replace(',', '.') + ", " + pVec.OriginalDistance.ToString().Replace(',', '.') + "," + pVec.ProccessedDistance.ToString().Replace(',', '.') + "," + pVec.OriginalHeading.ToString().Replace(',', '.') + "," + pVec.ProccessedHeading.ToString().Replace(',', '.') + ");";
                                //MessageBox.Show(cmd.CommandText);
                                cmd.ExecuteNonQuery();
                                overAll++;
                                progress = overAll * 100 / total;
                            }
                        }
                        else
                        {
                            cmd.CommandText = "CREATE TABLE [" + pTrackName + "] (Номер INT, Широта FLOAT, Долгота FLOAT, Дата DATE, Посчитанная_Широта FLOAT, Посчитанная_долгота FLOAT, Расстояние FLOAT );";
                            cmd.ExecuteNonQuery();
                            if (useFilter)
                            {
                                start = from - 1;
                                finish = to;
                                if (to > pTrack.ProccessedTrackItems.Length)
                                    finish = pTrack.ProccessedTrackItems.Length;
                            }
                            else
                            {
                                start = 0;
                                finish = pTrack.ProccessedTrackItems.Length;
                            }
                            for (int i = start; i < finish; i++)
                            {
                                ProccessedTrackItem pItem = pTrack.ProccessedTrackItems[i];
                                cmd.CommandText = "INSERT INTO [" + pTrackName + "] VALUES(" + (i + 1).ToString() + "," + pItem.OriginalLatitude.ToString().Replace(',', '.') + "," + pItem.OriginalLongitude.ToString().Replace(',', '.') + ",'" + pItem.MeasureDate.ToString() + "'," + pItem.ProccessedLatitude.ToString().Replace(',', '.') + "," + pItem.ProccessedLongitude.ToString().Replace(',', '.') + ", " + pItem.Distance.ToString().Replace(',', '.') + ");";
                                //MessageBox.Show(cmd.CommandText);
                                cmd.ExecuteNonQuery();
                                overAll++;
                                progress = overAll * 100 / total;
                            }
                        }
                    }
                }
                /*
                cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(1,'AAAA','2014-01-01');";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(2, 'BBBB','2014-01-03');";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(3, 'CCCC','2014-01-03');";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "UPDATE [table1] SET name = 'DDDD' WHERE id = 3;";
                cmd.ExecuteNonQuery();
                */
                conn.Close();
            }
            progress = 100;
        }
Пример #25
0
        /// <summary>
        /// Обработка набора данных в трек
        /// </summary>
        /// <param name="dataSet">набор данных</param>
        /// <returns>Трек</returns>
        private static Track ParseDataSet(DataSet dataSet, bool hasHeader)
        {
            DataTable dataTable = dataSet.Tables[0];
            DataRow[] rows = dataTable.Select();
            Track res = new Track();
            String latCol = null;
            String lonCol = null;
            String dateCol = null;
            String timeCol = null;
            if (hasHeader)
            {
                latCol = "Latitude";
                lonCol = "Longitude";
                int i = 0;
                while (i < dataTable.Columns.Count && !dataTable.Columns[i].ColumnName.ToLower().Contains("date"))
                    i++;
                if (i < dataTable.Columns.Count)
                    dateCol = dataTable.Columns[i].ColumnName;
                else
                    throw new Exception("Неверный формат файла");
                i = 0;
                while (i < dataTable.Columns.Count && !dataTable.Columns[i].ColumnName.ToLower().Contains("time"))
                    i++;
                if (i < dataTable.Columns.Count)
                    timeCol = dataTable.Columns[i].ColumnName;
                else
                    throw new Exception("Неверный формат файла");
            }
            else
            {
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    String cellVal = dataTable.Rows[0][i].ToString();
                    double testTouble;
                    DateTime testDt;
                    if (double.TryParse(cellVal.Replace(".", ","), out testTouble))
                    {
                        if (latCol == null)
                            latCol = dataTable.Columns[i].ColumnName;
                        else if (lonCol == null)
                            lonCol = dataTable.Columns[i].ColumnName;
                    }
                    else if (DateTime.TryParse(cellVal, out testDt))
                    {
                        if (dateCol == null)
                            dateCol = dataTable.Columns[i].ColumnName;
                        else if (timeCol == null)
                            timeCol = dataTable.Columns[i].ColumnName;
                    }

                }
            }
            foreach (DataRow row in rows)
            {
                double lat = row[latCol] is double ? (double)row[latCol] : double.Parse((row[latCol] as String).Replace('.', ','));
                double lon = row[lonCol] is double ? (double)row[lonCol] : double.Parse((row[lonCol] as String).Replace('.', ','));
                DateTime date = DateTime.Now;
                if (row[dateCol] is DateTime)
                {
                    date = (DateTime)row[dateCol];
                    DateTime time = (DateTime)row[timeCol];
                    date = date.AddHours(time.Hour);
                    date = date.AddMinutes(time.Minute);
                    date = date.AddSeconds(time.Second);
                }
                else
                {
                    date = DateTime.ParseExact(row[dateCol].ToString(), "MM.dd.yyyy", null);
                    DateTime time = DateTime.Parse(row[timeCol].ToString());
                    date = date.AddHours(time.Hour);
                    date = date.AddMinutes(time.Minute);
                    date = date.AddSeconds(time.Second);
                }
                TrackItem tempTrackItem = new TrackItem(lat, lon, date);
                res.AddTrackItem(tempTrackItem);
            }
            return res;
        }
 /// <summary>
 /// Получить среднее скользящее по средним разностям 
 /// </summary>
 /// <param name="pTrack">Трек со средними разностями</param>
 /// <param name="track">Исходный трек</param>
 /// <returns>Трек со средним скользящим</returns>
 private ProccessedTrack GetAverageFromDiffrences(ProccessedTrack pTrack, Track track)
 {
     ProccessedTrackItem[] pItems = pTrack.ProccessedTrackItems;
     ProccessedTrack res = new ProccessedTrack("Среднее из разностей");
     TrackItem[] trackItems = track.TrackItems;
     if (pItems.Length > 0)
     {
         res.AddProccessedTrackItem(pItems[0]);
     }
     for (int i = 1; i < pItems.Length; i++)
     {
         res.AddProccessedTrackItem(new ProccessedTrackItem(trackItems[i], res.ProccessedTrackItems[i - 1].ProccessedLatitude + pItems[i].ProccessedLatitude, res.ProccessedTrackItems[i - 1].ProccessedLongitude + pItems[i].ProccessedLongitude));
     }
     return res;
 }