void Awake() { Instance = this; StandardDataFilepath = Application.streamingAssetsPath + "/" + StandardDataFilepath; CustomDataFilepath = Application.streamingAssetsPath + "/" + CustomDataFilepath; EndRecording = false; IsActive = false; TotalGazeIterations = 0; StTimer = CustTimer = 0; NewGazeSegment = PreviousGazeSegment = new Vector2(-1, -1); CNewGazeSegment = CPreviousGazeSegment = -1; //initialize segments PanelSegments = new GazeSegment[NumSegments, NumSegments]; for (int i = 0; i < NumSegments; i++) { for (int j = 0; j < NumSegments; j++) { PanelSegments[i, j] = new GazeSegment(); } } for (int i = 0; i < CustomSegments.Length; i++) { CustomSegments[i].SegmentInfo = new GazeSegment(); } }
public CustomSegment() { SegmentInfo = new GazeSegment(); }
//JSON File stuff , copied from query manager. Maybe make them functions in a jsonmanager utility class? private void WriteDataToFile(string Filepath, int GridID) { if (GridID == 0) { Debug.Log("Saving standard grid data to file"); //Per trial info JsonGazeData trialData = new JsonGazeData(); trialData.UserID = QueryManager.GetUserID(); trialData.Maze = QueryManager.GetMazeID(); trialData.StartDate = StartRecordingDate.ToString(); trialData.EndDate = EndRecordingDate.ToString(); trialData.SegmentID = new JsonGazeSegmentData[NumSegments * NumSegments]; //Per segment info for (int i = 0; i < NumSegments; i++) { for (int j = 0; j < NumSegments; j++) { GazeSegment CurrentSegment = PanelSegments[i, j]; JsonGazeSegmentData SegmentInfo = new JsonGazeSegmentData(); SegmentInfo.x = i; SegmentInfo.y = j; SegmentInfo.TotalSegmentVisits = PanelSegments[i, j].TotalNumberOfVisits; SegmentInfo.AverageVisitDuration = PanelSegments[i, j].AvgVisitDuration; SegmentInfo.TotalVisitPercentage = (PanelSegments[i, j].VisitPercentage).ToString("#.00") + "%"; SegmentInfo.GazeVisits = new JsonVisitData[PanelSegments[i, j].SegmentVisits.Count]; //per segment visit info for (int k = 0; k < PanelSegments[i, j].SegmentVisits.Count; k++) { JsonVisitData visitdata = new JsonVisitData(); visitdata.Time = PanelSegments[i, j].SegmentVisits[k].VisitTimeStamp; visitdata.VisitDuration = PanelSegments[i, j].SegmentVisits[k].VisitDuration; SegmentInfo.GazeVisits[k] = visitdata; } trialData.SegmentID[i * (NumSegments) + j] = SegmentInfo; } } //write to file string json = JsonUtility.ToJson(trialData, true); //Appending in the write position in the file //Read the existing contents of the file string ExistingFile = File.ReadAllText(Filepath); //Find the position of the $ which shows the position where we will append the new object int AppendPosition = ExistingFile.IndexOf("$"); ExistingFile = ExistingFile.Insert(AppendPosition, json + ", \r\n"); //Write the new string in the file File.WriteAllText(Filepath, ExistingFile); } else if (GridID == 1) { Debug.Log("Saving custom grid data to file"); // I strongly dislike this //Per trial info JsonGazeData customTrialData = new JsonGazeData(); customTrialData.UserID = QueryManager.GetUserID(); customTrialData.Maze = QueryManager.GetMazeID(); customTrialData.StartDate = StartRecordingDate.ToString(); customTrialData.EndDate = EndRecordingDate.ToString(); customTrialData.CustomSegmentID = new JsonCustomSegmentData[CustomSegments.Length]; //Per segment info for (int i = 0; i < CustomSegments.Length; i++) { //CustomSegment CurrentSegment = CustomSegments[i]; JsonCustomSegmentData SegmentInfo = new JsonCustomSegmentData(); SegmentInfo.tag = CustomSegments[i].CustomTag; SegmentInfo.TotalSegmentVisits = CustomSegments[i].SegmentInfo.TotalNumberOfVisits; SegmentInfo.AverageVisitDuration = CustomSegments[i].SegmentInfo.AvgVisitDuration; SegmentInfo.TotalVisitPercentage = (CustomSegments[i].SegmentInfo.VisitPercentage).ToString("#.00") + "%"; SegmentInfo.GazeVisits = new JsonVisitData[CustomSegments[i].SegmentInfo.SegmentVisits.Count]; //per segment visit info for (int k = 0; k < CustomSegments[i].SegmentInfo.SegmentVisits.Count; k++) { JsonVisitData visitdata = new JsonVisitData(); visitdata.Time = CustomSegments[i].SegmentInfo.SegmentVisits[k].VisitTimeStamp; visitdata.VisitDuration = CustomSegments[i].SegmentInfo.SegmentVisits[k].VisitDuration; SegmentInfo.GazeVisits[k] = visitdata; } customTrialData.CustomSegmentID[i] = SegmentInfo; } //write to file string json = JsonUtility.ToJson(customTrialData, true); //Appending in the write position in the file //Read the existing contents of the file string ExistingFile = File.ReadAllText(Filepath); //Find the position of the $ which shows the position where we will append the new object int AppendPosition = ExistingFile.IndexOf("$"); ExistingFile = ExistingFile.Insert(AppendPosition, json + ", \r\n"); //Write the new string in the file File.WriteAllText(Filepath, ExistingFile); } }