Example #1
0
 public MatryxRound(int index, RoundDetails details) : this(index)
 {
     Details       = details;
     startDate     = Utils.Time.FromUnixTime(details.Start);
     endDate       = Utils.Time.FromUnixTime(details.Start + Details.Duration);
     reviewEndDate = Utils.Time.FromUnixTime(details.Start + details.Duration + details.Review);
 }
Example #2
0
        public ActionResult Index()
        {
            YearDetails  yr    = new YearDetails();
            RoundDetails round = new RoundDetails();

            ViewBag.dataSource  = GetLQASData();
            ViewBag.yearSource  = yr.GetYearCollection();
            ViewBag.roundSource = round.GetRoundCollection();
            return(View());
        }
Example #3
0
        private void LevelDetails_KeyDown(object sender, KeyEventArgs e)
        {
            try {
                int selectedCount = gridDetails.SelectedCells.Count;
                if (e.KeyCode == Keys.Delete && selectedCount > 0)
                {
                    HashSet <RoundInfo> rows = new HashSet <RoundInfo>();
                    int minIndex             = gridDetails.FirstDisplayedScrollingRowIndex;
                    for (int i = 0; i < selectedCount; i++)
                    {
                        DataGridViewCell cell = gridDetails.SelectedCells[i];
                        rows.Add((RoundInfo)gridDetails.Rows[cell.RowIndex].DataBoundItem);
                    }

                    if (MessageBox.Show(this, $"Are you sure you want to remove the selected ({rows.Count}) Shows?", "Remove Shows", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                    {
                        gridDetails.DataSource = null;

                        lock (StatsForm.StatsDB) {
                            StatsForm.StatsDB.BeginTrans();
                            foreach (RoundInfo info in rows)
                            {
                                RoundDetails.Remove(info);
                                StatsForm.RoundDetails.DeleteMany(x => x.ShowID == info.ShowID);
                            }
                            StatsForm.StatsDB.Commit();
                        }

                        gridDetails.DataSource = RoundDetails;
                        if (minIndex < RoundDetails.Count)
                        {
                            gridDetails.FirstDisplayedScrollingRowIndex = minIndex;
                        }
                        else if (RoundDetails.Count > 0)
                        {
                            gridDetails.FirstDisplayedScrollingRowIndex = RoundDetails.Count - 1;
                        }

                        StatsForm.ResetStats();
                    }
                }
                else if (e.KeyCode == Keys.Escape)
                {
                    Close();
                }
            } catch (Exception ex) {
                MessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public ActionResult Index()
        {
            YearDetails  yr    = new YearDetails();
            RoundDetails round = new RoundDetails();

            ViewBag.dataSource = GetLQASData();
            ViewBag.yearSource = yr.GetYearCollection();
            //ViewBag.roundSource = round.GetRoundCollection();

            List <Round> Rounds = _context2.Rounds.ToList();

            Rounds.Insert(0, new Round {
                RoundId = 0, ReportRoundName = "All"
            });
            ViewData["RoundList"] = new SelectList(Rounds, "RoundId", "ReportRoundName");

            List <Models.TreeGrid.Regions> Regions = _db.Regionlist.ToList();

            ViewBag.regionSource = new SelectList(Regions, "RegionName");
            return(View());
        }
Example #5
0
        private void gridDetails_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            string    columnName = gridDetails.Columns[e.ColumnIndex].Name;
            SortOrder sortOrder  = gridDetails.GetSortOrder(columnName);

            RoundDetails.Sort(delegate(RoundInfo one, RoundInfo two) {
                int roundCompare = one.Round.CompareTo(two.Round);
                int showCompare  = one.ShowID.CompareTo(two.ShowID);
                if (sortOrder == SortOrder.Descending)
                {
                    RoundInfo temp = one;
                    one            = two;
                    two            = temp;
                }
                switch (columnName)
                {
                case "ShowID":
                    showCompare = one.ShowID.CompareTo(two.ShowID);
                    return(showCompare == 0 ? roundCompare : showCompare);

                case "Round":
                    roundCompare = one.Round.CompareTo(two.Round);
                    return(roundCompare == 0 ? showCompare : roundCompare);

                case "Name":
                    string nameOne = one.Name;
                    LevelStats.DisplayNameLookup.TryGetValue(one.Name, out nameOne);
                    string nameTwo = two.Name;
                    LevelStats.DisplayNameLookup.TryGetValue(two.Name, out nameTwo);
                    int nameCompare = nameOne.CompareTo(nameTwo);
                    return(nameCompare != 0 ? nameCompare : roundCompare);

                case "Players":
                    int playerCompare = one.Players.CompareTo(two.Players);
                    return(playerCompare != 0 ? playerCompare : showCompare == 0 ? roundCompare : showCompare);

                case "Start": return(one.Start.CompareTo(two.Start));

                case "End": return((one.End - one.Start).CompareTo(two.End - two.Start));

                case "Finish": return(one.Finish.HasValue && two.Finish.HasValue ? (one.Finish.Value - one.Start).CompareTo(two.Finish.Value - two.Start) : one.Finish.HasValue ? -1 : 1);

                case "Qualified":
                    int qualifiedCompare = ShowStats == 2 ? string.IsNullOrEmpty(one.Name).CompareTo(string.IsNullOrEmpty(two.Name)) : one.Qualified.CompareTo(two.Qualified);
                    return(qualifiedCompare != 0 ? qualifiedCompare : showCompare == 0 ? roundCompare : showCompare);

                case "Position":
                    int positionCompare = one.Position.CompareTo(two.Position);
                    return(positionCompare != 0 ? positionCompare : showCompare == 0 ? roundCompare : showCompare);

                case "Score":
                    int scoreCompare = one.Score.GetValueOrDefault(-1).CompareTo(two.Score.GetValueOrDefault(-1));
                    return(scoreCompare != 0 ? scoreCompare : showCompare == 0 ? roundCompare : showCompare);

                case "Medal":
                    int tierOne     = one.Qualified ? one.Tier == 0 ? 4 : one.Tier : 5;
                    int tierTwo     = two.Qualified ? two.Tier == 0 ? 4 : two.Tier : 5;
                    int tierCompare = tierOne.CompareTo(tierTwo);
                    return(tierCompare != 0 ? tierCompare : showCompare == 0 ? roundCompare : showCompare);

                default:
                    int kudosCompare = one.Kudos.CompareTo(two.Kudos);
                    return(kudosCompare != 0 ? kudosCompare : showCompare == 0 ? roundCompare : showCompare);
                }
            });

            gridDetails.DataSource = null;
            gridDetails.DataSource = RoundDetails;
            gridDetails.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = sortOrder;
        }
Example #6
0
            public static bool StartNextRound(string group, out RoundDetails round)
            {
                var rand = new Random();

                round = null;

                if (string.IsNullOrWhiteSpace(group))
                {
                    return(false);
                }

                GroupDetails details = null;

                try
                {
                    Guard.EnterReadLock();
                    if (!GroupMap.TryGetValue(group, out details))
                    {
                        return(false);
                    }
                }
                finally
                {
                    Guard.ExitReadLock();
                }
                try
                {
                    details.InstanceGuard.EnterWriteLock();
                    if (details.Connections.Count == 0)
                    {
                        return(false);
                    }
                    if (details.Words.Count == 0)
                    {
                        return(false);
                    }

                    // fill in details for this round
                    details.Current = new RoundDetails()
                    {
                        Timeout = details.TimeoutSeconds
                    };

                    // choose who will be drawing
                    var available = new HashSet <string>();
                    foreach (var kvp in details.Connections)
                    {
                        if (!details.HasDrawn.Contains(kvp.Key))
                        {
                            available.Add(kvp.Key);
                        }
                    }
                    // choose from either the set of people that have not drawn or from the whole set
                    if (available.Count >= 1)
                    {
                        // get a random drawer who has not drawn
                        var index = rand.Next() % available.Count;
                        details.Current.ConnectionId = available.ToArray()[index];
                    }
                    else
                    {
                        // clear hasdrawn
                        details.HasDrawn.Clear();
                        // get a random drawer
                        var index = rand.Next() % details.Connections.Keys.Count;
                        details.Current.ConnectionId = details.Connections.Keys.ToArray()[index];
                    }
                    // add user to hasdrawn
                    details.HasDrawn.Add(details.Current.ConnectionId);
                    // set the details
                    if (!details.Connections.TryGetValue(details.Current.ConnectionId, out UserDetails user))
                    {
                        throw new Exception("Failed to get something that clearly is present");
                    }
                    details.Current.Username = user.Username;

                    // choose word
                    if (details.NextWordIndex >= details.Words.Count)
                    {
                        details.NextWordIndex = 0;
                    }
                    details.Current.Word = details.Words[details.NextWordIndex++];

                    // obfuscate the word
                    details.Current.ObfuscatedWord = Obfuscate(details.Current.Word);

                    // clear the folks that have already answered
                    details.HasAnswered.Clear();

                    // set valid time zones
                    details.Current.Start = DateTime.UtcNow;
                    details.Current.End   = details.Current.Start.AddSeconds(details.Current.Timeout);

                    // update the last round marker (used for purging old games)
                    details.LastRoundUtc = DateTime.UtcNow;

                    // mark that we are in a round
                    details.InRound = true;

                    // return the round
                    round = details.Current;
                }
                finally
                {
                    details.InstanceGuard.ExitWriteLock();
                }

                return(true);
            }
Example #7
0
            public static bool TryGetInRound(string group, out bool inround, out bool atendofround, out RoundDetails round)
            {
                round        = null;
                inround      = false;
                atendofround = false;
                if (string.IsNullOrWhiteSpace(group))
                {
                    return(false);
                }

                GroupDetails details = null;

                try
                {
                    Guard.EnterReadLock();
                    if (!GroupMap.TryGetValue(group, out details))
                    {
                        return(false);
                    }
                }
                finally
                {
                    Guard.ExitReadLock();
                }

                // first exit early if not in a round
                if (!details.InRound)
                {
                    return(true);
                }

                try
                {
                    details.InstanceGuard.EnterReadLock();

                    // we are currently in a round
                    inround      = true;
                    round        = details.Current;
                    atendofround = false;

                    // second check if we are within the time limit of this round
                    if (DateTime.UtcNow < details.Current.Start || DateTime.UtcNow > details.Current.End)
                    {
                        // we are outside of the timeout - we are at the end of the round
                        atendofround = true;
                        return(true);
                    }

                    // third do a quick check if the number of players is not the same as answered
                    if (details.Connections.Count != details.HasAnswered.Count)
                    {
                        return(true);
                    }

                    // fourth check that all the connections are present in answered
                    foreach (var conn in details.Connections.Keys)
                    {
                        // this player has not answered yet
                        if (!details.HasAnswered.Contains(conn))
                        {
                            return(true);
                        }
                    }

                    // everyone has answered - we are now at the end of the round
                    atendofround = true;
                    return(true);
                }
                finally
                {
                    details.InstanceGuard.ExitReadLock();
                }
            }