-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
585 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace CyclingApp.Models | ||
{ | ||
public class Activity | ||
{ | ||
public Guid Id { get; } | ||
|
||
/// <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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@page "/activity/{id:guid}" | ||
|
||
<PageTitle>Activity</PageTitle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
/// <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); | ||
} | ||
} | ||
} |
Oops, something went wrong.