Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 13 additions & 13 deletions Cookbook/ActivityDecode/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-dotnettools.csharp",
"mechatroner.rainbow-csv"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-dotnettools.csharp",
"mechatroner.rainbow-csv"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
]
}
56 changes: 28 additions & 28 deletions Cookbook/ActivityDecode/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ActivityDecode.dll",
"args": [
"${workspaceFolder}/Activity.fit"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/ActivityDecode.dll",
"args": [
"${workspaceFolder}/Activity.fit"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
82 changes: 41 additions & 41 deletions Cookbook/ActivityDecode/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/ActivityDecode.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
18 changes: 9 additions & 9 deletions Cookbook/ActivityDecode/ActivityDecode.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Garmin.FIT.Sdk" Version="*"/>
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Garmin.FIT.Sdk" Version="*"/>
</ItemGroup>
</Project>
184 changes: 92 additions & 92 deletions Cookbook/ActivityDecode/ActivityParser.cs
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2023 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using Dynastream.Fit;
using Extensions;

public class ActivityParser
{
private FitMessages _messages;
public bool IsActivityFile => _firstFileIdMesg != null ? (_firstFileIdMesg.GetType() ?? File.Invalid) == File.Activity : false;

public FileIdMesg _firstFileIdMesg => _messages.FileIdMesgs.FirstOrDefault();
public ActivityMesg _activityMesg => _messages.ActivityMesgs.FirstOrDefault();

public ActivityParser(FitMessages messages)
{
_messages = messages;
}

public List<SessionMessages> ParseSessions()
{
if (!IsActivityFile)
{
throw new Exception($"Expected FIT File Type: Activity, recieved File Type: {_firstFileIdMesg?.GetType()}");
}

// Create a read/write list of session messages
var sessionMesgs = new List<SessionMesg>(_messages.SessionMesgs);

// When there are no Sessions but there are Records create a Session message to recover as much data as possible
if (sessionMesgs.Count == 0 && _messages.RecordMesgs.Count > 0)
{
Dynastream.Fit.DateTime startTime = _messages.RecordMesgs[0].GetTimestamp();
Dynastream.Fit.DateTime timestamp = _messages.RecordMesgs[_messages.RecordMesgs.Count - 1].GetTimestamp();

var session = new SessionMesg();
session.SetStartTime(startTime);
session.SetTimestamp(timestamp);
session.SetTotalElapsedTime(timestamp.GetTimeStamp() - startTime.GetTimeStamp());
session.SetTotalTimerTime(timestamp.GetTimeStamp() - startTime.GetTimeStamp());

sessionMesgs.Add(session);
}

int recordsTaken = 0;

var sessions = new List<SessionMessages>(sessionMesgs.Count);
foreach (SessionMesg sessionMesg in sessionMesgs)
{
var session = new SessionMessages(sessionMesg)
{
Laps = _messages.LapMesgs.Skip(sessionMesg.GetFirstLapIndex() ?? 0).Take(sessionMesg.GetNumLaps() ?? 0).ToList(),

ClimbPros = _messages.ClimbProMesgs.Where(climb => climb.Within(sessionMesg)).ToList(),
Events = _messages.EventMesgs.Where(evt => evt.Within(sessionMesg)).ToList(),
DeviceInfos = _messages.DeviceInfoMesgs.Where(deviceInfo => deviceInfo.Within(sessionMesg)).ToList(),
Lengths = _messages.LengthMesgs.Where(length => length.Overlaps(sessionMesg)).ToList(),
Records = _messages.RecordMesgs.Skip(recordsTaken).Where(record => record.Within(sessionMesg)).ToList(),
SegmentLaps = _messages.SegmentLapMesgs.Where(segmentLap => segmentLap.Overlaps(sessionMesg)).ToList(),

TimerEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.Timer && evt.Within(sessionMesg)).ToList(),
FrontGearChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.FrontGearChange && evt.Within(sessionMesg)).ToList(),
RearGearChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.RearGearChange && evt.Within(sessionMesg)).ToList(),
RiderPositionChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.RiderPositionChange && evt.Within(sessionMesg)).ToList(),

FileId = _firstFileIdMesg,
Activity = _activityMesg,
};

recordsTaken += session.Records.Count;
sessions.Add(session);
}

return sessions;
}

public List<DeviceInfoMesg> DevicesWhereBatteryStatusIsLow()
{
var batteryStatus = new List<byte>() { BatteryStatus.Critical, BatteryStatus.Low };
var deviceInfos = new List<DeviceInfoMesg>();

deviceInfos = _messages.DeviceInfoMesgs.Where(info => batteryStatus.Contains(info.GetBatteryStatus() ?? BatteryStatus.Unknown)).ToList();
return deviceInfos;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2023 Garmin International, Inc.
// Licensed under the Flexible and Interoperable Data Transfer (FIT) Protocol License; you
// may not use this file except in compliance with the Flexible and Interoperable Data
// Transfer (FIT) Protocol License.
/////////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using Dynastream.Fit;
using Extensions;
public class ActivityParser
{
private FitMessages _messages;
public bool IsActivityFile => _firstFileIdMesg != null ? (_firstFileIdMesg.GetType() ?? File.Invalid) == File.Activity : false;
public FileIdMesg _firstFileIdMesg => _messages.FileIdMesgs.FirstOrDefault();
public ActivityMesg _activityMesg => _messages.ActivityMesgs.FirstOrDefault();
public ActivityParser(FitMessages messages)
{
_messages = messages;
}
public List<SessionMessages> ParseSessions()
{
if (!IsActivityFile)
{
throw new Exception($"Expected FIT File Type: Activity, recieved File Type: {_firstFileIdMesg?.GetType()}");
}
// Create a read/write list of session messages
var sessionMesgs = new List<SessionMesg>(_messages.SessionMesgs);
// When there are no Sessions but there are Records create a Session message to recover as much data as possible
if (sessionMesgs.Count == 0 && _messages.RecordMesgs.Count > 0)
{
Dynastream.Fit.DateTime startTime = _messages.RecordMesgs[0].GetTimestamp();
Dynastream.Fit.DateTime timestamp = _messages.RecordMesgs[_messages.RecordMesgs.Count - 1].GetTimestamp();
var session = new SessionMesg();
session.SetStartTime(startTime);
session.SetTimestamp(timestamp);
session.SetTotalElapsedTime(timestamp.GetTimeStamp() - startTime.GetTimeStamp());
session.SetTotalTimerTime(timestamp.GetTimeStamp() - startTime.GetTimeStamp());
sessionMesgs.Add(session);
}
int recordsTaken = 0;
var sessions = new List<SessionMessages>(sessionMesgs.Count);
foreach (SessionMesg sessionMesg in sessionMesgs)
{
var session = new SessionMessages(sessionMesg)
{
Laps = _messages.LapMesgs.Skip(sessionMesg.GetFirstLapIndex() ?? 0).Take(sessionMesg.GetNumLaps() ?? 0).ToList(),
ClimbPros = _messages.ClimbProMesgs.Where(climb => climb.Within(sessionMesg)).ToList(),
Events = _messages.EventMesgs.Where(evt => evt.Within(sessionMesg)).ToList(),
DeviceInfos = _messages.DeviceInfoMesgs.Where(deviceInfo => deviceInfo.Within(sessionMesg)).ToList(),
Lengths = _messages.LengthMesgs.Where(length => length.Overlaps(sessionMesg)).ToList(),
Records = _messages.RecordMesgs.Skip(recordsTaken).Where(record => record.Within(sessionMesg)).ToList(),
SegmentLaps = _messages.SegmentLapMesgs.Where(segmentLap => segmentLap.Overlaps(sessionMesg)).ToList(),
TimerEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.Timer && evt.Within(sessionMesg)).ToList(),
FrontGearChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.FrontGearChange && evt.Within(sessionMesg)).ToList(),
RearGearChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.RearGearChange && evt.Within(sessionMesg)).ToList(),
RiderPositionChangeEvents = _messages.EventMesgs.Where(evt => evt.GetEvent() == Event.RiderPositionChange && evt.Within(sessionMesg)).ToList(),
FileId = _firstFileIdMesg,
Activity = _activityMesg,
};
recordsTaken += session.Records.Count;
sessions.Add(session);
}
return sessions;
}
public List<DeviceInfoMesg> DevicesWhereBatteryStatusIsLow()
{
var batteryStatus = new List<byte>() { BatteryStatus.Critical, BatteryStatus.Low };
var deviceInfos = new List<DeviceInfoMesg>();
deviceInfos = _messages.DeviceInfoMesgs.Where(info => batteryStatus.Contains(info.GetBatteryStatus() ?? BatteryStatus.Unknown)).ToList();
return deviceInfos;
}
}
Loading
Loading