-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bec35a
commit ffd7aea
Showing
5 changed files
with
125 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Globalization; | ||
|
||
using CsvHelper; | ||
using CsvHelper.Configuration; | ||
|
||
using UnityEngine; | ||
|
||
using VHToolkit.Redirection; | ||
using Newtonsoft.Json; | ||
|
||
namespace VHToolkit.Logging | ||
{ | ||
public class JsonLogging : MonoBehaviour | ||
{ | ||
|
||
public string pathToFile = "LoggedData\\"; | ||
[SerializeField] private string fileNamePrefix; | ||
private string fileName; | ||
private readonly int bufferSize = 10; // number of records kept before writing to disk | ||
|
||
private List<RedirectionData> records = new(); | ||
|
||
private Interaction script; | ||
|
||
private void Start() | ||
{ | ||
CreateNewFile(); | ||
script = GetComponent<Interaction>(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
void writeRecords<Data, DataMap>(List<Data> records) where DataMap : ClassMap<Data> | ||
{ | ||
if (records.Count > bufferSize) | ||
{ | ||
using var writer = new StreamWriter(fileName, append: true); | ||
foreach (var record in records) { | ||
// writer.WriteLine(JsonConvert.SerializeObject(record)); | ||
} | ||
records.Clear(); | ||
} | ||
} | ||
|
||
records.Add(new RedirectionData(script)); | ||
writeRecords<RedirectionData, RedirectionDataMap>(records); | ||
} | ||
|
||
public void CreateNewFile() | ||
{ | ||
fileName = $"{pathToFile}{fileNamePrefix}{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.json"; | ||
using StreamWriter writer = new(fileName); | ||
using CsvWriter csv = new(writer, CultureInfo.InvariantCulture); | ||
records = new List<RedirectionData>(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Visuo-haptic Toolkit/Assets/Visuo-Haptic Toolkit/Scripts/Logging/JsonLogging.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters