Skip to content

Instantly share code, notes, and snippets.

@samueltardieu
Created November 26, 2025 21:39
Show Gist options
  • Select an option

  • Save samueltardieu/a91f4c2e326c5a51f4bc75e830d69a5b to your computer and use it in GitHub Desktop.

Select an option

Save samueltardieu/a91f4c2e326c5a51f4bc75e830d69a5b to your computer and use it in GitHub Desktop.
# Transform a file containing self-measures blood pressure measurements
# into a typst file that will be used to build a document to send
# to the physician.
#
# The format of the document is:
# ```
# One title line describing the dates of the self-measurements
# 120 78 77
# 121 76 80
# …
# ```
#
# The input file must contain 18 self-measurements lines:
# - 3 measurements of systolic/diastolic/heartbeat every session
# - 1 session on the morning, one of the evening
# - for three days
#
# The idea is that it is very fast to copy data from the blood pressure
# sensor to the file, without inserting the fractional symbol, etc.
#
# It will build a typst file using a template, containing the title
# and the measures, in which the means per session, per morning,
# per evening and total have been inserted. systolic and diastolic
# values will be divided by 10 and rounded to one fractional digit.
# Input file is given on the command line, and output file will have
# the same name with ".txt" replaced by ".typ"
⊏1&args
⊸(˙⍤≍"txt"◌°$"_._") # Check that name ends in .txt
⊸&fras
# Separate the first line, and all numbers by rows of 3, grouped into 6 blocks
↯6_3_3⊜(⊜⋕⊸≠@\s)⊸≠@\n°˜$"_\n_"
# Compute mean for every column of each group
# and append it at the end of the group
≡(⍜⍉≡(⊂⟜(÷₃/+)))
# Add the morning and evening means, and the general means
# after the measures and round all values
⁅⊂⊃♭₂(⊂⊃(⊟|÷₂+)∩⌟(÷₃/+≡⊣⊏)⟜+₁×₂⇡3)
# Divide blood pressure by 10 and join values into a typst array content
/$"_,_"♭≡(⍜↙₂÷₁₀)
# Write output file
&fwa⊃⋅⋅($"_.typ"°$"_.txt")˜$"#import \"template.typ\": *\n#automesures(\"_\", (_))\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment