protected function writeLapHeartRateDate(\XMLWriter $xmlWriter, Track $track)
    {
        $averageHeartRate = array();
        $maxHearRate = null;
        foreach ($track->trackPoints() as $trackPoint) {
            if ($trackPoint->hasExtension(HR::ID()) === true) {
                $pointHearRate = $trackPoint->extension(HR::ID())->value();

                $maxHearRate = max($maxHearRate, $pointHearRate);
                $averageHeartRate[] = $pointHearRate;
            }
        }

        if ($averageHeartRate !== array()) {
            $xmlWriter->startElement('AverageHeartRateBpm');
            $xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
            $hearRateValue = array_sum($averageHeartRate) / count($averageHeartRate);
            $xmlWriter->writeElement('Value', (string)$hearRateValue);
            $xmlWriter->endElement();
        }

        if ($maxHearRate !== null) {
            $xmlWriter->startElement('MaximumHeartRateBpm');
            $xmlWriter->writeAttributeNS('xsi', 'type', null, 'HeartRateInBeatsPerMinute_t');
            $xmlWriter->writeElement('Value', (string)$maxHearRate);
            $xmlWriter->endElement();
        }
    }