122 lines
6.7 KiB
C#
122 lines
6.7 KiB
C#
using Assets.Scripts;
|
|
using Assets.Scripts.Apis.Models;
|
|
using ChartAndGraph;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class RowerResult : PFUIPanel
|
|
{
|
|
RowerResultModel _model;
|
|
private GraphChart chartPace, chartRate, chartHR;
|
|
Transform dataContent;
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
var grid = transform.Find("Scroll View/Viewport/Content/Content/Table").GetComponent<GridLayoutGroup>();
|
|
float width = (App.canvasWidth - 60 - 3) / 4;
|
|
grid.cellSize = new Vector2(width, 37);
|
|
var grid1 = transform.Find("Scroll View/Viewport/Content/Content/Other/Datas").GetComponent<GridLayoutGroup>();
|
|
grid1.cellSize = new Vector2(width, 53);
|
|
chartPace = transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<GraphChart>();
|
|
chartPace.DataSource.VerticalViewOrigin = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15));
|
|
chartPace.DataSource.VerticalViewSize = ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15)) * -1;
|
|
chartRate = transform.Find("Scroll View/Viewport/Content/Content/ChartRate/Chart").GetComponent<GraphChart>();
|
|
chartHR = transform.Find("Scroll View/Viewport/Content/Content/ChartHeartRate/Chart").GetComponent<GraphChart>();
|
|
dataContent = transform.Find("Scroll View/Viewport/Content/Content");
|
|
UIManager.AddEvent(transform.Find("Exit").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
{
|
|
Close();
|
|
});
|
|
//var a = new List<ChartAndGraph.DoubleVector2>();
|
|
//for (int i = 0; i < 100; i++)
|
|
//{
|
|
// a.Add(new ChartAndGraph.DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(300))));
|
|
//}
|
|
//transform.Find("Scroll View/Viewport/Content/Content/ChartPace/Chart").GetComponent<RowerLargeDataFeed>().SetData(a);
|
|
}
|
|
public async void Initial(string id)
|
|
{
|
|
transform.Find("Scroll View").GetComponent<ScrollRect>().verticalNormalizedPosition = 1;
|
|
GetComponent<CanvasGroup>().alpha = 0;
|
|
var res = await ConfigHelper.rowerApi.GetDetail(id);
|
|
if (res.result)
|
|
{
|
|
_model = res.data;
|
|
dataContent.Find("Title").GetComponent<Text>().text = $"{_model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} Free Rowing";
|
|
dataContent.Find("Time").GetComponent<Text>().text = $"{_model.StartTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")} ~ {_model.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
dataContent.Find("TitleContent/Duration").GetComponent<Text>().text
|
|
= $"<color=#5c5c6e>Rowing time :</color> {TimeSpan.FromSeconds(_model.TotalTime).ToString()}";
|
|
dataContent.Find("TitleContent/Distance").GetComponent<Text>().text
|
|
= $"<color=#5c5c6e>Distance :</color> {_model.TotalDistance}M";
|
|
dataContent.Find("TitleContent/Device").GetComponent<Text>().text
|
|
= $"<color=#5c5c6e>Rowing equipment :</color> {_model.ManufacturerName}";
|
|
dataContent.Find("Table/AvgPower/Text").GetComponent<Text>().text
|
|
= $"{TimeSpan.FromSeconds(_model.AvgPace).ToString(@"mm\:ss")} /500M";
|
|
dataContent.Find("Table/AvgHR/Text").GetComponent<Text>().text
|
|
= $"{_model.AvgHeartRate} BPM";
|
|
dataContent.Find("Table/AvgRate/Text").GetComponent<Text>().text
|
|
= $"{_model.AvgRate.ToString("#0")} SPM";
|
|
dataContent.Find("Table/MaxPower/Text").GetComponent<Text>().text
|
|
= $"{TimeSpan.FromSeconds(_model.MaxPace).ToString(@"mm\:ss")} /500M";
|
|
dataContent.Find("Table/MaxHR/Text").GetComponent<Text>().text
|
|
= $"{_model.MaxHeartRate} BPM";
|
|
dataContent.Find("Table/MaxRate/Text").GetComponent<Text>().text
|
|
= $"{_model.MaxRate.ToString("#0")} SPM";
|
|
dataContent.Find("ChartPace/Avg/Value").GetComponent<Text>().text
|
|
= $"{TimeSpan.FromSeconds(_model.AvgPace).ToString(@"mm\:ss")} /500M";
|
|
dataContent.Find("ChartRate/Avg/Value").GetComponent<Text>().text
|
|
= $"{_model.AvgRate.ToString("#0")} SPM";
|
|
dataContent.Find("ChartHeartRate/Avg/Value").GetComponent<Text>().text
|
|
= $"{_model.AvgHeartRate.ToString("#0")} BPM";
|
|
dataContent.Find("ChartPace/Max/Value").GetComponent<Text>().text
|
|
= $"{TimeSpan.FromSeconds(_model.MaxPace).ToString(@"mm\:ss")} /500M";
|
|
dataContent.Find("ChartRate/Max/Value").GetComponent<Text>().text
|
|
= $"{_model.MaxRate.ToString("#0")} SPM";
|
|
dataContent.Find("ChartHeartRate/Max/Value").GetComponent<Text>().text
|
|
= $"{_model.MaxHeartRate.ToString("#0")} BPM";
|
|
dataContent.Find("Other/Datas/Calories/Value").GetComponent<Text>().text
|
|
= $"{(_model.Kj ?? 0).ToString("#0")} KCAL";
|
|
dataContent.Find("Other/Datas/StrokeCount/Value").GetComponent<Text>().text
|
|
= _model.StrokeCount.ToString();
|
|
//var b = _model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList();
|
|
//Debug.Log(_model.ChartList.Select((x, i) => new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace + UnityEngine.Random.value * 300)))).ToList());
|
|
//var a = new List<DoubleVector2>();
|
|
//for (int i = 0; i < 100; i++)
|
|
//{
|
|
// a.Add(new DoubleVector2(i, UnityEngine.Random.value * 200));
|
|
//}
|
|
chartPace.GetComponent<RowerLargeDataFeed>()
|
|
.SetData(_model.ChartList.Select((x, i) =>
|
|
{
|
|
if (x.Pace == 0)
|
|
{
|
|
return new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromHours(15)) - 2000);
|
|
}
|
|
else
|
|
{
|
|
return new DoubleVector2(i, ChartDateUtility.TimeSpanToValue(TimeSpan.FromMinutes(x.Pace)));
|
|
}
|
|
|
|
}).ToList());
|
|
chartRate.GetComponent<RowerLargeDataFeed>()
|
|
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.Rate)).ToList());
|
|
chartHR.GetComponent<RowerLargeDataFeed>()
|
|
//.SetData(a);
|
|
.SetData(_model.ChartList.Select((x, i) => new DoubleVector2(i, x.HeartRate)).ToList());
|
|
}
|
|
GetComponent<CanvasGroup>().DOFade(1, 0.3f);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
|