/// <inheritdoc/> public async Task <long> GetLatestRegionSizeAsync(Region region, long lastTimestamp, CancellationToken cancellationToken = default) { // Get boundaries for provided region Point regionPoint = new Point(region.LongitudePrefix, region.LatitudePrefix); // Create LINQ query var queryable = this.Container .GetItemLinqQueryable <InfectionReportRecord>(); RegionBoundary rb = RegionHelper.GetConnectedRegionsRange(region, this.RegionsExtension, this.RegionPrecision); long timeStampFilter = this._getTimestampFilter(lastTimestamp); // Execute query var size = await queryable .Where(r => r.Timestamp > timeStampFilter && r.RegionBoundary.Min.Latitude >= rb.Min.Latitude && r.RegionBoundary.Min.Latitude <= rb.Max.Latitude && r.RegionBoundary.Min.Longitude >= rb.Min.Longitude && r.RegionBoundary.Min.Longitude <= rb.Max.Longitude && r.Version == InfectionReportRecord.CURRENT_RECORD_VERSION ) .Select(r => r.Size) .SumAsync(cancellationToken) .ConfigureAwait(false); return(size); }
/// <inheritdoc/> public async Task <string> InsertAsync(InfectionReport report, Region region, CancellationToken cancellationToken = default) { if (report == null) { throw new ArgumentNullException(nameof(report)); } if (region == null) { throw new ArgumentNullException(nameof(region)); } region = RegionHelper.AdjustToPrecision(region); // Get allowed region boundary RegionBoundary boundary = RegionHelper.GetRegionBoundary(region); var record = new InfectionReportRecord(report) { RegionBoundary = new RegionBoundary(boundary), PartitionKey = InfectionReportRecord.GetPartitionKey(region) }; ItemResponse <InfectionReportRecord> response = await this.Container .CreateItemAsync <InfectionReportRecord>( record, new PartitionKey(record.PartitionKey), cancellationToken : cancellationToken ); return(response.Resource.Id); }
private void AssertRegionBounary(RegionBoundary expected, RegionBoundary actual) { Assert.AreEqual(expected.Min.Latitude, actual.Min.Latitude); Assert.AreEqual(expected.Max.Latitude, actual.Max.Latitude); Assert.AreEqual(expected.Min.Longitude, actual.Min.Longitude); Assert.AreEqual(expected.Max.Longitude, actual.Max.Longitude); }
void TestRegion(double lat, double lon, int precision, Tuple <double, double> first, Tuple <double, double> second) { var region = new Region { LatitudePrefix = lat, LongitudePrefix = lon, Precision = precision }; RegionBoundary rb = RegionHelper.GetRegionBoundary(region); Assert.AreEqual(rb.Min.Latitude, first.Item1); Assert.AreEqual(rb.Min.Longitude, first.Item2); Assert.AreEqual(rb.Max.Latitude, second.Item1); Assert.AreEqual(rb.Max.Longitude, second.Item2); }
///<summary> ///For given region, target precision and extension size, ///returns region boundary that gives available ranges of latitude/longitude ///for regions of target precision, overlapping with extension of given region /// </summary> /// <param name="region">Source <see cref="Region"/></param> /// <param name="extension">Size of region extension (in precision-aligned steps)</param> /// <param name="precision"> Target precision parameter. Any integer value.</param> /// <returns>Region boundary rb. Every region with Lat/Lon of corresponding RegionBoundary's min /// belonging to rb overlaps with extension of given region <see cref="Region"/> objects</returns> public static RegionBoundary GetConnectedRegionsRange(Region region, int extension, int precision) { RegionBoundary rb = RegionHelper.GetRegionBoundary(region); double step = PrecisionHelper.GetStep(precision); rb.Min.Latitude -= extension * step; rb.Min.Longitude -= extension * step; rb.Max.Latitude += (extension - 1) * step; rb.Max.Latitude += (extension - 1) * step; return rb; }
/// <summary> /// Creates a new <see cref="RegionBoundaryProperty"/> instance /// </summary> /// <param name="boundary">Source <see cref="RegionBoundary"/></param> public RegionBoundaryProperty(RegionBoundary boundary) { if (boundary != null) { this.Max = new Location { Longitude = boundary.Max.Longitude, Latitude = boundary.Max.Latitude }; this.Min = new Location { Longitude = boundary.Min.Longitude, Latitude = boundary.Min.Latitude }; } else { throw new ArgumentNullException(nameof(boundary)); } }
public string GenerateDownloadPackage(DateTime from, DateTime to, string region, int north, int south, int west, int east, string product, string format) { int result = 0; string dateFormatString = @"yyyy-MM-dd"; string dateTimeFormatString = @"yyyy-MM-dd hh:mm:ss"; int queryProductId = ConvertProductStringToId(product); if (queryProductId == 1 || queryProductId == 6) // For viirs { Region regionValue = RegionUtil.GetRegionFromDisplayName(region); if (north == -1000 || south == -1000 || west == -1000 || east == -1000) { RegionBoundary boundary = GetRegionBoundary(regionValue); north = boundary.North; south = boundary.South; west = boundary.West; east = boundary.East; } } else { north = 90; south = -90; west = -180; east = 180; } string downloadTaskName = DateTime.UtcNow.ToString("yyyy_MM_dd") + "_" + DateTime.UtcNow.Ticks.ToString(); using (MySqlConnection connection = new MySqlConnection(DatabaseConnectionstring)) { string queryCommandTextFormat = "INSERT INTO jpssflood.downloadtasks_v2 (CreatedTime, Name, StartTime, EndTime, Step, Product, Region, North, South, West, East, ProcessStartTime, ProcessEndTime, ImageFormat, Status) "; queryCommandTextFormat += "VALUES('{0}', '{1}', '{2}', '{3}', {4}, {5}, {6}, {7}, {8}, {9}, {10}, '{11}', '{12}', '{13}', {14})"; connection.Open(); MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.CommandText = string.Format(queryCommandTextFormat, DateTime.UtcNow.ToString(dateTimeFormatString) /*CreatedTime*/, downloadTaskName /*Name*/, from.ToString(dateFormatString) /*StartTime*/, to.ToString(dateFormatString) /*EndTime*/, 1, queryProductId, 1, north, south, west, east, DateTime.MinValue.ToString(dateTimeFormatString) /*ProcessStartTime*/, DateTime.MinValue.ToString(dateTimeFormatString) /*ProcessEndTime*/, format /*ImageFormat*/, 1 /*Status*/); result = command.ExecuteNonQuery(); } return(result == 1 ? downloadTaskName : string.Empty); }
public void Verify() { if (!IsGlobal && RegionBoundary.Count < 2) { throw new AnalyticalServicesException(23600, "RegionBoundary must have at least two boundary points"); } RegionBoundary.ForEach(bp => bp.Verify()); if (GridIncrement <= 0) { throw new AnalyticalServicesException(23600, "GridIncrement must be greater than 0."); // todo eventually check for this value; //(GridArea)^2/(PointArea)^2 * runDuration/timestep = constant. } OutputSettings.Verify(); }
/// <summary> /// Enumerates all regions of given precisions range connected with given <see cref="Region"/>/> /// Being connected means either intersects with the region extended by overlap amount of precision-aligned grids /// </summary> /// <param name="region">Source <see cref="Region"/></param> /// <param name="extension">Size of region extension (in precision-aligned steps)</param> /// <param name="precisionStart"> Start precision parameter. Any integer value.</param> /// <param name="precisionCount"> Count of precision parameters to include. Any non-negative integer value.</param> /// <returns>Collection of connected <see cref="Region"/> objects</returns> public static IEnumerable<Region> GetConnectedRegions(Region region, int extension, int precisionStart, int precisionCount = 1) { RegionBoundary rb = GetRegionBoundary(region); for (int precision = precisionStart; precision < precisionStart + precisionCount; ++precision) { double step = PrecisionHelper.GetStep(precision); for (double lat = rb.Min.Latitude - extension * step; lat < rb.Max.Latitude + extension * step; lat += step) { for (double lon = rb.Min.Longitude - extension * step; lon < rb.Max.Longitude + extension * step; lon += step) { yield return new Region { LatitudePrefix = lat, LongitudePrefix = lon, Precision = precision }; } } } }
/// <inheritdoc/> public async Task <IEnumerable <InfectionReportMetadata> > GetLatestAsync(Region region, long lastTimestamp, CancellationToken cancellationToken = default) { // Get boundaries for provided region Point regionPoint = new Point(region.LongitudePrefix, region.LatitudePrefix); // Create LINQ query var queryable = this.Container .GetItemLinqQueryable <InfectionReportRecord>(); RegionBoundary rb = RegionHelper.GetConnectedRegionsRange(region, this.RegionsExtension, this.RegionPrecision); long timeStampFilter = this._getTimestampFilter(lastTimestamp); // Execute query var iterator = queryable .Where(r => r.Timestamp > timeStampFilter && r.RegionBoundary.Min.Latitude >= rb.Min.Latitude && r.RegionBoundary.Min.Latitude <= rb.Max.Latitude && r.RegionBoundary.Min.Longitude >= rb.Min.Longitude && r.RegionBoundary.Min.Longitude <= rb.Max.Longitude && r.Version == InfectionReportRecord.CURRENT_RECORD_VERSION ) .Select(r => new InfectionReportMetadata { Id = r.Id, Timestamp = r.Timestamp }) .ToFeedIterator(); List <InfectionReportMetadata> results = new List <InfectionReportMetadata>(); while (iterator.HasMoreResults) { results.AddRange(await iterator.ReadNextAsync()); } return(results); }
//********************************************** protected virtual void Start() { boundary = transform.parent.GetComponent <RegionBoundary>(); Debug.Log(boundary); mobAnimator = transform.GetComponent <Animator>(); rb = transform.GetComponent <Rigidbody2D>(); currentHealth = 10f; playerPosition = GameObject.FindGameObjectWithTag(TagHelper.Player).transform; playerMask = LayerMask.GetMask(MaskHelper.Player); noticePlayer = false; timeReset = 5f; lookRight = true; lastPosX = transform.position.x; #region attack setting cooldownReset = iniCooldown; attackPoint = transform.Find(ObjectChilds.AttackPoint).transform; attackSize = new Vector2(MobAttackRangeX, MobAttackRangeY); #endregion //---------------- #region enemy behaviour isPatrolling = false; canRun = true; attackMode = false; cooldown = false; hitWall = false; canFollow = false; #endregion #region patrol setting leftBound = transform.parent.Find("LeftBound").transform.position.x; rightBound = transform.parent.Find("RightBound").transform.position.x; #endregion #region Tresure Drop coinPreb = Resources.Load <GameObject>("Coin"); gemPreb = Resources.Load <GameObject>("Gem"); #endregion }
private RegionBoundary GetRegionBoundary(Region region) { RegionBoundary boundary = new RegionBoundary { North = 90, South = -90, West = -180, East = 180 }; switch (region) { case Region.All: break; case Region.NorthAmerica: boundary.North = 72; boundary.South = 14; boundary.West = -168; boundary.East = -48; break; case Region.SouthAmerica: boundary.North = 14; boundary.South = -58; boundary.West = -84; boundary.East = -33; break; case Region.Europe: boundary.North = 72; boundary.South = 34; boundary.West = -25; boundary.East = 41; break; case Region.Africa: boundary.North = 34; boundary.South = -35; boundary.West = -17; boundary.East = 52; break; case Region.Asia: boundary.North = 54; boundary.South = -12; boundary.West = 32; boundary.East = 142; break; case Region.Australia: boundary.North = -3; boundary.South = -48; boundary.West = 112; boundary.East = 180; break; case Region.USAlaska: boundary.North = 72; boundary.South = 54; boundary.West = -169; boundary.East = -129; break; case Region.USNorthEast: boundary.North = 52; boundary.South = 35; boundary.West = -91; boundary.East = -66; break; case Region.USNorthCentral: boundary.North = 54; boundary.South = 35; boundary.West = -106; boundary.East = -81; break; case Region.USSouthEast: boundary.North = 36; boundary.South = 24; boundary.West = -91; boundary.East = -75; break; case Region.USMissouriBasin: boundary.North = 53; boundary.South = 36; boundary.West = -115; boundary.East = -90; break; case Region.USWestGulf: boundary.North = 40; boundary.South = 23; boundary.West = -115; boundary.East = -90; break; case Region.USNorthWest: boundary.North = 52; boundary.South = 35; boundary.West = -125; boundary.East = -113; break; case Region.USSouthWest: boundary.North = 45; boundary.South = 28; boundary.West = -125; boundary.East = -113; break; default: break; } return(boundary); }