public void ReadFromFile(string filename, out List <PupilDiameterRecord> tobiiList) { tobiiList = new List <PupilDiameterRecord>(); char separator = '\n'; char delimiter = '\t'; int N_timestampCol = 0, N_PupilDiameterLeftCol = 0, N_PupilDiameterRightCol = 0; long i = 0; using (StreamReader rd = new StreamReader(new FileStream(filename, FileMode.Open))) { string[] first_string_arr = { "" }; first_string_arr = rd.ReadLine().Split(delimiter); N_timestampCol = SearchColFirst(first_string_arr, "Recording timestamp"); N_PupilDiameterLeftCol = SearchColFirst(first_string_arr, "Pupil diameter left"); N_PupilDiameterRightCol = SearchColFirst(first_string_arr, "Pupil diameter right"); bool EndOfFile = false; while (!EndOfFile) { string[] str_arr = { "" }; string big_str = ""; EndOfFile = ReadPartOfFile(rd, out big_str); str_arr = big_str.Split(separator); foreach (string s in str_arr) { string[] tmp = { "" }; i++; tmp = s.Split(delimiter); if (tmp.Count() < 3) { continue; } PupilDiameterRecord PDR = new PupilDiameterRecord(); if (!long.TryParse(tmp[N_timestampCol], out PDR.time_ms)) { throw new Exception("Не могу преобразовать в timestamp строку " + tmp[N_timestampCol]); } if (!double.TryParse(tmp[N_PupilDiameterLeftCol], out PDR.DiameterLeft) && tobiiList.Count > 0) { PDR.DiameterLeft = tobiiList.Last().DiameterLeft; } if (!double.TryParse(tmp[N_PupilDiameterRightCol], out PDR.DiameterRight) && tobiiList.Count > 0) { PDR.DiameterRight = tobiiList.Last().DiameterRight; } tobiiList.Add(PDR); } } } }
private static void ParseInDirectory_SpecialGazeParams(string file_csv) { TobiiPupilDiametersCsvReader PDreader = new TobiiPupilDiametersCsvReader(); List <PupilDiameterRecord> PDrecords; PDreader.ReadFromFile(file_csv, out PDrecords); double PupilAvgDiameterLeft, PupilAvgDiameterRight; PupilDiameterRecord.GetAvgDiametersInList(PDrecords, out PupilAvgDiameterLeft, out PupilAvgDiameterRight); List <EyeMovementEventRecord> EMErecords; TobiiEyeMoveventEventsCsvReader EMEreader = new TobiiEyeMoveventEventsCsvReader(); string Date, Time; long fulltime_ms; EMEreader.ReadFromFile(file_csv, out EMErecords, out Time, out Date, out fulltime_ms); var fixations = from i in EMErecords where i.Type == EyeMovementType.Fixation select i; var saccades = from i in EMErecords where i.Type == EyeMovementType.Saccade select i; var searches = from i in EMErecords where i.Type == EyeMovementType.Search select i; double FixationsDurationSumm = fixations.Sum(n => n.duraion_ms); double SaccadesDurationSumm = saccades.Sum(n => n.duraion_ms); double SearchesDurationSumm = searches.Sum(n => n.duraion_ms); double FixationsPercent = FixationsDurationSumm / fulltime_ms; double SaccadesPercent = SaccadesDurationSumm / fulltime_ms; double SearchesPercent = SearchesDurationSumm / fulltime_ms; Console.WriteLine("{0} ......... {1:f1}-{2:f1} .... {3:d} ... {4} {5} .. {6:d}", Path.GetFileName(file_csv), PupilAvgDiameterLeft, PupilAvgDiameterRight, EMErecords.Count, Date, Time, fulltime_ms); Console.WriteLine("fix {0:f1} {3:p1} sac {1:f1} {4:p1} search{2:f1} {5:p1}", FixationsDurationSumm, SaccadesDurationSumm, SearchesDurationSumm, FixationsPercent, SaccadesPercent, SearchesPercent); using (StreamWriter wr = new StreamWriter(new FileStream(@"C:\__\SpecialParams.csv", FileMode.Append))) { wr.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}", Path.GetFileNameWithoutExtension(file_csv), Date, Time, PupilAvgDiameterLeft, PupilAvgDiameterRight, FixationsPercent, SaccadesPercent, SearchesPercent, FixationsDurationSumm, SaccadesDurationSumm, SearchesDurationSumm, fixations.Count(), saccades.Count(), searches.Count(), fulltime_ms, EMErecords.Count() ); } }