示例#1
0
        public void LoadRoot(GeneratorContext context, string query)
        {
            var locations           = new List <Miejsce>();
            LocationRootObject root = LocationProcessor.LoadLocation(query);

            foreach (var i in root.results)
            {
                locations.Add(new Miejsce()
                {
                    MiejsceId = i.place_id, Lat = i.geometry.location.lat, Lng = i.geometry.location.lng, Name = i.name, visitCount = 0, type = query
                });
            }
            locations.ForEach(g => context.Locations.AddOrUpdate(g));
            context.SaveChanges();
        }
示例#2
0
 public void SaveRouteInDb(GeneratorContext context, int numberOfObjects)
 {
     HumanType[] humanTypes = context.humanTypes.Include(x => x.humanLikings).ToArray();
     for (int humanNumber = 0; humanNumber <= numberOfObjects - 1; humanNumber++)
     {
         Human human = new Human();
         human.humanType      = humanTypes[random.Next(humanTypes.Length)];
         human.LocomotionType = locomotionTypes[random.Next(locomotionTypes.Length)];
         human = traffic.generateTraffic(context, human);
         if (human.HumanRoutes == null)
         {
             numberOfObjects--;
         }
         context.People.AddOrUpdate(human);
         context.SaveChanges();
     }
 }
        public void LoadRoot(GeneratorContext context, string query, string town, int radius)
        {
            string nextPageToken = null;
            var    locations     = new List <Location>();

            do
            {
                LocationRootObject root = LocationProcessor.LoadLocation(query, nextPageToken, town, radius);
                foreach (var i in root.results)
                {
                    locations.Add(new Location()
                    {
                        LocationId = i.place_id, Lat = i.geometry.location.lat,
                        Lng        = i.geometry.location.lng, Name = i.name, visitCount = 0, type = query
                    });
                }
                nextPageToken = root.next_page_token;
            }while (nextPageToken != null);
            locations.ForEach(g => context.Locations.AddOrUpdate(g));
            context.SaveChanges();
        }
        public void SaveRouteInDb(GeneratorContext context, string query)
        {
            char typeId = query[0];

            query = query.Substring(1);
            RootObject root = new RootObject();

            actualTime = random.Next(21600, 43200);
            var        positions   = new List <Pozycja>();
            RootObject rootChecked = HttpSinglePathGenerator.GetSinglePath(query);

            if (rootChecked.routes == null)
            {
                return;
            }
            root = rootChecked;
            int rootCount = root.routes.Count;

            foreach (var i in root.routes)
            {
                legCount = i.legs.Count;
                foreach (var j in i.legs)
                {
                    stepsCount = j.steps.Count;
                    actualTime = actualTime + random.Next(1200, 7200);
                    foreach (var k in j.steps)
                    {
                        actualTime = actualTime + k.duration.value;
                        positions.Add(new Pozycja {
                            Lat = k.start_location.lat, Lng = k.start_location.lng, actualTime = TimeSpan.FromSeconds(actualTime)
                        });
                    }
                }
            }
            var lastRoute = root.routes[rootCount - 1].legs[legCount - 1].steps[stepsCount - 1];

            positions.Add(new Pozycja {
                Lat = lastRoute.end_location.lat, Lng = lastRoute.end_location.lng, actualTime = TimeSpan.FromSeconds(actualTime + lastRoute.duration.value)
            });
            Human human = new Human();

            if (typeId == 's')
            {
                human.HumanType = "student";
            }
            else if (typeId == 'z')
            {
                human.HumanType = "zwykłyturysta";
            }
            else if (typeId == 'r')
            {
                human.HumanType = "religijnyturysta";
            }
            else
            {
                human.HumanType = "kulinarnyturysta";
            }
            human.Pozycje = positions;
            context.People.AddOrUpdate(human);
            context.SaveChanges();
        }