Example #1
0
        public ActionResult AddToTotals(string id)
        {
            ItemType currentItemType;
            if(!Enum.TryParse<ItemType>(id,true,out currentItemType))
                throw new ArgumentException("argument id is not an ItemType");

            WeeklyTop topForTotalModel = new WeeklyTop()
            {
                WeekNo = Convert.ToInt32(Request.Form["WeekNo"])
            };
            int noOfItems = (Request.Form.AllKeys.Length - 1) / 2;
            var topItems = new List<TopItem>();
            for (int i = 0; i < noOfItems; i++)
            {
                topItems.Add(
                    new TopItem { ItemName = Request.Form[string.Format("TopItems[{0}][ItemName]", i)], 
                    Rank = Convert.ToInt32(Request.Form[string.Format("TopItems[{0}][Rank]", i)]),ItemType= currentItemType});
            }
            topForTotalModel.TopItems = topItems;
            topForTotalModel.ItemType = currentItemType;

            TotalsAfterWeek totalsAfterWeek = new TotalsAfterWeek();
            ITopRecordProvider topTotalsProvider = ClientFactory.GetClient<ITopRecordProvider>();
            IAlgorythmPoolProvider algorythmPoolProvider = ClientFactory.GetClient<IAlgorythmPoolProvider>();

            topTotalsProvider.SaveTotalForItems(topForTotalModel,algorythmPoolProvider.GetCurrentAlgorythm(currentItemType).ScoreRule);
            totalsAfterWeek.TopItems = topTotalsProvider.GetTotalItems(currentItemType);
            totalsAfterWeek.WeekNo = topForTotalModel.WeekNo;
            return Json(totalsAfterWeek/*,JsonRequestBehavior.AllowGet*/);
        }
Example #2
0
        public void SaveTotalForItems(WeeklyTop topTotalForModel, Func<int, int> ScoreRule)
        {
            List<TopItem> existingItems = GetTotalItems(topTotalForModel.ItemType);

            foreach (TopItem topItem in topTotalForModel.TopItems)
            {
                var itemScore = ScoreRule(topItem.Rank);
                if (itemScore > 0)
                {
                    TopItem existingItem = existingItems.FirstOrDefault(i => i.ItemName == topItem.ItemName);
                    if (existingItem == null)
                    {
                        existingItem = new TopItem { ItemName = topItem.ItemName, EntryWeek = topTotalForModel.WeekNo, Score = itemScore, ItemType = topTotalForModel.ItemType, NumberOfPlays = topItem.NumberOfPlays };
                        existingItems.Add(existingItem);
                    }
                    else
                    {
                        existingItem.Score += itemScore;
                        existingItem.NumberOfPlays += topItem.NumberOfPlays;
                    }
                    RecalculateRanks(existingItems);
                }
                else
                    break;
            }
            _simulationCRUD.SaveTotalItems(topTotalForModel.ItemType, existingItems);

            List<WeekSummary> topRecordedItems = GetTopProcessed().ToList();
            topRecordedItems.AddRange(new List<WeekSummary> { new WeekSummary { ItemType = topTotalForModel.ItemType, WeekNo = topTotalForModel.WeekNo } });
            _simulationCRUD.SaveRecordedWeeks(topRecordedItems);

        }
Example #3
0
        public ActionResult Top(WeekSummary topWeekRequest)
        {

            IAlgorythmPoolProvider algoryhtmProvider = ClientFactory.GetClient<IAlgorythmPoolProvider>();
            ITopProvider topProvider = ClientFactory.GetClient<ITopProvider>();
            var availableWeeks = topProvider.GetAvailableWeeks(Utility.LastWeekNo(DateTime.Now));
            if (availableWeeks == null)
                return null;
            WeeklyTop weeklyTopModel = topProvider.GetTopByWeek(availableWeeks.FirstOrDefault(a=>a.WeekNo==topWeekRequest.WeekNo),
                algoryhtmProvider.GetCurrentAlgorythm(topWeekRequest.ItemType).NoOfItemsConsidered, topWeekRequest.ItemType);
            if (weeklyTopModel == null)
            {
                weeklyTopModel = new WeeklyTop();
                weeklyTopModel.ItemType = topWeekRequest.ItemType;
                weeklyTopModel.WeekNo = topWeekRequest.WeekNo;
            }
            
            return Json(weeklyTopModel, JsonRequestBehavior.AllowGet);
        }