health
I have a Garmin Fenix 6 Sapphire and it records some health statistics. Due to post-COVID I have problems with my health and keep a record of some health numbers.
This is a great learning project to refactor my current Python code to COBOL.
The first step is to read the health.csv and output the numbers.
* Author: Cees van de Griend
* Date: 2025-08-21
* Licence: EUPL-1.2
* Description: Import health.csv
IDENTIFICATION DIVISION.
PROGRAM-ID. import.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT csv ASSIGN TO 'health.csv'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD csv.
01 csv-file.
05 csv-line PIC x(80).
WORKING-STORAGE SECTION.
01 ws-line pic x(80) value spaces.
01 ws-eof pic x value 'N'.
01 ws-header pic x value 'Y'.
01 ws-health.
05 ws-date.
10 ws-year pic 9999.
10 filler pic x value '-'.
10 ws-month pic 99.
10 filler pic x value '-'.
10 ws-day pic 99.
05 filler pic x value space.
05 ws-sleep-score pic zz9 value 0.
05 filler pic x value space.
05 ws-body-battery-max pic zz9 value 0.
05 filler pic x value space.
05 ws-body-battery-min pic zz9 value 0.
05 filler pic x value space.
05 ws-activity-time pic zzz9 value 0.
05 filler pic x value space.
05 ws-defecation pic 9 value 0.
01 ws-header-1.
05 filler pic a(10) value 'Date '.
05 filler pic a value space.
05 filler pic a(3) value 'SS '.
05 filler pic a value space.
05 filler pic a(3) value 'BMa'.
05 filler pic a value space.
05 filler pic a(3) value 'BMi'.
05 filler pic a value space.
05 filler pic a(4) value 'ActT'.
05 filler pic a value space.
05 filler pic a value 'D'.
01 ws-header-2.
05 filler pic x(10) value '----------'.
05 filler pic x value space.
05 filler pic x(3) value '---'.
05 filler pic x value space.
05 filler pic x(3) value '---'.
05 filler pic x value space.
05 filler pic x(3) value '---'.
05 filler pic x value space.
05 filler pic x(4) value '----'.
05 filler pic x value space.
05 filler pic x value '-'.
PROCEDURE DIVISION.
open input csv.
display ws-header-1
end-display
display ws-header-2
end-display
perform until ws-eof = 'Y'
read csv into ws-line
at end
move 'Y' to ws-eof
not at end
* display ws-line
* end-display
if ws-header = 'Y' then
move 'N' to ws-header
else
unstring ws-line delimited by ',' into
ws-date
ws-sleep-score
ws-body-battery-max
ws-body-battery-min
ws-activity-time
ws-defecation
end-unstring
display ws-health
end-display
end-if
end-read
end-perform
close csv.
stop run.
end program import.
cees@dev01:~/prj/health$ ./import
Warning: program compiled against libxml 212 using older 209
Date SS BMa BMi ActT D
---------- --- --- --- ---- -
2024-07-15 65 68 15 56 3
2024-07-16 58 73 19 32 3
2024-07-17 76 79 15 162 2
2024-07-18 80 74 11 94 2
2024-07-19 75 65 5 143 4
2024-07-20 78 55 5 103 0
2024-07-21 79 65 5 67 3
2024-07-22 0 30 5 34 3
- SS: Sleep score from 0 to 100.
- BMa: Body Battery Max from 0 to 100.
- BMi: Body Battery Min from 0 to Body Battery Max.
- ActT: Minutes of active time.
- D: Defecation from 0 to 5.