骑行结束时间误差问题解决

This commit is contained in:
lishuo 2021-07-30 09:53:49 +08:00
parent 1919370a23
commit 12838266ba
7 changed files with 80 additions and 53 deletions

View File

@ -2436,7 +2436,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
mType: 0 mType: 0
Tooltips: Tooltips: Back
--- !u!1 &6558498177234723988 --- !u!1 &6558498177234723988
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -36,7 +36,7 @@ namespace Assets.Scenes.Ride.Scripts
//比赛开始前倒计时 //比赛开始前倒计时
if (count > 0 && !competitionModel.recorderData.Saved) if (count > 0 && !competitionModel.recorderData.Saved)
{ {
ShowCountDown(count, "Get ready!");//显示倒计时面板信息 ShowCountDown(count, "Get Ready!");//显示倒计时面板信息
Timer.gameObject.SetActive(false); Timer.gameObject.SetActive(false);
TimerTitle.gameObject.SetActive(false); TimerTitle.gameObject.SetActive(false);
} }

View File

@ -213,7 +213,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
List<CompetitionTopModel> CompetitionTopList = new List<CompetitionTopModel>(); List<CompetitionTopModel> CompetitionTopList = new List<CompetitionTopModel>();
var resultList = results.Take(6); var resultList = results.Take(6);
var count = 6 - resultList.Count(); //var count = 6 - resultList.Count();
//先取比赛结果 //先取比赛结果
foreach (var item in resultList) foreach (var item in resultList)
{ {
@ -228,22 +228,22 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
}); });
} }
if (count > 0) //if (count > 0)
{ //{
var ss = sort.Where(c => !resultList.Select(p => p.UserId).Contains(c.UserId)).Take(count); // var ss = sort.Where(c => !resultList.Select(p => p.UserId).Contains(c.UserId)).Take(count);
foreach (var item in ss) // foreach (var item in ss)
{ // {
CompetitionTopList.Add(new CompetitionTopModel // CompetitionTopList.Add(new CompetitionTopModel
{ // {
Index = item.Index, // Index = item.Index,
TripTime = "———", // TripTime = "———",
Country = item.CountryImg, // Country = item.CountryImg,
Name = item.Name, // Name = item.Name,
UserId = item.UserId, // UserId = item.UserId,
Head = item.Headimage, // Head = item.Headimage,
}); // });
} // }
} //}
#endregion #endregion

View File

@ -193,35 +193,40 @@ namespace Assets.Scenes.Ride.Scripts.Model
interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0)); interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0));
//service.CreateRecordCyclingData(interruptRecord); //service.CreateRecordCyclingData(interruptRecord);
//保存骑行记录txt //保存骑行记录txt
//var path = Helper.GetDataDir("MapWorkoutRecords" + "/" + interruptRecord.Id); //var path = Helper.GetDataDir("MapWorkoutRecords" + "/" + interruptRecord.Id);
//var path = PFConstants.MapWorkoutRecordFolder + "/" + interruptRecord.Id; //var path = PFConstants.MapWorkoutRecordFolder + "/" + interruptRecord.Id;
var fname = path + "/" + newFileName + ".txt";
var files = new List<string>(); var files = new List<string>();
using (var fs = new FileInfo(fname).OpenWrite()) try
{ {
var stream = new StreamWriter(fs); var fname = path + "/" + newFileName + ".txt";
stream.BaseStream.Seek(0, SeekOrigin.End); using (var fs = new FileInfo(fname).OpenWrite())
foreach (var item in RiderDatas)
{ {
stream.Write(item.Write() + "\r\n"); var stream = new StreamWriter(fs);
stream.BaseStream.Seek(0, SeekOrigin.End);
foreach (var item in RiderDatas)
{
stream.Write(item.Write() + "\r\n");
}
stream.Flush();
stream.Close();
files.Add(fname);
} }
stream.Flush(); //图片
stream.Close(); if (!string.IsNullOrEmpty(imageName))
files.Add(fname); {
files.Add(imageName);
}
//持久化序列化对象
var recordString = JsonConvert.SerializeObject(interruptRecord);
var recordFilePath = path + "/" + "record" + ".txt";
System.IO.File.WriteAllText(recordFilePath, recordString);
} }
//图片 catch (Exception ex)
if (!string.IsNullOrEmpty(imageName))
{ {
files.Add(imageName); Debug.Log(ex.Message);
} }
//持久化序列化对象
var recordString = JsonConvert.SerializeObject(interruptRecord);
var recordFilePath = path + "/" + "record" + ".txt";
System.IO.File.WriteAllText(recordFilePath, recordString);
recordData.Add(interruptRecord, files); recordData.Add(interruptRecord, files);
//Saved = true;
SaveDataAysnc(recordData, path); SaveDataAysnc(recordData, path);
} }
/// <summary> /// <summary>
@ -245,7 +250,6 @@ namespace Assets.Scenes.Ride.Scripts.Model
if (result.result && Directory.Exists(path)) if (result.result && Directory.Exists(path))
{ {
Helper.DelectDir(path); Helper.DelectDir(path);
Saved = true;
} }
} }
catch (Exception e) catch (Exception e)

View File

@ -90,9 +90,10 @@ namespace Assets.Scenes.Ride.Scripts
void Start() void Start()
{ {
Init(); Init();
//StartCoroutine("TestExcute");
} }
void Update() void Update()
{ {
Excute(); Excute();
AfterExcute(); AfterExcute();
@ -120,6 +121,21 @@ namespace Assets.Scenes.Ride.Scripts
chartDataSourceScript = mainController.chartDataSourceScript; chartDataSourceScript = mainController.chartDataSourceScript;
graph = mainController.graph; graph = mainController.graph;
} }
IEnumerator TestExcute()
{
while (true)
{
yield return new WaitForSeconds(1);
//CamControl();
timer -= Time.deltaTime;
if (timer <= 0)//定时器 一秒执行一次
{
BeforeRun();
Run();
timer = 1.0f;
}
}
}
protected virtual void Excute() protected virtual void Excute()
{ {
@ -129,7 +145,7 @@ namespace Assets.Scenes.Ride.Scripts
{ {
BeforeRun(); BeforeRun();
Run(); Run();
timer = 1.0f; timer = 1.0f + timer;
} }
} }
public bool stopRecord = false; public bool stopRecord = false;

View File

@ -616,9 +616,9 @@ public class CyclingController : DeviceServiceMonoBase
{ {
isStart = true; isStart = true;
startTime = UIManager.Now.GetDateTime(); startTime = UIManager.Now.GetDateTime();
//骑行累计毫秒 ////骑行累计毫秒
sw = new Stopwatch(); //sw = new Stopwatch();
sw.Start(); //sw.Start();
} }
else else
{ {
@ -640,16 +640,17 @@ public class CyclingController : DeviceServiceMonoBase
//退出或者完成骑行 //退出或者完成骑行
public void SetQuit() public void SetQuit()
{ {
//耗时巨大的代码 ////耗时巨大的代码
if (sw != null) //if (sw != null)
{ //{
sw.Stop(); // sw.Stop();
TimeSpan ts2 = (TimeSpan)(sw.Elapsed); // TimeSpan ts2 = (TimeSpan)(sw.Elapsed);
UnityEngine.Debug.Log(string.Format("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds)); // UnityEngine.Debug.Log(string.Format("Stopwatch总共花费{0}ms.", ts2.TotalMilliseconds));
//TODO后算接口需要增加累计毫秒字段 // //TODO后算接口需要增加累计毫秒字段
} //}
isStart = false; isStart = false;
isQuit = true; isQuit = true;
recorderData.EndTime = UIManager.Now.GetDateTime();
} }
#endregion #endregion
@ -676,6 +677,7 @@ public class CyclingController : DeviceServiceMonoBase
public void Save(double totalDistance) public void Save(double totalDistance)
{ {
//cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
isQuit = true; isQuit = true;
isStart = false; isStart = false;
string recordId = Guid.NewGuid().ToString(); string recordId = Guid.NewGuid().ToString();
@ -686,7 +688,6 @@ public class CyclingController : DeviceServiceMonoBase
string imageFileName = path +"/"+ Guid.NewGuid().ToString() + ".png"; string imageFileName = path +"/"+ Guid.NewGuid().ToString() + ".png";
CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName); CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
cyclingController.recorderData.StartTime = startTime; cyclingController.recorderData.StartTime = startTime;
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
cyclingController.recorderData.IsCompleted = totalDistance == mapData.TotalDistance; cyclingController.recorderData.IsCompleted = totalDistance == mapData.TotalDistance;
cyclingController.recorderData.EndDistance = totalDistance; cyclingController.recorderData.EndDistance = totalDistance;
cyclingController.recorderData.AntModelId = AntModelId; cyclingController.recorderData.AntModelId = AntModelId;

View File

@ -69,6 +69,12 @@ public class LocalRouteItem : MonoBehaviour, IPointerExitHandler, IPointerEnterH
{ {
var recordStr = File.ReadAllText(item); var recordStr = File.ReadAllText(item);
record = Newtonsoft.Json.JsonConvert.DeserializeObject<MapInterruptRecord>(recordStr); record = Newtonsoft.Json.JsonConvert.DeserializeObject<MapInterruptRecord>(recordStr);
//不是自己的记录不显示
var isself = record.UserId == App.CurrentUser.Id;
if (!isself)
{
this.gameObject.SetActive(false);
}
Name.text = record.RouteName; Name.text = record.RouteName;
Time.text = record.StartTime.ToString(); Time.text = record.StartTime.ToString();
RidingTime.text = $"<color={titleColor}>Riding time:</color>{record.Ticks}"; RidingTime.text = $"<color={titleColor}>Riding time:</color>{record.Ticks}";