Beispiel #1
0
        public JsonResult GetPairingInfo(string pairName)
        {
            var dataRows          = Repository.GetRepository().LoadData("Select * from t_pairingmatrix where pairone='" + pairName + "' OR pairtwo='" + pairName + "'").Rows.Cast <DataRow>();
            var pairCollatedInfos = new List <PairCollatedInfo>();
            var userArray         = GetAllUserDetails().ToList();
            var primaryPair       = userArray.Find(model => model.UserName == pairName);

            dataRows.ToList().ForEach(row =>
            {
                var pairone    = row["PAIRONE"].ToString();
                var pairtwo    = row["PAIRTWO"].ToString();
                var secondPair = pairone == pairName ? userArray.Find(model => model.UserName == pairtwo) : userArray.Find(model => model.UserName == pairone);

                var alreadyAvailableTuple = pairCollatedInfos.Find(info => info.SecondPair == secondPair);
                if (alreadyAvailableTuple != null)
                {
                    alreadyAvailableTuple.WorkedFor += Convert.ToDouble(row["PAIRTIME"]);
                }
                else
                {
                    var pairCollatedInfo = new PairCollatedInfo()
                    {
                        FirstPair  = primaryPair,
                        SecondPair = secondPair,
                        WorkedFor  = Convert.ToDouble(row["PAIRTIME"])
                    };
                    pairCollatedInfos.Add(pairCollatedInfo);
                }
            });

            return(new JsonResult()
            {
                Data = pairCollatedInfos, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Beispiel #2
0
        public ActionResult ViewStatistics(bool?isAllData)
        {
            var shouldShowAllData = isAllData.HasValue && isAllData.Value;
            var dataRows          = Repository.GetRepository().LoadData("Select * from t_pairingmatrix").Rows.Cast <DataRow>();

            ViewBag.PairingDetails = dataRows;
            var dataForPairing = dataRows;

            if (!shouldShowAllData)
            {
                var dayBeforeTwoWeeks = System.DateTime.Now.Subtract(new TimeSpan(14, 0, 0, 0));

                dataForPairing = dataRows.Where(row => Convert.ToDateTime(row["PAIRDATE"]) >= dayBeforeTwoWeeks);
            }

            var userArray = GetAllUserDetails().ToArray();

            var collatedPairDetails = new List <PairCollatedInfo>();
            var notPairedPeople     = new List <PairCollatedInfo>();
            var notLonePairedPeople = new List <PairCollatedInfo>();
            var lonePairedPeople    = new List <PairCollatedInfo>();

            for (var i = 0; i < userArray.Length; i++)
            {
                for (var j = i; j < userArray.Length; j++)
                {
                    var pairOne = userArray[i];
                    var pairTwo = userArray[j];
                    var allRowsOfThisCombination = dataForPairing.Where(
                        row => isThesePairsInAnyCombination(pairTwo, pairOne, row));
                    var workedForDays    = allRowsOfThisCombination.Sum(row => Convert.ToDouble(row["PAIRTIME"]));
                    var pairCollatedInfo = new PairCollatedInfo()
                    {
                        FirstPair = pairOne, SecondPair = pairTwo, WorkedFor = workedForDays
                    };
                    if (workedForDays.Equals(0))
                    {
                        if (pairOne != pairTwo)
                        {
                            notPairedPeople.Add(pairCollatedInfo);
                        }
                        else
                        {
                            notLonePairedPeople.Add(pairCollatedInfo);
                        }
                    }
                    else
                    {
                        if (pairOne != pairTwo)
                        {
                            collatedPairDetails.Add(pairCollatedInfo);
                        }
                        else
                        {
                            lonePairedPeople.Add(pairCollatedInfo);
                        }
                    }
                }
            }
            collatedPairDetails           = collatedPairDetails.OrderBy(info => info.WorkedFor).ToList();
            ViewBag.SuggestionPairDetails = collatedPairDetails;
            ViewBag.CollatedPairDetails   = collatedPairDetails.OrderBy(info => info.WorkedFor).Reverse().ToList();
            ViewBag.NotPairedInfo         = notPairedPeople;
            ViewBag.NotLonePairedInfo     = notLonePairedPeople;
            ViewBag.LonePairedInfo        = lonePairedPeople;
            ViewBag.ShowingAllData        = shouldShowAllData;
            var list = userArray.Select(model => model.UserName).ToList();

            list.Insert(0, "Please choose one user");
            ViewBag.UserNames = list;

            return(View());
        }