Exemplo n.º 1
0
        ///sky position
        public static void RecordGazePoint(double timestamp, Vector3 hmdpoint, Quaternion hmdrotation, Vector3 gpsloc, float compass, Vector3 floorPos) //looking at the camera far plane
        {
            gazebuilder.Append("{");

            JsonUtil.SetDouble("time", timestamp, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetVector("p", hmdpoint, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetQuat("r", hmdrotation, gazebuilder);

            if (CognitiveVR_Preferences.Instance.TrackGPSLocation)
            {
                gazebuilder.Append(",");
                JsonUtil.SetVector("gpsloc", gpsloc, gazebuilder);
                gazebuilder.Append(",");
                JsonUtil.SetFloat("compass", compass, gazebuilder);
            }
            if (CognitiveVR_Preferences.Instance.RecordFloorPosition)
            {
                gazebuilder.Append(",");
                JsonUtil.SetVector("f", floorPos, gazebuilder);
            }

            gazebuilder.Append("}");
            gazeCount++;
            if (gazeCount >= CognitiveVR_Preferences.Instance.GazeSnapshotCount)
            {
                SendGazeData();
            }
            else
            {
                gazebuilder.Append(",");
            }
        }
Exemplo n.º 2
0
        static void SetSnapshot(DynamicObjectSnapshot snap, StringBuilder builder)
        {
            builder.Append('{');

            JsonUtil.SetString("id", snap.Id, builder);
            builder.Append(',');
            JsonUtil.SetDouble("time", snap.Timestamp, builder);
            builder.Append(',');
            JsonUtil.SetVectorRaw("p", snap.posX, snap.posY, snap.posZ, builder);
            builder.Append(',');
            JsonUtil.SetQuatRaw("r", snap.rotX, snap.rotY, snap.rotZ, snap.rotW, builder);
            if (snap.DirtyScale)
            {
                builder.Append(',');
                JsonUtil.SetVectorRaw("s", snap.scaleX, snap.scaleY, snap.scaleZ, builder);
            }

            //properties should already be formatted, just need to append them here
            if (!string.IsNullOrEmpty(snap.Properties))
            {
                //properties are an array of a single object? weird
                builder.Append(",\"properties\":[{");
                builder.Append(snap.Properties);
                builder.Append("}]");
            }

            if (!string.IsNullOrEmpty(snap.Buttons))
            {
                builder.Append(",\"buttons\":{");
                builder.Append(snap.Buttons);
                builder.Append("}");
            }

            builder.Append("}"); //close object snapshot
        }
Exemplo n.º 3
0
        public static void SendCustomEvent(string category, List <KeyValuePair <string, object> > properties, float[] position, string dynamicObjectId = "")
        {
            if (Core.IsInitialized == false)
            {
                CognitiveVR.Util.logWarning("Custom Events cannot be sent before Session Begin!");
                return;
            }

            eventBuilder.Append("{");
            JsonUtil.SetString("name", category, eventBuilder);
            eventBuilder.Append(",");
            JsonUtil.SetDouble("time", Util.Timestamp(Time.frameCount), eventBuilder);
            if (!string.IsNullOrEmpty(dynamicObjectId))
            {
                eventBuilder.Append(',');
                JsonUtil.SetString("dynamicId", dynamicObjectId, eventBuilder);
            }
            eventBuilder.Append(",");
            JsonUtil.SetVector("point", position, eventBuilder);

            if (properties != null && properties.Count > 0)
            {
                eventBuilder.Append(",");
                eventBuilder.Append("\"properties\":{");
                for (int i = 0; i < properties.Count; i++)
                {
                    if (i != 0)
                    {
                        eventBuilder.Append(",");
                    }
                    if (properties[i].Value.GetType() == typeof(string))
                    {
                        JsonUtil.SetString(properties[i].Key, (string)properties[i].Value, eventBuilder);
                    }
                    else
                    {
                        JsonUtil.SetObject(properties[i].Key, properties[i].Value, eventBuilder);
                    }
                }
                eventBuilder.Append("}"); //close properties object
            }

            eventBuilder.Append("}"); //close transaction object
            eventBuilder.Append(",");

            CustomEventRecordedEvent(category, new Vector3(position[0], position[1], position[2]), properties, dynamicObjectId, Util.Timestamp(Time.frameCount));
            cachedEvents++;
            if (cachedEvents >= CognitiveVR_Preferences.Instance.TransactionSnapshotCount)
            {
                TrySendTransactions();
            }
        }
Exemplo n.º 4
0
        //looking at a media dynamic object
        //mediatime is milliseconds since the start of the video
        public static void RecordGazePoint(double timestamp, string objectid, Vector3 localgazepoint, Vector3 hmdpoint, Quaternion hmdrotation, Vector3 gpsloc, float compass, string mediasource, int mediatimeMs, Vector2 uvs, Vector3 floorPos)
        {
            gazebuilder.Append("{");

            JsonUtil.SetDouble("time", timestamp, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetString("o", objectid, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetVector("p", hmdpoint, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetQuat("r", hmdrotation, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetVector("g", localgazepoint, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetString("mediaId", mediasource, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetInt("mediatime", mediatimeMs, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetVector2("uvs", uvs, gazebuilder);

            if (CognitiveVR_Preferences.Instance.TrackGPSLocation)
            {
                gazebuilder.Append(",");
                JsonUtil.SetVector("gpsloc", gpsloc, gazebuilder);
                gazebuilder.Append(",");
                JsonUtil.SetFloat("compass", compass, gazebuilder);
            }
            if (CognitiveVR_Preferences.Instance.RecordFloorPosition)
            {
                gazebuilder.Append(",");
                JsonUtil.SetVector("f", floorPos, gazebuilder);
            }

            gazebuilder.Append("}");
            gazeCount++;
            if (gazeCount >= CognitiveVR_Preferences.Instance.GazeSnapshotCount)
            {
                SendGazeData();
            }
            else
            {
                gazebuilder.Append(",");
            }
            DynamicGazeRecordEvent(timestamp, objectid, localgazepoint, hmdpoint, hmdrotation);
        }
Exemplo n.º 5
0
        public static void SendCustomEvent(string category, Vector3 position)
        {
            TransactionBuilder.Append("{");
            JsonUtil.SetString("name", category, TransactionBuilder);
            TransactionBuilder.Append(",");
            JsonUtil.SetDouble("time", Util.Timestamp(), TransactionBuilder);
            TransactionBuilder.Append(",");
            JsonUtil.SetVector("point", position, TransactionBuilder);

            TransactionBuilder.Append("}"); //close transaction object
            TransactionBuilder.Append(",");

            cachedEvents++;
            if (cachedEvents >= maxCachedEvents)
            {
                SendTransactions();
            }
        }
Exemplo n.º 6
0
        public static void SendCustomEvent(string category, float[] position, string dynamicObjectId = "")
        {
            eventBuilder.Append("{");
            JsonUtil.SetString("name", category, eventBuilder);
            eventBuilder.Append(",");
            JsonUtil.SetDouble("time", Util.Timestamp(Time.frameCount), eventBuilder);
            if (!string.IsNullOrEmpty(dynamicObjectId))
            {
                eventBuilder.Append(',');
                JsonUtil.SetString("dynamicId", dynamicObjectId, eventBuilder);
            }
            eventBuilder.Append(",");
            JsonUtil.SetVector("point", position, eventBuilder);
            eventBuilder.Append("}"); //close transaction object
            eventBuilder.Append(",");

            cachedEvents++;
            if (cachedEvents >= CognitiveVR_Preferences.Instance.TransactionSnapshotCount)
            {
                TrySendTransactions();
            }
        }
Exemplo n.º 7
0
        public static void SendCustomEvent(string category, Dictionary <string, object> properties, float[] position)
        {
            TransactionBuilder.Append("{");
            JsonUtil.SetString("name", category, TransactionBuilder);
            TransactionBuilder.Append(",");
            JsonUtil.SetDouble("time", Util.Timestamp(), TransactionBuilder);
            TransactionBuilder.Append(",");
            JsonUtil.SetVector("point", position, TransactionBuilder);

            if (properties != null && properties.Keys.Count > 0)
            {
                TransactionBuilder.Append(",");
                TransactionBuilder.Append("\"properties\":{");
                foreach (var v in properties)
                {
                    if (v.Value.GetType() == typeof(string))
                    {
                        JsonUtil.SetString(v.Key, (string)v.Value, TransactionBuilder);
                    }
                    else
                    {
                        JsonUtil.SetObject(v.Key, v.Value, TransactionBuilder);
                    }
                    TransactionBuilder.Append(",");
                }
                TransactionBuilder.Remove(TransactionBuilder.Length - 1, 1); //remove last comma
                TransactionBuilder.Append("}");                              //close properties object
            }

            TransactionBuilder.Append("}"); //close transaction object
            TransactionBuilder.Append(",");

            cachedEvents++;
            if (cachedEvents >= maxCachedEvents)
            {
                SendTransactions();
            }
        }
Exemplo n.º 8
0
        static void SendTransactions()
        {
            cachedEvents = 0;
            //bundle up header stuff and transaction data

            //clear the transaction builder
            builder.Length = 0;

            //CognitiveVR.Util.logDebug("package transaction event data " + partCount);
            //when thresholds are reached, etc

            builder.Append("{");

            //header
            JsonUtil.SetString("userid", Core.UniqueID, builder);
            builder.Append(",");

            if (!string.IsNullOrEmpty(CognitiveVR_Preferences.LobbyId))
            {
                JsonUtil.SetString("lobbyId", CognitiveVR_Preferences.LobbyId, builder);
                builder.Append(",");
            }

            JsonUtil.SetDouble("timestamp", Core.SessionTimeStamp, builder);
            builder.Append(",");
            JsonUtil.SetString("sessionid", Core.SessionID, builder);
            builder.Append(",");
            JsonUtil.SetInt("part", partCount, builder);
            partCount++;
            builder.Append(",");

            JsonUtil.SetString("formatversion", "1.0", builder);
            builder.Append(",");

            //events
            builder.Append("\"data\":[");

            builder.Append(TransactionBuilder.ToString());

            if (TransactionBuilder.Length > 0)
            {
                builder.Remove(builder.Length - 1, 1); //remove the last comma
            }
            builder.Append("]");

            builder.Append("}");

            TransactionBuilder.Length = 0;

            //send transaction contents to scene explorer

            string packagedEvents = builder.ToString();

            if (string.IsNullOrEmpty(Core.TrackingSceneId))
            {
                Util.logDebug("Instrumentation.SendTransactions could not find CurrentSceneId! has scene been uploaded and CognitiveVR_Manager.Initialize been called?");
                return;
            }

            //sends all packaged transaction events from instrumentaiton subsystem to events endpoint on scene explorer
            string url = Constants.POSTEVENTDATA(Core.TrackingSceneId, Core.TrackingSceneVersionNumber);

            //byte[] outBytes = System.Text.UTF8Encoding.UTF8.GetBytes();

            //var headers = new Dictionary<string, string>();
            //headers.Add("Content-Type", "application/json");
            //headers.Add("X-HTTP-Method-Override", "POST");

            NetworkManager.Post(url, packagedEvents);
        }
Exemplo n.º 9
0
        private static void Core_OnSendData()
        {
            if (Fixations.Count <= 0)
            {
                CognitiveVR.Util.logDebug("Fixations.SendData found no data"); return;
            }

            //TODO should hold until extreme batch size reached
            if (string.IsNullOrEmpty(Core.TrackingSceneId))
            {
                CognitiveVR.Util.logDebug("Fixations.SendData could not find scene settings for scene! do not upload fixations to sceneexplorer");
                Fixations.Clear();
                return;
            }


            nextSendTime = Time.realtimeSinceStartup + CognitiveVR_Preferences.Instance.FixationSnapshotMaxTimer;
            lastSendTime = Time.realtimeSinceStartup;


            StringBuilder sb = new StringBuilder(1024);

            sb.Append("{");
            JsonUtil.SetString("userid", Core.UniqueID, sb);
            sb.Append(",");
            JsonUtil.SetString("sessionid", Core.SessionID, sb);
            sb.Append(",");
            JsonUtil.SetInt("timestamp", (int)Core.SessionTimeStamp, sb);
            sb.Append(",");
            JsonUtil.SetInt("part", jsonPart, sb);
            sb.Append(",");
            jsonPart++;

            sb.Append("\"data\":[");
            for (int i = 0; i < Fixations.Count; i++)
            {
                sb.Append("{");
                JsonUtil.SetDouble("time", System.Convert.ToDouble((double)Fixations[i].StartMs / 1000.0), sb);
                sb.Append(",");
                JsonUtil.SetLong("duration", Fixations[i].DurationMs, sb);
                sb.Append(",");
                JsonUtil.SetFloat("maxradius", Fixations[i].MaxRadius, sb);
                sb.Append(",");

                if (Fixations[i].IsLocal)
                {
                    JsonUtil.SetString("objectid", Fixations[i].DynamicObjectId, sb);
                    sb.Append(",");
                    JsonUtil.SetVector("p", Fixations[i].LocalPosition, sb);
                }
                else
                {
                    JsonUtil.SetVector("p", Fixations[i].WorldPosition, sb);
                }
                sb.Append("},");
            }
            if (Fixations.Count > 0)
            {
                sb.Remove(sb.Length - 1, 1); //remove last comma from fixation object
            }

            sb.Append("]}");

            Fixations.Clear();

            string url = CognitiveStatics.POSTFIXATIONDATA(Core.TrackingSceneId, Core.TrackingSceneVersionNumber);

            NetworkManager.Post(url, sb.ToString());
        }
Exemplo n.º 10
0
        private static void SendGazeData()
        {
            if (string.IsNullOrEmpty(Core.TrackingSceneId))
            {
                Util.logDebug("Cognitive GazeCore.SendData could not find scene settings for scene! do not upload gaze to sceneexplorer");
                return;
            }

            gazebuilder.Append("],");

            gazeCount = 0;

            //header
            JsonUtil.SetString("userid", Core.UniqueID, gazebuilder);
            gazebuilder.Append(",");

            if (!string.IsNullOrEmpty(CognitiveVR_Preferences.LobbyId))
            {
                JsonUtil.SetString("lobbyId", CognitiveVR_Preferences.LobbyId, gazebuilder);
                gazebuilder.Append(",");
            }

            JsonUtil.SetDouble("timestamp", (int)Core.SessionTimeStamp, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetString("sessionid", Core.SessionID, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetInt("part", jsonPart, gazebuilder);
            jsonPart++;
            gazebuilder.Append(",");

            JsonUtil.SetString("hmdtype", HMDName, gazebuilder);

            gazebuilder.Append(",");
            JsonUtil.SetFloat("interval", CognitiveVR.CognitiveVR_Preferences.Instance.SnapshotInterval, gazebuilder);
            gazebuilder.Append(",");

            JsonUtil.SetString("formatversion", "1.0", gazebuilder);

            if (Core.GetNewSessionProperties(false).Count > 0)
            {
                gazebuilder.Append(",");
                gazebuilder.Append("\"properties\":{");
                foreach (var kvp in Core.GetNewSessionProperties(true))
                {
                    if (kvp.Value.GetType() == typeof(string))
                    {
                        JsonUtil.SetString(kvp.Key, (string)kvp.Value, gazebuilder);
                    }
                    else
                    {
                        JsonUtil.SetObject(kvp.Key, kvp.Value, gazebuilder);
                    }
                    gazebuilder.Append(",");
                }
                gazebuilder.Remove(gazebuilder.Length - 1, 1); //remove comma
                gazebuilder.Append("}");
            }
            gazebuilder.Append("}");

            var    sceneSettings = Core.TrackingScene;
            string url           = Constants.POSTGAZEDATA(sceneSettings.SceneId, sceneSettings.VersionNumber);

            CognitiveVR.NetworkManager.Post(url, gazebuilder.ToString());

            //gazebuilder = new StringBuilder(70 * CognitiveVR_Preferences.Instance.GazeSnapshotCount + 200);
            gazebuilder.Length = 9;
            //gazebuilder.Append("{\"data\":[");
        }
Exemplo n.º 11
0
        static IEnumerator WriteJson()
        {
            while (true)
            {
                if (!ReadyToWriteJson)
                {
                    yield return(null);
                }
                else
                {
                    int totalDataToWrite = queuedManifest.Count + queuedSnapshots.Count;
                    totalDataToWrite = Mathf.Min(totalDataToWrite, CognitiveVR_Preferences.S_DynamicExtremeSnapshotCount);

                    var builder       = new System.Text.StringBuilder(200 + 128 * totalDataToWrite);
                    int manifestCount = Mathf.Min(queuedManifest.Count, totalDataToWrite);
                    int count         = Mathf.Min(queuedSnapshots.Count, totalDataToWrite - manifestCount);

                    if (queuedSnapshots.Count - count == 0 && queuedManifest.Count - manifestCount == 0)
                    {
                        ReadyToWriteJson = false;
                    }

                    bool threadDone = true;

                    builder.Append("{");

                    //header
                    JsonUtil.SetString("userid", Core.DeviceId, builder);
                    builder.Append(",");

                    if (!string.IsNullOrEmpty(Core.LobbyId))
                    {
                        JsonUtil.SetString("lobbyId", Core.LobbyId, builder);
                        builder.Append(",");
                    }

                    JsonUtil.SetDouble("timestamp", (int)Core.SessionTimeStamp, builder);
                    builder.Append(",");
                    JsonUtil.SetString("sessionid", Core.SessionID, builder);
                    builder.Append(",");
                    JsonUtil.SetInt("part", jsonPart, builder);
                    builder.Append(",");
                    jsonPart++;
                    JsonUtil.SetString("formatversion", "1.0", builder);
                    builder.Append(",");

                    //manifest entries
                    if (manifestCount > 0)
                    {
                        builder.Append("\"manifest\":{");
                        threadDone = false;

                        if (WriteImmediate)
                        {
                            for (int i = 0; i < manifestCount; i++)
                            {
                                if (i != 0)
                                {
                                    builder.Append(',');
                                }
                                var manifestentry = queuedManifest.Dequeue();
                                SetManifestEntry(manifestentry, builder);
                            }
                            threadDone = true;
                        }
                        else
                        {
                            new System.Threading.Thread(() =>
                            {
                                for (int i = 0; i < manifestCount; i++)
                                {
                                    if (i != 0)
                                    {
                                        builder.Append(',');
                                    }
                                    var manifestentry = queuedManifest.Dequeue();
                                    SetManifestEntry(manifestentry, builder);
                                }
                                threadDone = true;
                            }).Start();

                            while (!threadDone)
                            {
                                yield return(null);
                            }
                        }

                        if (count > 0)
                        {
                            builder.Append("},");
                        }
                        else
                        {
                            builder.Append("}");
                        }
                    }

                    //snapshots
                    if (count > 0)
                    {
                        builder.Append("\"data\":[");
                        threadDone = false;
                        if (WriteImmediate)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                if (i != 0)
                                {
                                    builder.Append(',');
                                }
                                var snap = queuedSnapshots.Dequeue();
                                SetSnapshot(snap, builder);
                                snap.ReturnToPool();
                            }
                            threadDone = true;
                        }
                        else
                        {
                            new System.Threading.Thread(() =>
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    if (i != 0)
                                    {
                                        builder.Append(',');
                                    }
                                    var snap = queuedSnapshots.Dequeue();
                                    SetSnapshot(snap, builder);
                                    snap.ReturnToPool();
                                }
                                threadDone = true;
                            }).Start();

                            while (!threadDone)
                            {
                                yield return(null);
                            }
                        }
                        builder.Append("]");
                    }
                    builder.Append("}");

                    string s   = builder.ToString();
                    string url = CognitiveStatics.POSTDYNAMICDATA(Core.TrackingSceneId, Core.TrackingSceneVersionNumber);
                    NetworkManager.Post(url, s);
                    DynamicManager.DynamicObjectSendEvent();
                }
            }
        }
Exemplo n.º 12
0
        static void SendTransactions()
        {
            if (cachedEvents == 0)
            {
                return;
            }

            if (!Core.IsInitialized)
            {
                return;
            }

            //TODO should hold until extreme batch size reached
            if (string.IsNullOrEmpty(Core.TrackingSceneId))
            {
                Util.logDebug("Instrumentation.SendTransactions could not find CurrentSceneId! has scene been uploaded and CognitiveVR_Manager.Initialize been called?");
                cachedEvents        = 0;
                eventBuilder.Length = 0;
                return;
            }

            autoTimer_nextSendTime = Time.realtimeSinceStartup + CognitiveVR_Preferences.Instance.DynamicSnapshotMaxTimer;
            minTimer_lastSendTime  = Time.realtimeSinceStartup;

            cachedEvents = 0;
            //bundle up header stuff and transaction data

            //clear the transaction builder
            builder.Length = 0;

            //CognitiveVR.Util.logDebug("package transaction event data " + partCount);
            //when thresholds are reached, etc

            builder.Append("{");

            //header
            JsonUtil.SetString("userid", Core.DeviceId, builder);
            builder.Append(",");

            if (!string.IsNullOrEmpty(Core.LobbyId))
            {
                JsonUtil.SetString("lobbyId", Core.LobbyId, builder);
                builder.Append(",");
            }

            JsonUtil.SetDouble("timestamp", Core.SessionTimeStamp, builder);
            builder.Append(",");
            JsonUtil.SetString("sessionid", Core.SessionID, builder);
            builder.Append(",");
            JsonUtil.SetInt("part", partCount, builder);
            partCount++;
            builder.Append(",");

            JsonUtil.SetString("formatversion", "1.0", builder);
            builder.Append(",");

            //events
            builder.Append("\"data\":[");

            builder.Append(eventBuilder.ToString());

            if (eventBuilder.Length > 0)
            {
                builder.Remove(builder.Length - 1, 1); //remove the last comma
            }
            builder.Append("]");

            builder.Append("}");

            eventBuilder.Length = 0;

            //send transaction contents to scene explorer

            string packagedEvents = builder.ToString();

            //sends all packaged transaction events from instrumentaiton subsystem to events endpoint on scene explorer
            string url = CognitiveStatics.POSTEVENTDATA(Core.TrackingSceneId, Core.TrackingSceneVersionNumber);

            NetworkManager.Post(url, packagedEvents);
            if (OnCustomEventSend != null)
            {
                OnCustomEventSend.Invoke();
            }
        }
Exemplo n.º 13
0
        private static void Core_OnSendData()
        {
            if (CachedSnapshots.Keys.Count <= 0)
            {
                CognitiveVR.Util.logDebug("Sensor.SendData found no data"); return;
            }

            var sceneSettings = Core.TrackingScene;

            if (sceneSettings == null)
            {
                CognitiveVR.Util.logDebug("Sensor.SendData found no SceneKeySettings"); return;
            }

            StringBuilder sb = new StringBuilder(1024);

            sb.Append("{");
            JsonUtil.SetString("name", Core.UniqueID, sb);
            sb.Append(",");

            if (!string.IsNullOrEmpty(CognitiveVR_Preferences.LobbyId))
            {
                JsonUtil.SetString("lobbyId", CognitiveVR_Preferences.LobbyId, sb);
                sb.Append(",");
            }

            JsonUtil.SetString("sessionid", Core.SessionID, sb);
            sb.Append(",");
            JsonUtil.SetDouble("timestamp", (int)Core.SessionTimeStamp, sb);
            sb.Append(",");
            JsonUtil.SetInt("part", jsonPart, sb);
            sb.Append(",");
            jsonPart++;
            JsonUtil.SetString("formatversion", "1.0", sb);
            sb.Append(",");


            sb.Append("\"data\":[");
            foreach (var k in CachedSnapshots.Keys)
            {
                sb.Append("{");
                JsonUtil.SetString("name", k, sb);
                sb.Append(",");
                sb.Append("\"data\":[");
                foreach (var v in CachedSnapshots[k])
                {
                    sb.Append(v);
                    sb.Append(",");
                }
                if (CachedSnapshots.Values.Count > 0)
                {
                    sb.Remove(sb.Length - 1, 1); //remove last comma from data array
                }
                sb.Append("]");
                sb.Append("}");
                sb.Append(",");
            }
            if (CachedSnapshots.Keys.Count > 0)
            {
                sb.Remove(sb.Length - 1, 1); //remove last comma from sensor object
            }
            sb.Append("]}");

            CachedSnapshots.Clear();
            currentSensorSnapshots = 0;

            string url = Constants.POSTSENSORDATA(sceneSettings.SceneId, sceneSettings.VersionNumber);

            //byte[] outBytes = System.Text.UTF8Encoding.UTF8.GetBytes();
            //CognitiveVR_Manager.Instance.StartCoroutine(CognitiveVR_Manager.Instance.PostJsonRequest(outBytes, url));
            NetworkManager.Post(url, sb.ToString());
        }
Exemplo n.º 14
0
        private static void SendGazeData()
        {
            if (gazeCount == 0)
            {
                return;
            }

            if (!Core.IsInitialized)
            {
                return;
            }

            if (string.IsNullOrEmpty(Core.TrackingSceneId))
            {
                Util.logDebug("Cognitive GazeCore.SendData could not find scene settings for scene! do not upload gaze to sceneexplorer");
                //dump gaze data
                gazebuilder.Length = 9;
                gazeCount          = 0;
                return;
            }

            if (gazebuilder[gazebuilder.Length - 1] == ',')
            {
                gazebuilder = gazebuilder.Remove(gazebuilder.Length - 1, 1);
            }

            gazebuilder.Append("],");

            gazeCount = 0;

            //header
            JsonUtil.SetString("userid", Core.DeviceId, gazebuilder);
            gazebuilder.Append(",");

            if (!string.IsNullOrEmpty(Core.LobbyId))
            {
                JsonUtil.SetString("lobbyId", Core.LobbyId, gazebuilder);
                gazebuilder.Append(",");
            }

            JsonUtil.SetDouble("timestamp", (int)Core.SessionTimeStamp, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetString("sessionid", Core.SessionID, gazebuilder);
            gazebuilder.Append(",");
            JsonUtil.SetInt("part", jsonPart, gazebuilder);
            jsonPart++;
            gazebuilder.Append(",");

            JsonUtil.SetString("hmdtype", HMDName, gazebuilder);

            gazebuilder.Append(",");
            JsonUtil.SetFloat("interval", CognitiveVR.CognitiveVR_Preferences.Instance.SnapshotInterval, gazebuilder);
            gazebuilder.Append(",");

            JsonUtil.SetString("formatversion", "1.0", gazebuilder);

            if (Core.ForceWriteSessionMetadata) //if scene changed and haven't sent metadata recently
            {
                Core.ForceWriteSessionMetadata = false;
                gazebuilder.Append(",");
                gazebuilder.Append("\"properties\":{");
                foreach (var kvp in Core.GetAllSessionProperties(true))
                {
                    if (kvp.Value.GetType() == typeof(string))
                    {
                        JsonUtil.SetString(kvp.Key, (string)kvp.Value, gazebuilder);
                    }
                    else
                    {
                        JsonUtil.SetObject(kvp.Key, kvp.Value, gazebuilder);
                    }
                    gazebuilder.Append(",");
                }
                gazebuilder.Remove(gazebuilder.Length - 1, 1); //remove comma
                gazebuilder.Append("}");
            }
            else if (Core.GetNewSessionProperties(false).Count > 0) //if a session property has changed
            {
                gazebuilder.Append(",");
                gazebuilder.Append("\"properties\":{");
                foreach (var kvp in Core.GetNewSessionProperties(true))
                {
                    if (kvp.Value.GetType() == typeof(string))
                    {
                        JsonUtil.SetString(kvp.Key, (string)kvp.Value, gazebuilder);
                    }
                    else
                    {
                        JsonUtil.SetObject(kvp.Key, kvp.Value, gazebuilder);
                    }
                    gazebuilder.Append(",");
                }
                gazebuilder.Remove(gazebuilder.Length - 1, 1); //remove comma
                gazebuilder.Append("}");
            }

            gazebuilder.Append("}");

            var    sceneSettings = Core.TrackingScene;
            string url           = CognitiveStatics.POSTGAZEDATA(sceneSettings.SceneId, sceneSettings.VersionNumber);

            CognitiveVR.NetworkManager.Post(url, gazebuilder.ToString());
            if (OnGazeSend != null)
            {
                OnGazeSend.Invoke();
            }

            //gazebuilder = new StringBuilder(70 * CognitiveVR_Preferences.Instance.GazeSnapshotCount + 200);
            gazebuilder.Length = 9;
            //gazebuilder.Append("{\"data\":[");
        }