private TimeSpan ComputeDuration(List <GPSLogEntry> entries) { int start = -1; int end = -1; for (int i = 0; i < entries.Count - 1; i++) { if (Constants.MIN_SPEED <= GlobalPoint.Distance(entries[i + 1], entries[i]) / ((double)(entries[i + 1].Time.Ticks - entries[i].Time.Ticks) / TimeSpan.TicksPerSecond)) { start = i; break; } } for (int i = entries.Count - 1; i > 0; i--) { if (Constants.MIN_SPEED <= GlobalPoint.Distance(entries[i - 1], entries[i]) / ((double)(entries[i].Time.Ticks - entries[i - 1].Time.Ticks) / TimeSpan.TicksPerSecond)) { end = i; break; } } if (start < end && start != -1) { new TimeSpan(entries[end].Time.Ticks - entries[start].Time.Ticks); } return(new TimeSpan(entries[entries.Count - 1].Time.Ticks - entries[0].Time.Ticks)); }
private static List <GPSLogEntry> GetApproximatingNodes(List <GPSLogEntry> fullSet, int targetCount = 7) { const double step = 0.0001; // the stemp by which bioas is incremented. const int minModificationsPerRun = 20; // allows to increase bias even if modifications were performed. int strictBiasBound = targetCount * 16; // defines the bound after which optimisations are removed List <GPSLogEntry> a, b; a = fullSet; b = new List <GPSLogEntry>(fullSet.Count); int modified = 0; double bias = 0; double sum = 0; double avg = 1; while (a.Count > targetCount) { //Console.WriteLine(a.Count + " bias: " + bias + " avg: " + avg); b.Add(a[0]); for (int i = 1; i < a.Count - 1; i++) { double A = GlobalPoint.Distance(a[i - 1], a[i]); // distancec too previus node double B = GlobalPoint.Distance(a[i + 1], a[i]); // distance to the next node double C = GlobalPoint.Distance(a[i - 1], a[i + 1]); // distance between neighbouring nodes //removes nodes with the least impact on total length (favours removal of nodes with nodes closer than average) if (A + B <= C * (1 + bias * (avg / C))) { modified++; i++; b.Add(a[i]); sum += C; } else { b.Add(a[i]); sum += A; } } if (!b[b.Count - 1].Equals(a[a.Count - 1])) { b.Add(a[a.Count - 1]); } if (modified < minModificationsPerRun && (b.Count > strictBiasBound || modified <= 1)) { bias += step; } else { modified = 0; } //formula works better if avg value is less than true average; Mhen list is small, correction for length is too great, thus avg value is locked at final stages avg = (a.Count >= strictBiasBound) ? (avg + avg + (sum / b.Count)) / 3 : avg; a = b; b = new List <GPSLogEntry>(a.Count); } return(a); }
public double CalculateDistance(GlobalPoint start, GlobalPoint end) { GeoCoordinate pin1 = new GeoCoordinate(start.Latitude, start.Longitude); GeoCoordinate pin2 = new GeoCoordinate(end.Latitude, end.Longitude); double distanceBetween = pin1.GetDistanceTo(pin2); return(distanceBetween); }
private bool IsDaylight(GlobalPoint point) { var above = point.Step(Direction.ABOVE); if (above == null) { return(true); } return(!above.IsSolid() && above.GetDepth() == MIN_DEPTH); }
public string GetInfo(Vector3 corner) { int x = (int)(corner.x - (position.x - 0.5f) * Cell.ROW_SIZE); int y = (int)(corner.y - (position.y - 0.5f) * Cell.ROW_SIZE); int z = (int)(corner.z - (position.z - 0.5f) * Cell.ROW_SIZE); var globalPoint = new GlobalPoint(this, new Point(x, y, z)); return(globalPoint + "\nDensity: " + globalPoint.GetDensity() + ", Depth: " + (0xff & globalPoint.GetDepth())); }
public async Task <bool> ExcelUploadAsync(ExcelUploadDto excelUploadDto) { if (excelUploadDto.ExcelFile != null && (Path.GetExtension(excelUploadDto.ExcelFile.FileName).Equals(".xlsx") || Path.GetExtension(excelUploadDto.ExcelFile.FileName).Equals(".xls"))) { using (var stream = new MemoryStream()) { await excelUploadDto.ExcelFile.CopyToAsync(stream); using (ExcelPackage ep = new ExcelPackage(stream)) { ExcelWorksheet worksheet = ep.Workbook.Worksheets[0]; int rowsCount = worksheet.Dimension.Rows; for (int row = 2; row <= rowsCount; row++) { GlobalPoint globalPoint = new GlobalPoint { Latitude = (float)(double)(worksheet.Cells[row, 2].Value), Longitude = (float)(double)(worksheet.Cells[row, 3].Value) }; Airport airport = new Airport { AirportName = worksheet.Cells[row, 1].Value.ToString(), GlobalPoint = globalPoint }; Airport isExist = _appDbContext.Airport .SingleOrDefault(m => m.AirportName == airport.AirportName); if (isExist != null) { _appDbContext.Airport.Remove(isExist); _appDbContext.GlobalPoint.Remove(isExist.GlobalPoint); } await _appDbContext.GlobalPoint.AddAsync(globalPoint); await _appDbContext.Airport.AddAsync(airport); } await _appDbContext.SaveChangesAsync(); } } return(true); } else { return(false); } }
private double ComputeLength(List <GPSLogEntry> entries, bool approximate = false) { GPSLogEntry prev = null; double ret = 0; foreach (var entry in entries) { if (!approximate || entry.ApproximatingFix) { if (prev != null) { ret += GlobalPoint.Distance(prev, entry); } prev = entry; } } return(ret); }
internal async Task <bool> IsGlobalPointValidForNewAirfield(Airfield airfield) { var temp = await _airfieldRepository.FilterListShallowAsync(ent => GlobalPoint.Distance(ent, airfield) < 2 *Constants.AIRFIELD_DESIGNATED_AREA_RADIUS); return(temp.Count == 0); }
public void Init() { // TODO As new chunks are loaded, we need some way to initialize those // without changing more points in the existing chunks than absolutly // neccessary. // Reset the depth value in each chunk in the graph to 0xff. // Also enqueue all chunks without any chunk above them and use these as // the base for the daylight check. var daylightQueue = new Queue <Chunk>(); owner.ForEachChunk(chunk => { chunk.GetLuminance().FillDepth(MAX_DEPTH); if (!chunk.HasNeighbour(Direction.ABOVE)) { daylightQueue.Enqueue(chunk); } }); var globalPoints = new Queue <GlobalPoint>(); // Process the queue of chunks that have been hit by daylight by setting // the depth of all points without anything above them to 0. Continue // by queueing up all chunks below until solid density is encountered. while (daylightQueue.Count > 0) { var current = daylightQueue.Dequeue(); var currentLuminance = current.GetLuminance(); var above = current.GetNeighbour(Direction.ABOVE); long daylightMaskAbove = above == null ? -1L : above.GetLuminance().bottomDaylightMask; currentLuminance.bottomDaylightMask = 0L; for (int i = 0; i < Point.PLANE_SIZE; i++) { var bit = 0x1L << i; if ((daylightMaskAbove & bit) != 0) { for (int j = Point.ROW_SIZE - 1; j >= 0; j--) { var point = new Point(i % Point.ROW_SIZE, j, i / Point.ROW_SIZE); var density = current.GetDensity(point); var globalPoint = new GlobalPoint(current, point); if (density <= MarchingCubes.DENSITY_THRESHOLD) { globalPoint.SetDepth(MIN_DEPTH); globalPoints.Enqueue(globalPoint); } else { globalPoint.SetDepth(0x1); break; } } } // If we hit the bottom of this chunk with daylight, mark it in // the bitset if (currentLuminance.depths[i] == MIN_DEPTH) { currentLuminance.bottomDaylightMask |= bit; } } // If at least one point of daylight reached the bottom layer, // enqueue the chunk below this one if (currentLuminance.bottomDaylightMask != 0L) { var below = current.GetNeighbour(Direction.BELOW); if (below != null) { daylightQueue.Enqueue(below); } } } // We now have a queue of all the points in the world that are located // directly under the sun. Process them in breadth-first order, setting // the depth of every additional point visited to the depth of the // previously visited point + 1. while (globalPoints.Count > 0) { var point = globalPoints.Dequeue(); var d = point.GetDepth(); if ((d & 0xff) < 0xff) { for (int n = 0; n < 6; n++) { var direction = (Direction)n; var nextPoint = point.Step(direction); if (nextPoint != null) { if (nextPoint.IsMaxDepth()) { nextPoint.SetDepth((byte)((0xff & d) + 1)); if (nextPoint.GetDensity() <= MarchingCubes.DENSITY_THRESHOLD) { globalPoints.Enqueue(nextPoint); } } } } } else { break; } } }
public void DataMining() { List <PilotLog> pilotLogs = _appDbContext.PilotLog.ToList(); foreach (var pilotLog in pilotLogs) { string text = System.Text.Encoding.UTF8.GetString(pilotLog.File); List <string> file = new List <string>(); string[] arr = text.Split('\n'); foreach (string item in arr) { file.Add(item); } string datumUnformed = file[1]; string datumYear = "20" + datumUnformed.Substring(9, 2); string datumMonth = datumUnformed.Substring(7, 2); string datumDay = datumUnformed.Substring(5, 2); // this is the FlightDate DateTime flightDate = new DateTime( Int32.Parse(datumYear), Int32.Parse(datumMonth), Int32.Parse(datumDay)); //select records, which begins with B foreach (string record in file) { if (record.IndexOf('B').Equals(0)) { string time = record.Substring(1, 6); string lati = record.Substring(7, 7); string longi = record.Substring(15, 8); string[] selector = new string[] { time, lati, longi }; gps.Add(selector); } } //find departure time and place string[] inspectorDep = new string[] { gps[0][0], gps[0][1], gps[0][2] }; inspectorDep = FindDepTimeAndPlace(inspectorDep); // find arrive time and place string[] inspectorArr = new string[] { gps[gps.Count - 1][0], gps[gps.Count - 1][1], gps[gps.Count - 1][2] }; inspectorArr = FindArrTimeAndPlace(inspectorArr); //calculate dep time: DateTime depTime = CalculateTime(inspectorDep[0], flightDate); //calculate arrive time DateTime arrTime = CalculateTime(inspectorArr[0], flightDate); // this is the FlightTime var flightTime = arrTime - depTime; // this is the dep place (GlobalPoint) float latitudeDep = GetLatitude(inspectorDep[1]); float longitudeDep = GetLongitude(inspectorDep[2]); // this is the arr place (GlobalPoint) float latitudeArr = GetLatitude(inspectorArr[1]); float longitudeArr = GetLongitude(inspectorArr[2]); GlobalPoint gpDep = new GlobalPoint { Latitude = latitudeDep, Longitude = longitudeDep }; GlobalPoint gpArr = new GlobalPoint { Latitude = latitudeArr, Longitude = longitudeArr }; Flight newFlightRecord = new Flight { FlightDate = flightDate, FlightTime = flightTime, TakeoffPlace = gpDep, LandPlace = gpArr, Status = Status.Waiting_For_Accept, UserId = pilotLog.UserId, }; // insert the new records into database: _appDbContext.GlobalPoint.Add(gpDep); _appDbContext.GlobalPoint.Add(gpArr); _appDbContext.Flight.Add(newFlightRecord); // remove from pilotlog db table the processed record _appDbContext.PilotLog.Remove(pilotLog); //calculate all of gps records for (int i = 0; i < gps.Count; i++) { GlobalPoint globalPoint = new GlobalPoint { Latitude = GetLatitude(gps[i][1]), Longitude = GetLongitude(gps[i][2]) }; Gps Gps = new Gps { TimeMoment = CalculateTime(gps[i][0], flightDate), GlobalPoint = globalPoint, Flight = newFlightRecord }; _appDbContext.GlobalPoint.Add(globalPoint); _appDbContext.Gps.Add(Gps); } _appDbContext.SaveChanges(); } }
public Task <Airfield> FindAround(IGlobalPoint globalPoint) { return(GetFullIncludes() .SingleAsync(ent => GlobalPoint.Distance(ent, globalPoint) <= Constants.AIRFIELD_DESIGNATED_AREA_RADIUS)); }