public static LocationEntry GetLastVisit(Position pos) { LocationEntry lastVisit = null; foreach (var entry in History) { double distance = Position.GetDistance(pos, entry); if (distance <= Constants.VISITED_DISTANCE_THRESHOLD) { if (lastVisit == null) { lastVisit = entry; } else { if (lastVisit.VisitedOn < entry.VisitedOn) { lastVisit = entry; } } } } return(lastVisit); }
private void RedirectPath(ServiceCtx context, long titleId, int flag, NcaContentType contentType) { string contentPath = ReadUtf8String(context); LocationEntry newLocation = new LocationEntry(contentPath, flag, titleId, contentType); context.Device.System.ContentManager.RedirectLocation(newLocation, _storageId); }
private static LocationEntry Fetch(DbDataReader reader) { LocationEntry entry = new LocationEntry(); try { if (!Convert.IsDBNull(reader["Latitude"])) { entry.Latitude = (double)reader["Latitude"]; } if (!Convert.IsDBNull(reader["Longitude"])) { entry.Longitude = (double)reader["Longitude"]; } if (!Convert.IsDBNull(reader["VisitedOn"])) { entry.VisitedOn = Convert.ToDateTime((string)reader["VisitedOn"]); } entry.IsKnown = (bool)reader["IsKnown"]; entry.KnownKey = (string)reader["KnownKey"]; if (double.IsInfinity(entry.Latitude)) { entry.Latitude = double.MaxValue; } if (double.IsInfinity(entry.Longitude)) { entry.Longitude = double.MaxValue; } } catch { } return(entry); }
private void RedirectPath(ServiceCtx Context, long TitleId, int Flag, ContentType ContentType) { string ContentPath = ReadUtf8String(Context); LocationEntry NewLocation = new LocationEntry(ContentPath, Flag, TitleId, ContentType); Context.Device.System.ContentManager.RedirectLocation(NewLocation, StorageId); }
public void TestLocationEntryBasics() { Config.IsInUnitTesting = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(1000); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); calcParameters.Options.Add(CalcOption.LocationsEntries); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory,"blub",wd.InputDataLogger); //CalcLocation cl = new CalcLocation("blub", 1, Guid.NewGuid().ToStrGuid()); //Mock<ILogFile> lf = new Mock<ILogFile>(); //CalcPerson cp = MakeCalcPerson(cl,calcParameters,lf.Object); HouseholdKey key = new HouseholdKey("hh1"); TimeStep ts = new TimeStep(1, 0, false); LocationEntry le = new LocationEntry(key, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); DateStampCreator dsc = new DateStampCreator(calcParameters); using (OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); old.AddLocationEntry(le); old.FinalSaveToDatabase(); } var lel = new LocationEntryLogger(wd.SqlResultLoggingService); var e = lel.Load(key); e.Count.Should().Be(1); wd.CleanUp(); } }
public async Task <IEnumerable <Guid> > FindNear(LocationEntry loc) { FieldDefinition <Geolocalizacao> fieldLocation = "location"; var utcTime = ConvertToUtc(loc.DateTime); var timeGreaterMinutes = utcTime.AddMinutes(30); var timeLessMinutes = utcTime.AddMinutes(-30); var filterPoint = GeoJson.Point(new GeoJson2DCoordinates(loc.Longitude, loc.Latitude)); var filterNearUsers = Builders <Geolocalizacao> .Filter.NearSphere(fieldLocation, filterPoint, 500); var filterUserNotEqualToSameUser = Builders <Geolocalizacao> .Filter.Ne(x => x.IdUser, loc.UserId); var filterGreater = Builders <Geolocalizacao> .Filter.Gt(x => x.Date, timeLessMinutes); var filterLess = Builders <Geolocalizacao> .Filter.Lt(x => x.Date, timeGreaterMinutes); var combineFilters = Builders <Geolocalizacao> .Filter.And(filterNearUsers, filterUserNotEqualToSameUser, filterGreater, filterLess); var nearUsersCursor = await _mongoContext.GetContext() .DistinctAsync(geolocalizacao => geolocalizacao.IdUser, combineFilters); return(nearUsersCursor.ToList()); }
private bool createTripEntry(LocationEntryViewModel location, LocationEntry entry, ApplicationUser user) { Location loc = new Location() { DisplayFriendlyName = location.Address, Latitude = location.Latitude, Longitude = location.Longitude, }; CheckIn checkIn = new CheckIn() { DateCreated = DateTime.Now, Location = loc, }; List <CheckIn> visits = new List <CheckIn>() { checkIn }; List <Badge> badges = new List <Badge>(); List <Badge> badgesInDb = db.Badges.ToList(); Trip trip = user.Trips.Where(x => x.TripName == location.tripName).FirstOrDefault(); if (trip == null) { return(false); } foreach (string badge in location.BadgeNames) { if (badgesInDb.Where(x => x.BadgeName == badge) == null) { badges.Add(new Badge() { BadgeName = badge }); } else { badges.Add(badgesInDb.Where(x => x.BadgeName == badge).FirstOrDefault()); } } if (entry == null) { entry = new LocationEntry() { DateCreated = DateTime.Now, Location = loc, LocationBadge = badges, Visits = visits, Comments = location.Comments }; trip.TripEntries.Add(entry); } else { entry.Visits.Add(checkIn); entry.LocationBadge = badges; } db.SaveChanges(); return(true); }
public static void Insert(LocationEntry entry) { using (DAC dac = new DAC()) { string statement = string.Format("INSERT INTO LocationHistory (Latitude, Longitude, VisitedOn, IsKnown, KnownKey) VALUES ({0}, {1}, '{2}', {3}, '{4}');", entry.Latitude, entry.Longitude, entry.VisitedOn, entry.IsKnown ? 1 : 0, entry.KnownKey); dac.ExecuteCommand(statement); } }
private static void SaveCurrentLocation() { Position pos = FromGeoposition(CurrentPosition); LocationEntry entry = KnownLocations.IsKnown(pos); History.Add(entry); LocationHistoryDAC.Insert(entry); }
public IActionResult Get() { try { List <Location> locations = new LocationEntry().Select(); return(Ok(locations)); } catch (Exception ex) { Log.ErrorToFile(ex.Message); return(BadRequest(ex.Message)); } }
private static bool VisitedThisPlaceWithinLastNMinutes(Position pos, double minutesThreshold) { if (pos.IsValid()) { LocationEntry lastVisit = LocationHelper.GetLastVisit(pos); if (lastVisit != null) { var minutesSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalMinutes; return(minutesSinceVisited <= minutesThreshold); } } return(false); }
private bool createLocationEntry(LocationEntryViewModel location, LocationEntry entry, ApplicationUser user) { Location loc = new Location() { DisplayFriendlyName = location.Address, Latitude = location.Latitude, Longitude = location.Longitude, }; CheckIn checkIn = new CheckIn() { DateCreated = DateTime.Now, Location = loc, }; List <CheckIn> visits = new List <CheckIn>() { checkIn }; List <Badge> badges = new List <Badge>(); List <Badge> badgesInDb = db.Badges.ToList(); foreach (string badge in location.BadgeNames) { badges.Add(new Badge() { BadgeName = badge }); } if (entry == null) { entry = new LocationEntry() { DateCreated = DateTime.Now, Location = loc, LocationBadge = badges, Visits = visits, Comments = location.Comments }; user.Diary.Add(entry); } else { entry.Visits.Add(checkIn); entry.LocationBadge = badges; } db.SaveChanges(); return(true); }
public void TestLocationEntryBasicsWithFile() { Config.IsInUnitTesting = true; using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { wd.InputDataLogger.AddSaver(new LocationEntryLogger(wd.SqlResultLoggingService)); DateTime startdate = new DateTime(2018, 1, 1); DateTime enddate = startdate.AddMinutes(1000); CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod(); calcParameters.Options.Add(CalcOption.LocationsEntries); //FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hhname", wd.InputDataLogger); //LocationsLogFile llf = new LocationsLogFile(true, fft, calcParameters); //CalcLocation cl = new CalcLocation("blub", 1, Guid.NewGuid().ToStrGuid()); //Mock<ILogFile> lf = new Mock<ILogFile>(); //CalcPerson cp = MakeCalcPerson(cl,calcParameters,lf.Object); //LocationEntry le = new LocationEntry(cp, 1, cl,calcParameters); //llf.WriteEntry(le, new HouseholdKey("HH1")); //llf.WriteEntry(le, new HouseholdKey("HH2")); //llf.WriteEntry(le, new HouseholdKey("HH3")); //llf.Close(); HouseholdKey key1 = new HouseholdKey("hh1"); TimeStep ts = new TimeStep(1, 0, false); LocationEntry le1 = new LocationEntry(key1, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); HouseholdKey key2 = new HouseholdKey("hh2"); LocationEntry le2 = new LocationEntry(key2, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); HouseholdKey key3 = new HouseholdKey("hh3"); LocationEntry le3 = new LocationEntry(key3, "personName", "personGuid".ToStrGuid(), ts, "locname", "locguid".ToStrGuid()); DateStampCreator dsc = new DateStampCreator(calcParameters); using (OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) { old.AddLocationEntry(le1); old.AddLocationEntry(le2); old.AddLocationEntry(le3); old.FinalSaveToDatabase(); } LocationEntryLogger lel = new LocationEntryLogger(wd.SqlResultLoggingService); var le = lel.Load(key1); Logger.Info("count: " + le.Count); string prev = JsonConvert.SerializeObject(le1, Formatting.Indented); string loaded = JsonConvert.SerializeObject(le[0], Formatting.Indented); loaded.Should().Be(prev); wd.CleanUp(); } }
/// <summary> /// Get info from entry and update properties accordingly /// </summary> /// <param name="entry"></param> private void ParseEntry(JournalEntry entry) { if (entry.Event == "FSDJump") { FSDJumpEntry jumpInfo = (FSDJumpEntry)entry; FuelLevel = jumpInfo.FuelLevel; CurrentPosition = jumpInfo.StarPos; } else if (entry.Event == "FuelScoop") { FuelScoopEntry scoopInfo = (FuelScoopEntry)entry; FuelLevel = scoopInfo.Total; } else if (entry.Event == "LoadGame") { LoadGameEntry loadGameInfo = (LoadGameEntry)entry; FuelLevel = loadGameInfo.FuelLevel; FuelCapacity = loadGameInfo.FuelCapacity; } else if (entry.Event == "Location") { LocationEntry locationInfo = (LocationEntry)entry; CurrentPosition = locationInfo.StarPos; } else if (entry.Event == "Promotion") { PromotionEntry promotionInfo = (PromotionEntry)entry; if (promotionInfo.RankName == "Explore") { RankExplore = new Rank("Exploration", promotionInfo.NewRank); } } else if (entry.Event == "Rank") { RankEntry rankInfo = (RankEntry)entry; RankExplore = new Rank("Exploration", rankInfo.Explore); } else if (entry.Event == "RefuelAll" || entry.Event == "RefuelPartial") { RefuelEntry refuelInfo = (RefuelEntry)entry; FuelLevel += refuelInfo.Amount; } UpdateProperties(); }
private async Task CheckIfHasRelationalAndAdd(Geolocalizacao position) { var location = new LocationEntry() { Latitude = position.Location.Coordinates.Latitude, Longitude = position.Location.Coordinates.Longitude, DateTime = position.Date, UserId = position.IdUser }; var near = await FindNearWorker(location); if (!near.Any()) { return; } var relationalFriends = await _timelineService.GetRelationalFriends(position.IdUser, near.ToList()); if (relationalFriends.isOk && relationalFriends.data != null && relationalFriends.data.idAmigos.Count > 0) { var friends = relationalFriends.data.idAmigos.Select(requestFriend => new Friend() { idAmigo = requestFriend }).ToList(); var request = new RequestMatchFriend { IdAmigos = friends }; var timeLineFriends = await _timelineService.GetShowTimeLine(position.IdUser, request); if (timeLineFriends.isOk && timeLineFriends.data != null && timeLineFriends.data.Count > 0) { var friendsGuids = timeLineFriends.data.Select(friend => friend.idAmigo).ToList(); foreach (var friend in friendsGuids) { await _timelineService.AddToTimeline(position.IdUser, friend); await _timelineService.AddToTimeline(friend, position.IdUser); } } } }
public IHttpActionResult emergencyCheckIn(LocationEntryViewModel entry) { var userId = User.Identity.GetUserId(); var AppUser = db.Users.Find(userId); LocationEntry location = new LocationEntry(); location.Comments = entry.Comments; location.DateCreated = DateTime.Now; location.Location = new Location() { DisplayFriendlyName = entry.Address, Latitude = entry.Latitude, Longitude = entry.Longitude }; AppUser.emergencyCheckIn = location; db.SaveChanges(); return(Ok()); }
public IHttpActionResult createEntry(LocationEntryViewModel location) { if (location == null) { return(BadRequest()); } try { var userId = User.Identity.GetUserId(); var AppUser = db.Users.Find(userId); if (location.tripName == null || location.tripName == "" || location.tripName == "My Diary") { LocationEntry entry = AppUser.Diary .Where(x => x.Location.DisplayFriendlyName == location.Address) .FirstOrDefault(); if (!createLocationEntry(location, entry, AppUser)) { return(BadRequest()); } ; } else { LocationEntry tripentry = AppUser .Trips .Where(x => x.TripName == location.tripName) .SelectMany(x => x.TripEntries) .Where(x => x.Location.DisplayFriendlyName == location.Address) .FirstOrDefault(); if (!createTripEntry(location, tripentry, AppUser)) { return(BadRequest()); } ; } return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public static LocationEntry IsKnown(Position pos) { LocationEntry entry = new LocationEntry() { Latitude = pos.Latitude, Longitude = pos.Longitude, VisitedOn = pos.FetchedOn }; foreach (var p in List) { if (Position.GetDistance(p, pos) <= Constants.VISITED_DISTANCE_THRESHOLD) { entry.IsKnown = true; entry.KnownKey = p.Key; } } return(entry); }
public LocationEntryViewModel getEmergencyCheckIn(string Username) { var userId = User.Identity.GetUserId(); var AppUser = db.Users.FirstOrDefault(x => x.UserName == Username); LocationEntryViewModel loc = new LocationEntryViewModel(); LocationEntry entry = AppUser.emergencyCheckIn; if (entry == null) { return(null); } else { loc.Address = entry.Location.DisplayFriendlyName; loc.Comments = entry.Comments; loc.DateCreated = entry.DateCreated.ToString(); loc.Latitude = entry.Location.Latitude; loc.Longitude = entry.Location.Longitude; } return(loc); }
public async Task Add(LocationEntry pGeo) { var invalidGuid = new Guid("00000000-0000-0000-0000-000000000000"); if (pGeo.UserId == invalidGuid) { return; } var geo2 = new Geolocalizacao { Location = new GeoJsonPoint <GeoJson2DGeographicCoordinates>( new GeoJson2DGeographicCoordinates(pGeo.Longitude, pGeo.Latitude) ), IdUser = pGeo.UserId, Date = ConvertToUtc(pGeo.DateTime), CreatedDate = DateTime.UtcNow, }; await _mongoContext.GetContext().InsertOneAsync(geo2); await CheckIfHasRelationalAndAdd(geo2); }
private void LocationEntry_Focused(object sender, FocusEventArgs e) { LocationEntry.Unfocus(); MainMap.IsVisible = true; }
public void AddLocationEntry(LocationEntry le) { _locationEntries.Add(le); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var total = await _service.GetCount(); const int totalToReturn = 100; var totalPages = total / totalToReturn; var all = await _service.GetAll(_offset, totalToReturn); foreach (var position in all) { var location = new LocationEntry() { Latitude = position.Location.Coordinates.Latitude, Longitude = position.Location.Coordinates.Longitude, DateTime = position.Date, UserId = position.IdUser }; var near = await _service.FindNearWorker(location); if (!near.Any()) { continue; } var friendsList = near.Select(user => new Friend() { idAmigo = user, }).ToList(); var relationalFriends = await _timelineService.GetRelationalFriends(position.IdUser, near.ToList()); if (relationalFriends.isOk && relationalFriends.data != null && relationalFriends.data.idAmigos.Count > 0) { var friends = relationalFriends.data.idAmigos.Select(requestFriend => new Friend() { idAmigo = requestFriend }).ToList(); var request = new RequestMatchFriend { IdAmigos = friends }; var timeLineFriends = await _timelineService.GetShowTimeLine(position.IdUser, request); if (timeLineFriends.isOk && timeLineFriends.data != null && timeLineFriends.data.Count > 0) { var guids = timeLineFriends.data.Select(friend => friend.idAmigo).ToList(); await _timelineService.AddToTimeline(position.IdUser, guids); } } } if (_offset > totalPages) { _offset = 0; } else { _offset += 1; } await Task.Delay(1000, stoppingToken); } }
public async void Post([FromBody]LocationEntry pGeo) { await _geoLocalizacaoService.Add(pGeo); }
public static void ExecuteLocationRecipes() { try { //execute buy-milk recipe var buyMilkRecipe = Repository.Instance.GetRecipe("Buy Milk"); if (buyMilkRecipe != null && buyMilkRecipe.IsAvailable && buyMilkRecipe.IsEnabled) { var work = KnownLocations.Get(KnownLocations.WORK); if (VisitedThisPlaceWithinLastNMinutes(work, Constants.LEFT_FROM_DURATION_THRESHOLD)) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Isn't your wife waiting?" }, { "AlertText", "Hope you have bought milk before going home." }, { "Persistent", true }, { "Delay", 500 } }; buyMilkRecipe.ScopeHours = TimeSpan.FromMinutes(Constants.LEFT_FROM_DURATION_THRESHOLD).TotalHours + 1; SendNotification(buyMilkRecipe, arguments); } } //execute car-service recipe var carServiceRecipe = Repository.Instance.GetRecipe("Car Service"); if (carServiceRecipe != null && carServiceRecipe.IsAvailable && carServiceRecipe.IsEnabled) { var carShowroom = KnownLocations.Get(KnownLocations.CAR_SHOWROOM); if (carShowroom.IsValid()) { LocationEntry lastVisit = LocationHelper.GetLastVisit(carShowroom); if (lastVisit != null) { var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays; if (daysSinceVisited >= Constants.CAR_SERVICE_INTERVAL) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Your car is doing good?" }, { "AlertText", "It's " + daysSinceVisited + " days since you visited the Car Showroom." }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(carServiceRecipe, arguments); } } } } //execute gym recipe var gymRecipe = Repository.Instance.GetRecipe("Gym"); if (gymRecipe != null && gymRecipe.IsAvailable && gymRecipe.IsEnabled) { var gym = KnownLocations.Get(KnownLocations.GYM); if (gym.IsValid()) { LocationEntry lastVisit = LocationHelper.GetLastVisit(gym); if (lastVisit != null) { var daysSinceVisited = DateTime.Now.Subtract(lastVisit.VisitedOn).TotalDays; if (daysSinceVisited >= Constants.MAX_GYM_VACATION) { var arguments = new Dictionary <string, object>() { { "HeaderText", "Aren't you health conscious?" }, { "AlertText", "It's " + daysSinceVisited + " days since you visited the Gym." }, { "Persistent", true }, { "Delay", 500 } }; SendNotification(gymRecipe, arguments); } } } } } catch (Exception exception) { Log.Error(exception); } }
public async Task<IActionResult> GetNear([FromBody]LocationEntry pGeo) { var result = await _geoLocalizacaoService.FindNear(pGeo); return Ok(result); }