示例#1
0
        public static IEnumerable <ABTestResult> GetResultsByGoal(string goal, string asofdate)
        {
            Dictionary <string, long> impressions = new Dictionary <string, long>();
            Dictionary <string, long> conversions = new Dictionary <string, long>();
            Dictionary <string, long> totalweight = new Dictionary <string, long>();
            Dictionary <string, long> totalviews  = new Dictionary <string, long>();

            ABTestImpressionClient             abtic           = new ABTestImpressionClient();
            CloudTableQuery <ABTestImpression> impressionQuery = abtic.GetAllByGoal(goal, asofdate);

            foreach (var i in impressionQuery.Execute())
            {
                if (impressions.ContainsKey(i.TestID))
                {
                    impressions[i.TestID]++;
                }
                else
                {
                    impressions[i.TestID] = 1;
                }
            }

            ABTestConversionClient             abtcc           = new ABTestConversionClient();
            CloudTableQuery <ABTestConversion> conversionQuery = abtcc.GetAllByGoal(goal, asofdate);

            foreach (var c in conversionQuery.Execute())
            {
                if (conversions.ContainsKey(c.TestID))
                {
                    conversions[c.TestID]++;
                    totalweight[c.TestID] += c.Weight;
                    totalviews[c.TestID]  += c.Views;
                }
                else
                {
                    conversions[c.TestID] = 1;
                    totalweight[c.TestID] = c.Weight;
                    totalviews[c.TestID]  = c.Views;
                }
            }
            List <ABTestResult> results = new List <ABTestResult>();

            foreach (var k in impressions.Keys)
            {
                results.Add(new ABTestResult
                {
                    TestID = k
                    ,
                    UniqueVisitors = impressions.ContainsKey(k) ? impressions[k] : 0
                    ,
                    TotalViews = totalviews.ContainsKey(k) ? totalviews[k] : 0
                    ,
                    ConversionCount = conversions.ContainsKey(k) ? conversions[k] : 0
                    ,
                    ConversionWeightSum = totalweight.ContainsKey(k) ? totalweight[k] : 0
                });
            }

            return(results);
        }
        //public string CreateImpression()
        //{

        //    return CreateImpression(null);
        //}
        //public string CreateImpression(string coupledView)
        //{
        //    return CreateImpression(null, coupledView);
        //}


        public void CreateGoalEntry(string goalName, string viewName, string testSuffix)
        {
            if (this.moduleName == null || this.moduleName == "")
            {
                throw new Exception("Module name not specified");
            }

            bool alreadyconverted = request.Cookies[APP_NAME + "." + goalName + ".converted"] != null;

            if (Force || !alreadyconverted)
            {
                string testName;
                if (testSuffix != null && testSuffix.Trim() != "")
                {
                    testName = moduleName + "." + viewName + "." + testSuffix;
                }
                else
                {
                    testName = moduleName + "." + viewName;
                }

                IncrementViewCountCookie(testName);

                bool skip = false;
                if (request != null && request.Cookies[APP_NAME + ".ab." + goalName] != null && request.Cookies[APP_NAME + ".ab." + goalName].Value == testName)
                {
                    skip = true;
                }

                if (Force || !skip)
                {
                    if (response != null)
                    {
                        response.Cookies[APP_NAME + ".ab." + goalName].Value = testName;
                    }

                    ABTestImpressionClient abtic = new ABTestImpressionClient();
                    abtic.AddImpression(moduleName, goalName, testName);
                }
            }
        }