/// <summary> /// Creates a new live test with the given type, and defines a control. /// </summary> /// <param name="testType"></param> /// <returns></returns> public static int CreateNewLiveMVT(TestTypesEnum testType) { int id = _History.Count; MultiVariateTest MVT = new MultiVariateTest(id, testType); _History.Add(MVT); return(id); }
/// <summary> /// /// </summary> /// <param name="testType"></param> /// <returns>With a suitable live MVT id for the given type of test</returns> public static int GetSuitableLiveMVTforNewGUIDAssignment(TestTypesEnum testType) { int i; for (i = 0; i < _History.Count; i++) { if (_History[i].IsActive && _History[i].TestType == testType) { return(i); } } return(-1); }
//public async Task<bool> InsertParagraphs(IEnumerable<ParagraphOutput> paragraphsInput) //{ // try // { // var paragraphs = new List<Paragraphs>(); // UnitOfWork.BeginTransaction(); // foreach (var para in paragraphsInput) // { // var paraTemp = new Paragraphs // { // Id = 0, // ContentP1 = para.ContentP1, // ContentP2 = para.ContentP2, // }; // await _paraRepo.InsertAsync(paraTemp); // var qtionsTemp = new List<Qtions>(); // para.Questions = para.Questions.OrderBy(_ => _.Position); // foreach (var qtion in para.Questions) // { // var qtionTemp = new Qtions // { // Id = 0, // ContentQ = qtion.ContentQ, // Answer1 = qtion.Answer1, // Answer2 = qtion.Answer2, // Answer3 = qtion.Answer3, // Answer4 = qtion.Answer4, // Part = qtion.Part, // TopicId = qtion.TopicId // }; // qtionsTemp.Add(qtionTemp); // } // _questionRepo.InsertRange(qtionsTemp); // await UnitOfWork.SaveChangesAsync(); // var paraQtions = new List<ParagraphQuestions>(); // var index = 1; // foreach (var qtion in qtionsTemp) // { // var paraQtion = new ParagraphQuestions // { // IdParagraph = paraTemp.Id, // IdQuestion = qtion.Id, // Position = index++ // }; // paraQtions.Add(paraQtion); // } // var exist = _paraQuestionRepo.GetByParaId(paraTemp.Id); // if (exist == null) // { // _paraQuestionRepo.InsertRange(paraQtions); // await UnitOfWork.SaveChangesAsync(); // return true; // } // } // } // catch (Exception) // { // } // UnitOfWork.RollbackTransaction(); // return false; //} public async Task <ResponseOutput> GetTest(TestTypesEnum testTypeId, int param) { var type = _testTypesRepo.Entities.FirstOrDefault(_ => _.Id == (int)testTypeId); var test = new Tests(); if (type == null) { return(new ResponseOutput(false, "TestType is invalid!")); } var questions = new List <QuestionViewModel>(); if (testTypeId == TestTypesEnum.Part) { test = await _repository.Entities .Where(_ => _.TypeId == (int)testTypeId && _.Part == param) .OrderBy(_ => Guid.NewGuid()) .FirstOrDefaultAsync(); } if (testTypeId == TestTypesEnum.Topic) { test = await CreateTest(param); } if (test != null) { var testQuestions = _testQuestionsRepo.Entities.Where(_ => _.TestId == test.Id).ToList(); foreach (var item in testQuestions) { var question = await GetQuestionByIdAsync(item.ItemId); question.Index = item.Position; questions.Add(question); } var testOutput = new TestViewModel { Id = test.Id, Title = test.Title, TypeId = test.TypeId, Questions = questions, }; return(new ResponseOutput(true, "", testOutput)); } return(new ResponseOutput(false)); }
public MultiVariateTest(int mvtid, TestTypesEnum tType) { id = mvtid; testType = tType; isActive = true; LaunchDateTime = DateTime.UtcNow; ResultType = TestResultType.Live; AssignedGuidsTotal = 0; Variation control = control = new Variation(0, true); if (tType == TestTypesEnum.ADDTOCARTBUTTON) { control.SetVariationType(AddToCartButton.GetCurrentWinnderControl()); } variants.Add(control); }
public static void PrintDashboard(CommandLineInterface _CLI) { int TotalMVTs = MVTHistory.GetMVTCount(false); int LiveMVTs = MVTHistory.GetMVTCount(true); int CompletedMVTs = TotalMVTs - LiveMVTs; int PositiveMVTs = MVTHistory.GetMVTCount(TestResultType.Positive); int NegativeMVTs = MVTHistory.GetMVTCount(TestResultType.Negative); int InconclusiveMVTs = MVTHistory.GetMVTCount(TestResultType.Inconclusive); MultiVariateTest[] LiveTests = MVTHistory.GetLiveTests(); string result = "************************** OVERALL TESTING SUMMARY *************************\n\n"; result += "Total MVTs launched: " + TotalMVTs.ToString() + " (" + CompletedMVTs.ToString() + " completed, " + LiveMVTs.ToString() + " currently live)\n"; result += "Test results:\t" + PositiveMVTs.ToString() + " Positive\t" + NegativeMVTs.ToString() + " Negative\t" + InconclusiveMVTs.ToString() + " Inconclusive (abandoned) \n\n"; if (LiveTests != null && LiveTests.Length > 0) { result += "******************************** LIVE TESTS ********************************\n"; for (int i = 0; i < LiveTests.Length; i++) { int testId = LiveTests[i].Id; TestTypesEnum type = LiveTests[i].TestType; string typeStr = ""; if (type == TestTypesEnum.ADDTOCARTBUTTON) { typeStr = "Add to Cart Btn"; } DateTime?launched = LiveTests[i].GetLaunchDateTime; int variantsNumber = LiveTests[i].GetNumberOfVariants(); MVTResult TResult = LiveTests[i].GetResult; result += "[MVT ID: " + testId.ToString() + "] [Type: " + typeStr + "] [Launch date: " + launched.ToString() + "]\n"; result += "[Variants: " + variantsNumber.ToString() + " (including control)]\n"; //Displaying ctr and test variant change details //Only "Add to cart" A/B test display supported currently. if (variantsNumber == 2 && type == TestTypesEnum.ADDTOCARTBUTTON) { AddToCartButtonVariation ctrVar = (AddToCartButtonVariation)LiveTests[i].GetVariant(0).GetVariationType(); AddToCartButtonVariation tstVar = (AddToCartButtonVariation)LiveTests[i].GetVariant(1).GetVariationType(); result += "[Control: "; if (ctrVar.colorPalette == null && ctrVar.addToCartTextCopies == null) { result += "No changes"; } else { if (ctrVar.colorPalette != null) { result += "Colour: " + ctrVar.colorPalette + " "; } if (ctrVar.addToCartTextCopies != null) { result += "Copy change: " + ctrVar.addToCartTextCopies; } } result += "]\n"; result += "[Test: "; if (tstVar.colorPalette == null && tstVar.addToCartTextCopies == null) { result += "No changes"; } else { if (tstVar.colorPalette != null) { result += "Colour: " + tstVar.colorPalette + " "; } if (tstVar.addToCartTextCopies != null) { result += "Copy change: " + tstVar.addToCartTextCopies; } } result += "]\n\n"; } //Displaying ctr and test variant visitors, cvr and stdev. Works for A/B only. if (TResult != null && variantsNumber == 2) { if (TResult.SampleSize.Length > 1 && TResult.Means.Length > 1 && TResult.ConvertedSize.Length > 1 && TResult.STDevs.Length > 1) { result += "\t[Visitors]\t[Converted]\t[%]\t[Std Dev]\n"; result += "CTRL\t" + TResult.SampleSize[0].ToString() + "\t\t" + TResult.ConvertedSize[0].ToString() + "\t\t" + TruncString((TResult.Means[0] * 100).ToString(), 4) + "%\t" + TruncString(TResult.STDevs[0].ToString(), 5) + "\n"; result += "TEST\t" + TResult.SampleSize[1].ToString() + "\t\t" + TResult.ConvertedSize[1].ToString() + "\t\t" + TruncString((TResult.Means[1] * 100).ToString(), 4) + "%\t" + TruncString(TResult.STDevs[1].ToString(), 5) + "\n\n"; result += "[T-score: " + TruncString(TResult.TScores[0].ToString(), 6) + "] " + "[Degree of freedom: " + TResult.DFree[0].ToString() + " (next known is " + TResult.NextDFree[0].ToString() + ")]\n"; result += "[Required P for next Degree of Freedom: " + TruncString(TResult.ReqPVal[0].ToString(), 6) + "]\n"; } } result += "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; } } else { //No live tests found, check if all completed. result += "\n No live tests running currently.\n"; if (AddToCartButton.IsAllVariationTested()) { result += "All the 'Add To Cart Button' type variants have been tested. The best performing variant is live on 100%."; } } _CLI.Out(result, false, false); }
public static Variation[] MatchLiveMVTWithTestType(string[] mvtlist, TestTypesEnum testType) { if (mvtlist == null) { return(null); } List <Variation> result = new List <Variation>(); foreach (string s in mvtlist) { string[] tmp = s.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); int iMvt = int.Parse(tmp[0]); int iVar = int.Parse(tmp[1]); int index = IndexById(iMvt); //check if this is a valid mvt id if (index == -1) { if (Configuration.IsDebugModeOn) { _CLI.Out("Cannot find the MVT id sent by the client.", true, false); } continue; } //Check if the assigned mvt is relevant if (_History[index].IsActive == false) { if (Configuration.IsDebugModeOn) { _CLI.Out("Error. The MVT sent by the client is not active, but has not been removed during the cleaning.", true, false); } continue; } //Check if the type is appropriate if (_History[index].TestType == testType) { //Get the containing variant Variation v = _History[index].GetVariant(iVar); if (v == null) { if (Configuration.IsDebugModeOn) { _CLI.Out("Error. Found mvt, but could not get variation index.", true, false); } continue; } else { result.Add(v); } } } if (result.Count == 0) { return(null); } else { return(result.ToArray()); } }