public IActionResult AddMatch(GaiaDbContext.Models.HomeViewModels.MatchInfoModel model) { if (ModelState.IsValid) { if (model.Id > 0) { MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == model.Id); //更新必要数据 matchInfoModel.Name = model.Name; matchInfoModel.Contents = model.Contents; matchInfoModel.IsAutoCreate = model.IsAutoCreate; matchInfoModel.NumberMax = model.NumberMax; //matchInfoModel.Name = model.Name; this.dbContext.MatchInfoModel.Update(matchInfoModel); } else { this.dbContext.MatchInfoModel.Add(model); } this.dbContext.SaveChanges(); return(Redirect("/MatchInfo/Index")); } return(View(model)); }
private List <MatchInfoModel> GetMatchModelListBySpieltag(int spieltag) { using (var client = new SvcFussballDB.SportsdataSoapClient()) { var matchList = new List <MatchInfoModel>(); var oddsList = WettfreundeScraper.Scrap(spieltag); var matches = client.GetMatchdataByGroupLeagueSaison(spieltag, SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison); foreach (var m in matches) { var matchInfoModel = new MatchInfoModel(); matchInfoModel.MatchId = m.matchID; matchInfoModel.KickoffTime = m.matchDateTime; matchInfoModel.IsFinished = m.matchIsFinished; matchInfoModel.HomeTeam = m.nameTeam1; matchInfoModel.AwayTeam = m.nameTeam2; matchInfoModel.HomeTeamIcon = m.iconUrlTeam1; matchInfoModel.AwayTeamIcon = m.iconUrlTeam2; matchInfoModel.HomeTeamScore = m.pointsTeam1; matchInfoModel.AwayTeamScore = m.pointsTeam2; // mixin odds quotes into match data { MixinOddsQuotes(oddsList, matchInfoModel); } matchList.Add(matchInfoModel); } return(matchList); } }
public static MatchInfoModel Create(FussballTippApp.SvcFussballDB.Matchdata match) { var matchModelObj = new MatchInfoModel(); matchModelObj.MatchId = match.matchID; matchModelObj.KickoffTime = match.matchDateTime; matchModelObj.HomeTeamScore = match.pointsTeam1; matchModelObj.AwayTeamScore = match.pointsTeam2; matchModelObj.HomeTeamIcon = match.iconUrlTeam1; matchModelObj.AwayTeamIcon = match.iconUrlTeam2; matchModelObj.HomeTeam = match.nameTeam1; matchModelObj.AwayTeam = match.nameTeam2; matchModelObj.IsFinished = match.matchIsFinished; if (match.matchResults != null && match.matchResults.Any()) { var result = (from r in match.matchResults orderby r.resultTypeId descending select r).FirstOrDefault(); if (result == null) { return(matchModelObj); } matchModelObj.HomeTeamScore = result.pointsTeam1; matchModelObj.AwayTeamScore = result.pointsTeam2; } return(matchModelObj); }
public IActionResult AddMatch(int?id) { if (id != null) { MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); return(View(matchInfoModel)); } return(View()); }
/// <summary> /// 添加匹配到匹配对列 /// </summary> /// <param name="userid"></param> /// <param name="roomtype"></param> public void AddMatch(int userid, SConst.GameType roomtype, ref ResponseStartMatchInfo info) { #region 如果当前有匹配对列 if (MatchInfo.Count > 0) { //创建一条匹配对列房间号的列表 List <int> Roomid = new List <int>(MatchInfo.Keys); for (int i = 0; i < Roomid.Count; i++) { //如果匹配对列和将要进行的游戏类型一致 if (MatchInfo[Roomid [i]].GameType == roomtype) { //如果当前对列中有队伍未满员 if (MatchInfo[Roomid[i]].Team.Count < MatchInfo[Roomid[i]].MaxPlayer) { //将玩家添加到匹配对列中 MatchInfo[Roomid[i]].Team.Add(userid); //添加返回给客户端的信息 info.PlayerCount = MatchInfo[Roomid[i]].Team.Count; info.MaxPlayer = MatchInfo[Roomid[i]].MaxPlayer; info.Type = roomtype; //添加玩家和房间号的映射 UserToMatch.Add(userid, Roomid[i]); DebugUtil.Instance.LogToTime(userid + "请求加入匹配对列成功,对列号为:" + Roomid[i]); IsFinish(Roomid[i]); return; } } } } #endregion #region 创建一个新的匹配对列 //创建一个新的匹配对列 MatchInfoModel model = new MatchInfoModel(); //设定当前具有玩家数量来开启游戏 model.MaxPlayer = 2; model.RoomId = GetMatchId(); model.GameType = roomtype; model.Team.Add(userid); //添加返回给客户端的信息 info.PlayerCount = model.Team.Count; info.MaxPlayer = model.MaxPlayer; info.Type = roomtype; //添加房间号和房间的映射 MatchInfo.Add(model.RoomId, model); //添加玩家和房间号的映射 UserToMatch.Add(userid, model.RoomId); //添加游戏是否开始的映射 if (!IsStartGame.ContainsKey(model.RoomId)) { IsStartGame.Add(model.RoomId, false); } DebugUtil.Instance.LogToTime(userid + "请求创建匹配对列成功,对列号为:" + model.RoomId); IsFinish(model.RoomId); #endregion }
/// <summary> /// 计分 /// </summary> /// <param name="matchInfoModel"></param> private void ScoreMatch(MatchInfoModel matchInfoModel) { //jsonData.data = matchInfoModel; matchInfoModel.MatchFinishNumber = 0; //分数清零 //查询当前报名人 List <MatchJoinModel> matchJoinModels = this.dbContext.MatchJoinModel .Where(item => item.matchInfo_id == matchInfoModel.Id).ToList(); foreach (MatchJoinModel matchJoinModel in matchJoinModels) { matchJoinModel.Score = 0; matchJoinModel.first = 0; matchJoinModel.second = 0; matchJoinModel.third = 0; matchJoinModel.fourth = 0; this.dbContext.MatchJoinModel.Update(matchJoinModel); } //查询当前比赛 IQueryable <GameInfoModel> gameInfoModels = this.dbContext.GameInfoModel.Where(item => item.matchId == matchInfoModel.Id); //遍历比赛 foreach (GameInfoModel gameInfoModel in gameInfoModels) { bool isFinish = DbGameSave.SaveMatchToDb(gameInfoModel, dbContext); if (isFinish) { matchInfoModel.MatchFinishNumber++; } } //如果7场全部结束,更新冠军 int gameCount = gameInfoModels.Count(); //如果结束场次是现有场次 if (matchInfoModel.MatchFinishNumber == gameCount) { //查询分数最高的 IQueryable <MatchJoinModel> match = this.dbContext.MatchJoinModel.Where(item => item.matchInfo_id == matchInfoModel.Id).OrderByDescending(item => item.Score); String username = match.ToList()[0].username; matchInfoModel.Champion = username; //进行中1变结束2 matchInfoModel.State = 2; //matchInfoModel.MatchFinishNumber = (short) gameCount; //结束时间 matchInfoModel.EndTime = DateTime.Now; //matchInfoModel.MatchTotalNumber = (short)gameCount; } this.dbContext.MatchInfoModel.Update(matchInfoModel); }
public async Task <JsonResult> DelMatch(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); if (matchInfoModel != null) { this.dbContext.MatchInfoModel.Remove(matchInfoModel); this.dbContext.SaveChanges(); jsonData.info.state = 200; } return(new JsonResult(jsonData)); }
private static void MixinOddsQuotes(List <OddsInfoModel> oddsList, MatchInfoModel m) { var homeTeamUpper = m.HomeTeam.ToUpper(); var awayTeamUpper = m.AwayTeam.ToUpper(); var oddsMatch = (from o in oddsList where (homeTeamUpper.Contains(o.HomeTeamSearch) || awayTeamUpper.Contains(o.AwayTeamSearch)) select o) .First(); m.HomeTeamOdds = oddsMatch.WinOdds; m.AwayTeamOdds = oddsMatch.LossOdds; m.DrawOdds = oddsMatch.DrawOdds; }
public ActionResult Standing18() { //ViewBag.Message = "World cup 2018 Info"; string json = string.Empty; string JsonText = FlagsConst.stdLink; MatchInfoModel mim = new MatchInfoModel(); mim.StdGroup = new List <StandingModel>(); //using (StreamReader reader = new StreamReader(JsonText)) //{ // json = reader.ReadToEnd(); //} using (WebClient wc = new WebClient()) { json = wc.DownloadString(JsonText); } JavaScriptSerializer jss = new JavaScriptSerializer(); var obj = jss.Deserialize <dynamic>(json); int len = obj.Length; for (int i = 0; i < len; i++) { StandingModel std = new StandingModel(); std.name = obj[i]["name"]; std.id = obj[i]["id"]; std.listStand = new List <GroupTeam>(); int lende = obj[i]["tableRows"].Length; for (int j = 0; j < lende; j++) { var match = new GroupTeam(); match.TeamName = obj[i]["tableRows"][j]["team"]["name"]; match.TeamId = obj[i]["tableRows"][j]["team"]["id"]; match.TeamFlag = FlagsConst.ptLink + match.TeamId.ToString() + ".png"; match.Position = obj[i]["tableRows"][j]["position"]; match.matchesTotal = obj[i]["tableRows"][j]["totalFields"]["matchesTotal"]; match.winTotal = obj[i]["tableRows"][j]["totalFields"]["winTotal"]; match.drawTotal = obj[i]["tableRows"][j]["totalFields"]["drawTotal"]; match.lossTotal = obj[i]["tableRows"][j]["totalFields"]["lossTotal"]; match.goalsTotal = obj[i]["tableRows"][j]["totalFields"]["goalsTotal"]; match.goalDiffTotal = obj[i]["tableRows"][j]["totalFields"]["goalDiffTotal"]; match.pointsTotal = obj[i]["tableRows"][j]["totalFields"]["pointsTotal"]; std.listStand.Add(match); } mim.StdGroup.Add(std); } return(PartialView("_Standing18", mim)); }
/// <summary> /// 初始化房间 /// </summary> /// <param name="model"></param> public void Init(MatchInfoModel model) { //初始化房间类型 GameType = model.GameType; //初始化队伍成员 TemeId.Clear(); TemeId.AddRange(model.Team); //初始化房间ID RoomId = model.RoomId; //初始化人数 MaxPlayer = model.MaxPlayer; //添加方位数量 for (int i = 0; i < MaxPlayer; i++) { Direction.Add(i); } //初始化玩家信息 for (int i = 0; i < model.Team.Count; i++) { FightUserModel m = new FightUserModel(); //获取用户信息 RoleInfo ri = cache.CacheFactory.user.Get(model.Team[i]); //如果获取到,则将玩家信息赋值给用户信息 if (ri != null) { m.coin = ri.coin; m.nickname = ri.nickname; m.id = ri.id; } //否则,设置为默认信息 else { m.coin = 0; m.nickname = "nickname"; m.id = model.Team[i]; } //赋值玩家当前方位 m.Direction = Direction[0]; Direction.RemoveAt(0); UserFight.Add(m.id, m); } //广播玩家信息 for (int i = 0; i < TemeId.Count; i++) { Broadcast(FightProtocol.PLAYERINFO_BRQ, UserFight[TemeId[i]]); } DebugUtil.Instance.LogToTime(RoomId + "房间初始化成功"); }
public static MatchInfoModel Create(WMTippApp.SvcFussballDB.Matchdata match) { var matchModelObj = new MatchInfoModel(); matchModelObj.MatchId = match.matchID; matchModelObj.KickoffTime = match.matchDateTime; matchModelObj.HomeTeamScore = match.pointsTeam1; matchModelObj.AwayTeamScore = match.pointsTeam2; matchModelObj.HomeTeamIcon = match.iconUrlTeam1; matchModelObj.AwayTeamIcon = match.iconUrlTeam2; matchModelObj.HomeTeam = match.nameTeam1; matchModelObj.AwayTeam = match.nameTeam2; matchModelObj.IsFinished = match.matchIsFinished; return(matchModelObj); }
public async Task <JsonResult> ExitMatch(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); //比赛信息 MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); if (matchInfoModel != null) { if (matchInfoModel.RegistrationEndTime < DateTime.Now) { jsonData.info.state = 0; jsonData.info.message = "报名时间截止"; } else if (matchInfoModel.State != 0) { jsonData.info.state = 0; jsonData.info.message = "已经开始,无法退出"; } else { MatchJoinModel matchJoinModel = this.dbContext.MatchJoinModel.SingleOrDefault(item => item.matchInfo_id == matchInfoModel.Id && item.username == HttpContext.User.Identity .Name); if (matchJoinModel != null) { //删除 this.dbContext.MatchJoinModel.Remove(matchJoinModel); //报名人数-1 matchInfoModel.NumberNow--; this.dbContext.MatchInfoModel.Update(matchInfoModel); this.dbContext.SaveChanges(); jsonData.info.state = 200; } else { jsonData.info.state = 0; jsonData.info.message = "没有报名"; } } } return(new JsonResult(jsonData)); }
private static bool IsSendEmailReminder(UserProfile user, MatchInfoModel matchObj, TippMatchModel tippObj) { if (user.HasEmailReminder == false) { return(false); } if ((tippObj == null || tippObj.MyTip.HasValue == false) && (matchObj.KickoffTime > DateTime.Now) && (DateTime.Now > matchObj.KickoffTime.AddDays(-1))) { return(true); } else { return(false); } }
/// <summary> /// 离开匹配队列 /// </summary> /// <param name="token"></param> /// <returns></returns> public int LeaveMatch(UserToken token) { int userid = CacheFactory.user.GetIdToToken(token); //判断是否含有匹配队列 if (!GetHaveMatch(token)) { DebugUtil.Instance.LogToTime(userid + "请求离开匹配失败,当前没有匹配队列"); return(-2); } //判断是否已经开始 if (GetStartGame(token)) { DebugUtil.Instance.LogToTime(userid + "请求离开匹配失败,游戏已经开始"); return(-1); } int roomid = UserToMatch[userid]; MatchInfoModel model = MatchInfo[roomid]; model.Team.Remove(userid); UserToMatch.Remove(userid); //如果当前没有玩家了,则移除匹配队列 if (model.Team.Count == 0) { MatchInfo.Remove(roomid); IsStartGame.Remove(roomid); DebugUtil.Instance.LogToTime(userid + "请求离开匹配成功,移除匹配队列" + roomid); } //否则,广播给此队列所有玩家 else { //将队伍成员信息广播给所有队伍成员 for (int i = 0; i < MatchInfo[roomid].Team.Count; i++) { UserToken tokens = CacheFactory.user.GetToken(MatchInfo[roomid].Team[i]); tokens.write(TypeProtocol.MATCH, MatchProtocol.MATCHINFO_BRQ, MatchInfo[roomid]); } DebugUtil.Instance.LogToTime(userid + "请求离开匹配成功,匹配队列" + roomid); } return(0); }
/// <summary> /// 创建房间 /// </summary> public void Create(MatchInfoModel model) { if (RoomDic.ContainsKey(model.RoomId)) { DebugUtil.Instance.LogToTime(model.RoomId + "房间已经存在,不可重新创建"); return; } FightRoom fight; //如果当前游戏是赢三张,则使用FightRoom的子类TPFightRoom if (model.GameType == GameProtocol.SConst.GameType.WINTHREEPOKER) { fight = new TPFightRoom(); } else { fight = new FightRoom(); } //初始化房间 fight.Init(model); //将房间号和房间绑定 RoomDic.Add(model.RoomId, fight); //将玩家和房间号绑定 string str = ""; for (int i = 0; i < model.Team.Count; i++) { if (UserToRoom.ContainsKey(model.Team[i])) { UserToRoom[model.Team[i]] = model.RoomId; } else { UserToRoom.Add(model.Team[i], model.RoomId); } str += model.Team[i] + "_"; } DebugUtil.Instance.LogToTime(model.RoomId + "房间_" + str + "创建成功"); }
/// <summary> /// 显示比赛详细 /// </summary> /// <param name="model"></param> /// <returns></returns> public IActionResult MatchShow(int id) { MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); if (matchInfoModel != null) { //查询当前报名人 IQueryable <MatchJoinModel> matchJoinModels = this.dbContext.MatchJoinModel.Where(item => item.matchInfo_id == matchInfoModel.Id).OrderByDescending(item => item.Score); //查询当前比赛 IQueryable <GameInfoModel> gameInfoModels = this.dbContext.GameInfoModel.Where(item => item.matchId == matchInfoModel.Id); MatchShowModel matchShowModel = new MatchShowModel() { MatchInfoModel = matchInfoModel, MatchJoinModels = matchJoinModels, GameInfoModels = gameInfoModels, }; return(View(matchShowModel)); } return(View(null)); }
private static void MixinOddsQuotes(List <OddsInfoModel> oddsList, MatchInfoModel m) { var homeTeamUpper = m.HomeTeam.ToUpper(); var awayTeamUpper = m.AwayTeam.ToUpper(); var oddsMatch = (from o in oddsList where (homeTeamUpper.Contains(o.HomeTeamSearch) && awayTeamUpper.Contains(o.AwayTeamSearch)) select o) .FirstOrDefault(); if (oddsMatch == null) { oddsMatch = (from o in oddsList where (homeTeamUpper.Contains(o.HomeTeamSearch2) && awayTeamUpper.Contains(o.AwayTeamSearch2)) select o) .FirstOrDefault(); } if (oddsMatch != null) { m.HomeTeamOdds = oddsMatch.WinOdds; m.AwayTeamOdds = oddsMatch.LossOdds; m.DrawOdds = oddsMatch.DrawOdds; } // find favorite and longshot tipp if (m.DrawOdds.HasValue && m.HomeTeamOdds.HasValue && m.AwayTeamOdds.HasValue) { double[] odds = new double[] { m.DrawOdds.Value, m.HomeTeamOdds.Value, m.AwayTeamOdds.Value }; } }
public ActionResult Index(int?Spieltag) { log.Debug("Index begin"); var allGroups = _matchDataRepository.GetAllGroups(); int currentSpieltag = Spieltag ?? SportsdataConfigInfo.Current.CurrentSpieltag; // build dropdown list data { var count = SportsdataConfigInfo.Current.EndSpieltag - SportsdataConfigInfo.Current.StartSpieltag + 1; var ddlSpieltageRange = (from e in allGroups where e.Id <= SportsdataConfigInfo.Current.EndSpieltag && e.Id >= SportsdataConfigInfo.Current.StartSpieltag select new SelectListItem() { Value = e.Id.ToString(), Text = e.Text, Selected = (e.Id == currentSpieltag) }); ViewBag.Spieltag = ddlSpieltageRange; } var model = new SpieltagModel(); model.GroupId = currentSpieltag; model.GroupName = allGroups.Find(g => g.Id == currentSpieltag).Text; var oddsList = _quoteRepository.GetOdds(currentSpieltag); var matches = _matchDataRepository.GetMatchesByGroup(currentSpieltag); matches = (from m in matches orderby m.KickoffTime select m).ToList(); foreach (var m in matches) { var modelAllInfo = new MatchInfoModel() { MatchId = m.MatchId, GroupId = m.GroupId, MatchNr = m.MatchNr, AwayTeam = m.AwayTeam, AwayTeamIcon = m.AwayTeamIcon, AwayTeamScore = m.AwayTeamScore, HomeTeam = m.HomeTeam, HomeTeamIcon = m.HomeTeamIcon, HomeTeamScore = m.HomeTeamScore, IsFinished = m.IsFinished, KickoffTime = m.KickoffTime }; // mixin odds quotes into match data MixinOddsQuotes(oddsList, modelAllInfo); using (var ctxt = new TippSpielContext()) { var myTippObject = (from t in ctxt.TippMatchList where t.MatchId == modelAllInfo.MatchId && t.User == User.Identity.Name select t) .FirstOrDefault(); if (myTippObject != null) { modelAllInfo.MyOdds = myTippObject.MyOdds; modelAllInfo.MyTip = myTippObject.MyTip; modelAllInfo.IsJoker = myTippObject.IsJoker; modelAllInfo.MyAmount = myTippObject.MyAmount; } } model.Matchdata.Add(modelAllInfo); } model.MaxJokers = TippspielConfigInfo.Current.MaxJokerTips; model.NumJokersUsed = model.Matchdata.Count(m => m.IsJoker); { log.DebugFormat("Tipp data stats: remote hits={0}, cache hits={1}", MatchDBStats.GetRemoteHits(), MatchDBStats.GetCacheHits()); } log.Debug("Index end"); return(View(model)); }
public ActionResult DailyReport(DateTime?Spieltag) { log.Debug("DailyReport begin"); var kickoff = Spieltag; // extract spieltage if (kickoff == null) { var match = _matchDataRepository.GetLastMatch(); if (match.MatchId == -1) { match = _matchDataRepository.GetNextMatch(); } kickoff = match.KickoffTimeUTC; } var matchFilter = (from m in _matchDataRepository.GetAllMatches() where m.KickoffTimeUTC.ToShortDateString() == kickoff.Value.ToShortDateString() && m.HasStarted == true select m); // build dropdown list data { var distinctByKickoff = (from m in _matchDataRepository.GetAllMatches() orderby m.KickoffTime select new { KickoffDate = m.KickoffTime.ToShortDateString(), KickoffDateUTC = m.KickoffTimeUTC.ToShortDateString() }) .DistinctBy(a => a.KickoffDateUTC); var ddlSpieltageRange = (from m in distinctByKickoff select new SelectListItem() { Value = m.KickoffDateUTC, Text = m.KickoffDate, Selected = (m.KickoffDateUTC == kickoff.Value.ToShortDateString()) }) .Distinct(); ViewBag.Spieltag = ddlSpieltageRange; } var viewModel = new DailyWinnerInfoModel(); { viewModel.MatchInfo = matchFilter.ToList(); } using (var ctxt = new TippSpielContext()) { var resultDict = new Dictionary <string, RankingInfoModel>(); using (var userCtxt = new UsersContext()) { // init result dict { foreach (var username in (from t in ctxt.TippMatchList select t.User).Distinct()) { var m = new RankingInfoModel(); m.User = username; m.DisplayName = (from u in userCtxt.UserProfiles where u.UserName == username select u.DisplayName) .FirstOrDefault(); resultDict.Add(username, m); viewModel.AllTippInfoDict.Add(username, new List <MatchInfoModel>()); } } } // 1. get all tipps for match with id foreach (var m in matchFilter) { var tippSet = (from t in ctxt.TippMatchList where t.MatchId == m.MatchId && t.MyTip.HasValue && t.MyAmount.HasValue && t.MyOdds.HasValue select t); foreach (var tip in tippSet) { var matchModelObj = new MatchInfoModel() { MatchId = m.MatchId, GroupId = m.GroupId, MatchNr = m.MatchNr, AwayTeam = m.AwayTeam, AwayTeamIcon = m.AwayTeamIcon, AwayTeamScore = m.AwayTeamScore, HomeTeam = m.HomeTeam, HomeTeamIcon = m.HomeTeamIcon, HomeTeamScore = m.HomeTeamScore, IsFinished = m.IsFinished, KickoffTime = m.KickoffTime }; matchModelObj.MyOdds = tip.MyOdds; matchModelObj.IsJoker = tip.IsJoker; if (tip.IsJoker == true) { matchModelObj.MyAmount = tip.MyAmount * TippspielConfigInfo.Current.JokerMultiplicator; } else { matchModelObj.MyAmount = tip.MyAmount; } matchModelObj.MyTip = tip.MyTip; if (matchModelObj.HasStarted == true) { resultDict[tip.User].TippCount++; resultDict[tip.User].TotalPoints += matchModelObj.MyPoints ?? 0.0; } if (matchModelObj.HasStarted == true) { viewModel.AllTippInfoDict[tip.User].Add(matchModelObj); } } } var resultList = (from kp in resultDict select kp.Value).ToList(); viewModel.Ranking = (from e in resultList orderby e.TotalPoints descending, e.PointAvg, e.TippCount descending select e) .ToList(); int counter = 1; viewModel.Ranking.ForEach(e => { e.Rang = counter++; }); } log.Debug("DailyReport end"); return(View(viewModel)); }
public ActionResult OverallStanding() { _matchDataRepository.GetCurrentGroup(); var groupModel = _matchDataRepository.GetCurrentGroup(); var maxSpieltag = groupModel.Id; using (var ctxt = new TippSpielContext()) { var resultDict = new Dictionary <string, RankingInfoModel>(); using (var userCtxt = new UsersContext()) { // init dict { foreach (var username in (from t in ctxt.TippMatchList select t.User).Distinct()) { var m = new RankingInfoModel(); m.User = username; m.DisplayName = (from u in userCtxt.UserProfiles where u.UserName == username select u.DisplayName) .FirstOrDefault(); resultDict.Add(username, m); } } } foreach (var tip in ctxt.TippMatchList.Where(t => t.MyTip.HasValue)) { var rankingObj = resultDict[tip.User]; var matchInfo = _matchDataRepository.GetMatchData(tip.MatchId); if (matchInfo.LeagueShortcut == SportsdataConfigInfo.Current.LeagueShortcut && tip.MyOdds.HasValue && tip.MyAmount.HasValue) { var matchModelObj = new MatchInfoModel() { MatchId = matchInfo.MatchId, MatchNr = matchInfo.MatchNr, AwayTeam = matchInfo.AwayTeam, AwayTeamIcon = matchInfo.AwayTeamIcon, AwayTeamScore = matchInfo.AwayTeamScore, HomeTeam = matchInfo.HomeTeam, HomeTeamIcon = matchInfo.HomeTeamIcon, HomeTeamScore = matchInfo.HomeTeamScore, IsFinished = matchInfo.IsFinished, KickoffTime = matchInfo.KickoffTime, GroupId = tip.GroupId, MyOdds = tip.MyOdds, MyAmount = tip.MyAmount, MyTip = tip.MyTip, IsJoker = tip.IsJoker, }; if (tip.IsJoker == true) { matchModelObj.MyAmount = tip.MyAmount * TippspielConfigInfo.Current.JokerMultiplicator; } else { matchModelObj.MyAmount = tip.MyAmount; } if (matchModelObj.HasStarted == true) { rankingObj.TippCount++; rankingObj.TotalPoints += matchModelObj.MyPoints ?? 0.0; rankingObj.TotalPointsClean += matchModelObj.MyPointsClean ?? 0.0; if (tip.IsJoker) { rankingObj.JokerUsed++; } } } } var resultList = (from kp in resultDict select kp.Value).ToList(); resultList = (from e in resultList orderby e.TotalPoints descending, e.PointAvg, e.TippCount descending select e) .ToList(); int counter = 1; resultList.ForEach(e => { e.Rang = counter++; }); return(View(resultList)); } }
private static void MixinOddsQuotes(List <OddsInfoModel> oddsList, MatchInfoModel m) { var homeTeamUpper = m.HomeTeam.ToUpper(); var awayTeamUpper = m.AwayTeam.ToUpper(); var oddsMatchObj = (from o in oddsList where (homeTeamUpper.Contains(o.HomeTeamSearch) || awayTeamUpper.Contains(o.AwayTeamSearch)) select o) .FirstOrDefault(); if (oddsMatchObj == null) { foreach (var el in oddsList) { { var longestElement = el.HomeTeamSearch.Split(new char[] { ' ' }, StringSplitOptions.None).OrderByDescending(i => i.Length).FirstOrDefault(); if (longestElement != null) { el.HomeTeamSearch = longestElement; } } { var longestElement = el.AwayTeamSearch.Split(new char[] { ' ' }, StringSplitOptions.None).OrderByDescending(i => i.Length).FirstOrDefault(); if (longestElement != null) { el.AwayTeamSearch = longestElement; } } } oddsMatchObj = (from o in oddsList where (homeTeamUpper.Contains(o.HomeTeamSearch) || awayTeamUpper.Contains(o.AwayTeamSearch)) select o) .First(); } var oddsMatch = oddsMatchObj; m.HomeTeamOdds = oddsMatch.WinOdds; m.AwayTeamOdds = oddsMatch.LossOdds; m.DrawOdds = oddsMatch.DrawOdds; // find favorite and longshot tipp if (m.DrawOdds.HasValue && m.HomeTeamOdds.HasValue && m.AwayTeamOdds.HasValue) { double[] odds = new double[] { m.DrawOdds.Value, m.HomeTeamOdds.Value, m.AwayTeamOdds.Value }; var favoriteOdds = odds.Min(); var longshotOdds = odds.Max(); if (odds[1] == favoriteOdds) { m.FavoriteTippIndex = 1; } else if (odds[2] == favoriteOdds) { m.FavoriteTippIndex = 2; } else if (odds[0] == favoriteOdds) { m.FavoriteTippIndex = 0; } if (odds[1] == longshotOdds) { m.LongshotTippIndex = 1; } else if (odds[2] == longshotOdds) { m.LongshotTippIndex = 2; } else if (odds[0] == longshotOdds) { m.LongshotTippIndex = 0; } } }
public ActionResult Index(int?Spieltag) { var spieltagInfo = OpenDBHelper.GetSpieltagInfo(_matchDataRepository); int currentSpieltag = (Spieltag.HasValue == true) ? Spieltag.Value : spieltagInfo.TippSpieltag; // build dropdown list data { var count = SportsdataConfigInfo.Current.EndSpieltag - SportsdataConfigInfo.Current.StartSpieltag + 1; var ddlSpieltageRange = (from e in Enumerable.Range(SportsdataConfigInfo.Current.StartSpieltag, count) select new SelectListItem() { Value = e.ToString(), Text = "Spieltag " + e.ToString(), Selected = (e == currentSpieltag) }); ViewBag.Spieltag = ddlSpieltageRange; } var model = new SpieltagModel(); model.Spieltag = currentSpieltag; if ((currentSpieltag == 34 || currentSpieltag == 0) && spieltagInfo.IsCompleted) { model.IsTippSpielFinished = true; return(View(model)); } List <OddsInfoModel> oddsList = null; try { oddsList = WettfreundeScraper.Scrap(currentSpieltag); } catch (Exception ex) { _log.Error("Error while scrab odds: " + ex.Message); string fixFilename = String.Format("Odds_{0}_{1}_{2}", SportsdataConfigInfo.Current.LeagueShortcut, SportsdataConfigInfo.Current.LeagueSaison, currentSpieltag); _log.Info("Try fix: " + fixFilename); ResourceManager rm = new ResourceManager(typeof(Resources)); var fixContent = rm.GetObject(fixFilename) as string; var oddScraper = new WettfreundeOddsBuLiScraper(); oddsList = oddScraper.GetOdds(fixContent, currentSpieltag.ToString()); } var matches = _matchDataRepository.GetMatchesByGroup(currentSpieltag); foreach (var m in matches) { var modelAllInfo = new MatchInfoModel() { MatchId = m.MatchId, AwayTeam = m.AwayTeam, AwayTeamIcon = m.AwayTeamIcon, AwayTeamScore = m.AwayTeamScore, HomeTeam = m.HomeTeam, HomeTeamIcon = m.HomeTeamIcon, HomeTeamScore = m.HomeTeamScore, IsFinished = m.IsFinished, KickoffTime = m.KickoffTime }; model.IsSpieltagFinished = (model.IsSpieltagFinished && modelAllInfo.IsFinished); // mixin odds quotes into match data { MixinOddsQuotes(oddsList, modelAllInfo); } using (var ctxt = new TippSpielContext()) { var myTippObject = (from t in ctxt.TippMatchList where t.MatchId == modelAllInfo.MatchId && t.User == User.Identity.Name select t) .FirstOrDefault(); if (myTippObject != null) { modelAllInfo.MyOdds = myTippObject.MyOdds; modelAllInfo.MyTip = myTippObject.MyTip; modelAllInfo.MyAmount = myTippObject.MyAmount; } } model.Matchdata.Add(modelAllInfo); } { _log.DebugFormat("Tipp data stats: remote hits={0}, cache hits={1}", MatchDBStats.GetRemoteHits(), MatchDBStats.GetCacheHits()); } return(View(model)); }
public ActionResult OverallStanding() { using (var client = new SvcFussballDB.SportsdataSoapClient()) { int maxSpieltag = OpenDBHelper.GetSpieltagInfo(_matchDataRepository).CurrentSpieltag; using (var ctxt = new TippSpielContext()) { var resultDict = new Dictionary <string, RankingInfoModel>(); using (var userCtxt = new UsersContext()) { // init dict { foreach (var username in (from t in ctxt.TippMatchList select t.User).Distinct()) { var m = new RankingInfoModel(); m.User = username; m.DisplayName = (from u in userCtxt.UserProfiles where u.UserName == username select u.DisplayName) .FirstOrDefault(); resultDict.Add(username, m); } } } foreach (var tip in ctxt.TippMatchList.Where(t => t.MyTip.HasValue)) { var rankingObj = resultDict[tip.User]; var matchInfo = _matchDataRepository.GetMatchData(tip.MatchId); var matchModelObj = new MatchInfoModel() { MatchId = matchInfo.MatchId, AwayTeam = matchInfo.AwayTeam, AwayTeamIcon = matchInfo.AwayTeamIcon, AwayTeamScore = matchInfo.AwayTeamScore, HomeTeam = matchInfo.HomeTeam, HomeTeamIcon = matchInfo.HomeTeamIcon, HomeTeamScore = matchInfo.HomeTeamScore, IsFinished = matchInfo.IsFinished, KickoffTime = matchInfo.KickoffTime, MyOdds = tip.MyOdds, MyAmount = tip.MyAmount, MyTip = tip.MyTip }; if (tip.MyOdds.HasValue && tip.MyAmount.HasValue) { matchModelObj.MyOdds = tip.MyOdds; matchModelObj.MyAmount = tip.MyAmount; matchModelObj.MyTip = tip.MyTip; if (matchModelObj.HasStarted == true) { rankingObj.TippCount++; rankingObj.TotalPoints += (matchModelObj.MyPoints.HasValue) ? matchModelObj.MyPoints.Value : 0.0; } // count longshot and favorite { rankingObj.TippCountFavorite += (matchModelObj.FavoriteTippIndex == tip.MyTip.Value) ? 1 : 0; rankingObj.TippCountLongshot += (matchModelObj.LongshotTippIndex == tip.MyTip.Value) ? 1 : 0; } } } var resultList = (from kp in resultDict select kp.Value).ToList(); resultList = (from e in resultList orderby e.TotalPoints descending, e.PointAvg, e.TippCount descending select e) .ToList(); int counter = 1; resultList.ForEach(e => { e.Rang = counter++; }); return(View(resultList)); } } }
public void MessageReceive(SocketModel model) { switch (model.command) { //0离开成功 -1游戏已经开始 -2不在房间内 case MatchProtocol.LEAVEMATCH_SRES: { switch (model.GetMessage <int>()) { case 0: case -2: //离开匹配成功后,加载主界面,关闭匹配界面 GameApp.Instance.GameLevelManagerScript.CloseSystemUI(GameResources.SystemUIType.MATCHPANEL); break; case -1: GameApp.Instance.CommonHintDlgScript.OpenHint("游戏已经开始"); break; } } break; //0开始匹配 -1当前余额不足 -2玩家已经在房间中 case MatchProtocol.STARTMATCH_SRES: { //接受匹配结果 ResponseStartMatchInfo m = model.GetMessage <ResponseStartMatchInfo>(); switch (m.Status) { //匹配成功 case 0: //加载匹配页面 GameApp.Instance.GameLevelManagerScript.LoadSyStemUI(GameResources.SystemUIType.MATCHPANEL, delegate() { GameObject go; if (GameApp.Instance.GameLevelManagerScript.SystemUICache.TryGetValue(GameResources.SystemUIType.MATCHPANEL, out go)) { if (!go.GetComponent <UI_match>()) { go.AddComponent <UI_match>(); } //刷新匹配界面信息 go.GetComponent <UI_match>().StartMatch(m); } }); break; case -1: GameApp.Instance.CommonHintDlgScript.OpenHint("当前余额不足"); break; case -2: GameApp.Instance.CommonHintDlgScript.OpenHint("已经在其他房间中,不可进行匹配"); break; } } break; case MatchProtocol.MATCHCLOSE_BRQ: { GameApp.Instance.TimeManagerScript.AddShedule(delegate() { GameApp.Instance.CommonHintDlgScript.OpenHint("游戏将于五秒后自动返回大厅"); this.Write(TypeProtocol.USER, UserProtocol.GETINFO_CREQ, null); }, 5000); } break; case MatchProtocol.MATCHFINISH_BRQ: { //TODO:LODE BATTLE //匹配成功加载battle场景 GameApp.Instance.GameLevelManagerScript.LoadScene(GameResources.SceneName.BATTLE); GameApp.Instance.GameLevelManagerScript.CloseSystemUI(GameResources.SystemUIType.MATCHPANEL); } break; case MatchProtocol.MATCHINFO_BRQ: { //刷新接收到的匹配信息 MatchInfoModel m = model.GetMessage <MatchInfoModel>(); if (GameApp.Instance.UI_matchScript != null) { GameApp.Instance.UI_matchScript.UpdateRoomRoleInfo(m); } } break; } }
/// <summary> /// 自动创建比赛 /// </summary> private void AutoCreateMatch(MatchInfoModel matchInfoModel) { //是否自动创建比赛 //并且只能创建7人的比赛 if (matchInfoModel.IsAutoCreate && matchInfoModel.NumberNow == matchInfoModel.NumberMax && matchInfoModel.NumberNow == 7) { //取出全部的报名人员 List <MatchJoinModel> matchJoinModels = this.dbContext.MatchJoinModel.Where(item => item.matchInfo_id == matchInfoModel.Id).ToList(); if (matchJoinModels.Count() == 7) { //int[7][4] rank = new int(); int[,] userOrder = new int[7, 4] { { 1, 5, 4, 3 }, { 5, 2, 6, 1 }, { 2, 4, 0, 5 }, { 4, 6, 3, 2 }, { 6, 0, 1, 4 }, { 0, 3, 5, 6 }, { 3, 1, 2, 0 } }; //创建游戏 NewGameViewModel newGameViewModel = new NewGameViewModel() { dropHour = 72, IsAllowLook = true, isHall = false, IsRandomOrder = false, IsRotatoMap = true, IsSocket = false, IsTestGame = false, jinzhiFaction = null, MapSelction = GameInfoAttribute.MapSelction[GameInfoAttribute.MapSelction.Count - 1].code, //Name = matchInfoModel.GameName, }; for (int i = 0; i < 7; i++) { string[] users = new string[] { matchJoinModels[userOrder[i, 0]].username, matchJoinModels[userOrder[i, 1]].username, matchJoinModels[userOrder[i, 2]].username, matchJoinModels[userOrder[i, 3]].username }; //游戏名称 if (matchInfoModel.GameName.Contains("{0}")) { newGameViewModel.Name = string.Format(matchInfoModel.GameName, i + 1); } else { newGameViewModel.Name = string.Concat(matchInfoModel.GameName, i + 1); } //创建游戏到内存 GameMgr.CreateNewGame(users, newGameViewModel, out GaiaGame gaiaGame, _userManager: _userManager); //保存到数据库 GameMgr.SaveGameToDb(newGameViewModel, "gaia", null, this.dbContext, gaiaGame, matchId: matchInfoModel.Id, userlist: users); } } //将游戏标准为进行状态 matchInfoModel.State = 1; //比赛场次 matchInfoModel.MatchTotalNumber = 7; //开始时间 matchInfoModel.StartTime = DateTime.Now; this.dbContext.MatchInfoModel.Update(matchInfoModel); this.dbContext.SaveChanges(); } }
/// <summary> /// 刷新当前匹配信息 /// </summary> public void UpdateRoomRoleInfo(MatchInfoModel model) { MatchCountText.text = "正在匹配中… " + model.Team.Count + "/" + model.MaxPlayer; MatchGameTypeText.text = GameApp.Instance.GameConst.GameName[(int)model.GameType]; }
public ActionResult MatchInfo18() { string json = string.Empty; string JsonText = FlagsConst.ftLink; WcInfoModel info = new WcInfoModel(); info.RoundLst = new List <RoundInfo>(); //using (StreamReader reader = new StreamReader(JsonText)) //{ // json = reader.ReadToEnd(); //} using (WebClient wc = new WebClient()) { json = wc.DownloadString(JsonText); } JavaScriptSerializer jss = new JavaScriptSerializer(); var obj = jss.Deserialize <dynamic>(json); int len = obj["tournaments"].Length; for (int i = 0; i < len; i++) { int lende = obj["tournaments"][i]["events"].Length; for (int j = 0; j < lende; j++) { var match = new MatchInfoModel(); match.MatchId = obj["tournaments"][i]["events"][j]["id"]; match.HomeTeam = obj["tournaments"][i]["events"][j]["homeTeam"]["name"]; match.AwayTeam = obj["tournaments"][i]["events"][j]["awayTeam"]["name"]; //HomeFlag = obj["object"]["tournaments"]["events"][i]["firstName"], //AwayFlag = obj["object"]["tournaments"]["events"][i]["firstName"], match.HomeId = obj["tournaments"][i]["events"][j]["homeTeam"]["id"]; match.AwayId = obj["tournaments"][i]["events"][j]["awayTeam"]["id"]; match.HomeFlag = FlagsConst.ptLink + match.HomeId.ToString() + ".png"; match.AwayFlag = FlagsConst.ptLink + match.AwayId.ToString() + ".png"; try { int hsc = obj["tournaments"][i]["events"][j]["homeScore"]["current"] == null ? "?" : obj["tournaments"][i]["events"][j]["homeScore"]["current"]; match.HomeScore = hsc.ToString(); int asc = obj["tournaments"][i]["events"][j]["awayScore"]["current"] == null ? "?" : obj["tournaments"][i]["events"][j]["awayScore"]["current"]; match.AwayScore = asc.ToString(); } catch (KeyNotFoundException ex) { match.HomeScore = "?"; match.AwayScore = "?"; } double time = obj["tournaments"][i]["events"][j]["startTimestamp"]; match.timeSt = unixConvert(time); //StatusMatch = obj["object"]["tournaments"]["events"][i]["firstName"], match.RoundInfo = obj["tournaments"][i]["events"][j]["roundInfo"]["round"]; //TimeMatch = obj["object"]["tournaments"]["events"][i]["firstName"], //DateMatch = obj["object"]["tournaments"]["events"][i]["firstName"] matches.Add(match); } //i++; } int k = 0; for (int i = 1; i <= 8; i++) { RoundInfo ri = new RoundInfo(); ri.RoundId = i; ri.Schelst = new List <MatchInfoModel>(); int lenr = 0; switch (i) { case 1: ri.RoundName = "Round 1"; lenr = 15; break; case 2: ri.RoundName = "Round 2"; lenr = 31; break; case 3: ri.RoundName = "Round 3"; lenr = 47; break; case 4: ri.RoundName = "Round 1/16"; lenr = 55; break; case 5: ri.RoundName = "Quarter-Final"; lenr = 59; break; case 6: ri.RoundName = "Semi-Final"; lenr = 61; break; case 7: ri.RoundName = "3rd"; lenr = 62; break; case 8: ri.RoundName = "Final"; lenr = 63; break; } for (int a = k; a <= lenr; a++) { ri.Schelst.Add(matches[a]); } k = lenr + 1; info.RoundLst.Add(ri); } return(PartialView("_MatchInfo18", info)); }