Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Keller253 committed Feb 12, 2024
1 parent b68c820 commit d625f75
Show file tree
Hide file tree
Showing 18 changed files with 585 additions and 181 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ root = true
# All files
[*]
indent_style = space
max_line_length = 80
guidelines = 80

# Xml files
[*.xml]
Expand All @@ -13,6 +15,10 @@ indent_size = 2

#### Core EditorConfig Options ####

# Line length
max_line_length = 120
guidelines = 120

# Indentation and spacing
indent_size = 4
tab_width = 4
Expand Down
2 changes: 1 addition & 1 deletion src/CyclingApp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34511.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CyclingApp", "CyclingApp\CyclingApp.csproj", "{61A08EFE-929E-4F2B-BFB6-479A5D0CF153}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CyclingApp", "CyclingApp\CyclingApp.csproj", "{61A08EFE-929E-4F2B-BFB6-479A5D0CF153}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 4 additions & 2 deletions src/CyclingApp/CyclingApp.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazor.Geolocation" Version="8.0.0" />
<PackageReference Include="Geolocation" Version="1.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.14.0" />
<!--<PackageReference Include="Thinktecture.Blazor.ScreenWakeLock" Version="1.0.0" />-->
<PackageReference Include="Thinktecture.Blazor.ScreenWakeLock" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions src/CyclingApp/Models/Activity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace CyclingApp.Models
{
public class Activity

Check warning on line 3 in src/CyclingApp/Models/Activity.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Activity'
{
public Guid Id { get; }

Check warning on line 5 in src/CyclingApp/Models/Activity.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Activity.Id'

/// <summary>
/// Creation time of the acitivity.
/// </summary>
public DateTime CreationTime { get; }

/// <summary>
/// Duration of the acitivity.
/// </summary>
public TimeSpan Duration { get; }

/// <summary>
/// Route of the activity.
/// </summary>
public ReadOnlyRoute Route { get; }

/// <summary>
/// Average speed during the activity in kilometers per hour.
/// </summary>
public double AvgSpeed { get; }

/// <summary>
/// Initializes a new instance of <see cref="Activity"/> class.
/// </summary>
public Activity(Guid id, DateTime creationTime, TimeSpan duration, ReadOnlyRoute route)
{
Id = id;
CreationTime = creationTime;
Duration = duration;
Route = route;
}
}
}
79 changes: 79 additions & 0 deletions src/CyclingApp/Models/GeoLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
namespace CyclingApp.Models
{
/// <summary>
/// Position and altitude on earth.
/// </summary>
public class GeoLocation
{
/// <summary>
/// Longitude in decimal degrees.
/// </summary>
public double Longitude { get; }

/// <summary>
/// Latitude in decimal degrees.
/// </summary>
public double Latitude { get; }

/// <summary>
/// Accuracy of the <see cref="Latitude"/> and <see cref="Longitude"/> properties, expressed in meters.
/// </summary>
public double Accuracy { get; }

/// <summary>
/// Altitude in meters, relative to nominal sea level.
/// </summary>
/// <value>
/// Can be <see langword="null"/> if the location source cannot provide the data.
/// </value>
public double? Altitude { get; }

/// <summary>
/// Accuracy of the altitude expressed in meters.
/// </summary>
/// <value>
/// Can be <see langword="null"/> if the original data source cannot provide the data.
/// </value>
public double? AltitudeAccuracy { get; }

/// <summary>
/// Direction towards which the device is facing. This value, specified in degrees, indicates how far off from
/// heading true north the device is. 0 degrees represents true north, and the direction is determined clockwise
/// (which means that east is 90 degrees and west is 270 degrees). If speed is 0, <see cref="Heading"/> is
/// <see cref="double.NaN"/>.
/// </summary>
/// <value>
/// Can be <see langword="null"/> if the original data source cannot provide the data.
/// </value>
public double? Heading { get; }

/// <summary>
/// Velocity of the device in meters per second.
/// </summary>
/// <value>
/// Can be <see langword="null"/> if the original data source cannot provide the data.
/// </value>
public double? Speed { get; }

/// <summary>
/// Time at which the location was retrieved.
/// </summary>
public DateTime Timestamp { get; }

/// <summary>
/// Initializes a new instance of <see cref="GeoLocation"/> class.
/// </summary>
public GeoLocation(DateTime timestamp, double longitude, double latitude, double accuracy,
double? altitude, double? altitudeAccuracy, double? heading, double? speed)
{
Timestamp = timestamp;
Longitude = longitude;
Latitude = latitude;
Accuracy = accuracy;
Altitude = altitude;
AltitudeAccuracy = altitudeAccuracy;
Heading = heading;
Speed = speed;
}
}
}
9 changes: 9 additions & 0 deletions src/CyclingApp/Models/ReadOnlyRoute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CyclingApp.Models
{
/// <summary>
/// A read-only route.
/// </summary>
/// <param name="waypoints">The waypoints of the route.</param>
public class ReadOnlyRoute(IList<GeoLocation> waypoints) : RouteBase(waypoints)
{ }
}
26 changes: 26 additions & 0 deletions src/CyclingApp/Models/Route.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace CyclingApp.Models
{
/// <summary>
/// An editable route.
/// </summary>
public class Route() : RouteBase([])
{
/// <summary>
/// Add a waypoint to the route.
/// </summary>
/// <param name="waypoint">The waypoint to add.</param>
public new void AddWaypoint(GeoLocation waypoint)
{
base.AddWaypoint(waypoint);
}

/// <summary>
/// Remove waypoint from the route.
/// </summary>
/// <param name="waypoint">The waypoint to remove.</param>
public new void RemoveWaypoint(GeoLocation waypoint)
{
base.RemoveWaypoint(waypoint);
}
}
}
90 changes: 90 additions & 0 deletions src/CyclingApp/Models/RouteBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.ObjectModel;

using Geolocation;

namespace CyclingApp.Models
{
/// <summary>
/// Base class for a route.
/// </summary>
public abstract class RouteBase
{
private readonly List<GeoLocation> _waypoints;

/// <summary>
/// Waypoints of the route.
/// </summary>
public ReadOnlyCollection<GeoLocation> Waypoints { get; }

/// <summary>
/// Distance of the route in absolute meters.
/// </summary>
public double Distance { get; private set; }

/// <summary>
/// Initializes a new instance of <see cref="RouteBase"/> class.
/// </summary>
protected RouteBase(IList<GeoLocation> waypoints)
{
_waypoints = new(waypoints);
Waypoints = new(_waypoints);

Distance = CalculateDistance();
}

/// <summary>
/// Calculate the average speed in kilometers per hour for the route.
/// </summary>
/// <param name="duration">The duration it took for the route.</param>
/// <returns>The average speed in kilometers per hour.</returns>
public double CalculateAvgSpeed(TimeSpan duration)
{
return Distance * 1000 / duration.TotalHours;
}

/// <summary>
/// Add a waypoint to the route.
/// </summary>
/// <param name="waypoint">The waypoint to add.</param>
protected void AddWaypoint(GeoLocation waypoint)
{
_waypoints.Add(waypoint);

Distance = CalculateDistance();
}

/// <summary>
/// Remove waypoint from the route.
/// </summary>
/// <param name="waypoint">The waypoint to remove.</param>
protected void RemoveWaypoint(GeoLocation waypoint)
{
_ = _waypoints.Remove(waypoint);

Distance = CalculateDistance();
}

private double CalculateDistance()
{
var distance = 0d;

if (_waypoints.Count < 2)
{
return distance;
}

var waypoints = _waypoints.OrderBy(x => x.Timestamp).ToList();
for (var i = 0; i < waypoints.Count - 1; i++)
{
var origin = waypoints[i];
var dest = waypoints[i + 1];

distance += GeoCalculator.GetDistance(origin.Latitude, origin.Longitude,
dest.Latitude, dest.Longitude,
0, DistanceUnit.Meters);
}

return distance;
}
}
}
3 changes: 3 additions & 0 deletions src/CyclingApp/Pages/Activity.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/activity/{id:guid}"

<PageTitle>Activity</PageTitle>
34 changes: 34 additions & 0 deletions src/CyclingApp/Pages/Activity.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CyclingApp.Services;

using Microsoft.AspNetCore.Components;

namespace CyclingApp.Pages
{
public partial class Activity

Check warning on line 7 in src/CyclingApp/Pages/Activity.razor.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Activity'
{
/// <summary>
/// Route of the page.
/// </summary>
public const string Route = "/Activity";

private Models.Activity? _activity;

/// <summary>
/// ID of the activity to show.
/// </summary>
[Parameter]
public Guid Id { get; set; }

/// <summary>
/// Service to get an activity.
/// </summary>
[Inject]
protected IActivityService ActivityService { get; set; } = default!;

/// <inheritdoc/>
protected override void OnParametersSet()
{
_activity = ActivityService.Activities.FirstOrDefault(x => x.Id == Id);
}
}
}
Loading

0 comments on commit d625f75

Please sign in to comment.