public void ParseContacts_ContactBehaviorShouldBeStrictWalk()
        {
            var parser  = new XGenParser("http://google.com");
            var segment = parser.ParseContacts(this.GetContactsDefinition(), JobType.Contacts).Single();

            segment.Behavior().Should().BeOfType <StrictWalk>();
        }
        public void DevicesFactory_WithDeviceDistibution_ShouldSetRequiredUserAgents(XGenParser parser, DeviceRepository repo)
        {
            var           factory       = XGenParser.Factories["Devices"];
            var           devices       = repo.GetAll();
            List <string> userAgentList = new List <string>();

            var definition = JObject.Parse(@"{
        'sony xperia z3':0.1,
        'sony xperia z2':0.1,
        'nokia lumia 930':0.3,
        'macintosh pc':0.3,
        'microsoft xbox one':0.2}");


            for (int i = 0; i < 1000; i++)
            {
                var segment = new VisitorSegment("");
                factory.UpdateSegment(segment, definition, parser);
                var target = new Request();
                segment.VisitorVariables.First(x => x.ProvidedVariables.Contains("UserAgent")).SetValues(target);
                userAgentList.Add(target.Variables["UserAgent"].ToString());
            }

            userAgentList.Count.Should().Be(1000);

            foreach (var device in definition)
            {
                var dev      = devices.First(x => x.Id == device.Key);
                var expected = device.Value.Value <double>();
                (userAgentList.Count(x => x == dev.UserAgent) / 1000d).Should().BeApproximately(expected, 0.04);
            }
        }
Ejemplo n.º 3
0
 public override void SetDefaults(VisitorSegment segment, XGenParser parser)
 {
     if (_setDefaults != null)
     {
         _setDefaults(segment, parser);
     }
 }
        public void ParseContacts_ShouldParseEmail()
        {
            var parser  = new XGenParser("http://google.com");
            var segment = parser.ParseContacts(this.GetContactsDefinition(), JobType.Contacts).Single();

            segment.Behavior().Should().BeOfType <StrictWalk>();
            segment.VisitVariables.OfType <IdentifiedContactDataVariable>().Single().Email.Should().Be("*****@*****.**");
        }
Ejemplo n.º 5
0
        public IVisitSimulator CreateSimulator()
        {
            var parser = new XGenParser(RootUrl);

            if (Specification["Segments"].Any())
            {
                var segments = parser.ParseSegments(Specification["Segments"], Type);
                return(new SegmentBasedSimulator(segments));
            }
            return(new  ContactBasedSimulator(parser.ParseContacts(Specification["Contacts"], Type)));
        }
        public void ParseContacts_TestJson_ShouldNotFail()
        {
            var parser   = new XGenParser("http://google.com");
            var segments = parser.ParseContacts(JToken.Parse(TestJson)["Specification"]["Contacts"], JobType.Contacts);

            segments.Count().Should().Be(7);
            segments.All(x => x.Behavior().GetType() == typeof(StrictWalk)).Should().BeTrue();
            segments.All(x => x.VisitVariables.OfType <IdentifiedContactDataVariable>().Single().Email == "*****@*****.**").Should().BeTrue();

            DateTime.Now.Subtract(segments.First().DateGenerator.Start.Value).TotalDays.Should().BeGreaterOrEqualTo(0.91);
        }
Ejemplo n.º 7
0
        public static void Outcomes()
        {
            var segments = new JObject();
            var seg      = segments["Default"] = new JObject();
            var outcomes = seg["Outcomes"] = new JObject();


            seg["StartDate"] = "2010-01-01";
            seg["EndDate"]   = "2010-01-02";
            outcomes["{75D53206-47B3-4391-BD48-75C42E5FC2CE}"] = .5;
            outcomes["{F4830B80-1BB1-4746-89C7-96EFE40DA572}"] = .5;


            var parser = new XGenParser("http://sc80rev150427");


            var sim = new SegmentBasedSimulator(parser.ParseSegments(segments, JobType.Visits));


            var counts = new Dictionary <Guid, int>();

            var visits = 0;

            foreach (var visitor in sim.NextVisitors(1))
            {
                foreach (var visit in visitor.Commit())
                {
                    ++visits;
                    foreach (var req in visit.Requests)
                    {
                        var oc = req.GetVariable <IEnumerable <TriggerOutcomeData> >("TriggerOutcomes");
                        if (oc != null)
                        {
                            foreach (var o in oc)
                            {
                                //System.Console.Out.WriteLine(o.DefinitionId);
                                counts[o.DefinitionId] = counts.GetOrDefault(o.DefinitionId) + 1;
                            }
                        }
                    }
                }
            }

            System.Console.Out.WriteLine("{0} visits", visits);
            foreach (var c in counts)
            {
                System.Console.Out.WriteLine("{0}: {1}", c.Key, c.Value);
            }
        }
Ejemplo n.º 8
0
        static void Parser2()
        {
            var emea = GeoRegion.Regions.First(area => area.Id == "amer");

            var geodata = GeoData.FromResource();

            var country = emea.Selector(geodata);


            var freqs = Enumerable.Range(0, 10000).Select(i => country()).GroupBy(c => c.Country.Name)
                        .ToDictionary(g => g.Key, g => g.Count());

            File.WriteAllLines(@"C:\Temp\Countries.txt", new[] { "Country\tCount" }.Concat(freqs.OrderByDescending(kv => kv.Value).Select(kv => kv.Key + "\t" + kv.Value)));

            return;



            Randomness.Seed(1337);


            var json = File.ReadAllText(@"C:\Temp\Xerox2.js");

            var def    = JObject.Parse(json);
            var parser = new XGenParser("http://sc80rev150427/api/xgen/");



            //var vars = new[]{""}


            var sw = Stopwatch.StartNew();

            var visits    = 0;
            var id        = 0;
            var contactId = 0;

            using (var f = File.CreateText(@"C:\Temp\XeroxOut2.txt"))
            {
                f.Write("Contact\tId\tVisitIndex\tStart\tEnd\tHour\tDuration\tPageViews\tCampaign\tCountry\tTimeZone\tContinent\tReferrer\tLandingPage\tSite");
                f.WriteLine();

                var threads = Enumerable.Range(0, 25).Select(i =>
                {
                    var t = new Thread(() =>
                    {
                        Randomness.Seed(1337 + i);
                        var segments = parser.ParseSegments(def["Segments"], JobType.Visits);
                        var sim      = new SegmentBasedSimulator(segments);

                        foreach (var v in sim.NextVisitors(80))
                        {
                            var myId = Interlocked.Increment(ref contactId);
                            System.Console.Out.WriteLine("Visitor at {0}", v.Start);
                            try
                            {
                                var visitIndex = 0;
                                foreach (var visit in v.Segment.Behavior().Commit(v))
                                {
                                    Interlocked.Increment(ref visits);
                                    System.Console.Out.WriteLine(" - Visit at {0}", visit.Start);
                                    //foreach (var req in visit.Requests)
                                    //{
                                    //    System.Console.Out.WriteLine("   " + req.Url);
                                    //}

                                    //var visit = v.AddVisit();
                                    //visit.AddRequest("");
                                    lock (f)
                                    {
                                        f.Write("Contact" + myId);
                                        f.Write("\t");
                                        f.Write("Visit" + Interlocked.Increment(ref id));
                                        f.Write("\t");
                                        f.Write(++visitIndex);
                                        f.Write("\t");
                                        f.Write(v.Start.Date.ToString("yyyy-MM-dd"));
                                        f.Write("\t");
                                        f.Write(v.End.Date.ToString("yyyy-MM-dd"));
                                        f.Write("\t");
                                        f.Write(v.Start.Hour);
                                        f.Write("\t");
                                        f.Write((v.End - v.Start).TotalSeconds);
                                        f.Write("\t");
                                        f.Write(visit.GetVariable <double>("PageViews"));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("Campaign", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("Country", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("TimeZone", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("Continent", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("Referrer", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("LandingPage", ""));
                                        f.Write("\t");
                                        f.Write(visit.GetVariable("Site", ""));

                                        f.WriteLine();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Console.Out.WriteLine("Error: " + ex);
                            }
                            System.Console.Out.WriteLine("{0:N0} visits ({1:N2} visits per second)", visits, visits / sw.Elapsed.TotalSeconds);
                        }
                    });
                    t.Start();
                    return(t);
                }).ToArray();

                foreach (var t in threads)
                {
                    t.Join();
                }

                System.Console.Out.WriteLine("{0:N0} visits in {1:N2} seconds", visits, sw.Elapsed.TotalSeconds);
            }
        }
Ejemplo n.º 9
0
 public virtual void UpdateSegment(VisitorSegment segment, JToken definition, XGenParser parser)
 {
 }
Ejemplo n.º 10
0
 public virtual void SetDefaults(VisitorSegment segment, XGenParser parser)
 {
 }
Ejemplo n.º 11
0
 public override void UpdateSegment(VisitorSegment segment, JToken definition, XGenParser parser)
 {
     if (_updateSegment != null)
     {
         _updateSegment(segment, definition, parser);
     }
 }
Ejemplo n.º 12
0
 public override void SetDefaults(VisitorSegment segment, XGenParser parser)
 {
     UpdateSegment(segment, new JObject(), parser);
 }
Ejemplo n.º 13
0
        public override void UpdateSegment(VisitorSegment segment, JToken definition, XGenParser parser)
        {
            var randomPagePct = definition.Value <double?>("RandomPagePercentage") ?? 0.2;

            Func <string> siteId = () => "website";

            if (definition["Site"] != null && definition["Site"].Any())
            {
                siteId = parser.ParseWeightedSet <string>(definition["Site"]);
            }

            Func <string> landingPage = () => null;

            if (definition["Item"] != null && definition["Item"].Any())
            {
                landingPage = parser.ParseWeightedSet <string>(definition["Item"]);
            }
            else
            {
                randomPagePct = 1d;
            }

            var randomPages = new Dictionary <string, Func <ItemInfo> >();

            foreach (var site in parser.InfoClient.Sites.Values
                     .Where(s => !string.IsNullOrEmpty(s.StartPath)))
            {
                var root = parser.InfoClient.Query(site.StartPath, maxDepth: null).FirstOrDefault();
                if (root == null)
                {
                    throw new Exception(string.Format("Root item for site {0} does not exist ({1})", site.Id, site.StartPath));
                }
                var homePct = 0.5;
                if (root.Children.Count == 0)
                {
                    homePct = 1;
                }
                var other = GetDescendants(root.Children).Select(t => t.Item1)
                            .Where(item => item.HasLayout).OrderBy(item => Randomness.Random.NextDouble())
                            .Exponential(0.8, 10);

                randomPages[site.Id] = () => Randomness.Random.NextDouble() < homePct ? root : other();
            }


            segment.VisitVariables.AddOrReplace(new LandingPageVariable(() =>
            {
                var page = parser.InfoClient.GetItemInfo(landingPage());
                var site = parser.InfoClient.Sites[siteId()];
                if (page == null || Randomness.Random.NextDouble() < randomPagePct)
                {
                    return(Tuple.Create(site, randomPages[site.Id]()));
                }

                for (var i = 0; i < 10 && !page.Path.StartsWith(site.StartPath); i++)
                {
                    site = parser.InfoClient.Sites[siteId()];
                }

                return(Tuple.Create(site, page));
            }, parser.InfoClient));
        }
Ejemplo n.º 14
0
        public override void UpdateSegment(VisitorSegment segment, JToken definition, XGenParser parser)
        {
            var weights = Enumerable.Range(1, 12).Select(i => 0d).ToArray();

            foreach (var kv in (JObject)definition)
            {
                weights[int.Parse(kv.Key) - 1] = kv.Value.Value <double>();
            }

            segment.DateGenerator.PartOfYear(t =>
            {
                t.Clear();
                t.MoveAbsolute(0, (weights[0] + weights[11]) / 2);
                for (var i = 0; i < weights.Length; i++)
                {
                    t.LineAbsolute(_partsOfYears[i + 1], weights[i]);
                }
                t.LineAbsolute(1, (weights[0] + weights[11]) / 2);
            });
        }