コード例 #1
0
ファイル: ExitPoll.cs プロジェクト: alexhersh/cvr-sdk-unity
        //the responses of all the questions in the set put together in a string and uploaded to the microservice at api.cognitivevr.io
        //each question is already sent as a transaction
        void SendQuestionResponses(string responses)
        {
            string url = Constants.POSTEXITPOLLRESPONSES(QuestionSetName, questionSetVersion);

            //byte[] bytes = System.Text.Encoding.ASCII.GetBytes(responses);

            CognitiveVR.Util.logDebug("ExitPoll Send Answers\nurl " + url);

            //var headers = new Dictionary<string, string>();//AUTH
            //headers.Add("Content-Type", "application/json");
            //headers.Add("X-HTTP-Method-Override", "POST");
            //headers.Add("Authorization", "APIKEY:DATA " + CognitiveVR_Preferences.Instance.APIKey);

            NetworkManager.Post(url, responses);
        }
コード例 #2
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);
        }
コード例 #3
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());
        }
コード例 #4
0
        private static void Core_OnSendData()
        {
            if (CachedSnapshots.Keys.Count <= 0)
            {
                CognitiveVR.Util.logDebug("Sensor.SendData found no data"); return;
            }

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


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


            StringBuilder sb = new StringBuilder(1024);

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

            if (!string.IsNullOrEmpty(Core.LobbyId))
            {
                JsonUtil.SetString("lobbyId", Core.LobbyId, 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++;
            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 = CognitiveStatics.POSTSENSORDATA(Core.TrackingSceneId, Core.TrackingSceneVersionNumber);

            //byte[] outBytes = System.Text.UTF8Encoding.UTF8.GetBytes();
            //CognitiveVR_Manager.Instance.StartCoroutine(CognitiveVR_Manager.Instance.PostJsonRequest(outBytes, url));
            NetworkManager.Post(url, sb.ToString());
        }
コード例 #5
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();
                }
            }
        }
コード例 #6
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();
            }
        }
コード例 #7
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());
        }