예제 #1
0
        public ExperimentSegment AddSegment(ExperimentSegment segment)
        {
            ExperimentSegment rtnSegment = null;

            using (DbCommand cmd = _db.GetSqlStringCommand(ExperimentQueries.AddExperimentSegment))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, segment.Name);
                _db.AddInParameter(cmd, "@SystemName", DbType.String, segment.SystemName);
                _db.AddInParameter(cmd, "@TargetPercentage", DbType.Double, segment.TargetPercentage);
                _db.AddInParameter(cmd, "@IsDefault", DbType.Int32, segment.IsDefault);
                _db.AddInParameter(cmd, "@ExperimentId", DbType.Int32, segment.ExperimentId);
                _db.AddInParameter(cmd, "@CreatedBy", DbType.String, segment.CreatedBy);

                using (IDataReader reader = _db.ExecuteReader(cmd))
                {
                    while (reader.Read())
                    {
                        rtnSegment = ReaderToExperimentSegment(reader);
                    }
                }
            }

            foreach (string variable in segment.Variables.Keys)
            {
                using (DbCommand cmd = _db.GetSqlStringCommand(ExperimentQueries.AddExperimentSegmentVariableValue))
                {
                    _db.AddInParameter(cmd, "@ExperimentId", DbType.Int32, segment.ExperimentId);
                    _db.AddInParameter(cmd, "@ExperimentSegmentID", DbType.Int32, rtnSegment.Id);
                    _db.AddInParameter(cmd, "@Name", DbType.String, variable);
                    _db.AddInParameter(cmd, "@Value", DbType.String, segment.Variables[variable]);

                    _db.AddOutParameter(cmd, "@ExperimentVariableID", DbType.Int32, 8);

                    rtnSegment.Variables.Add(variable, segment.Variables[variable]);

                    _db.ExecuteNonQuery(cmd);
                }
            }

            return rtnSegment;
        }
예제 #2
0
        protected ExperimentSegment ReaderToExperimentSegment(IDataReader reader)
        {
            var segment = new ExperimentSegment();

            if (reader["Id"] != DBNull.Value)
            {
                segment.Id = Convert.ToInt32(reader["Id"]);
            }

            if (reader["UID"] != DBNull.Value)
            {
                segment.UID = reader.GetGuid(reader.GetOrdinal("UID"));
            }

            if (reader["Name"] != DBNull.Value)
            {
                segment.Name = reader["Name"].ToString();
            }

            if (reader["SystemName"] != DBNull.Value)
            {
                segment.SystemName = reader["SystemName"].ToString();
            }

            if (reader["TargetPercentage"] != DBNull.Value)
            {
                segment.TargetPercentage = Convert.ToDouble(reader["TargetPercentage"]);
            }

            if (reader["IsDefault"] != DBNull.Value)
            {
                segment.IsDefault = Convert.ToBoolean(reader["IsDefault"]);
            }

            if (reader["ExperimentId"] != DBNull.Value)
            {
                segment.ExperimentId = Convert.ToInt32(reader["ExperimentId"]);
            }

            if (reader["CreatedBy"] != DBNull.Value)
            {
                segment.CreatedBy = reader["CreatedBy"].ToString();
            }

            if (reader["UpdatedBy"] != DBNull.Value)
            {
                segment.UpdatedBy = reader["UpdatedBy"].ToString();
            }

            if (reader["Created"] != DBNull.Value)
            {
                segment.Created = Convert.ToDateTime(reader["Created"]);
            }

            if (reader["Updated"] != DBNull.Value)
            {
                segment.Updated = Convert.ToDateTime(reader["Updated"]);
            }

            segment.Variables = new Dictionary<string, string>();
            return segment;
        }
예제 #3
0
        public void TestGetDefault()
        {
            Experiment exp = new Experiment()
            {
                Id = 100,
                Name = "TestExp",
                SystemName = "TestExp",
                TargetCohort = new AuthenticatedUsersCohort()
                {
                    Id = 200,
                    Name = "AllUsers",
                    SystemName = "AllUsers"
                },
                Segments = new List<ExperimentSegment>()
            };

            var segment1 = new ExperimentSegment()
            {
                Id = 300,
                ExperimentId = 100,
                TargetPercentage = 50,
                Name = "Option1",
                SystemName = "Option1"
            };

            exp.Segments.Add(segment1);

            var segment2 = new ExperimentSegment()
            {
                Id = 301,
                ExperimentId = 100,
                TargetPercentage = 50,
                Name = "Option2",
                SystemName = "Option2"
            };

            exp.Segments.Add(segment2);

            var defSeg = new ExperimentSegment()
            {
                Id = 302,
                ExperimentId = 100,
                TargetPercentage = 0,
                Name = "Default",
                SystemName = "Default",
                IsDefault=true
            };

            exp.Segments.Add(defSeg);

            var visitor = new Visitor()
            {
                ExperimentSegmentsLoaded = true,
                CohortsLoaded = true,
                AttributesLoaded = true,
                ConverstionsLoaded = true,
                DetailsLoaded = true,
                LandingUrlsLoaded = true,
                ReferrersLoaded = true,
                ExperimentSegments = new List<ExperimentSegment>(),
                Cohorts = new List<Cohort>(),
                Attributes = new Dictionary<string, string>(),
                Conversions = new List<Goal>(),
                FirstVisit = DateTime.Now,
                IsAuthenticated=false,
            };

            var hyp = ExperimentManager.Current.GetHypothesis(exp, visitor);

            Assert.IsNotNull(hyp);
            Assert.IsTrue(hyp == defSeg);
            Assert.AreEqual<int>(0, visitor.ExperimentSegments.Count);
            Assert.AreEqual<int>(0, visitor.Request.ExperimentSegments.Count);
        }
예제 #4
0
        public ExperimentSegment UpdateSegment(ExperimentSegment segment)
        {
            using (DbCommand cmd = _db.GetSqlStringCommand(ExperimentQueries.UpdateExperimentSegment))
            {
                _db.AddInParameter(cmd, "@Name", DbType.String, segment.Name);
                _db.AddInParameter(cmd, "@UpdatedBy", DbType.String, segment.UpdatedBy);
                _db.AddInParameter(cmd, "@TargetPercentage", DbType.Double, segment.TargetPercentage);
                _db.AddInParameter(cmd, "@IsDefault", DbType.Int32, segment.IsDefault);
                _db.AddInParameter(cmd, "@ExperimentSegmentId", DbType.Int32, segment.Id);

                _db.ExecuteNonQuery(cmd);
            }

            using (DbCommand cmd = _db.GetSqlStringCommand(ExperimentQueries.DeleteExperimentSegmentVariableValues))
            {
                _db.AddInParameter(cmd, "@ExperimentSegmentId", DbType.Int32, segment.Id);
                _db.ExecuteNonQuery(cmd);
            }

            foreach (string variable in segment.Variables.Keys)
            {
                using (DbCommand cmd = _db.GetSqlStringCommand(ExperimentQueries.AddExperimentSegmentVariableValue))
                {
                    _db.AddInParameter(cmd, "@ExperimentId", DbType.Int32, segment.ExperimentId);
                    _db.AddInParameter(cmd, "@ExperimentSegmentID", DbType.Int32, segment.Id);
                    _db.AddInParameter(cmd, "@Name", DbType.String, variable);
                    _db.AddInParameter(cmd, "@Value", DbType.String, segment.Variables[variable]);

                    _db.AddOutParameter(cmd, "@ExperimentVariableID", DbType.Int32, 8);

                    _db.ExecuteNonQuery(cmd);
                }
            }

            return segment;
        }