From dbeae779f049943e127bb0b7fe51b0040b1cc785 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Mon, 16 Oct 2017 14:48:20 +0200
Subject: [PATCH] adapt method of computing gearshift count

---
 .../OutputData/IModalDataContainer.cs         | 24 ++++++++++++++-----
 VectoCore/VectoCoreTest/VectoCoreTest.csproj  |  1 +
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/VectoCore/VectoCore/OutputData/IModalDataContainer.cs b/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
index b48aec3d79..c75d8e1eb5 100644
--- a/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
+++ b/VectoCore/VectoCore/OutputData/IModalDataContainer.cs
@@ -487,9 +487,17 @@ namespace TUGraz.VectoCore.OutputData
 			return 100 * sum / Duration(data);
 		}
 
+		/// <summary>
+		/// The following logic applies:
+		/// - shifting from gear A to gear B counts as gearshift (with or without traction interruption)
+		/// - shifting from gear A to neutral couts as gearshift if the vehicle stopped
+		/// </summary>
+		/// <param name="data"></param>
+		/// <returns></returns>
 		public static Scalar GearshiftCount(this IModalDataContainer data)
 		{
 			var prevGear = data.GetValues<uint>(ModalResultField.Gear).First();
+			var lastGear = prevGear;
 			var gearCount = 0;
 
 			var shifts = data.GetValues(x => new {
@@ -498,13 +506,17 @@ namespace TUGraz.VectoCore.OutputData
 			});
 			foreach (var entry in shifts) {
 				if (entry.Speed != null && entry.Speed.IsSmallerOrEqual(0.1)) {
-					prevGear = 0;
-					gearCount++;
+					if (prevGear != entry.Gear) {
+						gearCount++;
+					}
 				}
-				if (entry.Gear == 0 || entry.Gear == prevGear) {
-					continue;
+				if (entry.Gear != 0 && entry.Gear != prevGear) {
+					if (lastGear != entry.Gear) {
+						gearCount++;
+					}
+					lastGear = entry.Gear;
 				}
-				gearCount++;
+
 				prevGear = entry.Gear;
 			}
 			return gearCount.SI<Scalar>();
@@ -553,4 +565,4 @@ namespace TUGraz.VectoCore.OutputData
 			return retVal;
 		}
 	}
-}
\ No newline at end of file
+}
diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj
index bcdb592120..7f997ee209 100644
--- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj
+++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj
@@ -110,6 +110,7 @@
     <Compile Include="Models\Simulation\GetSectionTest.cs" />
     <Compile Include="Models\Simulation\DeclarationSimulationFactoryTest.cs" />
     <Compile Include="Reports\ActualModalSimulationDataTest.cs" />
+    <Compile Include="Reports\GearshiftCountTest.cs" />
     <Compile Include="Reports\ModDataTest.cs" />
     <Compile Include="Models\Simulation\MeasuredSpeedModeTest.cs" />
     <Compile Include="Models\Simulation\PwheelModeTests.cs" />
-- 
GitLab