summaryrefslogtreecommitdiff
path: root/grapher/Models/Calculations
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-09-26 02:10:29 -0400
committerGitHub <[email protected]>2020-09-26 02:10:29 -0400
commit9353f5b9adc50456fefc2e55aab5e57029e89682 (patch)
tree5d28926aee87c077ffc4ed7222469bbf2f28bd2c /grapher/Models/Calculations
parentMerge pull request #22 from JacobPalecki/GUI (diff)
parentSetActive changes field default, bugs fixed (diff)
downloadrawaccel-9353f5b9adc50456fefc2e55aab5e57029e89682.tar.xz
rawaccel-9353f5b9adc50456fefc2e55aab5e57029e89682.zip
Merge pull request #23 from JacobPalecki/GUI
Settings writer; GUI performance enhancement and touchups
Diffstat (limited to 'grapher/Models/Calculations')
-rw-r--r--grapher/Models/Calculations/AccelCalculator.cs73
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs22
2 files changed, 76 insertions, 19 deletions
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs
index f2a6c7c..e2f7bcc 100644
--- a/grapher/Models/Calculations/AccelCalculator.cs
+++ b/grapher/Models/Calculations/AccelCalculator.cs
@@ -67,9 +67,13 @@ namespace grapher.Models.Calculations
double maxSlope = 0.0;
double minSlope = Double.MaxValue;
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
- if (magnitudeDatum.magnitude <=0)
+ if (magnitudeDatum.magnitude <= 0)
{
continue;
}
@@ -77,7 +81,23 @@ namespace grapher.Models.Calculations
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outMagnitude = Magnitude(output.Item1, output.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter;
+ if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
+ {
+ data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
+ }
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < outMagnitude && logIndex < data.LogToIndex.Length)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
+
+ var ratio = outMagnitude / magnitudeDatum.magnitude;
if (ratio > maxRatio)
{
@@ -108,11 +128,6 @@ namespace grapher.Models.Calculations
data.AccelPoints.Add(magnitudeDatum.magnitude, ratio);
}
- if (!data.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
- {
- data.VelocityPoints.Add(magnitudeDatum.magnitude, outMagnitude);
- }
-
if (!data.GainPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.GainPoints.Add(magnitudeDatum.magnitude, slope);
@@ -120,9 +135,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitude = outMagnitude;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList());
data.MaxAccel = maxRatio;
data.MinAccel = minRatio;
data.MaxGain = maxSlope;
@@ -143,18 +167,38 @@ namespace grapher.Models.Calculations
Sensitivity = GetSens(ref settings);
+ double log = -2;
+ int index = 0;
+ int logIndex = 0;
+
foreach (var magnitudeDatum in magnitudeData)
{
+ if (magnitudeDatum.magnitude <= 0)
+ {
+ continue;
+ }
+
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outputWithoutSens = StripThisSens(output.Item1, output.Item2);
var magnitudeWithoutSens = Magnitude(outputWithoutSens.Item1, outputWithoutSens.Item2);
- var ratio = magnitudeDatum.magnitude > 0 ? magnitudeWithoutSens / magnitudeDatum.magnitude : 1;
+ var ratio = magnitudeWithoutSens / magnitudeDatum.magnitude;
if (!data.Combined.VelocityPoints.ContainsKey(magnitudeDatum.magnitude))
{
data.Combined.VelocityPoints.Add(magnitudeDatum.magnitude, magnitudeWithoutSens);
}
+ else
+ {
+ continue;
+ }
+
+ while (Math.Pow(10,log) < magnitudeWithoutSens && logIndex < data.Combined.LogToIndex.Length)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
+ }
var xRatio = settings.sensitivity.x * ratio;
var yRatio = settings.sensitivity.y * ratio;
@@ -241,9 +285,18 @@ namespace grapher.Models.Calculations
lastInputMagnitude = magnitudeDatum.magnitude;
lastOutputMagnitudeX = xOut;
lastOutputMagnitudeY = yOut;
+ index += 1;
+ }
+
+ index--;
+
+ while (log <= 5.0)
+ {
+ data.Combined.LogToIndex[logIndex] = index;
+ log += 0.01;
+ logIndex++;
}
- data.Combined.OrderedVelocityPointsList.AddRange(data.Combined.VelocityPoints.Values.ToList());
data.Combined.MaxAccel = maxRatio;
data.Combined.MinAccel = minRatio;
data.Combined.MaxGain = maxSlope;
diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs
index 54685a2..60d4c89 100644
--- a/grapher/Models/Calculations/AccelChartData.cs
+++ b/grapher/Models/Calculations/AccelChartData.cs
@@ -13,8 +13,8 @@ namespace grapher.Models.Calculations
AccelPoints = new SortedDictionary<double, double>();
VelocityPoints = new SortedDictionary<double, double>();
GainPoints = new SortedDictionary<double, double>();
- OrderedVelocityPointsList = new List<double>();
OutVelocityToPoints = new Dictionary<double, (double, double, double)>();
+ LogToIndex = new int[701];
}
#endregion Constructors
@@ -35,7 +35,7 @@ namespace grapher.Models.Calculations
public SortedDictionary<double, double> GainPoints { get; }
- public List<double> OrderedVelocityPointsList { get; }
+ public int[] LogToIndex { get; }
public Dictionary<double, (double, double, double)> OutVelocityToPoints { get; }
@@ -48,8 +48,8 @@ namespace grapher.Models.Calculations
AccelPoints.Clear();
VelocityPoints.Clear();
GainPoints.Clear();
- OrderedVelocityPointsList.Clear();
OutVelocityToPoints.Clear();
+ Array.Clear(LogToIndex, 0, LogToIndex.Length);
}
public (double, double, double) FindPointValuesFromOut(double outVelocityValue)
@@ -80,15 +80,19 @@ namespace grapher.Models.Calculations
public int GetVelocityIndex(double outVelocityValue)
{
- var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue);
-
- if (velIdx < 0)
+ var log = Math.Log10(outVelocityValue);
+ if (log < -2)
+ {
+ log = -2;
+ }
+ else if (log > 5)
{
- velIdx = ~velIdx;
+ log = 5;
}
- velIdx = Math.Min(velIdx, VelocityPoints.Count - 1);
- velIdx = Math.Max(velIdx, 0);
+ log = log * 100 + 200;
+
+ var velIdx = LogToIndex[(int)log];
return velIdx;
}