From 982e4e74e21152796de015f5c6ae2ab93438ee6c Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Thu, 7 Sep 2023 12:42:47 +0100 Subject: [PATCH] Parse unit "percent" (used by pvsaccelerator_space_utilization). Minor tidy. Signed-off-by: Konstantina Chremmou --- XenAdmin/Controls/CustomDataGraph/DataSet.cs | 45 +++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/XenAdmin/Controls/CustomDataGraph/DataSet.cs b/XenAdmin/Controls/CustomDataGraph/DataSet.cs index bff579f20..d6d2c8b43 100644 --- a/XenAdmin/Controls/CustomDataGraph/DataSet.cs +++ b/XenAdmin/Controls/CustomDataGraph/DataSet.cs @@ -41,7 +41,7 @@ public class DataSet : IComparable { private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - private const int NegativeValue = -1; + private const int NEGATIVE_VALUE = -1; /// /// Things can only be added to the beginning or end of this list; it should @@ -50,12 +50,12 @@ public class DataSet : IComparable public List Points = new List(); public bool Selected; public List CurrentlyDisplayed = new List(); - public IXenObject XenObject; + public readonly IXenObject XenObject; public readonly string Id = ""; - public string DataSourceName; + public readonly string DataSourceName; public string FriendlyName { get; } - private int MultiplyingFactor = 1; - public DataRange CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto); + private readonly int _multiplyingFactor = 1; + public readonly DataRange CustomYRange = new DataRange(1, 0, 1, Unit.None, RangeScaleMode.Auto); public bool Hide { get; } public DataSet(IXenObject xo, bool hide, string datasourceName, List datasources) @@ -87,10 +87,13 @@ public DataSet(IXenObject xo, bool hide, string datasourceName, List setsAdded, List { double value = Helpers.StringToDouble(str); bool isNanOrInfinity = double.IsNaN(value) || double.IsInfinity(value); - double yValue = isNanOrInfinity ? NegativeValue : value * MultiplyingFactor; + double yValue = isNanOrInfinity ? NEGATIVE_VALUE : value * _multiplyingFactor; #region cpu @@ -370,7 +373,7 @@ public void AddPoint(string str, long currentTime, List setsAdded, List } if (isNanOrInfinity || pt.Y < 0) - pt.Y = NegativeValue; + pt.Y = NEGATIVE_VALUE; else { double cpu_vals_added = 0d; @@ -395,8 +398,8 @@ public void AddPoint(string str, long currentTime, List setsAdded, List if (other != null && other.Points.Count - 1 == Points.Count) { yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0 - ? NegativeValue - : (value * MultiplyingFactor) - other.Points[other.Points.Count - 1].Y; + ? NEGATIVE_VALUE + : value * _multiplyingFactor - other.Points[other.Points.Count - 1].Y; other.Points[other.Points.Count - 1].Y = yValue; } } @@ -406,8 +409,8 @@ public void AddPoint(string str, long currentTime, List setsAdded, List if (other != null && other.Points.Count - 1 == Points.Count) { yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0 - ? NegativeValue - : other.Points[other.Points.Count - 1].Y - (value * MultiplyingFactor); + ? NEGATIVE_VALUE + : other.Points[other.Points.Count - 1].Y - value * _multiplyingFactor; } } else if (DataSourceName == "memory") @@ -416,8 +419,8 @@ public void AddPoint(string str, long currentTime, List setsAdded, List if (other != null && other.Points.Count - 1 == Points.Count) { yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0 - ? NegativeValue - : (value * MultiplyingFactor) - other.Points[other.Points.Count - 1].Y; + ? NEGATIVE_VALUE + : value * _multiplyingFactor - other.Points[other.Points.Count - 1].Y; other.Points[other.Points.Count - 1].Y = yValue; } } @@ -427,8 +430,8 @@ public void AddPoint(string str, long currentTime, List setsAdded, List if (other != null && other.Points.Count - 1 == Points.Count) { yValue = isNanOrInfinity || other.Points[other.Points.Count - 1].Y < 0 - ? NegativeValue - : other.Points[other.Points.Count - 1].Y - (value * MultiplyingFactor); + ? NEGATIVE_VALUE + : other.Points[other.Points.Count - 1].Y - value * _multiplyingFactor; } }