WE DONE BITCHES

This commit is contained in:
Chris Midkiff 2018-11-29 13:14:03 -05:00
parent be25651b21
commit 7f8f2f5a88
4 changed files with 127 additions and 125 deletions

View File

@ -1,78 +1,78 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
namespace Assets.Scripts namespace Assets.Scripts
{ {
class DataSet class DataSet
{ {
public List<Sample> Samples = new List<Sample>(); public List<Sample> Samples = new List<Sample>();
public void SaveDataSet() public void SaveDataSet()
{ {
UploadToElastic(); UploadToElastic();
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Platform,ParticipantID,Angle,Distance,Time,Direction,DotName,TrialIndex,DotIndex,Timestamp"); stringBuilder.AppendLine("Platform,ParticipantID,Angle,Distance,Time,Direction,DotName,TrialIndex,DotIndex,Timestamp");
Sample first = Samples[0]; Sample first = Samples[0];
string platform = first.Platform; string platform = first.Platform;
string trial = (first.TrialIndex + 1).ToString(); string trial = (first.TrialIndex + 1).ToString();
string participant = first.ParticipantID.ToString(); string participant = first.ParticipantID.ToString();
foreach (Sample sample in Samples) 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)); 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)); string path = Path.Combine(Application.persistentDataPath, string.Format("{0}-{1}-{2}.csv",platform,participant,trial));
using (StreamWriter streamWriter = File.CreateText(path)) using (StreamWriter streamWriter = File.CreateText(path))
{ {
streamWriter.Write(stringBuilder.ToString()); streamWriter.Write(stringBuilder.ToString());
} }
UploadToAstralQueen(string.Format("{0}-{1}-{2}", platform, participant, trial), stringBuilder.ToString()); UploadToAstralQueen(string.Format("{0}-{1}-{2}", platform, participant, trial), stringBuilder.ToString());
} }
private void UploadToAstralQueen(string name, string data) private void UploadToAstralQueen(string name, string data)
{ {
using (WebClient client = new WebClient()) using (WebClient client = new WebClient())
{ {
string endpoint = "http://astralqueen.bw.edu/hci/upload.php"; string endpoint = "http://astralqueen.bw.edu/hci/upload.php";
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string ud = "userStudyId=" + name + "&userStudyData=" + data; string ud = "userStudyId=" + name + "&userStudyData=" + data;
string response = client.UploadString(endpoint, ud); string response = client.UploadString(endpoint, ud);
UnityEngine.Debug.Log("Received Response: " + response); UnityEngine.Debug.Log("Received Response: " + response);
} }
} }
private void UploadToElastic() private void UploadToElastic()
{ {
JObject body = new JObject(); JObject body = new JObject();
JArray samples = new JArray(); JArray samples = new JArray();
foreach(Sample sample in Samples) foreach(Sample sample in Samples)
{ {
JObject sJ = new JObject(); JObject sJ = new JObject();
sJ.Add("platform", sample.Platform); sJ.Add("platform", sample.Platform);
sJ.Add("participantId", sample.ParticipantID); sJ.Add("participantId", sample.ParticipantID);
sJ.Add("angle", sample.Angle); sJ.Add("angle", sample.Angle);
sJ.Add("distance", sample.Distance); sJ.Add("distance", sample.Distance);
sJ.Add("time", sample.Time); sJ.Add("time", sample.Time);
sJ.Add("direction", sample.Direction); sJ.Add("direction", sample.Direction);
sJ.Add("dotName", sample.DotName); sJ.Add("dotName", sample.DotName);
sJ.Add("trialIndex", sample.TrialIndex); sJ.Add("trialIndex", sample.TrialIndex);
sJ.Add("dotIndex", sample.DotIndex); sJ.Add("dotIndex", sample.DotIndex);
sJ.Add("timestamp", sample.Timestamp); sJ.Add("timestamp", sample.Timestamp);
samples.Add(sJ); samples.Add(sJ);
} }
body.Add("samples", samples); body.Add("samples", samples);
using (var client = new WebClient()) using (var client = new WebClient())
{ {
client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.Headers[HttpRequestHeader.ContentType] = "application/json";
var resp = client.UploadString("http://home.superpichu.org:9009", body.ToString()); var resp = client.UploadString("http://home.superpichu.org:9009", body.ToString());
UnityEngine.Debug.Log("Recv: " + resp); UnityEngine.Debug.Log("Recv: " + resp);
} }
} }
} }
} }

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Net;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@ -27,15 +28,16 @@ public class ExperimentController : MonoBehaviour {
platform = "mouse"; platform = "mouse";
#endif #endif
#if UNITY_STANDALONE_WIN #if UNITY_STANDALONE_WIN
platform = "rift"; platform = "oculus";
#endif #endif
string response = "";
//FOR THE LOVE OF GOD FUCKING DELETE THIS, SERIOUSLY CHRIS DON'T YOU DARE FORGET using (WebClient client = new WebClient())
string fuck = "ewoidHJpYWxzIiA6IFsKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXSwKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXSwKICBbIkxlZnRMb25nIiwiUmlnaHRNZWRpdW0iLCJMZWZ0U2hvcnQiLCJVcE1lZGl1bSIsIlVwTG9uZyIsIlJpZ2h0U2hvcnQiXSwKICBbIlVwU2hvcnQiLCJSaWdodExvbmciLCJMZWZ0TWVkaXVtIiwiUmlnaHRNZWRpdW0iLCJMZWZ0TG9uZyIsIlVwTG9uZyJdLAogIFsiUmlnaHRTaG9ydCIsIlVwTWVkaXVtIiwiTGVmdE1lZGl1bSIsIkxlZnRTaG9ydCIsIlJpZ2h0TG9uZyIsIlVwU2hvcnQiXQpdLAoicGFydGljaXBhbnRJZCIgOiAxLAoiaW5wdXRNZXRob2QiIDogImNhcmRib2FyZCIKfQo="; {
byte[] decodedBytes = Convert.FromBase64String(fuck); string endpoint = "http://do.superpichu.org:5000/" + platform;
string decodedText = Encoding.UTF8.GetString(decodedBytes); response = client.DownloadString(endpoint);
UnityEngine.Debug.Log(decodedText); UnityEngine.Debug.Log("Received Response: " + response);
participant = new Participant(decodedText); }
participant = new Participant(response);
startDot = GameObject.Find("StartButton"); startDot = GameObject.Find("StartButton");
playerCamera = GameObject.FindGameObjectsWithTag("MainCamera")[0]; playerCamera = GameObject.FindGameObjectsWithTag("MainCamera")[0];
trialIndex = 0; trialIndex = 0;

View File

@ -1,21 +1,21 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace Assets.Scripts namespace Assets.Scripts
{ {
class Sample class Sample
{ {
public string Platform { get; set; } public string Platform { get; set; }
public int ParticipantID { get; set; } public int ParticipantID { get; set; }
public double Angle { get; set; } public double Angle { get; set; }
public double Distance { get; set; } public double Distance { get; set; }
public double Time { get; set; } public double Time { get; set; }
public bool Direction { get; set; } public bool Direction { get; set; }
public string DotName { get; set; } public string DotName { get; set; }
public int TrialIndex { get; set; } public int TrialIndex { get; set; }
public int DotIndex { get; set; } public int DotIndex { get; set; }
public long Timestamp { get; set; } public long Timestamp { get; set; }
} }
} }

View File

@ -1,18 +1,18 @@
{ {
"mappings": { "mappings": {
"_doc": { "_doc": {
"properties": { "properties": {
"platform":{"type":"keyword"}, "platform":{"type":"keyword"},
"participantId": {"type":"integer"}, "participantId": {"type":"integer"},
"angle":{"type":"double"}, "angle":{"type":"double"},
"distance":{"type":"double"}, "distance":{"type":"double"},
"time":{"type":"double"}, "time":{"type":"double"},
"direction":{"type":"boolean"}, "direction":{"type":"boolean"},
"dotName":{"type":"keyword"}, "dotName":{"type":"keyword"},
"trialIndex":{"type":"integer"}, "trialIndex":{"type":"integer"},
"dotIndex":{"type":"integer"}, "dotIndex":{"type":"integer"},
"timestamp":{"type":"date","format":"epoch_millis"} "timestamp":{"type":"date","format":"epoch_millis"}
} }
} }
} }
} }