internal static void ParseAllTxtToUnionTable(string mainDir)
        {
            List <TxtFileResult> txtFileResults = new List <TxtFileResult>();

            string[] files = Directory.GetFiles(mainDir, "*.txt", SearchOption.AllDirectories);



            foreach (string fullfilepath in files)
            {
                char separator     = '\n';
                char delimiter     = '\t';
                char separatorDirs = '\\';

                TxtFileResult txtFileResult = new TxtFileResult();

                string filepath = Path.GetFileName(fullfilepath);
                string dir      = Path.GetDirectoryName(fullfilepath);


                string dirToTagsTmp = dir.Replace(mainDir, "");
                txtFileResult.tags = dirToTagsTmp.Split(separatorDirs).ToList();

                int N_pos = filepath.IndexOf("№"); // ищем позицию номера
                txtFileResult.OrderNumber = filepath.Substring(N_pos, 3);

                txtFileResult.filename = filepath;


                using (StreamReader rd = new StreamReader(new FileStream(fullfilepath, FileMode.Open)))
                {
                    string[] str_arr = { "" };
                    string   big_str = "";
                    TobiiCsvReader.ReadPartOfFile(rd, out big_str); // TODO: я расчитываю что файл режимов будет меньше 10000 строк
                    str_arr = big_str.Split(separator);

                    int i = 0;

                    for (i = 0; i < str_arr.Length; i++)
                    {
                        if (str_arr[i] == "")
                        {
                            continue;
                        }
                        string[] tmp = { "" };
                        tmp = str_arr[i].Split(delimiter);
                        int      timeInMs          = int.Parse(tmp[0]) * 3_600_000 + int.Parse(tmp[1]) * 60_000 + int.Parse(tmp[2]) * 1000 + int.Parse(tmp[3]);
                        TimeSpan timeOfCurFixation = TimeSpan.FromMilliseconds(timeInMs);

                        txtFileResult.tobiiRecords.Add(new TobiiRecord()
                        {
                            time_ms = timeInMs, CurFZone = int.Parse(tmp[4])
                        });
                    }
                }
                txtFileResults.Add(txtFileResult);
            }

            WriteTxtFileResultAsync(@"C:\_\1.csv", txtFileResults);
        }
        //Файл ZonesInterpretation.txt у меня такого формата
        //  -1	    ?
        //  0	    ?
        //  1	    Курс
        //  2	    АГ
        //  3	    Вариометр
        //  4	    Внекаб.обст.
        //  5       Высота
        //  6	    Перегрузка
        //  7	    Скорость
        //  8	    Угол атаки
        //  9	    ПЛТ другое
        //  10	    ИКШ-Скорость
        //  11	    ИКШ-Высота
        //  12	    ИКШ-Авиагоризонт
        //  13	    Другое

        /// <summary>
        /// Читает файл с интерпретацией зон - перевод номеров зон в их названия
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static Dictionary <string, string> ReadZonesInterpretation(string filename)
        {
            Dictionary <string, string> ZonesInterpretation = new Dictionary <string, string>();

            using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open)))
            {
                char     separator = '\n';
                char     delimiter = '\t';
                string[] str_arr   = { "" };
                string   big_str   = "";
                TobiiCsvReader.ReadPartOfFile(rd, out big_str);
                str_arr = big_str.Split(separator);

                int i = 0;
                for (i = 0; i < str_arr.Length; i++)
                {
                    if (str_arr[i] == "")
                    {
                        continue;
                    }
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);

                    ZonesInterpretation.Add(tmp[0], tmp[1]);
                }
            }
            return(ZonesInterpretation);
        }
        private static void ParseInDirectory_WithoutKAndRFiles(string dir, string file_csv, string tab2File, int NZones, string kadrDefault = "")
        {
            TobiiCsvReader     tobiiCsvReader = new TobiiCsvReader();
            List <TobiiRecord> tobiiRecords   = new List <TobiiRecord>();

            tobiiCsvReader.TobiiCSCRead(file_csv, tobiiRecords, NZones);
            List <TobiiRecord> FiltredTobiiList = tobiiCsvReader.CompactTobiiRecords(tobiiRecords);
            TabOfKeys          tabOfKeys        = ExcelReader.ReadTabOfKeys(tab2File, "B");

            Regex           regex   = new Regex(@"id\d{3}");
            MatchCollection matches = regex.Matches(Path.GetFileName(file_csv));

            if (matches.Count > 1 || matches.Count == 0)
            {
                MessageBox.Show("В имени файла " + file_csv + " найдено неверное кол-во id (0 или более 1)"); return;
            }
            string FileId = matches[0].Value.Replace("id", "");


            FZoneTab           fZoneTab  = new FZoneTab();
            List <TobiiRecord> FZoneList = fZoneTab.Calculate(FiltredTobiiList, tabOfKeys);

            FZoneList = tobiiCsvReader.ClearFromGarbageZone(FZoneList, -1, FixationAddition);
            FZoneList = tobiiCsvReader.CompactTobiiRecords(FZoneList, "FZones");

            fZoneTab.WriteResult(file_csv.Replace(".csv", ".txt"), FZoneList);
        }
Exemple #4
0
        public Dictionary <string, long> ReadSyncToIdToDictionary(string filename)
        {
            Dictionary <string, long> SyncToIDDict = new Dictionary <string, long>();

            using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open)))
            {
                char     separator = '\n';
                char     delimiter = '\t';
                string[] str_arr   = { "" };
                string   big_str   = "";
                TobiiCsvReader.ReadPartOfFile(rd, out big_str);
                str_arr = big_str.Split(separator);

                int i = 0;
                for (i = 0; i < str_arr.Length; i++)
                {
                    if (str_arr[i] == "")
                    {
                        continue;
                    }
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);
                    SyncToIDDict.Add(tmp[0], long.Parse(tmp[1]));
                }
            }
            return(SyncToIDDict);
        }
Exemple #5
0
        public List <SaccadesCountOnInerval> ReadTxtToSaccadesCountOnInervalListSaccades(string filename)
        {
            List <SaccadesCountOnInerval> saccadesRecords = new List <SaccadesCountOnInerval>();

            using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open)))
            {
                char     separator = '\n';
                char     delimiter = '\t';
                string[] str_arr   = { "" };
                string   big_str   = "";
                TobiiCsvReader.ReadPartOfFile(rd, out big_str);
                str_arr = big_str.Split(separator);

                int i = 0;
                for (i = 0; i < str_arr.Length; i++)
                {
                    if (str_arr[i] == "")
                    {
                        continue;
                    }
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);

                    SaccadesCountOnInerval saccadesRecord = new SaccadesCountOnInerval();
                    saccadesRecord.time_beg      = int.Parse(tmp[0]);
                    saccadesRecord.time_end      = int.Parse(tmp[1]);
                    saccadesRecord.SaccadesCount = int.Parse(tmp[2]);

                    saccadesRecords.Add(saccadesRecord);
                }
            }
            return(saccadesRecords);
        }
Exemple #6
0
        public List <TobiiRecord> ReadTxtToTobiiRecordListZones5Hz(string filename)
        {
            List <TobiiRecord> tobiiRecords = new List <TobiiRecord>();

            using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open)))
            {
                char     separator = '\n';
                char     delimiter = '\t';
                string[] str_arr   = { "" };
                string   big_str   = "";
                TobiiCsvReader.ReadPartOfFile(rd, out big_str);
                str_arr = big_str.Split(separator);

                int i = 0;
                for (i = 0; i < str_arr.Length; i++)
                {
                    if (str_arr[i] == "")
                    {
                        continue;
                    }
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);

                    TobiiRecord tobiiRecord = new TobiiRecord();
                    tobiiRecord.time_ms  = int.Parse(tmp[0]);
                    tobiiRecord.CurFZone = int.Parse(tmp[1]);

                    tobiiRecords.Add(tobiiRecord);
                }
            }
            return(tobiiRecords);
        }
        private static async void RFilesGenerateInDirectory(string MainDir, string dir, string file_csv, string file_reg)
        {
            TobiiCsvReader  tobiiCsvReader = new TobiiCsvReader();
            List <Interval> Intervals      = new List <Interval>();

            Intervals = tobiiCsvReader.TobiiIntervalRead(file_csv);

            Interval.WriteResult(file_csv.Replace(".csv", ".txt"), Intervals);
            string mainFileName = Path.Combine(MainDir, "RFile.txt");

            Interval.AppendWriteResultAsync(mainFileName, Intervals, file_csv);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List <KadrInTime> kadrInTimes = ExcelReader.ReadKadrSets(@"C:\tmp\1.xlsx");

            foreach (var item in kadrInTimes)
            {
                TextBox1.Text += item.ToString() + Environment.NewLine;
            }
            TobiiCsvReader tobiiCsvReader = new TobiiCsvReader();

            string filename = @"C:\tmp\22.csv";

            tobiiCsvReader.tobiiList        = new List <TobiiRecord>(500000);
            tobiiCsvReader.FiltredTobiiList = new List <TobiiRecord>();
            tobiiCsvReader.TobiiCSCRead(filename, tobiiCsvReader.tobiiList);
        }
        public static void ParseInDirectory(string dir, string file_csv, string tab2File, int NZones)
        {
            TobiiCsvReader     tobiiCsvReader = new TobiiCsvReader();
            List <TobiiRecord> tobiiRecords   = new List <TobiiRecord>();

            tobiiCsvReader.TobiiCSCRead(file_csv, tobiiRecords, NZones);
            List <TobiiRecord> FiltredTobiiList = tobiiCsvReader.CompactTobiiRecords(tobiiRecords);
            TabOfKeys          tabOfKeys        = ExcelReader.ReadTabOfKeys(tab2File, "T");
            FZoneTab           fZoneTab         = new FZoneTab();

            List <TobiiRecord> FZoneList = fZoneTab.Calculate(FiltredTobiiList, tabOfKeys);

            FZoneList = tobiiCsvReader.ClearFromGarbageZone(FZoneList, -1, 500);
            FZoneList = tobiiCsvReader.CompactTobiiRecords(FZoneList, "FZones");

            fZoneTab.WriteResult(file_csv.Replace(".csv", ".txt"), FZoneList);
        }
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            TobiiCsvReader     tobiiCsvReader = new TobiiCsvReader();
            List <TobiiRecord> tobiiRecords   = new List <TobiiRecord>();

            tobiiCsvReader.TobiiCSCRead(@"C:\_\1\1.csv", tobiiRecords);
            List <TobiiRecord> FiltredTobiiList = tobiiCsvReader.CompactTobiiRecords(tobiiRecords);
            TabOfKeys          tabOfKeys        = ExcelReader.ReadTabOfKeys(@"C:\_\Tab2new.xlsx");
            List <KadrInTime>  kadrInTimes      = ExcelReader.ReadKadrSets(@"C:\_\1\1_k.xls");
            FZoneTab           fZoneTab         = new FZoneTab();

            fZoneTab.Calculate(FiltredTobiiList, kadrInTimes, tabOfKeys);
            fZoneTab.FZoneList = tobiiCsvReader.ClearFromGarbageZone(fZoneTab.FZoneList, -1, 500);
            fZoneTab.WriteResult(@"C:\tmp\1\1.txt");

            List <Interval> intervals       = ExcelReader.SeparatorIntervalsReadFromExcel(@"C:\_\1\1_reg.xls");
            ResultSeparator resultSeparator = new ResultSeparator(@"C:\_\1\reg\", intervals, fZoneTab.FZoneList, "1");

            resultSeparator.Separate();
        }
        public static void ParseInDirectory(string dir, string file_csv, string file_k, string file_reg, string tab2File)
        {
            TobiiCsvReader     tobiiCsvReader = new TobiiCsvReader();
            List <TobiiRecord> tobiiRecords   = new List <TobiiRecord>();

            tobiiCsvReader.TobiiCSCRead(file_csv, tobiiRecords);
            List <TobiiRecord> FiltredTobiiList = tobiiCsvReader.CompactTobiiRecords(tobiiRecords);
            TabOfKeys          tabOfKeys        = ExcelReader.ReadTabOfKeys(tab2File);
            List <KadrInTime>  kadrInTimes      = ExcelReader.ReadKadrSets(file_k);
            FZoneTab           fZoneTab         = new FZoneTab();

            fZoneTab.Calculate(FiltredTobiiList, kadrInTimes, tabOfKeys);
            fZoneTab.FZoneList = tobiiCsvReader.ClearFromGarbageZone(fZoneTab.FZoneList, -1, 500);
            fZoneTab.FZoneList = tobiiCsvReader.CompactTobiiRecords(fZoneTab.FZoneList);

            fZoneTab.WriteResult(file_csv.Replace(".csv", ".txt"));

            List <Interval> intervals       = ExcelReader.SeparatorIntervalsReadFromExcel(file_reg);
            ResultSeparator resultSeparator = new ResultSeparator(dir + @"\reg\", intervals, fZoneTab.FZoneList, Path.GetFileName(file_csv).Replace(".csv", "_"));

            resultSeparator.Separate();
        }
Exemple #12
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List <KadrInTime> kadrInTimes = ExcelReader.ReadKadrSets(@"C:\tmp\1.xlsx");

            foreach (var item in kadrInTimes)
            {
                TextBox1.Text += item.ToString() + Environment.NewLine;
            }
            TobiiCsvReader tobiiCsvReader = new TobiiCsvReader();

            string filename = @"C:\tmp\22.csv";

            tobiiCsvReader.tobiiList        = new List <TobiiRecord>(500000);
            tobiiCsvReader.FiltredTobiiList = new List <TobiiRecord>();
            int NZones = 0;

            if (!int.TryParse(TextBoxNZones.Text, out NZones))
            {
                System.Windows.MessageBox.Show("Задайте кол-во зон");
                return;
            }
            tobiiCsvReader.TobiiCSCRead(filename, tobiiCsvReader.tobiiList, NZones);
        }
        private static void ParseInDirectory_OneRegFile(string dir, string file_csv, string file_k, string file_r, string tab2File, int NZones, string kadrDefault = "", string tab2FileLastColumn = "T")
        {
            TobiiCsvReader     tobiiCsvReader = new TobiiCsvReader();
            List <TobiiRecord> tobiiRecords   = new List <TobiiRecord>();

            tobiiCsvReader.TobiiCSCRead(file_csv, tobiiRecords, NZones);
            List <TobiiRecord> FiltredTobiiList = tobiiCsvReader.CompactTobiiRecords(tobiiRecords);
            TabOfKeys          tabOfKeys        = ExcelReader.ReadTabOfKeys(tab2File, tab2FileLastColumn);

            Regex           regex   = new Regex(@"id\d{3}");
            MatchCollection matches = regex.Matches(Path.GetFileName(file_csv));

            if (matches.Count > 1 || matches.Count == 0)
            {
                MessageBox.Show("В имени файла " + file_csv + " найдено неверное кол-во id (0 или более 1)"); return;
            }
            string FileId = matches[0].Value.Replace("id", "");

            KadrIntervals kadrIntervals;

            kadrIntervals = SpecialFor9_41_SCENARY2.GetKadrIntervalsInXmlKFile(file_k, FileId);


            FZoneTab           fZoneTab  = new FZoneTab();
            List <TobiiRecord> FZoneList = fZoneTab.Calculate(FiltredTobiiList, kadrIntervals, tabOfKeys);

            FZoneList = tobiiCsvReader.ClearFromGarbageZone(FZoneList, -1, FixationAddition);
            FZoneList = tobiiCsvReader.CompactTobiiRecords(FZoneList, "FZones");

            fZoneTab.WriteResult(file_csv.Replace(".csv", ".txt"), FZoneList);

            SeparatorIntervals separatorIntervals = SpecialFor9_41_SCENARY2.GetSeparatorIntervalsInXmlKFile(file_r, FileId);

            ResultSeparator resultSeparator = new ResultSeparator(dir + @"\reg\", separatorIntervals.Intervals, FZoneList, Path.GetFileName(file_csv).Replace(".csv", "_"));

            resultSeparator.Separate();
        }
        public void TobiiExelRead(string filename, List <TobiiRecord> tobiiList, int ZoneColCount)
        {
            //считываем данные из Excel файла в двумерный массив
            Excel.Application xlApp = new Excel.Application(); //Excel
            Excel.Workbook    xlWB;                            //рабочая книга
            Excel.Worksheet   xlSht;                           //лист Excel
            xlWB  = xlApp.Workbooks.Open(filename);            //название файла Excel
            xlSht = xlWB.Worksheets[1];                        //название листа или 1-й лист в книге xlSht = xlWB.Worksheets[1];



            int iLastRow    = xlSht.Cells[xlSht.Rows.Count, "A"].End[Excel.XlDirection.xlUp].Row;                   //последняя заполненная строка в столбце А
            int iLastColumn = xlSht.Cells[1, xlSht.Columns.Count].End[Excel.XlDirection.xlToLeft].Column;           ////последний заполненный столбец в строке 1
            var arrData     = (object[, ])xlSht.Range[xlSht.Cells[1, 1], xlSht.Cells[iLastRow, iLastColumn]].Value; //берём данные с листа Excel

            //xlApp.Visible = true; //отображаем Excel
            xlWB.Close(false); //закрываем книгу, изменения не сохраняем
            xlApp.Quit();      //закрываем Excel

            char separator = '\n';
            char delimiter = '\t';

            //int N_timestampCol = 0, N_firstZoneCol = 0;
            //long i = 0;
            //using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open)))
            //{
            string[] first_string_arr = new string[iLastColumn];

            for (int i = 1; i <= iLastColumn; i++)
            {
                first_string_arr[i - 1] = arrData[1, i].ToString();
            }

            var N_timestampCol = TobiiCsvReader.SearchColFirst(first_string_arr, "Recording timestamp");
            var N_firstZoneCol = TobiiCsvReader.SearchColFirst(first_string_arr, "AOI hit [");

            bool EndOfFile = false;

            for (int i = 1; i < iLastRow; i++)
            {
                string[] tmp = new string[iLastColumn];
                for (int j = 0; j < iLastColumn; j++)
                {
                    tmp[j] = arrData[i + 1, j + 1].ToString();
                }
                TobiiRecord TR   = new TobiiRecord();
                var         time = arrData[i + 1, N_timestampCol + 1].ToString();
                if (!long.TryParse(time, out TR.time_ms))
                {
                    throw new Exception($"Не могу преобразовать в timestamp строку  {time}");
                }

                string[] Hits = new string[ZoneColCount];
                try
                {
                    Array.Copy(tmp, N_firstZoneCol, Hits, 0, ZoneColCount);
                }
                catch
                { Console.WriteLine("!!!"); }
                TR.zones = TobiiCsvReader.SearchCol(Hits, "1");
                tobiiList.Add(TR);
            }
            var FiltredTobiiList = new TobiiCsvReader().CompactTobiiRecords(tobiiList);
        }
Exemple #15
0
        internal static List <Interval> SeparatorIntervalsReadFromUnionTxt(string file_reg, string file_csv)
        {
            List <Interval> intervals = new List <Interval>();

            char separator = '\n';
            char delimiter = '\t';

            using (StreamReader rd = new StreamReader(new FileStream(file_reg, FileMode.Open)))
            {
                string[] first_string_arr = { "" };

                string[] str_arr = { "" };
                string   big_str = "";
                TobiiCsvReader.ReadPartOfFile(rd, out big_str); // TODO: я расчитываю что файл режимов будет меньше 10000 строк
                str_arr = big_str.Split(separator);

                int RowFirst = 0, RowLast = 0, i = 0;

                for (i = 0; i < str_arr.Length; i++)
                {
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);

                    if (tmp[0].Contains(file_csv))
                    {
                        int j;
                        RowFirst = i + 1;
                        for (j = RowFirst; j < str_arr.Length; j++)
                        {
                            string[] tmp2 = { "" };
                            tmp2 = str_arr[j].Split(delimiter);
                            if (tmp2[0] == "")
                            {
                                RowLast = j - 1;
                                break;
                            }
                        }
                        break;
                    }
                }

                for (i = RowFirst; i <= RowLast; i++)
                {
                    string[] tmp = { "" };
                    tmp = str_arr[i].Split(delimiter);
                    string Name    = tmp[0].Trim();
                    long   TimeBeg = 0;
                    long   TimeEnd = 0;
                    if (!long.TryParse(tmp[1], out TimeBeg))
                    {
                        MessageBox.Show(" SeparatorIntervalsReadFromUnionTxt - не парсится время " + tmp[1]); return(null);
                    }
                    if (!long.TryParse(tmp[2], out TimeEnd))
                    {
                        MessageBox.Show(" SeparatorIntervalsReadFromUnionTxt - не парсится время " + tmp[1]); return(null);
                    }

                    Interval interval = new Interval(Name, TimeBeg, TimeEnd);
                    intervals.Add(interval);
                }
            }
            return(intervals);
        }