// Need to return an array of List<Fixation>, and then calculate all features for each // element (slice) of the fixations. // We can either slice by: number of fixations or time period /* * private List<Slice> SliceFixations(List<Fixation> allFixations, int numberOfFixations) { * // go through the array, keeping tracking of teh current count and adding each fixation to the current slide * // when reach numberOfFixations, add current slice to array, then start a new slice * * List<Slice> slices = new List<Slice>(); * List<Fixation> currentSliceFixations = new List<Fixation>(); * RawToFixationConverter converter = new RawToFixationConverter(); * * int count = 0; * * foreach(Fixation fixation in allFixations) { * * count++; * currentSliceFixations.Add(fixation); * * if(count >= numberOfFixations) { * Slice slice = new Slice(); * * slice.fixations = currentSliceFixations; * slice.saccades = converter.GenerateSaccades(currentSliceFixations); * * slices.Add(slice); * currentSliceFixations = new List<Fixation>(); * } * } * * return slices; * } */ // number of slices = total time for fixations in ms / (timePeriod / 2) private List <Slice> SliceFixations(List <Fixation> allFixations, double timePeriod, double step) { List <Slice> slices = new List <Slice>(); RawToFixationConverter converter = new RawToFixationConverter(); double windowStep = step; // This is window step size. // increment some counter by halfTimePeriod until it is < length of all fixations - a single time period Fixation finalFixation = allFixations.Last(); for (double start = 0; start < finalFixation.endTime - timePeriod; start += windowStep) { double windowStart = start; double windowEnd = start + timePeriod; // Get the fixations within this window List <Fixation> fixationsInWindow = GetFixationsInTimePeriod(windowStart, windowEnd, allFixations); // As long as there was at least 3 fixation in that window if (fixationsInWindow.Count > 3) { // Create a new slice with those fixations. Slice slice = new Slice(); slice.fixations = fixationsInWindow; slice.saccades = converter.GenerateSaccades(fixationsInWindow); slices.Add(slice); } } return(slices); }
public string label; //F or B public Saccade(Fixation cur, Fixation next) { duration = next.timestamp - cur.timestamp + cur.duration; timestamp = cur.timestamp + cur.duration; length = Math.Sqrt((next.x - cur.x) * (next.x - cur.x) + (next.y - cur.y) * (next.y - cur.y)); x = cur.x; y = cur.y; idLine = cur.idLine; label = cur.label; }
private double distance(Fixation f1, Fixation f2) { double result = 0; double deltaXSquared = (f2.x - f1.x) * (f2.x - f1.x); double deltaYSquared = (f2.y - f1.y) * (f2.y - f1.y); result = Math.Sqrt(deltaXSquared + deltaYSquared); return(result); }
public void writeCleanFixationsToFile(String rawPath, Fixation fixation) { if (!File.Exists(rawPath)) { File.WriteAllText(rawPath, ""); File.WriteAllText(rawPath, "Stream,X,Y,LSLTimestamp,AdjustedUnix" + Environment.NewLine); } File.AppendAllText(rawPath, "Begin," + fixation.startPos.x + "," + fixation.startPos.y + "," + fixation.startPos.timestamp + "," + (TimeSpan.FromMilliseconds(fixation.startPos.timestamp).Seconds + _mainWindow.unixMSStartTime) + Environment.NewLine); foreach (DataPoint d in fixation.dataPos) { File.AppendAllText(rawPath, "Data," + d.x + "," + d.y + "," + d.timestamp + "," + (TimeSpan.FromMilliseconds(d.timestamp).Seconds + _mainWindow.unixMSStartTime) + Environment.NewLine); } File.AppendAllText(rawPath, "End," + fixation.endPos.x + "," + fixation.endPos.y + "," + fixation.endPos.timestamp + "," + (TimeSpan.FromMilliseconds(fixation.endPos.timestamp).Seconds + _mainWindow.unixMSStartTime) + Environment.NewLine); }
private List <Tuple <int, double> > DistancesFromPointToOtherPoints(System.Windows.Point centre, List <Fixation> fixations) { List <Tuple <int, double> > indexDistanceList = new List <Tuple <int, double> >(); for (int i = 0; i < fixations.Count; i++) { Fixation fixation = fixations[i]; int index = i; double distance = MathNet.Numerics.Distance.Euclidean(new double[] { centre.X, centre.Y }, new double[] { fixation.x, fixation.y }); Tuple <int, double> distanceForFixationIndex = new Tuple <int, double>(index, distance); indexDistanceList.Add(distanceForFixationIndex); } return(indexDistanceList); }
public IActionResult GetFixationsCsv(string video, string watch) { FileInfo f = new FileInfo(Video.Folder + video + "/" + watch); Watch watchObject = new Watch(f.FullName) { Video = new Video() { Name = video } }; var records = watchObject.LoadInfo(); if (!records.Any()) { return(NotFound()); } List <WatchInfoSpeed> list = WatchInfoSpeed.Compile(watchObject, records); var results = Fixation.Compile(watchObject, list.ToArray(), this.FixationThreshold); var filteredResults = results .Where(d => d.Duration > 100) .Where(d => d.Duration < 800) .Where(d => d.AverageEyeSpeed <= 6) .Select(d => new { StartTime = (int)d.StartTime, EndTime = (int)d.EndTime, Duration = (int)d.Duration, d.AverageEyeSpeed, X = (int)d.X, Y = (int)d.Y, }) .ToArray(); using (MemoryStream ms = new MemoryStream()) using (StreamWriter sw = new StreamWriter(ms)) using (CsvWriter writer = new CsvWriter(sw)) { writer.WriteRecords(filteredResults); return(Ok(Encoding.UTF8.GetString(ms.ToArray()))); } }
public static List <Fixation> loadFixationsFromFile(string filePath) { List <Fixation> validFixations = new List <Fixation>(); Fixation f = new Fixation(); f.dataPos = new List <DataPoint>(); string line; StreamReader file = new StreamReader(filePath); bool firstline = true; while ((line = file.ReadLine()) != null) { if (firstline) { firstline = false; continue; } string[] vals = line.Split(','); DataPoint dp = new DataPoint(float.Parse(vals[1]), float.Parse(vals[2]), float.Parse(vals[3])); //add val to list if (vals[0].Equals("Begin")) { f.startPos = dp; } else if (vals[0].Equals("Data")) { f.dataPos.Add(dp); } else if (vals[0].Equals("End")) { f.endPos = dp; f.completeFixation(validFixations.Count); validFixations.Add(f); f = new Fixation(); f.dataPos = new List <DataPoint>(); } } file.Close(); return(validFixations); }
public GazeEventArgs(double x, double y, long timestamp, Fixation fixation, bool scaled) { Timestamp = timestamp; Fixation = fixation; var screenRect = System.Windows.Forms.Screen.PrimaryScreen.Bounds; if (scaled) { Scaled = new Point(x, y); Screen = new Point(screenRect.Left + (Scaled.X * screenRect.Width), screenRect.Top + (Scaled.Y * screenRect.Height)); } else { Screen = new Point(x, y); Scaled = new Point((Screen.X - screenRect.Left) / screenRect.Width, (Screen.Y - screenRect.Top) / screenRect.Height); } }
private Fixation CreateFixation(FixationDataEventType fixationDataEventType, int x, int y) { Fixation fx = null; switch (fixationDataEventType) { case FixationDataEventType.Begin: fx = new Fixation(new Point(x, y), eFixationPhase.start); break; case FixationDataEventType.End: fx = new Fixation(new Point(x, y), eFixationPhase.finished); break; case FixationDataEventType.Data: fx = new Fixation(new Point(x, y), eFixationPhase.data); break; } return(fx); }
// KeyPress event private void TrialForm_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Escape) { StopTrials(); } else if (e.KeyChar == (char)Keys.Space && trialState == 0) { if (true) //if (gazeCentered()) { //Launch trials thread trialsThread = new Thread(new ThreadStart(TrialsRunningThread)) { IsBackground = true }; trialsThread.Start(); //Init tobbi gaze fixationDataStream = MainForm.tobii4C.Streams.CreateFixationDataStream(); fixationDataStream.Begin((x, y, timestamp) => { if (x != 0) { currentFixation = new Fixation(); currentFixation.x = x; currentFixation.y = y; currentFixation.timestamp = timestamp; } }); fixationDataStream.End((x, y, timestamp) => { currentFixation.timespan = timestamp; trialFixations.Add(currentFixation); }); } else { synth.SpeakAsync(fixCenterMsg); } } }
public IActionResult GetFixations(string video, string watch) { FileInfo f = new FileInfo(Video.Folder + video + "/" + watch); Watch watchObject = new Watch(f.FullName) { Video = new Video() { Name = video } }; var records = watchObject.LoadInfo(); if (!records.Any()) { return(NotFound()); } List <WatchInfoSpeed> list = WatchInfoSpeed.Compile(watchObject, records); var results = Fixation.Compile(watchObject, list.ToArray(), this.FixationThreshold); var filteredResults = results .Where(d => d.Duration > 100) .Where(d => d.Duration < 800) .Where(d => d.AverageEyeSpeed <= this.FixationThreshold) .Select(d => new { StartTime = (int)d.StartTime, EndTime = (int)d.EndTime, Duration = (int)d.Duration, AverageEyeSpeed = Math.Round(d.AverageEyeSpeed, 2, MidpointRounding.ToEven), X = (int)d.X, Y = (int)d.Y, }) .ToArray(); return(Ok(filteredResults)); }
private void FixationCore_OnFixationRecord(Fixation fixation) { if (!fixation.IsLocal) { return; } if (DynamicFocusTimes.ContainsKey(fixation.DynamicObjectId)) { //update this key var display = DynamicFocusTimes[fixation.DynamicObjectId]; display.Time += fixation.DurationMs; DynamicFocusTimes[fixation.DynamicObjectId] = display; } else { //add new key to dictionary string name; if (DynamicManager.GetDynamicObjectName(fixation.DynamicObjectId, out name)) { DynamicFocusTimes.Add(fixation.DynamicObjectId, new DynamicObjectDisplay(name, fixation.DurationMs)); } } }
private void fixationEvent(Fixation newFixation) { currentFixationLocation = newFixation.GetFixationLocation(); }
void EventSingleton_fixationEvent(Fixation newFixation) { //throw new NotImplementedException(); }
public static void processOnefile(string f) { Console.WriteLine("Processing the file: " + f); //read file List <string> lines = File.ReadAllLines(f).ToList(); lines.RemoveAt(0); Recording r = new Recording(); FixationLine fl = new FixationLine(); foreach (var l in lines) { Fixation fix = new Fixation(l); if (r.fixationLines.Count == 0 && fl.fixations.Count == 0) { fl.fixations.Add(fix); } else if (fix.idLine == fl.fixations[0].idLine) { fl.fixations.Add(fix); } else { r.fixationLines.Add(fl); fl = new FixationLine(); fl.fixations.Add(fix); } } //Add the last line r.fixationLines.Add(fl); double xReg = 0; //Process the label for the fixations for (int i = 0; i < r.fixationLines.Count; i++) { r.fixationLines[i].fixations[0].label = "F"; xReg = 0; for (int j = 1; j < r.fixationLines[i].fixations.Count; j++) { var cur = r.fixationLines[i].fixations[j]; var prev = r.fixationLines[i].fixations[j - 1]; if (cur.x < prev.x) { xReg = prev.x; cur.label = "B"; } else if (cur.x > xReg) { cur.label = "F"; } else { cur.label = "B"; } r.fixationLines[i].saccades.Add(new Saccade(prev, cur)); } } //Write everything in a new file string newPath = f.Replace("_fix.csv", "_fixSac.csv"); List <string> allLines = new List <string>(); string header = "timestamp; x; y; duration/length; fixation/saccade; Forward/Backward; idLine"; allLines.Add(header); foreach (var item in r.fixationLines) { foreach (var item1 in item.fixations) { string lineToWrite = item1.timestamp + ";" + item1.x + ";" + item1.y + ";" + item1.duration + ";f;" + item1.label + ";" + item1.idLine; allLines.Add(lineToWrite); } foreach (var item2 in item.saccades) { string lineToWrite = item2.timestamp + ";" + item2.x + ";" + item2.y + ";" + item2.length + ";s;" + item2.label + ";" + item2.idLine; allLines.Add(lineToWrite); } } System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; File.WriteAllLines(newPath, allLines); }
public List <Fixation> getCleanFixations() { Boolean fixationStart = false; List <Fixation> validFixations = new List <Fixation>(); //valid fixation candidate Fixation f = new Fixation(); //build valid fixations int i = 0; List <Tuple <string, DataPoint> > rawFixationPoints = new List <Tuple <string, DataPoint> >(); foreach (Tuple <string, DataPoint> bd in rawFixationBegPoints) { rawFixationPoints.Add(bd); } foreach (Tuple <string, DataPoint> dd in rawFixationDatPoints) { rawFixationPoints.Add(dd); } foreach (Tuple <string, DataPoint> ed in rawFixationEndPoints) { rawFixationPoints.Add(ed); } rawFixationPoints.Sort((Tuple <string, DataPoint> a, Tuple <string, DataPoint> b) => { //sort files into order based on number in title double a_num = a.Item2.timestamp; double b_num = b.Item2.timestamp; return(a_num.CompareTo(b_num)); }); foreach (Tuple <string, DataPoint> t in rawFixationPoints) { if (fixationStart && isValid(t.Item2)) //continue fixation { if (t.Item1 == "Begin") //discard malformed fixation and start a new fixation { f = new Fixation(); f.startPos = t.Item2; f.dataPos = new List <DataPoint>(); } else if (t.Item1 == "End") //complete valid fixation and add to list { fixationStart = false; f.endPos = t.Item2; f.completeFixation(i); validFixations.Add(f); f = new Fixation(); i++; } else //add data to fixation { f.dataPos.Add(t.Item2); } } else if (t.Item1 == "Begin" && isValid(t.Item2)) //start new fixation { fixationStart = true; f.startPos = t.Item2; f.dataPos = new List <DataPoint>(); } else if (!isValid(t.Item2)) //discard malformed fixation start a new fixation but don't record a value since current is invalid { f = new Fixation(); f.dataPos = new List <DataPoint>(); } } return(validFixations); }
private Fixation CreateFixation(FixationDataEventType fixationDataEventType, int x, int y) { Fixation fx = null; switch (fixationDataEventType) { case FixationDataEventType.Begin: fx = new Fixation(new Point(x, y), eFixationPhase.start); break; case FixationDataEventType.End: fx = new Fixation(new Point(x, y), eFixationPhase.finished); break; case FixationDataEventType.Data: fx = new Fixation(new Point(x, y), eFixationPhase.data); break; } return fx; }