Skip to content

Commit

Permalink
Correct timer window resource issue. Also fix delta split calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruffk committed Apr 27, 2021
1 parent 80b151a commit a7add23
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 3,894 deletions.
2 changes: 1 addition & 1 deletion ZwiftActivityMonitor/ZwiftActivityMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<Version>1.2.4</Version>
<Version>1.2.4.1</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion ZwiftActivityMonitor/forms/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void btnClose_Click(object sender, EventArgs e)
private void AboutForm_Load(object sender, EventArgs e)
{
Version version = Assembly.GetExecutingAssembly().GetName().Version;
lblProductVersion.Text = version.Major + "." + version.Minor + "." + version.Build;
lblProductVersion.Text = version.Major + "." + version.Minor + "." + version.Build + "." + version.Revision;
}

private void pbEnjoyFitness_Click(object sender, EventArgs e)
Expand Down
2 changes: 0 additions & 2 deletions ZwiftActivityMonitor/forms/AdvancedOptions.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ZwiftActivityMonitor/forms/AdvancedOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AdvancedOptions(ZPMonitorService zPMonitorService, ILogger<AdvancedOption

InitializeComponent();

m_logger.LogInformation($"Class {this.GetType()} initialized.");
this.Icon = Properties.Resources.cycling1;
}

private delegate void ProcessedRiderStateEventHandlerDelegate(object sender, RiderStateEventArgs e);
Expand Down
1,919 changes: 0 additions & 1,919 deletions ZwiftActivityMonitor/forms/AdvancedOptions.resx

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions ZwiftActivityMonitor/forms/MonitorTimer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ZwiftActivityMonitor/forms/MonitorTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public MonitorTimer(ILogger<MonitorTimer> logger)
Logger = logger;

InitializeComponent();

this.Icon = Properties.Resources.cycling1;
}

public int Minutes
Expand Down
1,919 changes: 0 additions & 1,919 deletions ZwiftActivityMonitor/forms/MonitorTimer.resx

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions ZwiftActivityMonitor/src/SplitsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,22 +373,29 @@ private void RiderStateEventHandler(object sender, RiderStateEventArgs e)
// Calculate how deep into the split distance the rider is.
int splitMeters = totalMeters - (m_splits.SplitDistanceAsMeters * m_splitCount);

double splitKmTravelled = Math.Round(splitMeters / 1000.0, 1);
double splitMiTravelled = Math.Round(splitKmTravelled / 1.609, 1);
// How much of the split is completed (expressed as percentage)
double splitCompletedPct = Math.Round(splitMeters / (double)m_splits.SplitDistanceAsMeters, 2);

// Compute distance, leave unrounded
double splitKmTravelled = splitMeters / 1000.0;
double splitMiTravelled = splitKmTravelled / 1.609;

double splitDistance = m_splits.SplitsInKm ? splitKmTravelled : splitMiTravelled;
double splitSpeed = Math.Round((splitDistance / splitTime.TotalSeconds) * 3600, 1);

// Now round the distance
splitDistance = Math.Round(splitDistance, 1);

//double splitAverageKph = Math.Round((splitKmTravelled / splitTime.TotalSeconds) * 3600, 1);
//double splitAverageMph = Math.Round((splitMiTravelled / splitTime.TotalSeconds) * 3600, 1);

if (goal != null)
{
// Calculate the deltaTime, positive number is good, negative bad.
TimeSpan deltaTime = goal.TotalTime.Subtract(runningTime);

if (splitKmTravelled >= goal.SplitDistanceKm)
{
// Calculate the deltaTime, positive number is good, negative bad.
TimeSpan deltaTime = goal.TotalTime.Subtract(runningTime);

// This completes the split. TotalDistance travelled and Delta is included.
SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, totalDistance, runningTime, m_splits.SplitsInKm, deltaTime);
OnSplitGoalCompletedEvent(args);
Expand All @@ -401,8 +408,17 @@ private void RiderStateEventHandler(object sender, RiderStateEventArgs e)
}
else
{
if (splitMeters - m_lastSplitMeters >= 100) // only raise update event every 100 meters or so
if (splitMeters - m_lastSplitMeters >= 1) // only raise update event every 100 meters or so
{
// Goal time of split start
TimeSpan splitStartTime = goal.TotalTime.Subtract(goal.SplitTime);

// Goal time to get to this point in the split
TimeSpan splitWaypointTime = splitStartTime.Add(goal.SplitTime.Multiply(splitCompletedPct));

// Calculate the deltaTime, positive number is good, negative bad.
TimeSpan deltaTime = splitWaypointTime.Subtract(runningTime);

// This is an update to the split in-progress. SplitDistance travelled is included.
SplitEventArgs args = new SplitEventArgs(m_splitCount + 1, splitTime, splitSpeed, splitDistance, runningTime, m_splits.SplitsInKm, deltaTime);
OnSplitUpdatedEvent(args);
Expand Down
82 changes: 49 additions & 33 deletions ZwiftActivityMonitor/usercontrols/TimerSetupControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions ZwiftActivityMonitor/usercontrols/TimerSetupControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ private bool ValidateSystemSettings(Control control)

switch (control.Name)
{
case "tbMins":
case "nMins":
try
{
tbMins.Text = tbMins.Text.Trim();
this.Minutes = int.Parse(tbMins.Text == "" ? "0" : tbMins.Text);
this.Minutes = Convert.ToInt32(nMins.Value);

if (this.Minutes < 0 || this.Minutes > 59)
{
Expand All @@ -59,11 +58,10 @@ private bool ValidateSystemSettings(Control control)
}
break;

case "tbSecs":
case "nSecs":
try
{
tbSecs.Text = tbSecs.Text.Trim();
this.Seconds = int.Parse(tbSecs.Text == "" ? "0" : tbSecs.Text);
this.Seconds = Convert.ToInt32(nSecs.Value);

if (this.Seconds < 0 || this.Seconds > 59)
{
Expand Down Expand Up @@ -112,11 +110,11 @@ public void HandleTooltipsSystemSettings(Control control, bool isEntering)

switch (control.Name)
{
case "tbMins":
case "nMins":
toolStripStatusLabel.Text = "Enter timer duration minutes.";
break;

case "tbSecs":
case "nSecs":
toolStripStatusLabel.Text = "Enter timer duration seconds.";
break;
}
Expand All @@ -139,8 +137,8 @@ private void btnStart_Click(object sender, EventArgs e)
{
bool errorOccurred = false;

errorOccurred = (errorOccurred || ValidateSystemSettings(tbMins));
errorOccurred = (errorOccurred || ValidateSystemSettings(tbSecs));
errorOccurred = (errorOccurred || ValidateSystemSettings(nMins));
errorOccurred = (errorOccurred || ValidateSystemSettings(nSecs));
errorOccurred = (errorOccurred || ValidateSystemSettings(rbStartImmediately));
errorOccurred = (errorOccurred || ValidateSystemSettings(rbStartWithEventTimer));

Expand Down

0 comments on commit a7add23

Please sign in to comment.