细节调整

This commit is contained in:
suntao 2020-10-27 10:20:47 +08:00
parent a9e8137aaa
commit fec18db7a8
10 changed files with 135 additions and 72 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="Host" value="http://47.97.84.8:81/"/> <add key="Host" value="https://wx.powerfun.com.cn/"/>
<add key="Top" value="100"/> <add key="Top" value="100"/>
<add key="ShowVirtualUser" value="true"/> <add key="ShowVirtualUser" value="true"/>
<add key="Ip" value="192.168.0.94"/> <add key="Ip" value="192.168.0.97"/>
<add key="Port" value="11000"/> <add key="Port" value="11000"/>
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -14,7 +14,7 @@ namespace OnlineUserPool.Hander
{ {
private static List<MapRecordRanking> mapRecordRankings; private static List<MapRecordRanking> mapRecordRankings;
private static object locker = new object();//防止服务端响应慢,多次加载 private static object locker = new object();//防止服务端响应慢,多次加载
private int top = int.Parse(ConfigHelp.Top); private int top = ConfigHelp.Top;
public MapRecordRankingHander() public MapRecordRankingHander()
{ {
@ -23,7 +23,7 @@ namespace OnlineUserPool.Hander
private void Init() 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()); mapRecordRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList());
} }
/// <summary> /// <summary>
@ -33,40 +33,44 @@ namespace OnlineUserPool.Hander
public List<MsgModel> GetVirtualUserData() public List<MsgModel> GetVirtualUserData()
{ {
List<MsgModel> msgModels = new List<MsgModel>(); List<MsgModel> msgModels = new List<MsgModel>();
if (mapRecordRankings != null && mapRecordRankings.Count > 0) if (mapRecordRankings != null)
{ {
for (int i = 0; i < mapRecordRankings.Count; i++) for (int i = 0; i < mapRecordRankings.Count; i++)
{ {
try try
{ {
var item = mapRecordRankings[i]; var item = mapRecordRankings[i];
item.CurrentIndex++;
TargetData targetData = item.GetCurrentTargetData(); TargetData targetData = item.GetCurrentTargetData();
List<string> prop = new List<string>() //List<string> prop = new List<string>()
{ //{
Math.Round(targetData._Speed, 2).ToString(), // Math.Round(targetData._Speed, 2).ToString(),
targetData._Power.ToString(), // targetData._Power.ToString(),
targetData._Cadence.ToString() // targetData._Cadence.ToString()
}; //};
msgModels.Add(new MsgModel() var info = new MsgModel()
{ {
exit = item.End, exit = item.End,
IsCompleted = 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) }, Point = new double[] { Math.Round(targetData._Lat, 6), Math.Round(targetData._Lon, 6) },
Prop = string.Join(',', prop), //Prop = string.Join(',', prop),
RouteId = item.RouteId, RouteId = item.RouteId,
EndDistance = targetData._Distance, EndDistance = Math.Round(targetData._Distance, 6),
ShowVirtual = true, ShowVirtual = true,
CommandType = 1, CommandType = 1,
IsVirtual = true, IsVirtual = true,
Speed = targetData._Speed Speed = targetData._Speed,
}); WeightKg = Math.Round(targetData._Power / item.Weight, 2),
} PreDistance = item.GetPreDistance()
catch (Exception e) };
{ msgModels.Add(info);
Log.Error("加载虚拟人物错误:" + e.Message);
}
} }
catch (Exception e)
{
Log.Error("加载虚拟人物错误:" + e.Message + "\r\n" + e.StackTrace);
}
}
} }
return msgModels; return msgModels;
} }
@ -79,20 +83,25 @@ namespace OnlineUserPool.Hander
lock (locker) lock (locker)
{ {
var end = mapRecordRankings.FindAll(n => n.End); var end = mapRecordRankings.FindAll(n => n.End);
if (end.Count == mapRecordRankings.Count) //if (end.Count == mapRecordRankings.Count)
{ //{
Init(); // Init();
} //}
if (end.Count > 0) 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); mapRecordRankings.RemoveAll(n => n.End);
var randomUser = WebService.GetMapRouteRandomUser(new RandomRankingUserRequestVM() if (virutalEndCount > 0)
{ {
top = int.Parse(ConfigHelp.Top) - end.Count, var randomUser = WebService.GetMapRouteRandomUser(ConfigHelp.Top - virutalEndCount, routeIds);
ids = mapRecordRankings.Select(n => n.UserId.ToString()).ToList()
}); var str = "参数:" + (ConfigHelp.Top - virutalEndCount) + "," + string.Join(",",routeIds) + "\r\n";
var addRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList()); str += "服务端返回:" + Newtonsoft.Json.JsonConvert.SerializeObject(randomUser) +"\r\n";
mapRecordRankings.AddRange(addRankings); Log.Information(str);
var addRankings = WebService.GetRecordFileFromServer(randomUser.Select(n => n.RankingId).ToList());
mapRecordRankings.AddRange(addRankings);
}
} }
} }
} }

View File

@ -35,7 +35,7 @@ namespace OnlineUserPool.Model
{ {
get get
{ {
return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 6000; return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 60;
} }
} }

View File

@ -12,7 +12,7 @@ namespace OnlineUserPool.Model
public int RouteId { get; set; } public int RouteId { get; set; }
public int Ticks { get; set; } public int Ticks { get; set; } = -1;
public Guid Id { get; set; } public Guid Id { get; set; }
@ -21,6 +21,10 @@ namespace OnlineUserPool.Model
public string WxHeadImg { get; set; } public string WxHeadImg { get; set; }
public string NickName { get; set; } public string NickName { get; set; }
/// <summary>
/// 体重,用于计算功率体重比
/// </summary>
public double Weight { get; set; }
/// <summary> /// <summary>
/// 总点位数据 /// 总点位数据
@ -40,27 +44,28 @@ namespace OnlineUserPool.Model
/// </summary> /// </summary>
public int CurrentIndex public int CurrentIndex
{ {
get get; set;
{ //get
if (_BeginIndex != 0) //{
{ //if (_BeginIndex != 0)
_BeginIndex++; //{
if (End) // _BeginIndex++;
{ // if (End)
return this.Count - 1; // {
} // return this.Count - 1;
return this._BeginIndex; // }
} // return this._BeginIndex;
else //}
{ //else
_BeginIndex = 1; //{
return _BeginIndex; // _BeginIndex = 1;
Random random = new Random(); // return _BeginIndex;
_BeginIndex = random.Next(0, this.Count); // Random random = new Random();
return _BeginIndex; // _BeginIndex = random.Next(0, this.Count);
} // return _BeginIndex;
} //}
} //}
} = -1;
/// <summary> /// <summary>
/// 是否已到头 /// 是否已到头
@ -69,7 +74,8 @@ namespace OnlineUserPool.Model
{ {
get get
{ {
return this._BeginIndex >= this.Count; //return this._BeginIndex >= this.Count;
return this.CurrentIndex >= this.Count;
} }
} }
@ -79,7 +85,18 @@ namespace OnlineUserPool.Model
/// <returns></returns> /// <returns></returns>
public TargetData GetCurrentTargetData() public TargetData GetCurrentTargetData()
{ {
if(CurrentIndex > this.record.Length - 1)
{
return TargetData.Read(this.record[this.record.Length - 1]);
}
return TargetData.Read(this.record[CurrentIndex]); return TargetData.Read(this.record[CurrentIndex]);
} }
public double GetPreDistance()
{
if (CurrentIndex < 1) return 0;
return TargetData.Read(this.record[CurrentIndex - 1])._Distance;
}
} }
} }

View File

@ -13,10 +13,12 @@ namespace OnlineUserPool.Model
public bool exit = false; public bool exit = false;
public double Speed { get; set; } public double Speed { get; set; }
/// <summary> ///// <summary>
/// 需要展示的属性 ///// 需要展示的属性
/// </summary> ///// </summary>
public string Prop { get; set; } //public string Prop { get; set; }
public double PreDistance { get; set; }
public double EndDistance { get; set; } public double EndDistance { get; set; }
/// <summary> /// <summary>
@ -29,5 +31,14 @@ namespace OnlineUserPool.Model
public byte CommandType { get; set; } public byte CommandType { get; set; }
public bool IsVirtual { get; set; } public bool IsVirtual { get; set; }
//public double Power { get; set; }
//public double Weight { get; set; }
/// <summary>
/// 功率体重比
/// </summary>
public double WeightKg { get; set; }
} }
} }

View File

@ -51,7 +51,11 @@ namespace OnlineUserPool.Model
{ {
target._Lat = double.Parse(split[6]); target._Lat = double.Parse(split[6]);
target._Lon = double.Parse(split[7]); target._Lon = double.Parse(split[7]);
target._Bearing = double.Parse(split[8]);
if (split.Length >= 9)
{
target._Bearing = double.Parse(split[8]);
}
} }
return target; return target;
} }

View File

@ -7,7 +7,7 @@ namespace OnlineUserPool.Unility
class ConfigHelp class ConfigHelp
{ {
public static string Host { get; set; } 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 bool ShowVirtualUser { get; set; }
public static string Ip { get; set; } public static string Ip { get; set; }
@ -18,7 +18,7 @@ namespace OnlineUserPool.Unility
static ConfigHelp() static ConfigHelp()
{ {
Host = System.Configuration.ConfigurationManager.AppSettings["Host"]; 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"]); ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowVirtualUser"]);
Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"]; Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]); Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);

View File

@ -3,6 +3,7 @@
using OnlineUserPool.Model; using OnlineUserPool.Model;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -48,14 +49,21 @@ namespace OnlineUserPool.Unility
/// <returns></returns> /// <returns></returns>
public static List<MapRecordRanking> GetRecordFileFromServer(List<string> id) public static List<MapRecordRanking> GetRecordFileFromServer(List<string> id)
{ {
return PostAsync<JsonResult<List<MapRecordRanking>>>("Map/GetCyclingRecordsById", id).ConfigureAwait(false).GetAwaiter().GetResult().data; if (!id.Any())
{
return new List<MapRecordRanking>();
}
return PostAsync<JsonResult<List<MapRecordRanking>>>("MapRecord/GetRandomList", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
} }
public static List<MapRouteAndUserQueryVM> GetMapRouteRandomUser(RandomRankingUserRequestVM requestVM) public static List<MapRouteAndUserQueryVM> GetMapRouteRandomUser(int top, IEnumerable<int> routeIds)
{ {
return PostAsync<JsonResult<List<MapRouteAndUserQueryVM>>>($"Map/GetRandomRankingUserRecord", requestVM).ConfigureAwait(false).GetAwaiter().GetResult().data; var routeIdsStr = "";
if(routeIds != null)
{
routeIdsStr = string.Join(",", routeIds);
}
return GetAsync<JsonResult<List<MapRouteAndUserQueryVM>>>($"MapRecord/GetRandomRankingUserRecord?top={ top }&routeIds={ routeIdsStr }").ConfigureAwait(false).GetAwaiter().GetResult().data;
} }
} }
} }

View File

@ -30,9 +30,20 @@ namespace OnlineUserPool.ViewModels
public ObservableCollection<MsgModel> Customers { get; private set; } = public ObservableCollection<MsgModel> Customers { get; private set; } =
new ObservableCollection<MsgModel>(); new ObservableCollection<MsgModel>();
private string _Title = "";
public string Title
{
get { return _Title; }
set
{
SetProperty(ref _Title, value);
}
}
public MainWindowViewModel() public MainWindowViewModel()
{ {
Title = $"{ ConfigHelp.Ip }:{ ConfigHelp.Port }";
dispatcher = Dispatcher.CurrentDispatcher; dispatcher = Dispatcher.CurrentDispatcher;
//Customers.Add("suntao"); //Customers.Add("suntao");
@ -143,10 +154,13 @@ namespace OnlineUserPool.ViewModels
dispatcher.Invoke(() => dispatcher.Invoke(() =>
{ {
Customers.Clear(); Customers.Clear();
foreach (var item in receiveMes) foreach (var item in receiveMes)
{ {
if (Customers.Any(c => c.MemberId == item.MemberId))
{
continue;
}
Customers.Add(item); Customers.Add(item);
} }
@ -179,7 +193,7 @@ namespace OnlineUserPool.ViewModels
} }
catch (Exception e) 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) catch (Exception e)
{ {
Log.Error(item.IPEndPoint.ToString() + ":" + e.Message); Log.Error($"{ item.IPEndPoint.ToString() }:{ e.Message }\r\n{ e.StackTrace }");
} }
} }
} }

View File

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OnlineUserPool" xmlns:prism="http://prismlibrary.com/" xmlns:local="clr-namespace:OnlineUserPool" xmlns:prism="http://prismlibrary.com/"
mc:Ignorable="d" prism:ViewModelLocator.AutoWireViewModel="True" mc:Ignorable="d" prism:ViewModelLocator.AutoWireViewModel="True"
Title="MainWindow" Height="450" Width="800"> Title="{ Binding Title }" Height="450" Width="800">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>