Parses Blood Pressure Statistics
BP Diag parses blood pressure statistics from data files. It generates some statistics and prints them to STDERR. You can export the collected data (and the gathered statistics) to JSON (dump to STDOUT). And you can also generate SVG or PNG charts from it.:
bpdiag [OPTIONS] [OUTPUT [OUTPUT OPTIONS]].. [PARSER [PARSER OPTIONS]] FILENAME..
To see a list of possible command line options run:
Lets say we got a file called
bloodpressure.txt containing the following
values in a simple format. This is a good job for our default parser (there
are other parsers, but more on this later):
136/83/65, 132/82/70 144/82/86, 137/81/75, -, 143/80/68 131/82/60, 144/82/64, 136/79/67, 140/80/62 136/83/68, 138/80/99, -, 133/74/65 136/79/67, 131/76/64, 135/81/72, 136/75/61 127/79/72
So if we run BP Diag over the file like this:
We got the following results:
Parsed 17 value(s)... Statistics (min, max, avg): :: SYS...: 127, 144, 136 :: DIA...: 74, 83, 79 :: PULSE.: 60, 99, 69
We can also dump the results to JSON with
--json or generate a line
chart from it with
--chart (for more options see below).
Modular Input: Parsers
Parsers define how the input from the given files is transformed into instances of the Measurements class. Those contain containing the data for each parsed measurement.
BP Diag comes with a couple of parsers, but it's easy to write your own if they don't fit your needs (just take a look at the source documentation of the module).
Parser: Plaintext [plain]
The plaintext parser is good to grab values from simple text files, like copied from a note taking app or whatever. It's for files that just store a couple of SYS, DIA and PULSE values.
For each line the
--delimiter (default is
,) is used to split multiple
entries on the line. And
/) is used to split the
entries into the SYS, DIA and PULSE values. Entries that just contain
--skip string (default:
-) are skipped.
Number of measurements per line
Per default all values are gathered one after the other. But you can use the
--entries option to set a fixed number of measurements per line.
What this means is that only that much values are used per line (even if there
are more) and if a line contains less than entries values, the remaining
ones are filled with
None values. Also values that are the skip string
are not ignored, but stored as a None value too.
This can be helpful in cases where you have a given number of measurements per line and you want to keep them aligned even if sometimes a measurement is skipped / missing (eg. because you take three measures a day and keep them on a line).:
bpdiag.py --json --compact --entries 4 bloodpressure.txt
Will result in the following JSON:
Parser: Regular Expression [regex]
Parses each line with a regular expression. Every named group becomes an
attribute of the resulting Measurement instance. A named group looks
(?P<name-of-the-grp>), and you need at least a group for
SYS, DIA and PULSE, but you can grab as many info from the line as you want,
it will get stored in the Measurement instance.
This is the default regex, it captures date, time, sys, dia and
pulse. But you can give set any regular expression with the
Parser: JSON [json]
Parses one JSON array from all given files. Each entry in the array needs to
be either an array with exactly three values for SYS, DIA and PULSE or -
--as-obj is used - a JSON object, in which case all key/value pairs get
As we already seen, you will always get some statistics-output to STDERR. But you can also export the gathered data to a number of formats:
There are a couple of ways to do this, but always the JSON dump is written to STDOUT, so you can redirect the dump to a file.
You can dump the data as an array of SYS, DIA, PULS arrays with the
option. Or as an array of objects with the
--json-obj option (this will
include all attributes of the Measurement instances, not just SYS, DIA
and PULSE). If you want the gathered statistics too, use
There are a couple of options to govern how the dump is formated, see the
--help output for info on that.
To generate SVG charts, you need to have PyGal installed (see below). Other
than that, just use the
--chart option to have a chart called
generated in your current directory. There are more options to this, take a
look at the
Instead of the interactive SVG charts you can use PNG as output format. Just
--png option along with
--chart. You need a couple more
dependencies for that though, take a look below.
You can install BP Diag with pip or from source.
Install with pip
pip install --user bpdiag
Install from source
You can fetch the latest sourceball from github and unpack it, or just clone
git clone git://github.com/brutus/bpdiag. If you
got the source, change into the directory and use
python setup.py --user install
pip install --user pygal
pip install --user CairoSVG tinycss cssselect
Bugs and Contribution
BP Diag is at home at: https://github.com/brutus/bpdiag/
If you want to run the test cases, see that you got nose installed and run
nosetests from the
bpdiag directory (the one containing the module).
If you got bpdiag already installed, run them like this:
If something fails, please get in touch.
If you find any bugs, issues or anything, please use the issue tracker.