AR文件更新流程&AR网络延时问题
This commit is contained in:
1 parent
16cd2fd26b
commit
74ba5790f9
18 files changed
+867
-508
No files matched your search
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
@@ -14,13 +13,12 @@ using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.AR;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
public class VideoLoading : MonoBehaviour, IProgress<float>
|
||||
public class VideoLoading : MonoBehaviour
|
||||
{
|
||||
VideoGameManager manager { get; set; }
|
||||
|
||||
private Text mapName;
|
||||
private RawImage mapRouteImage;
|
||||
private CanvasGroup canvasGroup;
|
||||
@@ -35,26 +33,27 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
private Text slope;
|
||||
private GameObject panel;
|
||||
private GameObject download;
|
||||
private GameObject watch;
|
||||
|
||||
protected GameObject loadingPanel { get; set; }
|
||||
|
||||
private GameObject watch ;
|
||||
protected GameObject loadingPanel;
|
||||
private Text level;
|
||||
private Text rideNum;
|
||||
private Text uploadByUserName;
|
||||
private RawImage head;
|
||||
private RawImage country;
|
||||
private RawImage mapCountry;
|
||||
private RawImage altitudeGraph { get; set; }
|
||||
private RawImage altitudeGraph;
|
||||
private Transform mapRanking;
|
||||
private Text mapId;
|
||||
private Text downloadText { get; set; }
|
||||
private Text downloadText;
|
||||
private Transform ui;
|
||||
private MapRoute route;
|
||||
|
||||
protected float process = 0;//0-100 %
|
||||
|
||||
private VideoGameManager manager { get; set; }
|
||||
private MapRoute route;
|
||||
private ARDownloader downloader;
|
||||
private CancellationTokenSource cancelToken { get; set; }
|
||||
private bool startBtnLock = false;
|
||||
private bool downloading = false;
|
||||
private float total = 1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -104,31 +103,12 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
processText.text = $"{(f).ToString("#0")}%";
|
||||
});
|
||||
|
||||
|
||||
download = transform.Find("Panel/Download").gameObject;
|
||||
watch = transform.Find("Panel/Watch").gameObject;
|
||||
|
||||
UIManager.AddEvent(watch, UnityEngine.EventSystems.EventTriggerType.PointerClick, WatchHandler);
|
||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||
|
||||
var fileName = route.FileName;// "12067924_720p.mp4";
|
||||
var url = route.Url; //@"http://192.168.0.97:6031/12067924_720p.mp4";
|
||||
var path = PFConstants.VideoFolder;
|
||||
var filepath = path + "/" + fileName;
|
||||
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
watch.SetActive(true);
|
||||
slider.value = 100;
|
||||
download.gameObject.SetActive(false);
|
||||
manager.SetMedia(filepath);
|
||||
}
|
||||
else
|
||||
{
|
||||
watch.SetActive(false);
|
||||
//检查本地文件是否存在 如果存在直接设置mediaPlayer 否则显示下载按钮
|
||||
UIManager.AddEvent(download.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, DownloadAsync);
|
||||
}
|
||||
|
||||
#region
|
||||
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
||||
rideNum = panel.transform.Find("RideNum").GetComponent<Text>();
|
||||
@@ -177,9 +157,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
{
|
||||
panel.transform.Find("RideTip").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
||||
});
|
||||
|
||||
UIManager.AddEvent(download.gameObject, EventTriggerType.PointerClick, DownloadAsync);
|
||||
#endregion
|
||||
|
||||
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
||||
|
||||
CheckUpdate();
|
||||
}
|
||||
|
||||
private async void CheckUpdate()
|
||||
{
|
||||
downloader = new ARDownloader(route);
|
||||
var showDownload = await downloader.CheckAllAsync();
|
||||
var isContinue = App.routeResult != null;
|
||||
|
||||
watch.SetActive(!showDownload && !isContinue);
|
||||
download.gameObject.SetActive(showDownload);
|
||||
|
||||
if (!showDownload)
|
||||
{
|
||||
InitializeVideo();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeVideo()
|
||||
{
|
||||
var path = PFConstants.VideoFolder + "/" + route.FileName;
|
||||
slider.value = 100;
|
||||
manager.SetMedia(path);
|
||||
}
|
||||
|
||||
protected void InitGameObjectData()
|
||||
@@ -267,18 +273,14 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
},false,true);
|
||||
}
|
||||
|
||||
private bool downloading = false;
|
||||
private CancellationTokenSource cancelToken;
|
||||
private async void DownloadAsync(BaseEventData baseEvent)
|
||||
{
|
||||
if (downloading)
|
||||
return;
|
||||
|
||||
beforeDownload();
|
||||
await startDownloading();
|
||||
if (downloading) return;
|
||||
ResetDownload();
|
||||
await StartDownloading();
|
||||
}
|
||||
|
||||
private void beforeDownload()
|
||||
private void ResetDownload()
|
||||
{
|
||||
downloading = true;
|
||||
download.SetActive(false);
|
||||
@@ -287,45 +289,47 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
downloadText.text = "0%";
|
||||
}
|
||||
|
||||
private async Task startDownloading()
|
||||
private async Task StartDownloading()
|
||||
{
|
||||
var route = manager.mapRoute;
|
||||
var path = PFConstants.VideoFolder;
|
||||
slider.maxValue = downloader.Total * 100;
|
||||
if(downloader.IsVideoDownloaded)
|
||||
await downloader.DownLoadVideoAsync(Progress.Create<float>(HandleProgress));
|
||||
if(downloader.IsARRouteDownloaded)
|
||||
await downloader.DownLoadARRouteAsync(Progress.Create<float>(HandleProgress));
|
||||
if(downloader.IsARDataDownloaded)
|
||||
await downloader.DownLoadARDataAsync(Progress.Create<float>(HandleProgress));
|
||||
|
||||
var localPath = PFConstants.ARFolder;
|
||||
var arDataPath = route.ARConfig;
|
||||
var videoRoute = route.VideoRoute;
|
||||
var dataPath = $"{localPath}/{route.Id}";
|
||||
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||
|
||||
cancelToken = new CancellationTokenSource();
|
||||
|
||||
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
|
||||
await Loom.DownloadToFileAsync(videoRoute, $"{dataPath}/route-{route.Id}.json");
|
||||
var res = await Loom.DownloadToFileAsync(route.Url, $"{path}/{route.FileName}",this,cancelToken);
|
||||
if (res.isDone)
|
||||
{
|
||||
var filepath = $"{PFConstants.VideoFolder}/{route.FileName}";
|
||||
manager.SetMedia(filepath);
|
||||
|
||||
rideNow.enabled = true;
|
||||
rideNow.interactable = true;
|
||||
|
||||
downloadText.text = App.GetLocalString("Ride Now");
|
||||
downloading = false;
|
||||
}
|
||||
//cancelToken = new CancellationTokenSource();
|
||||
//CompleteDownLoad();
|
||||
}
|
||||
|
||||
public void Report(float value)
|
||||
private void HandleProgress(float value)
|
||||
{
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
if (cancelToken != null && cancelToken.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
slider.value += (float)Math.Round(value * 100, 0);
|
||||
Debug.Log(value);
|
||||
|
||||
slider.value = value < 1 ? (float)Math.Round(value * 100, 0) : 100;
|
||||
downloadText.text = slider.value.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
var progress = slider.value / slider.maxValue * 100;
|
||||
downloadText.text = progress.ToString(CultureInfo.InvariantCulture) + "%";
|
||||
|
||||
var isComplete = slider.value == slider.maxValue;
|
||||
if (isComplete)
|
||||
CompleteDownLoad();
|
||||
}
|
||||
|
||||
private void CompleteDownLoad()
|
||||
{
|
||||
var filepath = $"{PFConstants.VideoFolder}/{route.FileName}";
|
||||
manager.SetMedia(filepath);
|
||||
watch.GetComponent<Button>().enabled = true;
|
||||
rideNow.enabled = true;
|
||||
rideNow.interactable = true;
|
||||
downloadText.text = App.GetLocalString("Ride Now");
|
||||
downloading = false;
|
||||
}
|
||||
|
||||
//进入观察模式
|
||||
private void WatchHandler(BaseEventData data)
|
||||
{
|
||||
@@ -360,20 +364,27 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
return;
|
||||
}
|
||||
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
UIManager.ShowConfirm("Tips", "CancelDownloadConfirm",
|
||||
() =>
|
||||
{
|
||||
cancelToken?.Cancel();
|
||||
SceneManager.LoadSceneAsync("MainScene");
|
||||
UIManager.CloseConfirm();
|
||||
},
|
||||
2,
|
||||
() =>
|
||||
{
|
||||
UIManager.CloseConfirm();
|
||||
});
|
||||
CancelDownload();
|
||||
}
|
||||
|
||||
private void CancelDownload()
|
||||
{
|
||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||
|
||||
UIManager.ShowConfirm("Tips", "CancelDownloadConfirm",
|
||||
() =>
|
||||
{
|
||||
cancelToken?.Cancel();
|
||||
SceneManager.LoadSceneAsync("MainScene");
|
||||
UIManager.CloseConfirm();
|
||||
},
|
||||
2,
|
||||
() =>
|
||||
{
|
||||
UIManager.CloseConfirm();
|
||||
});
|
||||
}
|
||||
|
||||
private async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||
{
|
||||
var result = await ConfigHelper.mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
||||
@@ -391,6 +402,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
||||
}
|
||||
}
|
||||
|
||||
private void DowloadCallBack(string url, RawImage rawImage)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(url))
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (manager != null)
|
||||
if (manager != null && manager.GetMapRoute() != null)
|
||||
{
|
||||
mapName.text = manager.GetMapRoute().Name;
|
||||
if (manager.CurrentPlayer != null)
|
||||
|
||||
@@ -62,7 +62,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
public GameObject videoPlayer;
|
||||
public GameObject target;
|
||||
public int CurrentUserId { get; set; }
|
||||
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -119,34 +118,49 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
yield return null;
|
||||
videoLoading.Init();//初始化loading页面
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
|
||||
private float tcpTimer = 0f;
|
||||
private void FixedUpdate()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
while (timer <= 0)
|
||||
if (cyclingController == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (cyclingController == null)
|
||||
return;
|
||||
|
||||
try
|
||||
timer -= Time.deltaTime;
|
||||
tcpTimer -= Time.deltaTime;
|
||||
while (timer <= 0)
|
||||
{
|
||||
cyclingController.Run(null);//发送数据到tcp
|
||||
|
||||
var onlineRiders = cyclingController.riders;
|
||||
CreateOnlineUser(onlineRiders); //解析tcp返回数据
|
||||
|
||||
if (isStart)
|
||||
{
|
||||
ComputePlayerRuntimeData();
|
||||
ticks++;
|
||||
}
|
||||
TickTimer();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
while (tcpTimer <= 0)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
MillTimer();
|
||||
}
|
||||
timer += 1f;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void TickTimer()
|
||||
{
|
||||
if (isStart)
|
||||
{
|
||||
ComputePlayerRuntimeData();
|
||||
ticks++;
|
||||
}
|
||||
timer +=1f;
|
||||
}
|
||||
|
||||
private void MillTimer()
|
||||
{
|
||||
cyclingController.Run(null);//发送数据到tcp
|
||||
var onlineRiders = cyclingController.riders;
|
||||
CreateOnlineUser(onlineRiders); //解析tcp返回数据
|
||||
tcpTimer += 0.2f;
|
||||
}
|
||||
|
||||
//计算骑手的数据
|
||||
@@ -302,7 +316,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//移除退出的选手
|
||||
private void RemovePlayers(List<BaseRider> list)
|
||||
{
|
||||
|
||||
var players = FindObjectsOfType<OnlineVideoPlayer>();
|
||||
foreach (var item in players)
|
||||
{
|
||||
@@ -371,10 +384,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
//开始游戏
|
||||
public void StartGame()
|
||||
{
|
||||
//if (startTime != DateTime.MinValue)
|
||||
{
|
||||
startTime = UIManager.Now.GetDateTime();
|
||||
}
|
||||
startTime = UIManager.Now.GetDateTime();
|
||||
isStart = true;
|
||||
}
|
||||
//骑行是否开始
|
||||
@@ -445,7 +455,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
}
|
||||
return mapRoute;
|
||||
}
|
||||
|
||||
|
||||
public void ShowUpRemainTime(double remain)
|
||||
{
|
||||
@@ -477,18 +486,22 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
|
||||
RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
||||
}
|
||||
|
||||
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
||||
{
|
||||
UIManager.AddEvent(sender, eventType, unityAction);
|
||||
}
|
||||
|
||||
public Texture GetCountryImageByCode(string code)
|
||||
{
|
||||
return UIManager.Instance.loginRegOptions.GetCountryImage(code);
|
||||
}
|
||||
|
||||
public Texture GetCountryImageByName(string name)
|
||||
{
|
||||
return UIManager.Instance.loginRegOptions.GetCountryImageByName(name);
|
||||
}
|
||||
|
||||
public Vector2d Along(double endDistance)
|
||||
{
|
||||
if (mapData != null)
|
||||
@@ -504,6 +517,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
||||
return new Vector2d(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
App.gameRoomDetail = null;
|
||||
|
||||
@@ -17,48 +17,55 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
//private readonly MapWorkoutService service = new MapWorkoutService();
|
||||
|
||||
public UserResultModel CurrentUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属人ID
|
||||
/// </summary>
|
||||
public int BelongUserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.CurrentUser.Id;
|
||||
}
|
||||
get { return App.CurrentUser.Id; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录是否完毕
|
||||
/// </summary>
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否需要计算排名
|
||||
/// </summary>
|
||||
public bool IsNeedRanking { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行记录索引(用于中断骑行,继续骑行)
|
||||
/// </summary>
|
||||
public int ContinueIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行状态
|
||||
/// </summary>
|
||||
public CyclingStateEnum CyclingState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 赛事Id
|
||||
/// </summary>
|
||||
public int Competitionid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前已经骑行的距离(表示用户现在在的距离,并不是实际骑的距离)
|
||||
/// </summary>
|
||||
public double EndDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上次骑行的距离
|
||||
/// </summary>
|
||||
public double PreDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 继续骑行记录标志
|
||||
/// </summary>
|
||||
public string ContinueMark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 厂商Id
|
||||
/// </summary>
|
||||
@@ -67,14 +74,17 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
public string ManufacturerName { get; set; }
|
||||
|
||||
public int? AntModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行数据
|
||||
/// </summary>
|
||||
public List<TargetData> RiderDatas = new List<TargetData>();
|
||||
|
||||
/// <summary>
|
||||
/// 当前路线
|
||||
/// </summary>
|
||||
public Route CurrentRoute { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 骑行记录Id
|
||||
/// </summary>
|
||||
@@ -88,14 +98,17 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
/// 当前给骑行台发送数据的模式
|
||||
/// </summary>
|
||||
public SendDataMode SendDataMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 临时使用的坡度
|
||||
/// </summary>
|
||||
public double SlopeGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 临时使用的海拔
|
||||
/// </summary>
|
||||
public double Elevation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前路书开始的距离
|
||||
/// </summary>
|
||||
@@ -108,6 +121,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
public int? LastFrame { get; set; }
|
||||
|
||||
public int RoomId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经保存成功
|
||||
/// </summary>
|
||||
@@ -123,25 +137,25 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
|
||||
public RouteResultParam selectParam { get; set; }
|
||||
|
||||
public int SaveWithLocalRecordAysnc(CyclingModel cyclingModel, RouteResultParam selectParam, string imageName,string recordId,string path)
|
||||
public int SaveWithLocalRecordAysnc(CyclingModel cyclingModel, RouteResultParam selectParam, string imageName,
|
||||
string recordId, string path)
|
||||
{
|
||||
Saved = true;
|
||||
Dictionary<MapInterruptRecord, List<string>> recordData = new Dictionary<MapInterruptRecord, List<string>>();
|
||||
var recordData = new Dictionary<MapInterruptRecord, List<string>>();
|
||||
if (RiderDatas.Count <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string newFileName = Guid.NewGuid().ToString();
|
||||
int FTP = Helper.GetFtp();
|
||||
double NP = Helper.GetNP(RiderDatas);
|
||||
|
||||
var newFileName = Guid.NewGuid().ToString();
|
||||
var FTP = Helper.GetFtp();
|
||||
var NP = Helper.GetNP(RiderDatas);
|
||||
//强度
|
||||
double IF = NP / FTP;
|
||||
var IF = NP / FTP;
|
||||
//训练量
|
||||
double TSS = (RiderDatas.Count * NP * IF) / (FTP * 3600) * 100;
|
||||
var TSS = (RiderDatas.Count * NP * IF) / (FTP * 3600) * 100;
|
||||
var averagePower = Helper.AveragePower(RiderDatas);
|
||||
|
||||
// AntManufacturer manufacturer = service.GetAntManufacturer(ManufacturerId).data;
|
||||
//var recordId = Guid.NewGuid().ToString();
|
||||
|
||||
var ticks = RiderDatas.Last().Ticks;
|
||||
var interruptRecord = new MapInterruptRecord
|
||||
{
|
||||
@@ -151,17 +165,15 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
TotalDistance = CurrentRoute.RouteInstance.Distance,
|
||||
UserId = BelongUserId,
|
||||
RecordFileName = newFileName + ".txt",
|
||||
Ftp = FTP,//FTP设置
|
||||
Ftp = FTP,
|
||||
IF = Math.Round(IF, 2),
|
||||
Kj = RiderDatas.Sum(a => a._Power) / 1000,//消耗
|
||||
Kj = RiderDatas.Sum(a => a._Power) / 1000, //消耗
|
||||
Tss = Math.Round(TSS, 2),
|
||||
EndDistance = EndDistance,
|
||||
IsCompleted = IsCompleted,
|
||||
|
||||
//TrainingTime = TimeHelper.FormatSeconds(RiderDatas.Last().Ticks),//训练时间
|
||||
NormalizedPower = Math.Floor(NP),//标准化功率
|
||||
AveragePower = averagePower,//平均功率
|
||||
MaxPower = RiderDatas.Max(a => a._Power),//最大功率
|
||||
NormalizedPower = Math.Floor(NP), //标准化功率
|
||||
AveragePower = averagePower, //平均功率
|
||||
MaxPower = RiderDatas.Max(a => a._Power), //最大功率
|
||||
WeightKg = Math.Round(averagePower / App.CurrentUser.Weight, 2),
|
||||
Weight = App.CurrentUser.Weight,
|
||||
BicycleWeight = App.CurrentUser.BicycleWeight,
|
||||
@@ -169,14 +181,14 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
ContinueIndex = ContinueIndex,
|
||||
IsDelete = false,
|
||||
MapCompetitionId = Competitionid,
|
||||
ManufacturerName = ManufacturerName,//manufacturer == null ? "" : manufacturer.Name,
|
||||
ManufacturerName = ManufacturerName,
|
||||
DeviceNumber = DeviceNumber,
|
||||
IsRanking = IsNeedRanking,
|
||||
CurrentRouteStartDistance = CurrentRouteStartDistance,
|
||||
ManufacturerId = ManufacturerId,
|
||||
AntModelId = AntModelId,
|
||||
StartTime = StartTime,
|
||||
CreateTime = EndTime, //StartTime.AddSeconds(ticks),
|
||||
CreateTime = EndTime,
|
||||
Ticks = ticks,
|
||||
Mode = cyclingModel.ToString(),
|
||||
Param = Newtonsoft.Json.JsonConvert.SerializeObject(selectParam),
|
||||
@@ -185,10 +197,10 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
LastFrame = LastFrame,
|
||||
RoomId = RoomId
|
||||
};
|
||||
//var range = new MapSpeedRange().GetSpeedRange(RiderDatas, CurrentRoute.RouteInstance.Distance);
|
||||
interruptRecord.SpeedRange = null; //JsonConvert.SerializeObject(range);
|
||||
|
||||
double process = Math.Round((EndDistance - interruptRecord.CurrentRouteStartDistance) / CurrentRoute.RouteInstance.Distance, 2);
|
||||
interruptRecord.SpeedRange = null;
|
||||
|
||||
var process = Math.Round((EndDistance - interruptRecord.CurrentRouteStartDistance) / CurrentRoute.RouteInstance.Distance, 2);
|
||||
interruptRecord.Progress = process > 1 ? 1 : process;
|
||||
|
||||
var cadences = RiderDatas.Where(a => a._Cadence.HasValue && a._Cadence.Value > 0);
|
||||
@@ -196,19 +208,16 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
interruptRecord.AverageCadence = Math.Round(cadences.Average(a => a._Cadence.GetValueOrDefault(0)));
|
||||
}
|
||||
|
||||
interruptRecord.MaxCadence = Math.Round(RiderDatas.Max(a => a._Cadence.GetValueOrDefault(0)));
|
||||
interruptRecord.AverageHeartRate = Math.Round(RiderDatas.Average(a => a._HeartRate.GetValueOrDefault(0)));
|
||||
interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0));
|
||||
//service.CreateRecordCyclingData(interruptRecord);
|
||||
//保存骑行记录txt
|
||||
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords" + "/" + interruptRecord.Id);
|
||||
//var path = PFConstants.MapWorkoutRecordFolder + "/" + interruptRecord.Id;
|
||||
var files = new List<string>();
|
||||
try
|
||||
{
|
||||
var fname = path + "/" + newFileName + ".txt";
|
||||
using (var fs = new FileInfo(fname).OpenWrite())
|
||||
var fileName = path + "/" + newFileName + ".txt";
|
||||
using (var fs = new FileInfo(fileName).OpenWrite())
|
||||
{
|
||||
var stream = new StreamWriter(fs);
|
||||
stream.BaseStream.Seek(0, SeekOrigin.End);
|
||||
@@ -218,13 +227,15 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
}
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
files.Add(fname);
|
||||
files.Add(fileName);
|
||||
}
|
||||
|
||||
//图片
|
||||
if (!string.IsNullOrEmpty(imageName))
|
||||
{
|
||||
files.Add(imageName);
|
||||
}
|
||||
|
||||
//持久化序列化对象
|
||||
var recordString = JsonConvert.SerializeObject(interruptRecord);
|
||||
var recordFilePath = path + "/" + "record" + ".txt";
|
||||
@@ -235,48 +246,44 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
Helper.DelectDir(path);
|
||||
Debug.Log(ex.Message);
|
||||
}
|
||||
|
||||
recordData.Add(interruptRecord, files);
|
||||
return SaveDataAysnc(recordData, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存数据
|
||||
/// </summary>
|
||||
/// <param name="base64Image"></param>
|
||||
/// <returns></returns>
|
||||
public int SaveDataAysnc(Dictionary<MapInterruptRecord, List<string>> data,string path)
|
||||
public int SaveDataAysnc(Dictionary<MapInterruptRecord, List<string>> data, string path)
|
||||
{
|
||||
if (data != null && data.Count > 0)
|
||||
if (data == null || data.Count <= 0) return -1;
|
||||
|
||||
try
|
||||
{
|
||||
//var path = Helper.GetDataDir("MapWorkoutRecords");
|
||||
//Task.Run(() => {
|
||||
try
|
||||
{
|
||||
var record = data.FirstOrDefault();
|
||||
MapInterruptRecordApi service = new MapInterruptRecordApi();
|
||||
var result = service.Add(record.Key, record.Value);
|
||||
var record = data.FirstOrDefault();
|
||||
var service = new MapInterruptRecordApi();
|
||||
var result = service.Add(record.Key, record.Value);
|
||||
|
||||
if (result.result)
|
||||
if (result.result)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
//删除文件
|
||||
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
Helper.DelectDir(path);
|
||||
}
|
||||
//});
|
||||
return result.data.RankingId;
|
||||
Helper.DelectDir(path);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
return result.data.RankingId;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class TempRecordData
|
||||
{
|
||||
public int RoomId { get; set; }
|
||||
|
||||
@@ -26,6 +26,18 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public static string CreateFileIfNotExsit(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.CreateText(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public double Distance(Vector2d from, Vector2d to)
|
||||
{
|
||||
var pt1 = Turf.Point(new double[] { from.x, from.y });
|
||||
|
||||
Reference in new issue
Block a user