Skip to content

Instantly share code, notes, and snippets.

@dmalikov
Created July 15, 2024 22:59
Show Gist options
  • Save dmalikov/9fed4e5aabb7bf4d00361715083b96d3 to your computer and use it in GitHub Desktop.
Save dmalikov/9fed4e5aabb7bf4d00361715083b96d3 to your computer and use it in GitHub Desktop.
remove HR from garmin activity

Remove HR from TCX file

Requirements

stack is required. On MacOS it can be installed via brew install stack.

Usage

Assuming there is an affected Garmin activity that you want to remove HR data from.

  1. Export TCX file from the affected activity.

  2. Delete the activity.

  3. Execute the script.

./remove-hr.hs ./activity_16430490680.tcx > ./activity_16430490680_nohr.tcx

  1. Upload the fixed TCX file.
#!/usr/bin/env stack
-- stack script --resolver lts-20.15 --package xml
import Data.Maybe (catMaybes)
import System.Environment (getArgs)
import Text.XML.Light.Input
import Text.XML.Light.Output
import Text.XML.Light.Types
main :: IO ()
main = do
filename <- head <$> getArgs
xml <- parseXML <$> readFile filename
mapM_ (putStrLn . showContent) . catMaybes $ filterHR <$> xml
filterHR :: Content -> Maybe Content
filterHR (Elem e) | qName (elName e) == "HeartRateBpm" = Nothing
filterHR (Elem e) | otherwise = Just . Elem $ e { elContent = catMaybes (filterHR <$> elContent e) }
filterHR x = Just x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment