forked from powerfun/udpservice
细节调整
This commit is contained in:
parent
a9e8137aaa
commit
fec18db7a8
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<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="ShowVirtualUser" value="true"/>
|
||||
<add key="Ip" value="192.168.0.94"/>
|
||||
<add key="Ip" value="192.168.0.97"/>
|
||||
<add key="Port" value="11000"/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
@ -14,7 +14,7 @@ namespace OnlineUserPool.Hander
|
||||
{
|
||||
private static List<MapRecordRanking> 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());
|
||||
}
|
||||
/// <summary>
|
||||
@ -33,38 +33,42 @@ namespace OnlineUserPool.Hander
|
||||
public List<MsgModel> GetVirtualUserData()
|
||||
{
|
||||
List<MsgModel> msgModels = new List<MsgModel>();
|
||||
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<string> prop = new List<string>()
|
||||
{
|
||||
Math.Round(targetData._Speed, 2).ToString(),
|
||||
targetData._Power.ToString(),
|
||||
targetData._Cadence.ToString()
|
||||
};
|
||||
msgModels.Add(new MsgModel()
|
||||
//List<string> prop = new List<string>()
|
||||
//{
|
||||
// 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
|
||||
});
|
||||
Speed = targetData._Speed,
|
||||
WeightKg = Math.Round(targetData._Power / item.Weight, 2),
|
||||
PreDistance = item.GetPreDistance()
|
||||
};
|
||||
msgModels.Add(info);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("加载虚拟人物错误:" + e.Message);
|
||||
Log.Error("加载虚拟人物错误:" + e.Message + "\r\n" + e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,22 +83,27 @@ 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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ namespace OnlineUserPool.Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 6000;
|
||||
return DateTime.Now.Subtract(LastActiveTime).TotalSeconds > 60;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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; }
|
||||
/// <summary>
|
||||
/// 体重,用于计算功率体重比
|
||||
/// </summary>
|
||||
public double Weight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总点位数据
|
||||
@ -40,27 +44,28 @@ namespace OnlineUserPool.Model
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已到头
|
||||
@ -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
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,10 +13,12 @@ namespace OnlineUserPool.Model
|
||||
|
||||
public bool exit = false;
|
||||
public double Speed { get; set; }
|
||||
/// <summary>
|
||||
/// 需要展示的属性
|
||||
/// </summary>
|
||||
public string Prop { get; set; }
|
||||
///// <summary>
|
||||
///// 需要展示的属性
|
||||
///// </summary>
|
||||
//public string Prop { get; set; }
|
||||
|
||||
public double PreDistance { get; set; }
|
||||
|
||||
public double EndDistance { get; set; }
|
||||
/// <summary>
|
||||
@ -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; }
|
||||
/// <summary>
|
||||
/// 功率体重比
|
||||
/// </summary>
|
||||
public double WeightKg { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,8 +51,12 @@ namespace OnlineUserPool.Model
|
||||
{
|
||||
target._Lat = double.Parse(split[6]);
|
||||
target._Lon = double.Parse(split[7]);
|
||||
|
||||
if (split.Length >= 9)
|
||||
{
|
||||
target._Bearing = double.Parse(split[8]);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"]);
|
||||
|
||||
@ -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
|
||||
/// <returns></returns>
|
||||
public static List<MapRecordRanking> GetRecordFileFromServer(List<string> id)
|
||||
{
|
||||
return PostAsync<JsonResult<List<MapRecordRanking>>>("Map/GetCyclingRecordsById", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
|
||||
public static List<MapRouteAndUserQueryVM> GetMapRouteRandomUser(RandomRankingUserRequestVM requestVM)
|
||||
if (!id.Any())
|
||||
{
|
||||
return PostAsync<JsonResult<List<MapRouteAndUserQueryVM>>>($"Map/GetRandomRankingUserRecord", requestVM).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
return new List<MapRecordRanking>();
|
||||
}
|
||||
return PostAsync<JsonResult<List<MapRecordRanking>>>("MapRecord/GetRandomList", id).ConfigureAwait(false).GetAwaiter().GetResult().data;
|
||||
}
|
||||
|
||||
|
||||
public static List<MapRouteAndUserQueryVM> GetMapRouteRandomUser(int top, IEnumerable<int> routeIds)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,9 +30,20 @@ namespace OnlineUserPool.ViewModels
|
||||
public ObservableCollection<MsgModel> Customers { get; private set; } =
|
||||
new ObservableCollection<MsgModel>();
|
||||
|
||||
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 }");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition></RowDefinition>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user