public void SendMessage(ErgData ergData, Segment currentSegment) { if (client != null) { client.SendMessage(ergData, currentSegment); } }
void Start() { ergData = new ErgData(); ErgDataEvent e = new ErgDataEvent(ergData); InteroEventManager.GetEventManager().SendEvent(e); }
void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent) { // currentErgData = ergDataEvent.ergData; if (playerref.activeInHierarchy) { for (int i = 0; i < physicsManagers.Length; ++i) { Rigidbody rigidBody = players[i].GetComponent <Rigidbody>(); float v = rigidBody.velocity.x; float x = rigidBody.position.x; InteroBody1D body = null; if (currentSegment != null) { ErgData e = new ErgData(); e.Copy(ergDataEvent.ergData); e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData); body = physicsManagers[i].UpdateLocation(x, v, e); //hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData); } else { body = physicsManagers[i].UpdateLocation(x, v, ergDataEvent.ergData); } rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z); rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z); // print(i+ "update " + body.distance); } } }
public void UpdateRival(OSCErgDataEvent ergEvent) { if (rivals == null) { return; } print("UpdateRival index1 " + ergEvent.senderId); print("UpdateRival index2 " + rivals); GameObject rival = rivals[ergEvent.senderId]; PhysicsManager physicsManager = physicsManagers[ergEvent.senderId]; Rigidbody rigidBody = rival.GetComponent <Rigidbody>(); float v = rigidBody.velocity.x; float x = rigidBody.position.x; // float z = ergEvent.senderId * 2.0f; ErgData e = new ErgData(); e.Copy(ergEvent.ergData); e.distance = ergEvent.segment.getProgressedDistance(ergEvent.ergData); print("UpdateRival p Distance " + e.distance); if (e.distance < 0.1 && e.distance > -0.1) { physicsManager.ResetLocation(); } InteroBody1D body = physicsManager.UpdateLocation(x, v, e); rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z); rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z); }
// public CanvasController canvas; public void UpdateWorkoutSummary(ErgData[] avgErgDatas, Segment[] segments)//List<WorkoutJSON> workouts, string workoutId) { // canvas.ShowworkoutSumaryView(); content.sizeDelta = new Vector2(0, segments.Length * 400); // Workout for (int i = 0; i < segments.Length; i++) { Segment s = segments[i]; ErgData e = avgErgDatas[i]; // Segment segment = new SegmentTime() // 60 width of item float spawnY = i * 220; //newSpawn Position Vector3 pos = new Vector3(0.0f, -spawnY, SpawnPoint.position.z); //instantiate item GameObject SpawnedItem = Instantiate(item, pos, SpawnPoint.rotation); //setParent SpawnedItem.transform.SetParent(SpawnPoint, false); //get ItemDetails Component WorkoutSummaryItem segmentItem = SpawnedItem.GetComponent <WorkoutSummaryItem>(); //set type segmentItem.UpdateSegmentSummary(s, e); } }
void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent) { ErgData currentErgData = ergDataEvent.ergData; if (player.activeInHierarchy) { if (currentSegment != null) { int i = currentSegment.index; print("OnStartSegmentEventJJJ " + i); auth.PostMessage(i, currentErgData); } /* * Rigidbody rigidBody = player.GetComponent<Rigidbody>(); * float v = rigidBody.velocity.x; * float x = rigidBody.position.x; * InteroBody1D body = physicsManager.UpdateLocation(x, v, ergDataEvent.ergData); * rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z); * rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z); * // update hud * if(currentSegment!=null) * hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData); */ } // UnityEngine.Debug.Log("got ergData " + ergDataEvent.ergData); }
void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent) { ErgData erg = ergDataEvent.ergData; textTime.text = erg.time + ""; textPace.text = erg.pace + ""; textDistance.text = erg.distance + ""; }
public override async Task <string> PostMessage(int id, int segmentIndex, ErgData e) { PostMessageT postM = new PostMessageT(id, segmentIndex, e); string payload = UnityEngine.JsonUtility.ToJson(postM); var content = new StringContent(payload, System.Text.Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(backendAPIAddress + "/user/", content); var responseString = await response.Content.ReadAsStringAsync(); return(responseString); }
public float getSPMFrom(ErgData ergData) { if (isConstraintDistance) { return(getSPMFromConstraint(ergData.distance)); } else { print("time constr"); return(getSPMFromConstraint(ergData.time / 60.0f)); } }
public void SetFields(ErgData e) { float d = e.distance, t = e.time; float power = e.power, pace = e.pace; float spm = e.spm; mDistance.text = string.Format("{0}", Mathf.Floor(d)); mTime.text = timeToString(t); mWatts.text = string.Format("{0}", power); mPace.text = string.Format("{0}", timeToString(pace)); mSPM.text = string.Format("{0}", spm); }
void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent) { ErgData ergData = ergDataEvent.ergData; // Debug.Log("OnErgDataEvent local"); if (player.activeInHierarchy && currentSegment != null) { print("Local " + ergData); leaderboard.UpdateRankLocal(netManager.GetName(), currentSegment.getProgressedDistance(ergData), ergData, currentSegment); netManager.SendMessage(ergData, currentSegment); } // UnityEngine.Debug.Log("got ergData " + ergDataEvent.ergData); }
void IListenerOSC.OnOSCErgDataEvent(OSCErgDataEvent ergEvent) { return; string username = ergEvent.socketSender.username; ErgData e = ergEvent.ergData; Segment s = ergEvent.segment; float d = s.getProgressedDistance(e); print(username + " xx OSC " + ergEvent.ergData + "|" + d); leaderboard.UpdateRank(username, d, e, s); // rivalController.UpdateRival(ergEvent); }
void initActions() { actionReadErgData = (string nameCharacteristic, byte[] data) => { // File.WriteAllBytes("Foo.txt", data); // Requires System.IO output.text = String.Format("{0}|{1}|{2}|{3}", data[0], data[1], data[2], data[3]); ErgData erg = ErgData.FromBytes(data); // OnErgData(erg); factoryCommunication.OnErgData(erg); output1.text = String.Format("{0}", erg.ToString()); // output1.text = String.Format("We got this {0} {1}",BitConverter.IsLittleEndian,data.Length); BluetoothLEHardwareInterface.ReadCharacteristic(_connectedID, _serviceUUID, _characteristicUUID, actionReadErgData); }; }
void IListenerErg.OnErgDataEvent(ErgDataEvent ergDataEvent) { // currentErgData = ergDataEvent.ergData; if (player.activeInHierarchy) { Rigidbody rigidBody = player.GetComponent <Rigidbody>(); float v = rigidBody.velocity.x; float x = rigidBody.position.x; InteroBody1D body = null; /* * * // update hud * if (currentSegment != null) * { * ErgData e = new ErgData(); * e.Copy(ergDataEvent.ergData); * e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData); * // $"Hello, {name}! Today is {date.DayOfWeek}, * * print($"Progress d {e.distance}\t{x}\t{v}"); * // float d = currentSegment.getProgressedDistance(ergDataEvent.ergData); * // print("loc xx erg " + ergDataEvent.ergData + "|"+d); * // print(ergDataEvent.ergData); * * body = physicsManager.UpdateLocation(x, v, e); * hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData); * // physicsManager.se * * } * else*/ if (currentSegment != null) { ErgData e = new ErgData(); e.Copy(ergDataEvent.ergData); e.distance = currentSegment.getProgressedDistance(ergDataEvent.ergData); body = physicsManager.UpdateLocation(x, v, e); hud.DisplayCurrentSegment(currentSegment, ergDataEvent.ergData); } else { body = physicsManager.UpdateLocation(x, v, ergDataEvent.ergData); } rigidBody.velocity = new Vector3(body.velocity, rigidBody.velocity.y, rigidBody.velocity.z); rigidBody.position = new Vector3(body.distance, rigidBody.position.y, rigidBody.position.z); } }
public override InteroBody1D UpdateLocation(float realDistance, float realSpeed, ErgData e) { // UnityEngine.Debug.Log("Jojo"); InteroBody1D targetLocation = new InteroBody1D(e); //return targetLocation; // InteroBody1D newLocation = new InteroBody1D(e); // first time? if (previousLocation == null) { // teleport to new location previousLocation = targetLocation; return(new InteroBody1D(e.distance, 0)); } else { float dT = targetLocation.time - previousLocation.time; if (dT < 0.0001f) { previousLocation.copy(targetLocation); // mantain the old speed return(new InteroBody1D(realDistance, realSpeed)); } float deltaDistance = targetLocation.distance - realDistance; float speed = deltaDistance / dT; // Debug.Log($"delta\t{e.distance}\t{deltaDistance}\t{dT}"); if (System.Math.Abs(deltaDistance) > 15) { // teleport to new location previousLocation.copy(targetLocation); return(new InteroBody1D(e.distance, realSpeed)); } // PID controller float deltaForce = kD * speed + kP * (targetLocation.distance - realDistance); previousLocation.copy(targetLocation); if (deltaForce > 0.0f) { deltaForce = 0.0f; } InteroBody1D body = new InteroBody1D(realDistance, deltaForce); return(body); } }
public void UpdateRank(string name, float v, ErgData ergData, Segment segment) { if (leaderboard == null) { return; } ErgData e = new ErgData(); Segment s = Segment.Factory(segment); e.Copy(ergData); leaderboard.UpdateRank(name, v, e, s); LinkedList <RankNode> ranks = leaderboard.GetRankings(); UpdateRankList(ranks); }
public void DisplayCurrentSegment(Segment segment, ErgData progressValue) { if (progressValue != null) { textObjective.text = $"{progressValue.spm}/" + segment.objective.targetValue + " spm"; } else { textObjective.text = segment.objective.targetValue + " spm"; } textDuration.text = segment.getTextRemaining(progressValue);// segment.getTextRemaining(); segRecuperacion.SetActive(SegmentIntensity.EASY == segment.typeIntensity); segFuerte.SetActive(SegmentIntensity.FAST == segment.typeIntensity); segMedio.SetActive(SegmentIntensity.MEDIUM == segment.typeIntensity); string[] strDifficulty = { "recuperaciĆ³n", "medio", "Fuerte!" }; textDifficulty.text = strDifficulty[(int)segment.typeIntensity];// SegmentTime.timeToString((int)segment.getRemaining(0)); }
internal void UpdateSegmentSummary(Segment s, ErgData e) { segmentType.text = strDifficulty[(int)s.typeIntensity]; // .type.ToString(); segmentObjective.text = s.getTextObjective(); // workout.segments[i].target.spm.ToString(); segmentDuration.text = s.getTextRemaining(0); // workout.segments[i].duration.ToString(); //set background color //no se que valores arroja intensity porque es del tipo SegmentIntensity // pero para cambiar el color del fondo seria //segmentItem.intensity.color = el color // s avgPace.text = SegmentTime.timeToString((int)e.pace); distancie.text = (int)Math.Round(e.distance) + " m"; time.text = SegmentTime.timeToMSString(e.time); avgSPM.text = e.spm + "";; avgPower.text = e.avgPower + " W"; avgHR.text = e.heartrate + " BPM"; }
public override InteroBody1D UpdateLocation(float realDistance, float realSpeed, ErgData e) { // UnityEngine.Debug.Log("Jojo"); InteroBody1D targetLocation = new InteroBody1D(e); return(targetLocation); /* * // InteroBody1D newLocation = new InteroBody1D(e); * // first time? * if (previousLocation == null) * { * // teleport to new location * previousLocation = targetLocation; * return new InteroBody1D(e.distance, 0); * } * else * { * float dT = targetLocation.time - previousLocation.time; * * if (dT < 0.0001f) * { * previousLocation.copy(targetLocation); * // mantain the old speed * return new InteroBody1D(realDistance, realSpeed); * } * * float deltaDistance = targetLocation.distance - realDistance; * float speed = deltaDistance / dT; * // Debug.Log($"delta\t{e.distance}\t{deltaDistance}\t{dT}"); * if (System.Math.Abs(deltaDistance) > 15) * { * // teleport to new location * previousLocation.copy(targetLocation); * return new InteroBody1D(e.distance, realSpeed); * } * // PID controller * float deltaForce = kD * speed + kP * (targetLocation.distance - realDistance); * previousLocation.copy(targetLocation); * return new InteroBody1D(realDistance, deltaForce); * } */ }
void SetRank(int i, RankNode rank) { if (rankLocal == null) { return; } // rank.progressDistance Debug.Log("SetRank 1" + rankLocal); Debug.Log("SetRank 2" + rank); Debug.Log("SetRank 3" + rankNameTexts); Debug.Log("SetRank 3" + rankNameTexts.Length); rankNameTexts[i].text = (i + 1) + " " + GetShortName(rank.username); ErgData e = rank.ergData; Segment s = rank.segment; rankStatsTexts[i].text = SegmentTime.timeToString((int)rank.ergData.pace) + " " + rank.ergData.spm + " " + (int)(rank.progressDistance - rankLocal.progressDistance) + " m"; // + rank.ergData.heartrate; mapController.UpdatePosition(i, rank, rankLocal); // rankStatsTexts[i].text = SegmentTime.timeToString((int)e.pace) + " " + (s.getProgressedDistance(e)*-1);// + "|" + s.getProgressedDistance(e); }
public void UpdatePosition(int i, RankNode rank, RankNode rankLocal) { // rank.ergData ErgData e = rank.ergData; Segment s = Segment.Factory(rank.segment); Segment sl = Segment.Factory(rankLocal.segment); // e.distance = s.getProgressedDistance(e); // print(s.type+" s\t" + s.start + "\t" + s.end + "\t" + s.Progress(e) + "\t" + s.getTextRemaining(e)); // rank.progressDistance - rankLocal.progressDistance //Segment s = Segment.Factory(segment); Debug.Log("Jijjjo" + e.time + " " + e.distance); Debug.Log("Intero " + rank.progressDistance); // Debug.Log(s.end); // currentSegment.getProgressedDistance UpdatePosition(i, sl.Progress(e)); }
// Start is called before the first frame update // Update is called once per frame public void ShowSegmentSummary(SegmentEndEvent segmentEndEvent, StatisticManager statisticManager) { ErgData e = statisticManager.GetSegmentErgDataStats(); textPace.text = SegmentTime.timeToString((int)e.pace); textSPM.text = e.spm + "/" + segmentEndEvent.currentSegment.getTextObjective(); // textObjective.text = segmentEndEvent.currentSegment.getTextObjective(); textPower.text = e.avgPower + " watts"; // ErgData[] ergs = (ErgData[]).ToArray(); string ret = ""; ErgData[] s = statisticManager.ergSegmentStack.ToArray(); for (int i = 0; i < s.Length; ++i) { e = s[i]; ret += "[" + e.pace + ", " + e.spm + ", " + e.avgPower + "] "; } print("jojo " + ret); layout.SetActive(true); Invoke("HideSegmentSummary", 5); }
public void UpdateRankLocal(string name, float v, ErgData ergData, Segment segment) { rankLocal = new RankNode(name, v, ergData, segment); UpdateRank(name, v, ergData, segment); }
public async Task PostMessage(int segmentNum, ErgData e) { Debug.Log("PostMessage"); // await interoCloud.PostMessage(historyId, segmentNum, e); }
public async Task PostMessage(int segmentNum, ErgData e) { // print("PostMessage" + historyId+ segmentNum+ e); Debug.Log("PostMessage"); await interoCloud.PostMessage(historyId, segmentNum, e); }