public void PerformProjection_OneMatchingBookRecommendations_IncreasedRatings() { _rec1obj = _recommendation1.Object; _rec1obj.SpotLength = _rec1Length; var reccomendations = new List <Recommendation>() { _rec1obj }; var rating = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(_dayPart, reccomendations, _targetStrikeWeightStartDate, _targetStrikeWeightEndDate, _campaignSalesAreaList); foreach (var key in rating) { _recommendationsTotalForDayPart += (int)key.Value; } Assert.IsTrue(_recommendationsTotalForDayPart == _rec1Rating); }
public void PerformProjection_RecommendationOutsideStrikeWeightDate_ZeroRatings() { _ = _recommendation1.Setup(r => r.StartDateTime).Returns(_targetStrikeWeightEndDate.AddDays(1)); //TEST - setting to be outside of target strike weight _rec1obj = _recommendation1.Object; //get the object here in order to set the NodaTime Duration - otherwise get 'invalid setup of non-vitual..' _rec1obj.SpotLength = _rec1Length; var reccomendations = new List <Recommendation>() { _rec1obj }; var rating = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(_dayPart, reccomendations, _targetStrikeWeightStartDate, _targetStrikeWeightEndDate, _campaignSalesAreaList); foreach (var key in rating) { _recommendationsTotalForDayPart += (int)key.Value; } //_recommendation1.Object StartDateTime has been setup to be later than target end date, so the returned ratings total should be 0 Assert.IsTrue(_recommendationsTotalForDayPart == 0); }
public void PerformProjection_MatchingRecommendationsNeighbouringTimeSlices_CorrectRating() { _ = _recommendation2.Setup(r => r.StartDateTime).Returns(new DateTime(2018, 1, 1, 2, 0, 0)); _rec1obj = _recommendation1.Object; _rec1obj.SpotLength = _rec1Length; _rec2obj = _recommendation2.Object; _rec2obj.SpotLength = _rec2Length; var reccomendations = new List <Recommendation>() { _rec1obj, _rec2obj }; _dayPart.Timeslices[1].FromTime = _timeslice1To; //2 daypart timeslices set to (00:00 to 01:00 && 01:00 to 08:00 hours) var rating = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(_dayPart, reccomendations, _targetStrikeWeightStartDate, _targetStrikeWeightEndDate, _campaignSalesAreaList); foreach (var key in rating) { _recommendationsTotalForDayPart += (int)key.Value; } //both recommendations are inside the timeslices of the day part, so the returned total should be equal to the sum of both Assert.IsTrue(_recommendationsTotalForDayPart == _rec1Rating - _rec2Rating); }
public void PerformProjection_RecommendationInsideStrikeWeightButOutsideTimeSlice_CorrectRating() { //setting _recommendation2.StartDateTime (02 hours) to be outside of the 2 daypart timeslices (00:00 to 01:00 && 06:00 to 08:00 hours) _ = _recommendation2.Setup(r => r.StartDateTime).Returns(new DateTime(2018, 1, 1, 2, 0, 0)); _rec1obj = _recommendation1.Object; _rec1obj.SpotLength = _rec1Length; _rec2obj = _recommendation2.Object; _rec2obj.SpotLength = _rec2Length; var reccomendations = new List <Recommendation>() { _rec1obj, _rec2obj }; var rating = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(_dayPart, reccomendations, _targetStrikeWeightStartDate, _targetStrikeWeightEndDate, _campaignSalesAreaList); foreach (var key in rating) { _recommendationsTotalForDayPart += (int)key.Value; } //_recommendation2.Object has been setup to be outside of the time slices included in the day part, so the returned total should equal only to the ratings in _recommendation1.Object Assert.IsTrue(_recommendationsTotalForDayPart == _rec1Rating); }
public void PerformProjection_RecommendationInsideStrikeWeightButNonMatchingTimesliceDOW_CorrectRating() { //4th Jan 2018 = Thursday in rec2, DOW in daypart.timeslices are Mon, Tues, Wed _ = _recommendation2.Setup(r => r.StartDateTime).Returns(new DateTime(2018, 1, 4, 0, 0, 0)); _rec1obj = _recommendation1.Object; _rec1obj.SpotLength = _rec1Length; _rec2obj = _recommendation2.Object; _rec2obj.SpotLength = _rec2Length; var reccomendations = new List <Recommendation>() { _rec1obj, _rec2obj }; var rating = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(_dayPart, reccomendations, _targetStrikeWeightStartDate, _targetStrikeWeightEndDate, _campaignSalesAreaList); foreach (var key in rating) { _recommendationsTotalForDayPart += (int)key.Value; } //_recommendation2.Object has been setup to be a thursday, so the returned total should equal only to the ratings in _recommendation1.Object Assert.IsTrue(_recommendationsTotalForDayPart == _rec1Rating); }
public IHttpActionResult GetGroupWithScenarioRecommendations(Guid scenarioId, String group) { var campaignRefList = _mapper.Map <List <CampaignModel> >(_campaignRepository.GetByGroup(group)); //clone to get a deep level copy as the campaignRefList will only contain a shallow copy; //the Clone() methods for all the objects inside the campaign object have all been amended so they will be a copy and not a reference var campaignList = new List <CampaignModel>(); foreach (var campRefDoc in campaignRefList) { var campDoc = campRefDoc.Clone(); campaignList.Add((CampaignModel)campDoc); } var scenarioRecommendations = _recommendationRepository.GetByScenarioId(scenarioId); scenarioRecommendations = scenarioRecommendations.Where(r => r.ExternalCampaignNumber.Contains(group)); decimal recommendationsTotalRatingsForDayPart = 0; Dictionary <NodaTime.Duration, decimal> lengthRatings = new Dictionary <NodaTime.Duration, decimal>(); List <string> salesAreasList = new List <string>(); campaignList.ForEach(campaignDoc => { campaignDoc.SalesAreaCampaignTarget.ForEach(salesAreaCampaignTarget => { salesAreaCampaignTarget.CampaignTargets.ForEach(campaignTarget => { salesAreasList.Clear(); foreach (var item in salesAreaCampaignTarget.SalesAreaGroup.SalesAreas) { salesAreasList.Add(item); } campaignTarget.StrikeWeights.ForEach(strikeWeight => { strikeWeight.DayParts.ForEach(dayPart => { recommendationsTotalRatingsForDayPart = 0; //reset at beginning of each day part //get dictionary list of time lengths and ratings for this dayPart.. lengthRatings = CampaignProjectionProcessing.ProjectRatingsForCampaignDayPart(dayPart, scenarioRecommendations, strikeWeight.StartDate, strikeWeight.EndDate, salesAreasList); //if there are some ratingsPredictions for this day part section then add them to the appropriate parts of the camapaign document to be returned to api call if (lengthRatings.Count > 0) { //update different totals of this campaign document using the array of length counts passed back from each day part.... //individual lengths in salesAreaCampaignTarget totals and campaigndoc actual totals.. foreach (var multi in salesAreaCampaignTarget.Multiparts) { foreach (var len in multi.Lengths) { foreach (var item in lengthRatings) { if (len == item.Key) { multi.CurrentPercentageSplit += item.Value; campaignDoc.ActualRatings += item.Value; } } } } //individual lengths in the strikeweights totals.. int lenCnt = 0; foreach (var len in strikeWeight.Lengths) { foreach (var item in lengthRatings) { if (len.length == item.Key) { strikeWeight.Lengths[lenCnt].CurrentPercentageSplit = strikeWeight.Lengths[lenCnt].CurrentPercentageSplit + (int)item.Value; //keep a running total for where there are diffrent lengths in doc; not the case for Nine recommendationsTotalRatingsForDayPart += item.Value; } } lenCnt++; } //strikeweight totals, from running total above.. strikeWeight.CurrentPercentageSplit += recommendationsTotalRatingsForDayPart; //daypart totals, from running total above.. dayPart.CurrentPercentageSplit += recommendationsTotalRatingsForDayPart; } }); }); }); }); }); return(Ok(campaignList)); }