private Node GetNodeFromCluster(ClusterLeaf pattern) { return(new Node(pattern.FileName) { Text = pattern.Region }); }
public RoutePredictionResult PredictEndLocation(double lat, double lon, DateTime time) { var prediction = new RoutePredictionResult(); // check how many start points we have within a cluster // and iterate through the cluster hierachy to get at least 1 location // TODO: filter using time of the day (morning, midday, evening, night), week day, month,... ClusterItem <LocationInstance <TripSummary> > cluster = startLocationRoot.GetLeaf(lat, lon); prediction.ClusterLevel = 0; while (cluster.GetNrOfLocations() == 0) { var parentItem = cluster.GetParentItem(); if (parentItem != null) { if (parentItem is ClusterItem <LocationInstance <TripSummary> > ) { cluster = parentItem as ClusterItem <LocationInstance <TripSummary> >; prediction.ClusterLevel++; } else { // return an empty prediction result return(prediction); } } else { // return an empty prediction result return(prediction); } } Dictionary <ClusterLeaf <TripSummary>, RoutePredictionItem> leafs = new Dictionary <ClusterLeaf <TripSummary>, RoutePredictionItem>(); // create a list of endLocation leafs and count how many times an endlocation is part of the leaf foreach (var location in cluster.GetLocations()) { ClusterLeaf <TripSummary> leaf = location.LocationObject.GetParentItem() as ClusterLeaf <TripSummary>; if (!leafs.ContainsKey(leaf)) { leafs[leaf] = new RoutePredictionItem() { Lat = leaf.CenterLat, Lon = leaf.CenterLon, NrOfEndPoints = 0, NrOfDayMatches = 0, NrOfTimeMatches = 0, NrOfWorkdayMatches = 0 }; } leafs[leaf].NrOfEndPoints++; leafs[leaf].TripIds.Add(location.LocationObject.LocationObject.TripId); if (location.LocationObject.LocationObject.StartTime.DayOfWeek == time.DayOfWeek) { leafs[leaf].NrOfDayMatches++; } ; if (IsWeekend(location.LocationObject.LocationObject.StartTime) == IsWeekend(time)) { leafs[leaf].NrOfWorkdayMatches++; } if (GetTimeSlot(location.LocationObject.LocationObject.StartTime) == GetTimeSlot(time)) { leafs[leaf].NrOfTimeMatches++; } leafs[leaf].CalculateProbability(cluster.GetNrOfLocations()); } prediction.Predictions = leafs.Values.ToList(); prediction.Predictions.Sort(); return(prediction); }