private static MetricDatum[] BuildMetrics(string name, StandardUnit unit, int metricCount) { return(Enumerable .Range(0, metricCount) .Select(i => BuildMetric(name, unit, rnd.Next(1, 100))) .ToArray()); }
public Axis InferYAxis(IList <Tuple <StandardUnit, double> > dataRanges) { double highest = dataRanges.Any() ? dataRanges.Max(x => x.Item2) : 0d; double lowest = dataRanges.Any() ? dataRanges.Min(x => x.Item2) : 0d; var yAxis = new LinearAxis { Position = AxisPosition.Left, Minimum = lowest, IntervalLength = 30, Maximum = highest, TicklineColor = OxyColor.FromArgb(0, 0, 0, 0), MajorGridlineStyle = LineStyle.Solid, MajorGridlineColor = OxyColor.FromRgb(230, 230, 230), MinorGridlineStyle = LineStyle.Solid, MinorGridlineColor = OxyColor.FromRgb(244, 244, 244) }; if (!dataRanges.Any()) { return(yAxis); } StandardUnit unit = dataRanges.First().Item1; // Only apply formatting for specific unit // if all data points are using the same if (dataRanges.All(x => x.Item1 == unit)) { yAxis.LabelFormatter = unit.GetLabelFormatter(); } return(yAxis); }
protected override void PostElementParse(ref List <Match> .Enumerator tokens, AppenderValue appenderValue, string aggregate = null) { string unit; if (!string.IsNullOrEmpty(aggregate)) { var t = StandardUnit.FindValue(aggregate.ToLowerInvariant()); if (t.ToString() != aggregate.ToLowerInvariant()) //If conversion capitalizes unit then it is valid and should not be included in rest. { ((MetricDatumAppenderValue)appenderValue).Unit = aggregate; return; } } if (tokens.MoveNext()) { if (!string.IsNullOrEmpty(unit = tokens.Current.Groups["word"].Value)) { var t = StandardUnit.FindValue(unit.ToLowerInvariant()); if (t.ToString() != unit.ToLowerInvariant()) //If conversion capitalizes unit then it is valid and should not be included in rest. { tokens.MoveNext(); ((MetricDatumAppenderValue)appenderValue).Unit = unit; } } } }
public Size(double value, StandardUnit standardUnit) { _value = value; _unit = new List <KeyValuePair <StandardUnit, Rational> >() { new KeyValuePair <StandardUnit, Rational>(standardUnit, new Rational(1)) }; }
void OnEnable() { selectedUnit = buildManager.GetUnitToPlace(); standardUnit = selectedUnit.gameObject.GetComponent <StandardUnit>(); UpdateAwakenPanelInfo(); }
public double To(StandardUnit to) { if (to == _from) { return(_value); } return(PerformConvert(to)); }
private static MetricDatum BuildMetric(string name, StandardUnit unit, double value) { return(new MetricDatum { MetricName = name, Unit = unit, Value = value, TimestampUtc = RoundDown(DateTime.UtcNow, TimeSpan.FromMinutes(1)).AddMinutes(-rnd.Next(0, 30)) }); }
private static StatisticSet Aggregate(IEnumerable <MetricDatum> data, StandardUnit unit) { return(new StatisticSet { Maximum = MakeStatistic(data, unit, d => d.Maximum).Max(), Minimum = MakeStatistic(data, unit, d => d.Minimum).Min(), Sum = MakeStatistic(data, unit, d => d.Sum).Sum(), SampleCount = data.Select(d1 => d1.StatisticValues == null ? 1 : d1.StatisticValues.SampleCount).Sum() }); }
public MetricDatumEventProcessor(bool configOverrides, StandardUnit unit, string @namespace, string metricName, string timestamp, string value, Dictionary <string, Dimension> dimensions) { _configOverrides = configOverrides; _unit = unit; _namespace = @namespace; _metricName = metricName; _timestamp = timestamp; _value = value; _dimensions = dimensions; }
public void AddCount(string name, double val, StandardUnit unit) { ThrowIfClosed(); this.datapoints.Add(new MetricDatum() { MetricName = name, Value = val, StorageResolution = 1, Unit = unit, TimestampUtc = DateTime.UtcNow, }); }
public AwsMetricRequest(string name, AwsMetricRequest other, StandardUnit u = null, Statistic?stat = null) { ns = other.ns; metricName = name; unit = u == null ? other.unit : u; utcFrom = other.utcFrom; utcTo = other.utcTo; stats = new HashSet <Statistic>(other.stats); dimensions = new Dictionary <string, string>(other.dimensions); if (stat.HasValue) { SetStatistics(stat.Value); } }
void UpdateAwakenPanelInfo() { if (standardUnit == null) { standardUnit = selectedUnit.GetComponent <AwokenUnit>().originalUnit; } if (standardUnit != null) { for (int i = 0; i < pathButtons.Length; i++) { int index = i; // Needed so the listener doesn't receive the last element in the loop pathButtons[i].button.onClick.AddListener(() => OnButtonClick(index)); if (standardUnit.awokenUnits.Length > 0) { if (standardUnit.awokenUnits[i] != null) { pathButtons[i].Unit = standardUnit.awokenUnits[i]; pathButtons[i].nameText.text = standardUnit.awokenUnits[i].unitName; pathButtons[i].awokenSprite.sprite = standardUnit.awokenUnits[i].unitSprite; pathButtons[i].awokenSprite.material = standardUnit.awokenUnits[i].GetComponent <SpriteRenderer>().sharedMaterial; // Highlights the button if the unit has been purchased and is located within the unlocked units dictionary if (unitManager.unlockedUnits.ContainsKey(standardUnit.awokenUnits[i].unitName)) { Unit unlockedUnit = unitManager.unlockedUnits[standardUnit.awokenUnits[i].unitName]; pathButtons[i].button.GetComponent <Image>().color = pathButtons[i].unlockedColor; pathButtons[i].costText.text = "Unlocked!"; } else { pathButtons[i].button.GetComponent <Image>().color = pathButtons[i].originalColor; pathButtons[i].costText.text = standardUnit.awokenUnits[i].baseCost + " Gems"; } } else { pathButtons[i].Unit = null; pathButtons[i].nameText.text = "Coming Soon!"; pathButtons[i].awokenSprite.sprite = standardUnit.unitSprite; } } } } unitName.text = selectedUnit.unitName; levelReqTxt.text = "Level: " + standardUnit.levelToAwaken; }
private double PerformConvert(StandardUnit to) { if (_converterGraph == null) { GenerateGraph(); } var queue = new Queue <UnitGraphNode>(); var visited = new HashSet <UnitGraphNode>(); var multipliers = new Dictionary <UnitGraphNode, double>(); var fromNode = _converterGraph[_from]; queue.Enqueue(fromNode); multipliers.Add(fromNode, 1.0); while (queue.Any()) { var n = queue.Dequeue(); if (_converterGraph[to] == n) { if (!fromNode.Links.Select(l => l.Value.OtherNode).Contains(n)) { fromNode.LinkTo(n, multipliers[n]); } return(multipliers[n] * _value); } if (!visited.Contains(n)) { visited.Add(n); var multiplier = multipliers[n]; foreach (var link in n.Links.Values) { if (!visited.Contains(link.OtherNode)) { queue.Enqueue(link.OtherNode); if (!multipliers.ContainsKey(link.OtherNode)) { multipliers.Add(link.OtherNode, multiplier * link.Multiplier); } } } } } throw new ConversionNotSupportedException(); }
public IEnumerator SpawnUnit() { while (true) { //would be fun to make a random enemy spawn, rather than always std >>> big. //if there is time... //would also be nice if they turned to the front... if (allUnitsSpawned == false) { if (currentStdUnitNr < maxStdUnitNr) { StandardUnit stdUnit = stdUnitPool.Rent() as StandardUnit; SetUpUnit(stdUnit); currentStdUnitNr++; } else if (currentBigUnitNr < maxBigUnitNr) { BigUnit bigUnit = bigUnitPool.Rent() as BigUnit; SetUpUnit(bigUnit); currentBigUnitNr++; } } if (currentStdUnitNr == maxStdUnitNr && currentBigUnitNr == maxBigUnitNr) { allUnitsSpawned = true; //Making sure all targets are gone before starting next wave. if (TowerBase.targets.Count == 0) { if (currentWave != maxWaves) { currentWave++; StartWave(); yield break; } else { GameManager.StartNextLevel(); } } } yield return(new WaitForSeconds(spawnTimer)); } }
static CloudWatchSink() { _unitMap = new Dictionary <MetricUnit, StandardUnit>(); foreach (MetricUnit key in Enum.GetValues(typeof(MetricUnit))) { var standardUnitField = typeof(StandardUnit) .GetTypeInfo() .GetDeclaredField(key.ToString()); if (standardUnitField != null) { StandardUnit cloudWatchUnit = (StandardUnit)standardUnitField .GetValue(null); _unitMap.Add(key, cloudWatchUnit); } } }
internal static Func <double, string> GetLabelFormatter(this StandardUnit unit) { if (unit == StandardUnit.Bits) { return((value) => ((long)value).Bits().Humanize(DoubleFormatting)); } if (unit == StandardUnit.BitsSecond) { return((value) => ((long)value).Bits().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Kilobytes) { return((value) => value.Kilobytes().Humanize(DoubleFormatting)); } if (unit == StandardUnit.KilobytesSecond) { return((value) => value.Kilobytes().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Bytes) { return((value) => value.Bytes().Humanize(DoubleFormatting)); } if (unit == StandardUnit.BytesSecond) { return((value) => value.Bytes().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Megabytes) { return((value) => value.Megabytes().Humanize(DoubleFormatting)); } if (unit == StandardUnit.MegabytesSecond) { return((value) => value.Megabytes().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Gigabytes) { return((value) => value.Gigabytes().Humanize(DoubleFormatting)); } if (unit == StandardUnit.GigabytesSecond) { return((value) => value.Gigabytes().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Terabytes) { return((value) => value.Terabytes().Humanize(DoubleFormatting)); } if (unit == StandardUnit.TerabytesSecond) { return((value) => value.Terabytes().Per(TimeSpan.FromSeconds(1)).Humanize(DoubleFormatting)); } if (unit == StandardUnit.Milliseconds) { return((value) => TimeSpan.FromMilliseconds(value).HumanizeShort()); } if (unit == StandardUnit.Seconds) { return((value) => TimeSpan.FromSeconds(value).HumanizeShort()); } if (unit == StandardUnit.Microseconds) { return((value) => value.ToString(DoubleFormatting) + " μs"); } if (unit == StandardUnit.Percent) { return((value) => value.ToString(DoubleFormatting) + "%"); } return((value) => value.ToString("N0")); }
public AwsMetricRequest Unit(StandardUnit unit) { this.unit = unit; return(this); }
public AwsMetricRequest Copy(string name, StandardUnit u = null, Statistic?stat = null) => new AwsMetricRequest(name, this, u, stat);
void ReturnStdUnitToPool(StandardUnit unit) { stdUnitPool.UnRent(unit); unit.gameObject.SetActive(false); }
public object ConvertFrom(object source) { return(StandardUnit.FindValue(source as string)); }
public UnitConverter From(StandardUnit standardUnit) { _from = standardUnit; return(this); }
private UnitGraphNode(string s) { _unit = new StandardUnit(s); }
public MetricDatum WithUnit(StandardUnit value) { _unit = value; return(this); }
private static IEnumerable <double> MakeStatistic(IEnumerable <MetricDatum> data, StandardUnit unit, Func <StatisticSet, double> func) { return(data.Select(d => d.StatisticValues == null ? UnitConverter.Convert(d.Value).From(d.Unit).To(unit) : UnitConverter.Convert(func(d.StatisticValues)).From(d.Unit).To(unit))); }