public async Task CreateLocationHistoryAsync(LocationHistory history) { await _context.LocationHistory .AddAsync(history); await _context.SaveChangesAsync(); }
public async Task <QueryRequest> GetQueryRequestAsync(LocationHistory locationHistory) { return(await Task.FromResult(new QueryRequest { StartDate = locationHistory.Locations.Min(l => l.TimestampMsUnix).ToDateTime(), EndDate = locationHistory.Locations.Max(l => l.TimestampMsUnix).ToDateTime(), IntervalType = IntervalType.Every12Hours })); }
public async Task <LocationHistory> GetLocationHistory(DateTimeOffset from) { var user = await DependencyService.Get <UserRepository>().GetUserAsync(); var history = new LocationHistory(from, new LocationHistory.Entry[] {}); if (user == null || !user.HasHomeLocation) { return(history); } var locations = await DependencyService.Get <LocationRecordRepository>().GetLocationRecordsAsync(from); var earliestRecord = locations.FirstOrDefault(); if (earliestRecord == null) { return(history); } var startDay = new DateTimeOffset(earliestRecord.Timestamp.Date, earliestRecord.Timestamp.Offset); var endDate = DateTimeOffset.Now; var currentDay = startDay; var entries = new List <LocationHistory.Entry>(); while (currentDay < endDate) { var nextDay = startDay.AddDays(1); var entry = new LocationHistory.Entry { Day = currentDay, }; for (var i = 0; i < 24; i++) { var currentHour = currentDay.AddHours(i); var nextHour = currentDay.AddHours(i + 1); var locationsInCurrentHour = locations.Where(x => x.Timestamp >= currentHour && x.Timestamp < nextHour).ToArray(); if (locationsInCurrentHour.Length == 0) { entry.MissingDataHours++; } else if (WasAlwaysHome(user, locationsInCurrentHour)) { entry.HoursAtHome++; } } entries.Add(entry); currentDay = nextDay; } return(new LocationHistory(history.From, entries.ToArray())); }
public ActionResult <LocationHistory> Locations(int?page, int?count) { page = page ?? 1; count = count ?? 50; int totalCount = 0; LocationHistory result = GetPageLatestCourseLocationHistory(false, (int)page, (int)count, ref totalCount); Response.Headers.Add("X-Total-Count", totalCount.ToString()); return(result); }
public async Task CreateLocationHistoryAsync(string userId, double latitude, double longitude, DateTime timeStamp) { LocationHistory history = new LocationHistory() { UserId = userId, Latitude = latitude, Longitude = longitude, TimeStamp = timeStamp }; await _context.LocationHistories.AddAsync(history); await _context.SaveChangesAsync(); }
public ActionResult <VehicleFeedInfosFollow> FleetVehicleInfos(string token) { DateTimeOffset fromTime; DateTimeOffset toTime = DateTimeOffset.Now.ToUniversalTime(); if (string.IsNullOrEmpty(token)) { //TODO: When null, should be set to 'now' //for the demo, set start time = 5/1/19 fromTime = new DateTimeOffset(2019, 05, 01, 0, 0, 0, 0, TimeSpan.FromHours(0)).ToUniversalTime(); } else { string strFromTime = m_dataProtector.Unprotect(token); if (!DateTimeOffset.TryParse(strFromTime, out fromTime)) { return(BadRequest("token parameter invalid")); } } var vfif = new VehicleFeedInfosFollow(); vfif.token = m_dataProtector.Protect(toTime.ToString()); LocationHistory locHistory = GetCourseLocationHistory(fromTime.DateTime, toTime.DateTime, true); List <VehicleFaultCodeEvent> flaggedEventHistory = m_Context.VehicleFaultCodeEvent.Where( x => x.triggerDate >= fromTime && x.triggerDate <= toTime && x.urgentFlag == true).ToList(); List <VehiclePerformanceEvent> performanceEventHistory = m_Context.VehiclePerformanceEvent .Include(VehiclePerformanceThreshold => VehiclePerformanceThreshold.thresholds) .Where( x => x.eventStart >= fromTime && x.eventStart <= toTime).ToList(); List <VehicleFaultCodeEvent> vehicleFaultCodeEventHistory = m_Context.VehicleFaultCodeEvent.Where( x => x.triggerDate >= fromTime && x.triggerDate <= toTime).ToList(); VehicleInfoHistory history = new VehicleInfoHistory { coarseVehicleLocationTimeHistories = locHistory, flaggedVehicleFaultEvents = VehicleFaultCodeListToModelList(flaggedEventHistory), vehiclePerformanceEvents = VehiclePerformanceListToModelList(performanceEventHistory), vehicleFaultCodeEvents = VehicleFaultCodeListToModelList(vehicleFaultCodeEventHistory) }; vfif.feed = history; return(vfif); }
public void Update(int x, int y, int walls) { if (Location != null) { LocationHistory.Add(Location); } else { Location = new Cell(); } Location.X = x; Location.Y = y; AvailableWalls = walls; }
public async Task SaveToLocationHistoryAsync(LocationHistory locData) { if (base.LoadTableSilent(Constants.LocationHistoryTableName)) { if (string.IsNullOrEmpty(locData.PartitionKey)) { locData.PartitionKey = locData.ProfileID; } locData.RowKey = locData.ClientTimeStamp.ToString(); locData.ClientDateTime = new DateTime(locData.ClientTimeStamp); TableOperation insertLocation = TableOperation.InsertOrReplace(locData); await base.EntityTable.ExecuteAsync(insertLocation); } }
public static List <Location> PrepareLocations(LocationHistory history, IntervalType intervalType) { var day = 0; var hour = 0; var locations = new List <Location>(); foreach (var location in history.Locations) { if (location?.TimestampMs == null || location.LatitudeE7 == 0 || location.LongitudeE7 == 0) { continue; } var date = location.Date; if (intervalType == IntervalType.Day) { if (day == date.Day) { continue; } } else if (intervalType == IntervalType.Every12Hours) { if (hour < 12 && day == date.Day && date.Hour < 12) { continue; } if (hour >= 12 && hour < 24 && day == date.Day && date.Hour >= 12 && date.Hour < 24) { continue; } } else { if (hour == date.Hour) { continue; } } hour = date.Hour; day = date.Day; locations.Add(location); } return(locations); }
public async Task <List <CheckPoint> > ParseLocationHistoryAsync(LocationHistory locationHistory, QueryRequest model, ProgressChangedEventHandler callback) { var locations = BorderCrossingHelper.PrepareLocations(locationHistory, model.IntervalType); var filteredLocations = locations.Where(l => l.Date >= model.StartDate && l.Date <= model.EndDate).OrderBy(l => l.TimestampMsUnix).ToList(); var currentLocation = filteredLocations.First(); var currentCountry = GetCountryName(currentLocation.Point); var i = 0; var count = filteredLocations.Count(); var checkPoints = new List <CheckPoint> { BorderCrossingHelper.LocationToCheckPoint(currentLocation, currentCountry) }; foreach (var location in filteredLocations) { await Task.Run(() => { i++; callback(this, new ProgressChangedEventArgs((int)(100.0 * i / count), null)); var countryName = GetCountryName(location.Point); if (currentCountry == countryName) { currentLocation = location; return; } var range = locationHistory.Locations.Where(lh => lh.TimestampMsUnix >= currentLocation.TimestampMsUnix && lh.TimestampMsUnix <= location.TimestampMsUnix).ToList(); var checkPoint = BorderCrossingHelper.FindCheckPoint(range, currentLocation, currentCountry, location, countryName, GetCountryName); checkPoints.Add(checkPoint); currentCountry = countryName; currentLocation = location; }); } var last = filteredLocations.Last(); checkPoints.Add(BorderCrossingHelper.LocationToCheckPoint(last, GetCountryName(last.Point))); return(checkPoints); }
public async Task <IActionResult> PostLocationHistory([FromBody] LocationHistory locationHistory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = _httpContextAccessor.CurrentUserId(); if (!locationHistory.UserId.Equals(userId)) { return(Unauthorized()); } locationHistory.TimeStamp = DateTime.Now.ToUniversalTime(); _context.LocationHistory.Add(locationHistory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLocationHistory", new { id = locationHistory.HistoryID }, locationHistory)); }
/// <summary> /// Converts this instance of <see cref="LocationHistory"/> to an instance of <see cref="LocationHistoryDTO"/>. /// </summary> /// <param name="entity"><see cref="LocationHistory"/> to convert.</param> public static LocationHistoryDTO ToDTO(this LocationHistory entity) { if (entity == null) { return(null); } var dto = new LocationHistoryDTO(); dto.ID = entity.ID; dto.LocationID = entity.LocationID; dto.Name = entity.Name; dto.ModifiedByUserID = entity.ModifiedByUserID; dto.ModifiedDate = entity.ModifiedDate; dto.AuditDate = entity.AuditDate; entity.OnDTO(dto); return(dto); }
/// <summary> /// Converts this instance of <see cref="LocationHistoryDTO"/> to an instance of <see cref="LocationHistory"/>. /// </summary> /// <param name="dto"><see cref="LocationHistoryDTO"/> to convert.</param> public static LocationHistory ToEntity(this LocationHistoryDTO dto) { if (dto == null) { return(null); } var entity = new LocationHistory(); entity.ID = dto.ID; entity.LocationID = dto.LocationID; entity.Name = dto.Name; entity.ModifiedByUserID = dto.ModifiedByUserID; entity.ModifiedDate = dto.ModifiedDate; entity.AuditDate = dto.AuditDate; dto.OnEntity(entity); return(entity); }
public async Task PutAsync(Int32 id, LocationHistory _locationHistory) { var entity = _unitOfWork.GetRepoInstance <LocationHistory>().GetById(id); if (entity == null) { return; } entity.date = _locationHistory.date; entity.latitudeL = _locationHistory.latitudeL; entity.longitude = _locationHistory.longitude; entity.order = _locationHistory.order; _unitOfWork.GetRepoInstance <LocationHistory>().Update(entity); await _unitOfWork.saveAsync(); }
public ActionResult <LocationHistory> Locations(string startTime, string stopTime, int?page, int?count) { if (!DateTime.TryParse(startTime, null, System.Globalization.DateTimeStyles.RoundtripKind, out DateTime startDate)) { return(BadRequest("Invalid startTime")); } if (!DateTime.TryParse(stopTime, null, System.Globalization.DateTimeStyles.RoundtripKind, out DateTime stopDate)) { return(BadRequest("Invalid stopTime")); } page = page ?? 1; count = count ?? 50; int totalCount = 0; LocationHistory result = GetPageLocationHistory(startDate, stopDate, false, (int)page, (int)count, ref totalCount); Response.Headers.Add("X-Total-Count", totalCount.ToString()); return(result); }
public ActionResult <VehicleInfoHistory> FleetVehicleInfos(string startTime, string stopTime) { if (!DateTime.TryParse(startTime, null, System.Globalization.DateTimeStyles.RoundtripKind, out DateTime startDate)) { return(BadRequest("Invalid startTime")); } if (!DateTime.TryParse(stopTime, null, System.Globalization.DateTimeStyles.RoundtripKind, out DateTime stopDate)) { return(BadRequest("Invalid stopTime")); } LocationHistory locHistory = GetCourseLocationHistory(startDate, stopDate, true); List <VehicleFaultCodeEvent> flaggedEventHistory = m_Context.VehicleFaultCodeEvent.Where( x => x.triggerDate >= startDate && x.triggerDate <= stopDate && x.urgentFlag == true).ToList(); List <VehiclePerformanceEvent> performanceEventHistory = m_Context.VehiclePerformanceEvent .Include(VehiclePerformanceThreshold => VehiclePerformanceThreshold.thresholds) .Where( x => x.eventStart >= startDate && x.eventStart <= stopDate).ToList(); List <VehicleFaultCodeEvent> vehicleFaultCodeEventHistory = m_Context.VehicleFaultCodeEvent.Where( x => x.triggerDate >= startDate && x.triggerDate <= stopDate).ToList(); VehicleInfoHistory result = new VehicleInfoHistory { coarseVehicleLocationTimeHistories = locHistory, flaggedVehicleFaultEvents = VehicleFaultCodeListToModelList(flaggedEventHistory), vehiclePerformanceEvents = VehiclePerformanceListToModelList(performanceEventHistory), vehicleFaultCodeEvents = VehicleFaultCodeListToModelList(vehicleFaultCodeEventHistory) }; return(result); }
void Getsword() { player = GameObject.FindGameObjectWithTag("Player"); //IM SORRY FOR THIS swordloc = player.transform.GetChild(0).GetChild(3).GetChild(0).GetChild(0).GetChild(0).GetComponent <LocationHistory>(); }
/// <summary> /// Private method for creating a LocationHistoryDetailsDTO from a LocationHistory /// </summary> /// <param name="locationHistory">LocationHistory to be used</param> /// <returns>Data transfer object for location history details</returns> private static LocationHistoryDetailsDTO LocationHistoryToLocationHistoryDetailsDTO(LocationHistory locationHistory) => new LocationHistoryDetailsDTO { RecordId = locationHistory.RecordId, CartId = locationHistory.CartId, CartCoordinates = locationHistory.CartCoordinates, RecordDate = locationHistory.RecordDate, Site = locationHistory.Site };
public async Task PostAsync(LocationHistory _locationHistory) { _unitOfWork.GetRepoInstance <LocationHistory>().Insert(_locationHistory); await _unitOfWork.saveAsync(); }
public HistoryRecorder() { MessagingCenter.Subscribe <HistoryRecorder, HistoryItem>(this, LocationSubmitted, (recorder, historyItem) => LocationHistory.Add(historyItem)); }
public async Task <ActionResult <LocationHistoryDetailsDTO> > AddLocationToHistory(LocationHistoryDTO locationHistoryDTO) { try { var cartIdExists = _context.Carts.Any(c => c.CartId == locationHistoryDTO.CartId); var siteIdExists = _context.Sites.Any(s => s.SiteId == locationHistoryDTO.SiteId); //check if cartid exists if (!cartIdExists && locationHistoryDTO.CartId != null) { //add error message ModelState.AddModelError("CartId", "No cart found with given cart id."); } //check if siteid exists if (!siteIdExists && locationHistoryDTO.SiteId != null) { //add error message ModelState.AddModelError("SiteId", "No site found with given site id."); } //if model is not valid return error messages if (!ModelState.IsValid) { return(BadRequest(ModelState.ToDictionary(x => x.Key, x => x.Value.Errors.Select(e => e.ErrorMessage).ToArray()))); } //tries to parse cart coordinates to NpgsqlPoint. if exception, return bad request var coords = new NpgsqlPoint();; try { coords = NpgsqlPoint.Parse(locationHistoryDTO.CartCoordinates); } catch (FormatException e) { //if exception is caught write to console and return error message Console.WriteLine("{0} Exception caught.", e); //add error message ModelState.AddModelError("CartCoordinates", "Invalid input: CartCoordinates must be specified using the following syntax \'(x,y)\' where x and y are the respective coordinates, as floating-point numbers."); return(BadRequest(ModelState.ToDictionary(x => x.Key, x => x.Value.Errors.Select(e => e.ErrorMessage).ToArray()))); } //create location history var locationHistory = new LocationHistory { CartId = locationHistoryDTO.CartId, SiteId = locationHistoryDTO.SiteId, CartCoordinates = coords, RecordDate = DateTime.Now }; //insert location history _context.LocationHistories.Add(locationHistory); await _context.SaveChangesAsync(); //rerturn the new location history details return(CreatedAtAction( nameof(GetLocationHistoryByRecordId), new { recordId = locationHistory.RecordId }, LocationHistoryToLocationHistoryDetailsDTO(locationHistory))); } catch (InvalidOperationException e) { //if exception is caught write to console and return error message Console.WriteLine("{0} Exception caught.", e); return(BadRequest(new { ApiProblem = "Invalid JSON format sent." })); } }
private void AddLocationHistory(LocationHistory locationHistory, string requestId) { _cache.Set(requestId, locationHistory, TimeSpan.FromMinutes(15)); }
public async Task <LocationHistory> CreateAsync(LocationHistory locationHistory) { locationHistory.Id = await _locationHistoryRepository.InsertAndGetIdAsync(locationHistory); return(locationHistory); }
public void MoveDrone(Vector2D location, Vector2D input, double time) { LocationHistory.Add(new HistoryItem(location, time)); InputHistory.Add(new HistoryItem(input, time)); }
/// <summary> /// Invoked when <see cref="ToEntity"/> operation is about to return. /// </summary> /// <param name="entity"><see cref="LocationHistory"/> converted from <see cref="LocationHistoryDTO"/>.</param> static partial void OnEntity(this LocationHistoryDTO dto, LocationHistory entity);
/// <summary> /// Invoked when <see cref="ToDTO"/> operation is about to return. /// </summary> /// <param name="dto"><see cref="LocationHistoryDTO"/> converted from <see cref="LocationHistory"/>.</param> static partial void OnDTO(this LocationHistory entity, LocationHistoryDTO dto);
public void Delete(int locationHistoryId) { LocationHistory eventO = _context.LocationsHistoriesContext.Find(locationHistoryId); _context.LocationsHistoriesContext.Remove(eventO); }
public void Update(LocationHistory eventO) { _context.Entry(eventO).State = EntityState.Modified; }
public void Insert(LocationHistory eventO) { _context.LocationsHistoriesContext.Add(eventO); }
public async Task <string> Add(LocationHistory employeeLocations) { var t = await _locationMongoDbRepository.AddAsync(employeeLocations); return(t.Id); }