public GetRegionCommand( IRegionCache regionCache, RegionMapper regionMapper) { _regionCache = regionCache; _regionMapper = regionMapper; }
private void ExecuteTest(RegionMapper mapper, int startPosition, int?endPosition, List <CalledAllele> expectedAlleles, bool mapAll = false) { var noCalls = new List <CalledAllele>(); CalledAllele noCall; while ((noCall = mapper.GetNextEmptyCall(startPosition, endPosition)) != null) { noCalls.Add(noCall); } Assert.Equal(expectedAlleles.Count, noCalls.Count()); foreach (var noCallResult in noCalls) { Assert.True(expectedAlleles.Any(e => e.ReferencePosition == noCallResult.ReferencePosition && e.ReferenceAllele == noCallResult.ReferenceAllele && e.AlternateAllele == noCallResult.AlternateAllele && e.Chromosome == noCallResult.Chromosome && e.Genotype == noCallResult.Genotype)); Assert.True(noCallResult.Filters.Contains(FilterType.LowDepth)); Assert.Equal(1, noCallResult.Filters.Count); } }
public QueryNumbers(CfQueryNumbers source) { MaxResults = source.MaxResults; FirstResult = source.FirstResult; Region = RegionMapper.ToRegion(source.Region); LabelName = source.LabelName; }
public CreateRegionCommand( IUserAuthorizationService userAuthorizationService, CoreDbContext coreDbContext, RegionMapper regionMapper) { _userAuthorizationService = userAuthorizationService; _coreDbContext = coreDbContext; _regionMapper = regionMapper; }
public CfRegionQueryResult QueryRegions(CfRegionQuery queryRegions) { var resourceList = BaseRequest <ResourceList>(HttpMethod.Get, new RegionQuery(queryRegions), new CallfireRestRoute <Number>(null, NumberRestRouteObjects.Regions, null)); var region = resourceList.Resource == null ? null : resourceList.Resource.Select(r => RegionMapper.FromRegion((Region)r)).ToArray(); return(new CfRegionQueryResult(resourceList.TotalResults, region)); }
public void Map() { // set up test var intervals = new List <Region> { new Region(4, 10), new Region(15, 17), new Region(25, 39), new Region(50, 55), new Region(60, 70), new Region(80, 80) }; var mapper = new RegionMapper(_chrReference, new ChrIntervalSet(intervals, "chr1"), 20); // ------------------------------------ // coverage starts after interval start - make sure beginning positions arent skipped // ------------------------------------ var expectedAlleles = new List <CalledAllele>(); AddReferenceNoCallsByRange(expectedAlleles, new List <Tuple <int, int> >() { new Tuple <int, int>(6, 10) }); ExecuteTest(mapper, 6, 11, expectedAlleles); // ------------------------------------ // skip second interval, fully covers third interval and partially the fourth // ------------------------------------ expectedAlleles.Clear(); AddReferenceNoCallsByRange(expectedAlleles, new List <Tuple <int, int> >() { new Tuple <int, int>(25, 39), new Tuple <int, int>(50, 52), }); ExecuteTest(mapper, 20, 52, expectedAlleles); // ------------------------------------ // empty region - no interval overlap // ------------------------------------ expectedAlleles.Clear(); ExecuteTest(mapper, 56, 59, expectedAlleles); // ------------------------------------ // all the rest // ------------------------------------ expectedAlleles.Clear(); AddReferenceNoCallsByRange(expectedAlleles, new List <Tuple <int, int> >() { new Tuple <int, int>(80, 80) }); ExecuteTest(mapper, 71, null, expectedAlleles, true); }
public Number(CfNumber source) { Number1 = source.Number1; NationalFormat = source.NationalFormat; TollFree = source.TollFree; Region = RegionMapper.ToRegion(source.Region); if (source.Status.HasValue) { Status = EnumeratedMapper.ToSoapEnumerated <NumberStatus>(source.Status.Value.ToString()); StatusSpecified = true; } LeaseInfo = LeaseInfoMapper.ToLeaseInfo(source.LeaseInfo); NumberConfiguration = NumberConfigurationMapper.ToNumberConfiguration(source.NumberConfiguration); }
public RegionRepository() { regionMapper = new RegionMapper(); }
public RegionService() { regionRepository = new RegionRepository(); regionMapper = new RegionMapper(); }
/// <summary> /// Creates a consolidated pricing term from a regularly formatted pricing term /// that comes directly from the price list API. Used when you've already identified the on /// demand pricing term and have separated out just the reserved pricing terms. /// </summary> /// <param name="product"></param> /// <param name="ondemand"></param> /// <param name="reservedterms"></param> /// <returns></returns> public static IEnumerable <ReservedInstancePricingTerm> Build(Product product, PricingTerm ondemand, IEnumerable <PricingTerm> reservedterms) { if (product == null) { throw new ArgumentNullException("product"); } if (ondemand == null) { throw new ArgumentNullException("ondemand"); } if (reservedterms == null) { throw new ArgumentNullException("reservedterms"); } if (!reservedterms.Any()) { throw new ArgumentException("You must supply at least 1 reserved term."); } double onDemandCost = -1; // Get the on demand hourly cost // DynamoDB has free tier price dimensions in the same on demand object, so make // sure we pick the first that does not have free tier in the description KeyValuePair <string, PriceDimension> dimension = ondemand.PriceDimensions.FirstOrDefault(x => !x.Value.Description.Contains(FREE_TIER, StringComparison.OrdinalIgnoreCase)); if (dimension.Value == null) { onDemandCost = 0; } else if (!Double.TryParse(dimension.Value.PricePerUnit.First().Value, out onDemandCost)) { throw new FormatException($"Could not parse the on demand price {dimension.Value.PricePerUnit.First().Value} for sku: {product.Sku}."); } string platform = GetPlatform(product); string region = RegionMapper.GetRegionFromUsageType(product.Attributes.GetValueOrDefault("usagetype")); // Only EC2 has tenancy if (!product.Attributes.TryGetValue("tenancy", out string tenancy)) { tenancy = "Shared"; } // Each pricing term will have the price dimensions for the upfront and recurring costs foreach (PricingTerm term in reservedterms) { PriceDimension upfront = term.PriceDimensions .Select(x => x.Value) .FirstOrDefault(x => !String.IsNullOrEmpty(x.Description) && x.Description.Equals("upfront fee", StringComparison.OrdinalIgnoreCase)); PriceDimension recurring = term.PriceDimensions .Select(x => x.Value) .FirstOrDefault(x => !String.IsNullOrEmpty(x.Description) && !x.Description.Equals("upfront fee", StringComparison.OrdinalIgnoreCase)); double hourlyRecurring = 0; // Only check for recurring, since some may have no upfront if (recurring == null) { // This should never happen throw new KeyNotFoundException($"The pricing term in {product.Attributes.GetValueOrDefault("servicecode")} for sku {term.Sku} and offer term code {term.OfferTermCode} did not contain a price dimension for hourly usage charges."); } else { // Parse out the rate if (!Double.TryParse(recurring.PricePerUnit.First().Value, out hourlyRecurring)) { throw new FormatException($"Could not parse the recurring price per unit of {recurring.PricePerUnit.First().Value} for sku {term.Sku}, offer term code {term.OfferTermCode}, in service {product.Attributes.GetValueOrDefault("servicecode")}."); } } double upfrontFee = 0; if (upfront != null) { // Parse out upfront fee if (!Double.TryParse(upfront.PricePerUnit.First().Value, out upfrontFee)) { throw new FormatException($"Could not parse the upfront cost of {upfront.PricePerUnit.First().Value} for sku {term.Sku}, offer term code {term.OfferTermCode}, in service {product.Attributes.GetValueOrDefault("servicecode")}."); } } string operatingSystem = String.Empty; if (product.Attributes.ContainsKey("operatingsystem")) { operatingSystem = product.Attributes.GetValueOrDefault("operatingsystem"); } else { operatingSystem = platform; } int vCPU = 0; if (product.Attributes.ContainsKey("vcpu")) { Int32.TryParse(product.Attributes.GetValueOrDefault("vcpu"), out vCPU); } double memory = 0; if (product.Attributes.ContainsKey("memory")) { string memoryString = product.Attributes.GetValueOrDefault("memory").Replace(",", ""); Match memoryMatch = _MemoryRegex.Match(memoryString); if (memoryMatch.Success) { Double.TryParse(memoryMatch.Groups[1].Value, out memory); } } string usageType = product.Attributes.GetValueOrDefault("usagetype"); string instanceType = usageType; if (product.Attributes.ContainsKey("instancetype")) { instanceType = product.Attributes.GetValueOrDefault("usagetype"); } yield return(new ReservedInstancePricingTerm( term.Sku, term.OfferTermCode, product.Attributes.GetValueOrDefault("servicecode"), platform, operatingSystem, instanceType, product.Attributes.GetValueOrDefault("operation"), usageType, tenancy, region, vCPU, memory, onDemandCost, hourlyRecurring, upfrontFee, term.TermAttributes.LeaseContractLength, term.TermAttributes.PurchaseOption, term.TermAttributes.OfferingClass, AWSPriceListApi.Model.Term.RESERVED )); } }
/// <summary> /// Builds a row item from the current line of the csv reader, this method /// does not change the position of the csv reader. If the row item /// does not describe a "reservable" charge, then null is returned /// </summary> /// <param name="reader">The csv reader to read from</param> /// <returns></returns> public static CsvRowItem Build(CsvReader reader) { string instanceType = String.Empty; // The field names are case sensitive if (reader.TryGetField <string>("operation", out string operation) && !String.IsNullOrEmpty(operation) && reader.TryGetField <string>("usagetype", out string usageType) && allUsageTypes.IsMatch(usageType) && reader.TryGetField <string>("servicecode", out string serviceCode) && !String.IsNullOrEmpty(serviceCode) && (Constants.InstanceBasedReservableServices.Contains(serviceCode) ? reader.TryGetField("instance type", out instanceType) : true) ) { reader.TryGetField <string>("sku", out string sku); reader.TryGetField <double>("priceperunit", out double pricePerUnit); reader.TryGetField <string>("leasecontractlength", out string leaseContractLength); reader.TryGetField <string>("pricedescription", out string priceDescription); reader.TryGetField <string>("offertermcode", out string offerTermCode); reader.TryGetField <int>("vcpu", out int vCPU); reader.TryGetField <string>("memory", out string memoryString); double memory = 0; if (!String.IsNullOrEmpty(memoryString)) { memoryString = memoryString.Replace(",", ""); Match memoryMatch = memoryRegex.Match(memoryString); if (memoryMatch.Success) { Double.TryParse(memoryMatch.Groups[1].Value, out memory); } } Term termType = Term.ON_DEMAND; if (reader.TryGetField <string>("termtype", out string termString)) { termType = EnumConverters.ConvertToTerm(termString); } if (String.IsNullOrEmpty(instanceType)) { // This will probably only happen for DynamoDB instanceType = usageType; } PurchaseOption purchaseOption = PurchaseOption.ON_DEMAND; if (reader.TryGetField <string>("purchaseoption", out string PurchaseOptionString)) { purchaseOption = EnumConverters.ConvertToPurchaseOption(PurchaseOptionString); } OfferingClass offeringClass = OfferingClass.STANDARD; if (reader.TryGetField <string>("offeringclass", out string offeringClassString)) { offeringClass = EnumConverters.ConvertToOfferingClass(offeringClassString); } // Only EC2 has tenancy if (!reader.TryGetField <string>("tenancy", out string tenancy)) { tenancy = "Shared"; } int lease = String.IsNullOrEmpty(leaseContractLength) ? 0 : Int32.Parse(Regex.Match(leaseContractLength, "^([0-9]+)").Groups[1].Value); string platform = GetPlatform(reader); if (!reader.TryGetField <string>("operating system", out string operatingSystem)) { if (!String.IsNullOrEmpty(platform)) { operatingSystem = platform; } else { operatingSystem = serviceCode; } } return(new CsvRowItem( sku, offerTermCode, termType, lease, pricePerUnit, vCPU, memory, purchaseOption, offeringClass, tenancy, instanceType, platform, operatingSystem, operation, usageType, serviceCode, RegionMapper.GetRegionFromUsageType(usageType), priceDescription )); } else { return(null); } }
// Source: https://www.czso.cz/csu/czso/pocet-obyvatel-v-obcich-k-112019 static void Main(string[] args) { var db = new ApplicationDbContext(); CsvParserOptions csvParserOptions = new CsvParserOptions(false, ';'); // Console.WriteLine("-- Purging all tables --"); db.Populations.RemoveRange(db.Populations.ToArray()); db.Municipalities.RemoveRange(db.Municipalities.ToArray()); db.Districts.RemoveRange(db.Districts.ToArray()); db.Regions.RemoveRange(db.Regions.ToArray()); db.SaveChanges(); // Console.WriteLine("-- Setting regions --"); RegionMapper csvRegionMapper = new RegionMapper(); CsvParser <Region> csvRegionParser = new CsvParser <Region>(csvParserOptions, csvRegionMapper); var regions = csvRegionParser .ReadFromFile(@"Files/Regions.csv", Encoding.UTF8) .ToList(); foreach (var item in regions) { Console.WriteLine(item.Result.Name); db.Regions.Add(item.Result); } db.SaveChanges(); // Console.WriteLine("-- Setting districts --"); DistrictMapper csvDistrictMapper = new DistrictMapper(); CsvParser <District> csvDistrictParser = new CsvParser <District>(csvParserOptions, csvDistrictMapper); var districts = csvDistrictParser .ReadFromFile(@"Files/Districts.csv", Encoding.UTF8) .ToList(); foreach (var item in districts) { Console.WriteLine(item.Result.Name); db.Districts.Add(item.Result); } db.SaveChanges(); // Console.WriteLine("-- Setting municipalities --"); MunicipalityMapper csvMunicipalityMapper = new MunicipalityMapper(); CsvParser <MunicipalityPopulation> csvMunicipalityParser = new CsvParser <MunicipalityPopulation>(csvParserOptions, csvMunicipalityMapper); var municipalities2020 = csvMunicipalityParser .ReadFromFile(@"Files/2020.csv", Encoding.UTF8) .ToList(); foreach (var item in municipalities2020) { Console.WriteLine(item.Result.Name); db.Municipalities.Add(new Municipality { LAU1 = item.Result.LAU1, LAU2 = item.Result.LAU2, Name = item.Result.Name, }); } db.SaveChanges(); Console.WriteLine("-- Adding population data 2020 --"); foreach (var item in municipalities2020) { Console.WriteLine(item.Result.Name); db.Populations.Add(new Population { LAU2 = item.Result.LAU2, Year = 2020, Total = item.Result.Total, Men = item.Result.Men, Women = item.Result.Women, Age = Convert.ToDouble(item.Result.Age), MensAge = Convert.ToDouble(item.Result.MensAge), WomensAge = Convert.ToDouble(item.Result.WomensAge) }); } db.SaveChanges(); var municipalities2019 = csvMunicipalityParser .ReadFromFile(@"Files/2019.csv", Encoding.UTF8) .ToList(); Console.WriteLine("-- Adding population data 2019 --"); foreach (var item in municipalities2019) { Console.WriteLine(item.Result.Name); db.Populations.Add(new Population { LAU2 = item.Result.LAU2, Year = 2019, Total = item.Result.Total, Men = item.Result.Men, Women = item.Result.Women, Age = Convert.ToDouble(item.Result.Age), MensAge = Convert.ToDouble(item.Result.MensAge), WomensAge = Convert.ToDouble(item.Result.WomensAge) }); } db.SaveChanges(); }
public SearchAvailableNumbers(CfSearchAvailableNumbers source) { Region = RegionMapper.ToRegion(source.Region); TollFree = source.TollFree; Count = source.Count; }
public RegionQuery(CfRegionQuery source) { MaxResults = source.MaxResults; FirstResult = source.FirstResult; Region = RegionMapper.ToRegion(source.Region); }
public CreateNumberOrderBulkLocal(CfCreateNumberOrderBulkLocal source) { Count = source.Count; Region = RegionMapper.ToRegion(source.Region); }
public List <RegionDto> ObtenerRegiones(int?codRegion) { var result = _regionDao.ObtenerRegiones(codRegion); return(RegionMapper.ToDto(result)); }