public async Task RemoveSMEAndRebuild(int id) { var temp = dataRepository.Filter().Last(); List <Sme> SmeListLeft = temp.SmeList.Where(x => x.Z3kId != id).ToList(); List <Team> teams = new List <Team>(); foreach (var sme in temp.SmeList) { teams.AddRange(sme.Teams); } Distribution dist = new Distribution(teams.Distinct().ToList(), SmeListLeft); dist.Build(); DistributionData data = new DistributionData(); data.SmeList = dist.SmeList; data.Time = DateTime.Now; dataRepository.Delete(temp); //await dataRepository.SaveChanges(); dataRepository.Create(data); await dataRepository.SaveChanges(); }
public void PreventAggregationAndAggregationDataMismatch_Distribution_Count() { var tagValues1 = TagValues.Create(new List <string>() { V1, V2 }); var tagValues2 = TagValues.Create(new List <string>() { V10, V20 }); AggregationAndAggregationDataMismatch( CreateView(DISTRIBUTION), new Dictionary <TagValues, IAggregationData>() { { tagValues1, DistributionData.Create(1, 1, 1, 1, 0, new List <long>() { 0L, 1L, 0L }) }, { tagValues2, CountData.Create(100) }, }); }
public static float GetAbundance(double latitude, double longitude, string resourceName, int bodyId, int resourceType = 0, double altitude = 0) { try { var northing = Utilities.Deg2Rad(latitude); var easting = Utilities.Deg2Rad(longitude); var body = FlightGlobals.Bodies.FirstOrDefault(b => b.flightGlobalsIndex == bodyId); var biome = GetBiome(northing, easting, body); var seed = RegolithScenario.Instance.gameSettings.seed; seed *= (bodyId + 1); seed += resourceName.Length * resourceName.Substring(1).ToCharArray().First(); seed += body.bodyName.Length * body.bodyName.Substring(1).ToCharArray().First(); if (biome != null) { seed += Convert.ToInt32(biome.mapColor.grayscale * 4096) * (resourceType + 1); } //First - we need to determine our data set for randomization. //Is there biome data? DistributionData distro = null; var biomeName = "UNKNOWN"; if (biome != null) { biomeName = biome.name; } var biomeConfigs = BiomeResources.Where( r => r.PlanetName == body.bodyName && r.BiomeName == biomeName && r.ResourceName == resourceName && r.ResourceType == resourceType).ToList(); var planetConfigs = PlanetaryResources.Where( r => r.PlanetName == body.bodyName && r.ResourceName == resourceName && r.ResourceType == resourceType).ToList(); var globalConfigs = GlobalResources.Where( r => r.ResourceName == resourceName && r.ResourceType == resourceType).ToList(); //Extrapolate based on matching overrides if (biomeConfigs.Any()) { distro = GetBestResourceData(biomeConfigs); seed *= 2; } else if (planetConfigs.Any()) { distro = GetBestResourceData(planetConfigs); seed *= 3; } else if (globalConfigs.Any()) { distro = GetBestResourceData(globalConfigs); seed *= 4; } else { return(0f); } var rand = new Random(seed); //Our Simplex noise: var noiseSeed = new int[8]; for (int ns = 0; ns < 8; ns++) { noiseSeed[ns] = rand.Next(); } var spx = new NoiseGenerator(noiseSeed); var noiseX = (float)northing; var noiseY = (float)easting; var noiseZ = (rand.Next(100)) / 100f; var noise = spx.noise(noiseX, noiseY, noiseZ); var presenceRoll = rand.Next(100); var isPresent = (presenceRoll <= distro.PresenceChance); if (!isPresent) { return(0f); } //Abundance begins with a starting range. var min = (int)(distro.MinAbundance * 1000); var max = (int)(distro.MaxAbundance * 1000); //In case someone is silly if (min > max) { max = min + 1; } var ab = rand.Next(min, max); //Start with lower abundance float lowAbundance = ab / 1000f; //Our upper bound uses our variance. float highAbuncance = lowAbundance + (lowAbundance * distro.Variance / 100); //Default is average var abundance = (lowAbundance + highAbuncance) / 2; //Applies to all but interplanetary if (resourceType <= 2) { //Otherwise, it's a function of noise. abundance = lowAbundance + (noise * (highAbuncance - lowAbundance)); } //Altitude band - only applies to atmospheric and interplanetary if (resourceType >= 2 && distro.HasVariableAltitude()) { var rad = body.Radius; var ideal = ((rad * distro.MinAltitude) + (rad * distro.MaxAltitude)) / 2; //print("REGO: IDEAL = " + ideal); var range = rand.Next((int)(rad * distro.MinRange), (int)(rad * distro.MaxRange)); var diff = Math.Abs(ideal - altitude); var rangePerc = diff / range; var modifier = 1d - rangePerc; abundance *= (float)modifier; } if (abundance <= Utilities.FLOAT_TOLERANCE) { return(0f); } //Return it as a float not a percent return(abundance / 100); } catch (Exception e) { print("[REGO] - Error in - RegolithResourceMap_GetAbundance - " + e.Message); return(0f); } }
public void GetMetricSamples_ReturnsExpected() { var opts = new MetricsEndpointOptions(); var stats = new OpenCensusStats(); var ep = new MetricsEndpoint(opts, stats); SetupTestView(stats, Sum.Create(), null, "test.test1"); var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1")); IAggregationData aggData = SumDataDouble.Create(100); Assert.NotNull(viewData); var result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); var sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Sum.Create(), null, "test.test2"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test2")); aggData = SumDataLong.Create(100); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Count.Create(), null, "test.test3"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test3")); aggData = CountData.Create(100); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); SetupTestView(stats, Mean.Create(), null, "test.test4"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test4")); aggData = MeanData.Create(100, 50, 1, 500); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Equal(2, result.Count); sample = result[0]; Assert.Equal(50, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); sample = result[1]; Assert.Equal(100 * 50, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 10.0, 20.0 })), null, "test.test5"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test5")); aggData = DistributionData.Create(100, 50, 5, 200, 5, new List <long>() { 10, 20, 20 }); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Equal(3, result.Count); sample = result[0]; Assert.Equal(50, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); sample = result[1]; Assert.Equal(200, sample.Value); Assert.Equal(MetricStatistic.MAX, sample.Statistic); sample = result[2]; Assert.Equal(100 * 50, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); }
public void TestEquals() { var a1 = SumDataDouble.Create(10.0); var a2 = SumDataDouble.Create(20.0); var a3 = SumDataLong.Create(20); var a5 = CountData.Create(40); var a6 = CountData.Create(80); var a7 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a8 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 100L }); var a9 = DistributionData.Create(110, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a10 = DistributionData.Create(10, 110, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a11 = DistributionData.Create(10, 10, -1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a12 = DistributionData.Create(10, 10, 1, 5, 0, new List <long>() { 0L, 10L, 0L }); var a13 = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>() { 0L, 10L, 0L }); var a14 = MeanData.Create(5.0, 1, 5.0, 5.0); var a15 = MeanData.Create(-5.0, 1, -5.0, -5.0); var a16 = LastValueDataDouble.Create(20.0); var a17 = LastValueDataLong.Create(20); var a1a = SumDataDouble.Create(10.0); var a2a = SumDataDouble.Create(20.0); var a3a = SumDataLong.Create(20); var a5a = CountData.Create(40); var a6a = CountData.Create(80); var a7a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a8a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 100L }); var a9a = DistributionData.Create(110, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a10a = DistributionData.Create(10, 110, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a11a = DistributionData.Create(10, 10, -1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a12a = DistributionData.Create(10, 10, 1, 5, 0, new List <long>() { 0L, 10L, 0L }); var a13a = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>() { 0L, 10L, 0L }); var a14a = MeanData.Create(5.0, 1, 5.0, 5.0); var a15a = MeanData.Create(-5.0, 1, -5.0, -5.0); var a16a = LastValueDataDouble.Create(20.0); var a17a = LastValueDataLong.Create(20); Assert.Equal(a1, a1a); Assert.Equal(a2, a2a); Assert.Equal(a3, a3a); Assert.Equal(a5, a5a); Assert.Equal(a6, a6a); Assert.Equal(a7, a7a); Assert.Equal(a8, a8a); Assert.Equal(a9, a9a); Assert.Equal(a10, a10a); Assert.Equal(a11, a11a); Assert.Equal(a12, a12a); Assert.Equal(a13, a13a); Assert.Equal(a14, a14a); Assert.Equal(a15, a15a); Assert.Equal(a16, a16a); Assert.Equal(a17, a17a); }
public void PreventNullBucketCountList() { // thrown.expect(NullPointerException.class); // thrown.expectMessage("bucket counts should not be null."); Assert.Throws <ArgumentNullException>(() => DistributionData.Create(1, 1, 1, 1, 0, null)); }
public void TestMatchAndGet() { List <IAggregationData> aggregations = new List <IAggregationData>() { SumDataDouble.Create(10.0), SumDataLong.Create(100000000), CountData.Create(40), MeanData.Create(100.0, 10, 300.0, 500.0), DistributionData.Create(1, 1, 1, 1, 0, new List <long>() { 0L, 10L, 0L }), LastValueDataDouble.Create(20.0), LastValueDataLong.Create(200000000L), }; List <object> actual = new List <object>(); foreach (IAggregationData aggregation in aggregations) { aggregation.Match <object>( (arg) => { actual.Add(arg.Sum); return(null); }, (arg) => { actual.Add(arg.Sum); return(null); }, (arg) => { actual.Add(arg.Count); return(null); }, (arg) => { actual.Add(arg.Mean); return(null); }, (arg) => { actual.Add(arg.BucketCounts); return(null); }, (arg) => { actual.Add(arg.LastValue); return(null); }, (arg) => { actual.Add(arg.LastValue); return(null); }, (arg) => { throw new ArgumentException(); }); } Assert.Equal(10.0, actual[0]); Assert.Equal(100000000L, actual[1]); Assert.Equal(40L, actual[2]); Assert.Equal(100.0, actual[3]); Assert.Equal(new List <long>() { 0L, 10L, 0L }, actual[4]); Assert.Equal(20.0, actual[5]); Assert.Equal(200000000L, actual[6]); }
private static DistributionData GetBestResourceData(List<ResourceData> configs) { try { var distro = new DistributionData { Variance = configs.First().Distribution.Variance, PresenceChance = configs.First().Distribution.PresenceChance, MinAbundance = configs.First().Distribution.MinAbundance, MaxAbundance = configs.First().Distribution.MaxAbundance }; foreach (var config in configs) { var cd = config.Distribution; if (cd.PresenceChance > 0 && cd.PresenceChance > distro.PresenceChance) distro.PresenceChance = cd.PresenceChance; if (cd.MinAbundance > 0 && cd.MinAbundance < distro.MinAbundance) distro.MinAbundance = cd.MinAbundance; if (cd.MaxAbundance > 0 && cd.MaxAbundance > distro.MaxAbundance) distro.MaxAbundance = cd.MaxAbundance; if (cd.Variance > 0 && cd.Variance > distro.Variance) distro.Variance = cd.Variance; if (cd.MinAltitude > 0 && cd.MinAltitude < distro.MinAltitude) distro.MinAltitude = cd.MinAltitude; if (cd.MaxAltitude > 0 && cd.MaxAltitude > distro.MaxAltitude) distro.MaxAltitude = cd.MaxAltitude; if (cd.MinRange > 0 && cd.MinRange < distro.MinRange) distro.MinRange = cd.MinRange; if (cd.MaxRange > 0 && cd.MaxRange > distro.MaxRange) distro.MaxRange = cd.MaxRange; } return distro; } catch (Exception e) { print("[REGO] - Error in - RegolithResourceMap_GetBestResourceData - " + e.Message); return null; } }
private void LoadDtaFromExcel() { try { distributionData = new DistributionData(); distributionData.Name = $"CALC-DISTRIBUTION-{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"; distributionData.TimeCreate = DateTime.Now; distributionData.User = Core.User; distributionData.Id = Guid.NewGuid(); ExcelHelper excelHelper = new ExcelHelper(); int countread = 0; distributionDataItems = excelHelper.ReadExcelDistribution(distributionData.Id, tstxtPath.Text); //var orderByDescendingResult = (from s in importMapWorkMemberDetails // orderby s.No ascending // select s).ToList(); if (distributionDataItems != null) { countread = distributionDataItems.Count; distributionData.TotalRecord = distributionDataItems.Count; distributionData.Note = $"Load data from excel is successfull, Total record: {countread}"; distributionData.DistributionDataItems = distributionDataItems; distributionData.TotalRecord = distributionDataItems.Count; dgvEditFileImport.Invoke(new MethodInvoker(delegate { dgvEditFileImport.DataSource = distributionDataItems; for (int i = 0; i < dgvEditFileImport.Rows.Count; i++) { if ((bool)dgvEditFileImport.Rows[i].Cells["StatusLoad"].Value == true) { dgvEditFileImport.Rows[i].Cells["StatusLoad"].Style.BackColor = Color.Green; dgvEditFileImport.Rows[i].Cells["StatusLoad"].Style.ForeColor = Color.White; } else { dgvEditFileImport.Rows[i].Cells["StatusLoad"].Style.BackColor = Color.Red; dgvEditFileImport.Rows[i].Cells["StatusLoad"].Style.ForeColor = Color.White; } if (dgvEditFileImport.Rows[i].Cells["strContractTime"].Value.ToString() != string.Empty) { dgvEditFileImport.Rows[i].Cells["strContractTime"].Style.BackColor = Color.Red; dgvEditFileImport.Rows[i].Cells["strContractTime"].Style.ForeColor = Color.White; } } })); statusTripMain.Invoke(new MethodInvoker(delegate { tssLblInfo.Text = distributionData.Note; })); } else { dgvEditFileImport.Invoke(new MethodInvoker(delegate { dgvEditFileImport.DataSource = new List <DistributionDataItem>(); })); statusTripMain.Invoke(new MethodInvoker(delegate { tssLblInfo.Text = "Load data from Excel file be error!"; })); } } catch (Exception ex) { distributionData = new DistributionData(); pcloader.Invoke(new MethodInvoker(delegate { pcloader.Visible = false; })); MessageBox.Show(ex.ToString()); } }