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(); }
public Human generateTraffic(GeneratorContext context, Human human) { RandomObjective randomObjective = new RandomObjective(); List <Location> noclegi = context.Locations.Where(g => g.type == "lodging").ToList(); var random = new Random();//zainicjowanie generatora liczb losowych int actualTime = random.Next(21600, 43200); Location nocleg; Leg leg = null; string objective; do { nocleg = noclegi[random.Next(noclegi.Count)];//wybranie noclegu o losowym indeksie objective = randomObjective.generateRandomObjective (context, human.humanType.humanLikings.ToArray()); leg = HttpSinglePathGenerator.GetSinglePath(nocleg.LocationId, objective); } while (leg == null); foreach (var i in leg.steps) { i.actualTime = TimeSpan.FromSeconds( TimeProcessor.calculateTime(actualTime, i.duration.value)); } actualTime += random.Next(1800, 7200); human.HumanRoutes = new List <Leg>(); human.HumanRoutes.Add(leg); int howManyLocation = random.Next(1, human.humanType.numberOfLocations); for (int j = 0; j <= howManyLocation - 1; j++) { string newObjective = randomObjective.generateRandomObjective (context, human.humanType.humanLikings.ToArray()); leg = HttpSinglePathGenerator.GetSinglePath(objective, newObjective); if (leg == null) { howManyLocation--; } else { foreach (var i in leg.steps) { i.actualTime = TimeSpan.FromSeconds( TimeProcessor.calculateTime(actualTime, i.duration.value)); } human.HumanRoutes.Add(leg); objective = newObjective; actualTime += random.Next(1800, 7200); } } leg = HttpSinglePathGenerator.GetSinglePath(objective, nocleg.LocationId); if (leg == null) { return(null); } foreach (var i in leg.steps) { i.actualTime = TimeSpan.FromSeconds( TimeProcessor.calculateTime(actualTime, i.duration.value)); } human.HumanRoutes.Add(leg); return(human); }