diff --git a/App.config b/App.config
index e11b596..c121d2d 100644
--- a/App.config
+++ b/App.config
@@ -1,10 +1,10 @@
-
+
-
+
\ No newline at end of file
diff --git a/Hander/MapRecordRankingHander.cs b/Hander/MapRecordRankingHander.cs
index 3cf89c0..eca7cdc 100644
--- a/Hander/MapRecordRankingHander.cs
+++ b/Hander/MapRecordRankingHander.cs
@@ -14,7 +14,7 @@ namespace OnlineUserPool.Hander
{
private static List mapRecordRankings;
private static object locker = new object();//防止服务端响应慢,多次加载
- private int top = int.Parse(ConfigHelp.Top);
+ private int top = ConfigHelp.Top;
public MapRecordRankingHander()
{
@@ -23,7 +23,7 @@ namespace OnlineUserPool.Hander
private void Init()
{
- var randomUser = WebService.GetMapRouteRandomUser(new RandomRankingUserRequestVM() { top = top });
+ var randomUser = WebService.GetMapRouteRandomUser(top, null);
mapRecordRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList());
}
///
@@ -33,40 +33,44 @@ namespace OnlineUserPool.Hander
public List GetVirtualUserData()
{
List msgModels = new List();
- if (mapRecordRankings != null && mapRecordRankings.Count > 0)
+ if (mapRecordRankings != null)
{
for (int i = 0; i < mapRecordRankings.Count; i++)
{
try
{
var item = mapRecordRankings[i];
+ item.CurrentIndex++;
TargetData targetData = item.GetCurrentTargetData();
- List prop = new List()
- {
- Math.Round(targetData._Speed, 2).ToString(),
- targetData._Power.ToString(),
- targetData._Cadence.ToString()
- };
- msgModels.Add(new MsgModel()
+ //List prop = new List()
+ //{
+ // Math.Round(targetData._Speed, 2).ToString(),
+ // targetData._Power.ToString(),
+ // targetData._Cadence.ToString()
+ //};
+ var info = new MsgModel()
{
exit = item.End,
IsCompleted = item.End,
- MemberId = -item.UserId,//虚拟的人Id变为负数
+ MemberId = item.UserId,//虚拟的人Id变为负数
Point = new double[] { Math.Round(targetData._Lat, 6), Math.Round(targetData._Lon, 6) },
- Prop = string.Join(',', prop),
+ //Prop = string.Join(',', prop),
RouteId = item.RouteId,
- EndDistance = targetData._Distance,
+ EndDistance = Math.Round(targetData._Distance, 6),
ShowVirtual = true,
CommandType = 1,
IsVirtual = true,
- Speed = targetData._Speed
- });
- }
- catch (Exception e)
- {
- Log.Error("加载虚拟人物错误:" + e.Message);
- }
+ Speed = targetData._Speed,
+ WeightKg = Math.Round(targetData._Power / item.Weight, 2),
+ PreDistance = item.GetPreDistance()
+ };
+ msgModels.Add(info);
}
+ catch (Exception e)
+ {
+ Log.Error("加载虚拟人物错误:" + e.Message + "\r\n" + e.StackTrace);
+ }
+ }
}
return msgModels;
}
@@ -79,20 +83,25 @@ namespace OnlineUserPool.Hander
lock (locker)
{
var end = mapRecordRankings.FindAll(n => n.End);
- if (end.Count == mapRecordRankings.Count)
- {
- Init();
- }
+ //if (end.Count == mapRecordRankings.Count)
+ //{
+ // Init();
+ //}
if (end.Count > 0)
{
+ var virutalEndCount = mapRecordRankings.Count(d => d.UserId < 0 && d.End);
+ var routeIds = mapRecordRankings.Select(n => n.RouteId).ToList();
mapRecordRankings.RemoveAll(n => n.End);
- var randomUser = WebService.GetMapRouteRandomUser(new RandomRankingUserRequestVM()
+ if (virutalEndCount > 0)
{
- top = int.Parse(ConfigHelp.Top) - end.Count,
- ids = mapRecordRankings.Select(n => n.UserId.ToString()).ToList()
- });
- var addRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList());
- mapRecordRankings.AddRange(addRankings);
+ var randomUser = WebService.GetMapRouteRandomUser(ConfigHelp.Top - virutalEndCount, routeIds);
+
+ var str = "参数:" + (ConfigHelp.Top - virutalEndCount) + "," + string.Join(",",routeIds) + "\r\n";
+ str += "服务端返回:" + Newtonsoft.Json.JsonConvert.SerializeObject(randomUser) +"\r\n";
+ Log.Information(str);
+ var addRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList());
+ mapRecordRankings.AddRange(addRankings);
+ }
}
}
}
diff --git a/Model/HostModel.cs b/Model/HostModel.cs
index 054102e..2b828c5 100644
--- a/Model/HostModel.cs
+++ b/Model/HostModel.cs
@@ -35,7 +35,7 @@ namespace OnlineUserPool.Model
{
get
{
- return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 6000;
+ return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 60;
}
}
diff --git a/Model/MapRecordRanking.cs b/Model/MapRecordRanking.cs
index a59a25a..dfc9a67 100644
--- a/Model/MapRecordRanking.cs
+++ b/Model/MapRecordRanking.cs
@@ -12,7 +12,7 @@ namespace OnlineUserPool.Model
public int RouteId { get; set; }
- public int Ticks { get; set; }
+ public int Ticks { get; set; } = -1;
public Guid Id { get; set; }
@@ -21,6 +21,10 @@ namespace OnlineUserPool.Model
public string WxHeadImg { get; set; }
public string NickName { get; set; }
+ ///
+ /// 体重,用于计算功率体重比
+ ///
+ public double Weight { get; set; }
///
/// 总点位数据
@@ -40,27 +44,28 @@ namespace OnlineUserPool.Model
///
public int CurrentIndex
{
- get
- {
- if (_BeginIndex != 0)
- {
- _BeginIndex++;
- if (End)
- {
- return this.Count - 1;
- }
- return this._BeginIndex;
- }
- else
- {
- _BeginIndex = 1;
- return _BeginIndex;
- Random random = new Random();
- _BeginIndex = random.Next(0, this.Count);
- return _BeginIndex;
- }
- }
- }
+ get; set;
+ //get
+ //{
+ //if (_BeginIndex != 0)
+ //{
+ // _BeginIndex++;
+ // if (End)
+ // {
+ // return this.Count - 1;
+ // }
+ // return this._BeginIndex;
+ //}
+ //else
+ //{
+ // _BeginIndex = 1;
+ // return _BeginIndex;
+ // Random random = new Random();
+ // _BeginIndex = random.Next(0, this.Count);
+ // return _BeginIndex;
+ //}
+ //}
+ } = -1;
///
/// 是否已到头
@@ -69,7 +74,8 @@ namespace OnlineUserPool.Model
{
get
{
- return this._BeginIndex >= this.Count;
+ //return this._BeginIndex >= this.Count;
+ return this.CurrentIndex >= this.Count;
}
}
@@ -79,7 +85,18 @@ namespace OnlineUserPool.Model
///
public TargetData GetCurrentTargetData()
{
+ if(CurrentIndex > this.record.Length - 1)
+ {
+ return TargetData.Read(this.record[this.record.Length - 1]);
+ }
return TargetData.Read(this.record[CurrentIndex]);
}
+
+ public double GetPreDistance()
+ {
+ if (CurrentIndex < 1) return 0;
+
+ return TargetData.Read(this.record[CurrentIndex - 1])._Distance;
+ }
}
}
diff --git a/Model/MsgModel.cs b/Model/MsgModel.cs
index f88afc6..769a0b1 100644
--- a/Model/MsgModel.cs
+++ b/Model/MsgModel.cs
@@ -13,10 +13,12 @@ namespace OnlineUserPool.Model
public bool exit = false;
public double Speed { get; set; }
- ///
- /// 需要展示的属性
- ///
- public string Prop { get; set; }
+ /////
+ ///// 需要展示的属性
+ /////
+ //public string Prop { get; set; }
+
+ public double PreDistance { get; set; }
public double EndDistance { get; set; }
///
@@ -29,5 +31,14 @@ namespace OnlineUserPool.Model
public byte CommandType { get; set; }
public bool IsVirtual { get; set; }
+
+ //public double Power { get; set; }
+ //public double Weight { get; set; }
+ ///
+ /// 功率体重比
+ ///
+ public double WeightKg { get; set; }
+
+
}
}
diff --git a/Model/TargetData.cs b/Model/TargetData.cs
index abb3c85..d1df023 100644
--- a/Model/TargetData.cs
+++ b/Model/TargetData.cs
@@ -51,7 +51,11 @@ namespace OnlineUserPool.Model
{
target._Lat = double.Parse(split[6]);
target._Lon = double.Parse(split[7]);
- target._Bearing = double.Parse(split[8]);
+
+ if (split.Length >= 9)
+ {
+ target._Bearing = double.Parse(split[8]);
+ }
}
return target;
}
diff --git a/Unility/ConfigHelp.cs b/Unility/ConfigHelp.cs
index 3bef739..54473ff 100644
--- a/Unility/ConfigHelp.cs
+++ b/Unility/ConfigHelp.cs
@@ -7,7 +7,7 @@ namespace OnlineUserPool.Unility
class ConfigHelp
{
public static string Host { get; set; }
- public static string Top { get; set; }
+ public static int Top { get; private set; }
public static bool ShowVirtualUser { get; set; }
public static string Ip { get; set; }
@@ -18,7 +18,7 @@ namespace OnlineUserPool.Unility
static ConfigHelp()
{
Host = System.Configuration.ConfigurationManager.AppSettings["Host"];
- Top = System.Configuration.ConfigurationManager.AppSettings["Top"];
+ Top = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowVirtualUser"]);
Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
diff --git a/Unility/WebService.cs b/Unility/WebService.cs
index 44caa4d..bd13763 100644
--- a/Unility/WebService.cs
+++ b/Unility/WebService.cs
@@ -3,6 +3,7 @@
using OnlineUserPool.Model;
using System.Collections.Generic;
+using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@@ -48,14 +49,21 @@ namespace OnlineUserPool.Unility
///
public static List GetRecordFileFromServer(List id)
{
- return PostAsync>>("Map/GetCyclingRecordsById", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
+ if (!id.Any())
+ {
+ return new List();
+ }
+ return PostAsync>>("MapRecord/GetRandomList", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
}
- public static List GetMapRouteRandomUser(RandomRankingUserRequestVM requestVM)
+ public static List GetMapRouteRandomUser(int top, IEnumerable routeIds)
{
- return PostAsync>>($"Map/GetRandomRankingUserRecord", requestVM).ConfigureAwait(false).GetAwaiter().GetResult().data;
+ var routeIdsStr = "";
+ if(routeIds != null)
+ {
+ routeIdsStr = string.Join(",", routeIds);
+ }
+ return GetAsync>>($"MapRecord/GetRandomRankingUserRecord?top={ top }&routeIds={ routeIdsStr }").ConfigureAwait(false).GetAwaiter().GetResult().data;
}
-
-
}
}
diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs
index edbdf3a..59ca9b7 100644
--- a/ViewModels/MainWindowViewModel.cs
+++ b/ViewModels/MainWindowViewModel.cs
@@ -30,9 +30,20 @@ namespace OnlineUserPool.ViewModels
public ObservableCollection Customers { get; private set; } =
new ObservableCollection();
+ private string _Title = "";
+ public string Title
+ {
+ get { return _Title; }
+ set
+ {
+ SetProperty(ref _Title, value);
+ }
+ }
public MainWindowViewModel()
{
+ Title = $"{ ConfigHelp.Ip }:{ ConfigHelp.Port }";
+
dispatcher = Dispatcher.CurrentDispatcher;
//Customers.Add("suntao");
@@ -143,10 +154,13 @@ namespace OnlineUserPool.ViewModels
dispatcher.Invoke(() =>
{
-
Customers.Clear();
foreach (var item in receiveMes)
{
+ if (Customers.Any(c => c.MemberId == item.MemberId))
+ {
+ continue;
+ }
Customers.Add(item);
}
@@ -179,7 +193,7 @@ namespace OnlineUserPool.ViewModels
}
catch (Exception e)
{
- Log.Error("NotifyClient:" + e.Message);
+ Log.Error($"NotifyClient:{ e.Message }\r\n{ e.StackTrace }");
}
}
@@ -195,7 +209,7 @@ namespace OnlineUserPool.ViewModels
}
catch (Exception e)
{
- Log.Error(item.IPEndPoint.ToString() + ":" + e.Message);
+ Log.Error($"{ item.IPEndPoint.ToString() }:{ e.Message }\r\n{ e.StackTrace }");
}
}
}
diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml
index 5fecdc9..cdd95d2 100644
--- a/Views/MainWindow.xaml
+++ b/Views/MainWindow.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OnlineUserPool" xmlns:prism="http://prismlibrary.com/"
mc:Ignorable="d" prism:ViewModelLocator.AutoWireViewModel="True"
- Title="MainWindow" Height="450" Width="800">
+ Title="{ Binding Title }" Height="450" Width="800">