we done with data entry BITCH!
This commit is contained in:
parent
5c9c0f5214
commit
be25651b21
78
Assets/Scripts/DataSet.cs
Normal file
78
Assets/Scripts/DataSet.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Assets.Scripts
|
||||||
|
{
|
||||||
|
class DataSet
|
||||||
|
{
|
||||||
|
public List<Sample> Samples = new List<Sample>();
|
||||||
|
|
||||||
|
public void SaveDataSet()
|
||||||
|
{
|
||||||
|
UploadToElastic();
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.AppendLine("Platform,ParticipantID,Angle,Distance,Time,Direction,DotName,TrialIndex,DotIndex,Timestamp");
|
||||||
|
Sample first = Samples[0];
|
||||||
|
string platform = first.Platform;
|
||||||
|
string trial = (first.TrialIndex + 1).ToString();
|
||||||
|
string participant = first.ParticipantID.ToString();
|
||||||
|
foreach (Sample sample in Samples)
|
||||||
|
{
|
||||||
|
stringBuilder.AppendLine(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", sample.Platform, sample.ParticipantID, sample.Angle, sample.Distance, sample.Time, sample.Direction, sample.DotName, sample.TrialIndex, sample.DotIndex, sample.Timestamp));
|
||||||
|
}
|
||||||
|
string path = Path.Combine(Application.persistentDataPath, string.Format("{0}-{1}-{2}.csv",platform,participant,trial));
|
||||||
|
using (StreamWriter streamWriter = File.CreateText(path))
|
||||||
|
{
|
||||||
|
streamWriter.Write(stringBuilder.ToString());
|
||||||
|
}
|
||||||
|
UploadToAstralQueen(string.Format("{0}-{1}-{2}", platform, participant, trial), stringBuilder.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UploadToAstralQueen(string name, string data)
|
||||||
|
{
|
||||||
|
using (WebClient client = new WebClient())
|
||||||
|
{
|
||||||
|
string endpoint = "http://astralqueen.bw.edu/hci/upload.php";
|
||||||
|
|
||||||
|
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
|
||||||
|
string ud = "userStudyId=" + name + "&userStudyData=" + data;
|
||||||
|
string response = client.UploadString(endpoint, ud);
|
||||||
|
UnityEngine.Debug.Log("Received Response: " + response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UploadToElastic()
|
||||||
|
{
|
||||||
|
JObject body = new JObject();
|
||||||
|
JArray samples = new JArray();
|
||||||
|
foreach(Sample sample in Samples)
|
||||||
|
{
|
||||||
|
JObject sJ = new JObject();
|
||||||
|
sJ.Add("platform", sample.Platform);
|
||||||
|
sJ.Add("participantId", sample.ParticipantID);
|
||||||
|
sJ.Add("angle", sample.Angle);
|
||||||
|
sJ.Add("distance", sample.Distance);
|
||||||
|
sJ.Add("time", sample.Time);
|
||||||
|
sJ.Add("direction", sample.Direction);
|
||||||
|
sJ.Add("dotName", sample.DotName);
|
||||||
|
sJ.Add("trialIndex", sample.TrialIndex);
|
||||||
|
sJ.Add("dotIndex", sample.DotIndex);
|
||||||
|
sJ.Add("timestamp", sample.Timestamp);
|
||||||
|
samples.Add(sJ);
|
||||||
|
}
|
||||||
|
body.Add("samples", samples);
|
||||||
|
using (var client = new WebClient())
|
||||||
|
{
|
||||||
|
client.Headers[HttpRequestHeader.ContentType] = "application/json";
|
||||||
|
var resp = client.UploadString("http://home.superpichu.org:9009", body.ToString());
|
||||||
|
UnityEngine.Debug.Log("Recv: " + resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/DataSet.cs.meta
Normal file
11
Assets/Scripts/DataSet.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 78ec62a53d82d9848baad99b8154106b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
21
Assets/Scripts/Sample.cs
Normal file
21
Assets/Scripts/Sample.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Assets.Scripts
|
||||||
|
{
|
||||||
|
class Sample
|
||||||
|
{
|
||||||
|
public string Platform { get; set; }
|
||||||
|
public int ParticipantID { get; set; }
|
||||||
|
public double Angle { get; set; }
|
||||||
|
public double Distance { get; set; }
|
||||||
|
public double Time { get; set; }
|
||||||
|
public bool Direction { get; set; }
|
||||||
|
public string DotName { get; set; }
|
||||||
|
public int TrialIndex { get; set; }
|
||||||
|
public int DotIndex { get; set; }
|
||||||
|
public long Timestamp { get; set; }
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Sample.cs.meta
Normal file
11
Assets/Scripts/Sample.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1b24c123fd47d68448a4aee725ec250c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
18
index.json
Normal file
18
index.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"mappings": {
|
||||||
|
"_doc": {
|
||||||
|
"properties": {
|
||||||
|
"platform":{"type":"keyword"},
|
||||||
|
"participantId": {"type":"integer"},
|
||||||
|
"angle":{"type":"double"},
|
||||||
|
"distance":{"type":"double"},
|
||||||
|
"time":{"type":"double"},
|
||||||
|
"direction":{"type":"boolean"},
|
||||||
|
"dotName":{"type":"keyword"},
|
||||||
|
"trialIndex":{"type":"integer"},
|
||||||
|
"dotIndex":{"type":"integer"},
|
||||||
|
"timestamp":{"type":"date","format":"epoch_millis"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user