public MatchArchive GetMatches(uint teamId, DateTime startDate, DateTime endDate) { List <Match> matches = new List <Match>(); DateTime curMonthStart = startDate; Team team = null; // 15 minute grid endDate = endDate.AddSeconds(-endDate.Second); endDate = endDate.AddMinutes(-(endDate.Minute % 15)); while (curMonthStart < endDate) { DateTime curMonthEnd = new DateTime(curMonthStart.Year, curMonthStart.Month, 1).AddMonths(1).AddSeconds(-1); if (curMonthEnd > endDate) { curMonthEnd = endDate; } string url = new StringBuilder("file=matchesarchive&version=1.1") .Append("&teamID=").Append(teamId) .Append("&FirstMatchDate=").Append(curMonthStart.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) .Append("&LastMatchDate=").Append(curMonthEnd.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)).ToString(); XDocument doc = XDocument.Load(ChppAccessor.GetDataReader(url, DataFlags.Static)); XElement elTeam = doc.Root.AssertElement("Team"); Team compTeam = MatchParserHelper.GetTeam(elTeam, string.Empty); if (teamId != compTeam.ID) { throw new Exception("received wrong team info"); } team = compTeam; // assert dates foreach (XElement el in doc.Descendants("Match")) { matches.Add(MatchParserHelper.GetMatch(el)); } curMonthStart = curMonthEnd.AddSeconds(1); } // TODO: team may be null here (if endDate < startDate) MatchArchive ar = new MatchArchive(team, startDate, endDate); ar.Matches = matches; return(ar); }
public MatchDetails GetMatchDetails(uint matchId) { string url = new StringBuilder("file=matchdetails&version=2.0&matchID=") .Append(matchId) .Append("&matchEvents=true") .ToString(); XDocument doc = XDocument.Load(ChppAccessor.GetDataReader(url, DataFlags.Static)); XElement elMatch = doc.Root.AssertElement("Match"); Match match = MatchParserHelper.GetMatch(elMatch); MatchDetails md = new MatchDetails(match.ID, match.Type, match.HomeTeam, match.AwayTeam); md.Date = match.Date; XElement elHomeTeam = elMatch.AssertElement("HomeTeam"); XElement elAwayTeam = elMatch.AssertElement("AwayTeam"); uint homeGoals = uint.Parse(elHomeTeam.AssertElement("HomeGoals").Value); uint awayGoals = uint.Parse(elAwayTeam.AssertElement("AwayGoals").Value); md.FinalScore = new Score(homeGoals, awayGoals); XElement elArena = elMatch.Element("Arena"); if (elArena != null) { md.Visitors = new Crowd(); XElement elVisitors = elArena.Element("SoldTotal"); if (elVisitors != null) { md.Visitors.Total = uint.Parse(elVisitors.Value); } elVisitors = elArena.Element("SoldTerraces"); if (elVisitors != null) { md.Visitors.Terraces = uint.Parse(elVisitors.Value); } elVisitors = elArena.Element("SoldBasic"); if (elVisitors != null) { md.Visitors.BasicSeats = uint.Parse(elVisitors.Value); } elVisitors = elArena.Element("SoldRoof"); if (elVisitors != null) { md.Visitors.SeatsUnderRoof = uint.Parse(elVisitors.Value); } elVisitors = elArena.Element("SoldVIP"); if (elVisitors != null) { md.Visitors.Vip = uint.Parse(elVisitors.Value); } } IList <Goal> goals = new List <Goal>(); foreach (XElement elGoal in doc.Root.Descendants("Goal")) { goals.Add(new Goal( md, uint.Parse(elGoal.AssertElement("ScorerMinute").Value), new Score( uint.Parse(elGoal.AssertElement("ScorerHomeGoals").Value), uint.Parse(elGoal.AssertElement("ScorerAwayGoals").Value)), new Team( int.Parse(elGoal.AssertElement("ScorerTeamID").Value), "unnamed team"), new Player( int.Parse(elGoal.AssertElement("ScorerPlayerID").Value), // this handles negative dummy players elGoal.AssertElement("ScorerPlayerName").Value))); } md.Goals = goals; IList <MatchEvent> events = new List <MatchEvent>(); foreach (XElement elEvent in doc.Root.Descendants("Event")) { events.Add(new MatchEvent( match, uint.Parse(elEvent.Attribute("Index").Value), (MatchEvent.MatchEventType) uint.Parse(elEvent.AssertElement("EventKey").Value.Split('_')[0]), uint.Parse(elEvent.AssertElement("Minute").Value), elEvent.AssertElement("EventText").Value, int.Parse(elEvent.AssertElement("SubjectTeamID").Value), int.Parse(elEvent.AssertElement("SubjectPlayerID").Value), // this handles negative dummy players int.Parse(elEvent.AssertElement("ObjectPlayerID").Value))); // this handles negative dummy players } md.Events = events; md.HomeRatings = new Ratings(uint.Parse(elHomeTeam.AssertElement("RatingMidfield").Value), uint.Parse(elHomeTeam.AssertElement("RatingLeftDef").Value), uint.Parse(elHomeTeam.AssertElement("RatingRightDef").Value), uint.Parse(elHomeTeam.AssertElement("RatingMidDef").Value), uint.Parse(elHomeTeam.AssertElement("RatingLeftAtt").Value), uint.Parse(elHomeTeam.AssertElement("RatingRightAtt").Value), uint.Parse(elHomeTeam.AssertElement("RatingMidAtt").Value)); md.AwayRatings = new Ratings(uint.Parse(elAwayTeam.AssertElement("RatingMidfield").Value), uint.Parse(elAwayTeam.AssertElement("RatingLeftDef").Value), uint.Parse(elAwayTeam.AssertElement("RatingRightDef").Value), uint.Parse(elAwayTeam.AssertElement("RatingMidDef").Value), uint.Parse(elAwayTeam.AssertElement("RatingLeftAtt").Value), uint.Parse(elAwayTeam.AssertElement("RatingRightAtt").Value), uint.Parse(elAwayTeam.AssertElement("RatingMidAtt").Value)); md.HomeLineup = GetLineup(md.ID, md.HomeTeam.ID); md.AwayLineup = GetLineup(md.ID, md.AwayTeam.ID); return(md); }