/// <summary> /// 匹配人员坐标 /// </summary> /// <param name="SubjectString"></param> private void MatchPerson(string SubjectString) { try { string strPosition = Regex.Match(SubjectString, "\\|[0-9]*\\|-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*").Value; if (!string.IsNullOrEmpty(strPosition)) { FramePosition position = FramePosition.Parse(strPosition.Substring(1, strPosition.LastIndexOf("|") - 1), strPosition.Substring(strPosition.LastIndexOf("|") + 1)); if (position != null) { if (Rmode == Runmode.Match) { Cmatch?.AddPosition(position); } else if (rmode == Runmode.Train) { Ctrain?.AddPosition(position); } } } } catch (ArgumentException ex) { LogText.Error("MatchPerson", ex.Message); } }
/// <summary> ///一发处理 /// </summary> private void FirstServeEvent(Track fistTrack) { match_event ev = CreateNewEvent(); //判断是内角还是外角发球 double middleValue = Court.Width / 2; ///判断是否内角发球 if (Math.Abs(middleValue - fistTrack.FirstPosition.Position.X) > 2057.5) { ev.EventType = (int)MatchEventType.OutFistServe; } else { ev.EventType = (int)MatchEventType.InnerFirstServe; } ev.EventResult = (int)processSingleTrack(fistTrack); if (ev.EventResult != (int)MatchEventResult.SCORE) { LogText.Error("CompleteRand", "数据出错:轨迹{0}", fistTrack.TraceString);; } DataProviderServices.instance.AddMatchEvent(ev); LogText.Info("FirstServeEvent", "一发判断:" + ev.EventResult.ToString()); }
/// <summary> /// 普通的发球 /// </summary> /// <param name="fistTrack"></param> /// <returns></returns> private match_event ServeEvent(Track fistTrack) { match_event ev = CreateNewEvent(); //判断是内角还是外角发球 double middleValue = Court.Width / 2; ///判断是否内角发球 if (Math.Abs(middleValue - fistTrack.FirstPosition.Position.X) > 2057.5) { ev.EventType = (int)MatchEventType.OutFistServe; } else { ev.EventType = (int)MatchEventType.InnerFirstServe; } ev.EventResult = (int)processSingleTrack(fistTrack); if (ev.EventResult != (int)MatchEventResult.SCORE) { LogText.Error("CompleteRand", "数据出错:轨迹{0}", fistTrack.TraceString);; } return(ev); }
/// <summary> /// 找到该轨迹的发起人 /// </summary> /// <param name="newTrack"></param> /// <returns></returns> public bool SetTrackOwner(Track newTrack) { //轨迹的所属人 User u = Players.First(o => o.Userinfo.Direction * newTrack.Direction > 0); if (u != null) { //估计的所属人 newTrack.Owner = u; FramePosition position = newTrack.Owner.AllPositions.LastOrDefault(o => o.FrameNumber <= newTrack.FirstPosition.FrameNumber); if (position != null) { newTrack.OwnerStartPosition = position; LogText.Info("SetTrackOwner01", "轨迹起始坐标:{0},人的坐标{1},人的场地{2}", newTrack.FirstPosition, position, u.Userinfo.Direction > 0?"A":"B"); } else { //设置人的最后一个坐标为当前轨迹起始时,人的轨迹坐标 newTrack.OwnerStartPosition = newTrack.Owner.AllPositions.LastOrDefault(); LogText.Info("SetTrackOwner02", "将当前轨迹所有人的最后一个坐标点设置为轨迹起始时,对应的人的坐标,可能会导致左右手判断出错"); LogText.Info("SetTrackOwner01", "轨迹起始坐标:{0},人的坐标{1},人的场地{2}", newTrack.FirstPosition, position, u.Userinfo.Direction > 0 ? "A" : "B"); } return(true); } else { LogText.Error("SetTrackOwner03", "没有找到该轨迹对应的人员的同帧号坐标,轨迹起始帧号:" + newTrack.FirstPosition.FrameNumber); } return(false); }
/// <summary> /// 处理接发球 /// </summary> /// <param name="tracks"></param> private match_event ProcessRecive(IList <Track> tracks) { match_event serv = ServeEvent(tracks[0]); if (tracks[0].Status != MatchEventResult.INSIDE) { LogText.Error("CompleteRand", "数据出现异常,roundID:" + currentRound.Id); } match_event ev = CreateNewEvent(); //修正如果上条轨迹是没有落地点,判断是不是截杀揭发球 if (tracks[0].Status == MatchEventResult.OUT_SIDE) { tracks[0].Status = MatchEventResult.INSIDE; serv.EventResult = (int)MatchEventResult.INSIDE; ev.EventType = (int)MatchEventType.CutRecive; LogText.Info("ProcessRecive", "修改上条轨迹结果,将出界改为界内,当前事件为截杀事件"); } else if (tracks[0].Status == MatchEventResult.INSIDE) { ev.EventType = (int)MatchEventType.CommonRecive; LogText.Info("ProcessRecive", "普通接发球"); } DataProviderServices.instance.AddMatchEvent(serv); ev.EventResult = (int)processSingleTrack(tracks[1], false); LogText.Info("ProcessRecive", "记录当前事件的结果,并保存上一条轨迹事件到数据库中"); return(ev); }
/// <summary> /// 读取制定key的配置文件 /// </summary> /// <param name="key"></param> /// <returns></returns> public static string ReadConfig(string key) { if (System.Configuration.ConfigurationManager.AppSettings.AllKeys.Contains(key)) { return(System.Configuration.ConfigurationManager.AppSettings[key]); } else { LogText.Error("ReadConfig", $"配置文件中缺少key:{key}"); } return(string.Empty); }
/// <summary> /// 从字符串中解析出对象 /// </summary> /// <param name="strValue"></param> /// <returns></returns> public static Track Parse(string strValue) { Track t = new RigourTech.Track(); if (string.IsNullOrEmpty(strValue)) { return(null); } string[] items = strValue.Split('|'); if (items.Length != 6) { LogText.Error("Track.pase", "数据格式错误:" + strValue); } MatchCollection results = Regex.Matches(items[1], "[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*"); foreach (Match m in results) { t.Trace.Add(FramePosition.Parse(m.Value.Substring(0, m.Value.LastIndexOf(",")))); } MatchCollection mtouchdownpoints = Regex.Matches(items[1], "-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*"); if (mtouchdownpoints.Count == 2) { t.Touchdown_P1 = Point3D.Prase(mtouchdownpoints[0].Value); t.Touchdown_P2 = Point3D.Prase(mtouchdownpoints[1].Value); } else { LogText.Error("Track.pase", "数据格式错误:" + strValue); } MatchCollection mtimes = Regex.Matches(items[2], "[0-9]*"); if (mtimes.Count == 2) { t.BeginTime = long.Parse(mtimes[0].Value); t.Endtime = long.Parse(mtimes[1].Value); } else { LogText.Error("Track.pase", "数据格式错误:" + strValue); } t.TouchdonwMarkNumber = Regex.Match(items[3], "[0-9]?").Value; t.Radius = double.Parse(Regex.Match(items[3], "[0-9]*\\.[0-9]*").Value); t.MaxRotateSpeed = double.Parse(items[4]); return(t); }
/// <summary> /// 匹配人员坐标 /// </summary> /// <param name="SubjectString"></param> private void MatchPerson(string SubjectString) { try { string strPosition = Regex.Match(SubjectString, "\\|[0-9]*\\|-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*").Value; if (!string.IsNullOrEmpty(strPosition)) { FramePosition position = FramePosition.Parse(strPosition); if (position != null) { AddPosition(position); } } } catch (ArgumentException ex) { LogText.Error("MatchPerson", ex.Message); } }
/// <summary> /// 获得场地参数信息,只能读取double类型的值配置 /// </summary> /// <param name="key"></param> /// <returns></returns> private double GetConfig(string key) { try { string value = System.Configuration.ConfigurationManager.AppSettings[key]; if (!string.IsNullOrEmpty(value)) { double dvalue; if (double.TryParse(value, out dvalue)) { return(dvalue); } } } catch (Exception ex) { LogText.Error("GetConfig", "读取配置文件出错:" + ex.Message); } return(0); }
public bool DeterminTrackTouchDown(Track newTrack) { //判断指定轨迹的落地点是否指定的训练范围中 Trainner t = newTrack.Owner as Trainner; if (t != null) { foreach (System.Windows.Rect rect in t.TargetMarks) { if (rect.Contains(newTrack.Touchdown_P1.Point2D) || rect.Contains(newTrack.Touchdown_P2.Point2D)) { return(true); } } } else { LogText.Error("DeterminTrackTouchDown", "轨迹的所有者不是训练者"); } return(false); }
private void GetMarksFromString(string targetTouchDowns) { if (string.IsNullOrEmpty(targetTouchDowns)) { LogText.Error("GetMarksFromString", "训练的指定落地区域为空"); return; } MatchCollection result = Regex.Matches(targetTouchDowns, "\\([0 - 9] *,[0 - 9] *\\)"); if (result.Count > 0) { for (int i = 0; i < result.Count / 2; i++) { Point p1 = Point.Parse(result[i * 2].Value); Point p2 = Point.Parse(result[i * 2 + 1].Value); TargetMarks.Add(new Rect(p1, p2)); } } else { LogText.Error("GetMarksFromString", "没有符合规则的训练指定区域信息," + targetTouchDowns); } }
/// <summary> /// 从字符串中解析出对象 /// </summary> /// <param name="strValue"></param> /// <returns></returns> public static Track Parse(string strValue) { Track t = new RigourTech.Service.Track(); if (string.IsNullOrEmpty(strValue)) { return(null); } t.TraceString = strValue; string[] items = strValue.Split('|'); if (items.Length != 6) { LogText.Error("Track.pase", "数据格式错误:" + strValue); } MatchCollection results = Regex.Matches(items[1], "[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*"); foreach (System.Text.RegularExpressions.Match m in results) { t.Trace.Add( FramePosition.Parse( m.Value.Substring(0, m.Value.IndexOf(",")), m.Value.Substring(m.Value.IndexOf(",") + 1) ) ); } MatchCollection mtouchdownpoints = Regex.Matches(items[2], "-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*,-?[0-9]*\\.[0-9]*"); if (mtouchdownpoints.Count == 2) { t.Touchdown_P1 = Point3D.Prase(mtouchdownpoints[0].Value); t.Touchdown_P2 = Point3D.Prase(mtouchdownpoints[1].Value); } else { LogText.Error("Track.pase", "数据格式错误:" + items[2]); } MatchCollection mtimes = Regex.Matches(items[3], "[0-9]"); if (mtimes.Count == 2) { t.BeginTime = long.Parse(mtimes[0].Value); t.Endtime = long.Parse(mtimes[1].Value); } else { LogText.Error("Track.pase", "数据格式错误:" + items[3]); } string[] vls = items[4].Split(';'); if (vls.Length == 2) { t.TouchdonwMarkNumber = vls[0]; t.Radius = double.Parse(vls[1]); } t.MaxRotateSpeed = double.Parse(items[5]); t.Direction = Convert.ToInt32(t.FirstPosition?.Position.Y - t.EndPosition?.Position.Y); LogText.Info("Track.prase", "成功解析出一条轨迹:方向{0},旋转速度{1},落地区域{2},半径{3}", t.direction, t.MaxRotateSpeed, t.TouchdonwMarkNumber, t.radius); return(t); }
/// <summary> /// 当前回合完成,可以分析当前回合内的数据 /// 一发失败 /// </summary> public bool CompleteRand() { IList <Track> tracks = currentRound.Tracks; if (tracks.Count == 0) { LogText.Error("CompleteRand", "当前回合的轨迹数为0,发生数据错误"); return(false); } //一发 if (tracks.Count == 1) { LogText.Info("CompleteRand", "当前回合只有1条轨迹"); FirstServeEvent(tracks[0]); SetWinner(currentRound, tracks[0]); if (tracks[0].Status == MatchEventResult.SCORE) { return(true); } else { return(false); } } else if (tracks.Count == 2) { Track firstT = tracks[0]; ///一发失败,从第二个轨迹开始开始计算 ///第一条轨迹已经判断过了,并且一二两条轨迹都是同一个人 if (firstT.Status != MatchEventResult.UNKNOW && firstT.Owner.Equals(tracks[1].Owner)) { LogText.Info("CompleteRand", "一发失误,开始进行二发"); SecondServ(); //设定二发的赢球人 SetWinner(currentRound, tracks[1]); return(true); } else { currentRound.CompetitionCount = 1; match_event reciveEvent = ProcessRecive(tracks); DataProviderServices.instance.AddMatchEvent(reciveEvent); SetWinner(currentRound, tracks[1]); LogText.Info("CompleteRand", "普通的两条轨迹处理完成"); } } else if (tracks.Count > 2) { LogText.Info("CompleteRand", "大于2条轨迹回合处理"); match_event serv = ProcessRecive(tracks); for (int i = 2; i <= tracks.Count - 1; i++) { match_event ev = CreateNewEvent(); if (tracks[i - 1].Status == MatchEventResult.OUT_SIDE) { tracks[i - 1].Status = MatchEventResult.INSIDE; serv.EventResult = (int)MatchEventResult.INSIDE; DataProviderServices.instance.AddMatchEvent(serv); } ev.EventResult = (int)processSingleTrack(tracks[i], false); serv = ev; } DataProviderServices.instance.AddMatchEvent(serv); SetWinner(currentRound, tracks[tracks.Count - 1]); } currentRound.Save(); return(true); }