A lose collection of code I reuse in different (scientific) projects.
Module | analy |
Generate output for analysis in form of tables and figures. |
Module | bandas |
Helpers with pandas . |
Module | khq |
Scoring mode of the German version of the King's Health Questionnaire described in Bjelic-Radisci V et al. (2005) DOI: 10.1055/s-2005-872957. |
Module | report |
That module can create reports from data objects like pandas.DataFrame , images or figures (e.g. based on seaborn or matplotlib ). |
Module | stausberg |
Calculation of comorbidity score based on the structure of the ICD-10 described in Stausberg; Hagn (2015): New Morbidity and Comorbidity Scores based on the Structure of the ICD-10 DOI: 10.1371/journal.pone.0143365... |
Module | zuf |
Scoring mode of the ZUF-8 "Fragenbogen zur Patientenzufriedenheit". A German translation based on the CSQ-8 "Client Satisfaction Questionnaire". |
Module | _buhtzology |
Undocumented |
Module | _datacontainer |
The bandas data container. |
From __init__.py
:
Function | generate |
Combine basename, path and timestamp to a filepath of an existing file. |
Function | get |
Build a string representing the application name and its version. |
Function | get |
Return the current branch and last commit hash. |
Function | how |
Calculate the number of elements in one piece when a bigger list of elements is cut into pieces depending on rules. |
Function | runtime |
Gives the runtime as a string. |
Function | setup |
Setup the root logger with a console and a file handler. |
Function | shorten |
Shorten strings to a given limit but keep them unique to the list. |
Variable | __full |
Full name string including version, branch, commit. |
Variable | __version__ |
Version string of the package. |
Variable | meta |
Undocumented |
Function | _package |
Get package metadata and return it as a dict. |
str
, file_suffix: str
, folder_path: pathlib.Path
= None, age_offset: int
= 0) -> pathlib.Path
:
(source)
¶
Combine basename, path and timestamp to a filepath of an existing file.
Generates a path of an existing file with a timestamp in its name based on a name stem, a file suffix. Optionally a folder different from current working dir (default) and an offset for the file age (based on the timestamp in filename) can be set.
The original file names should contain a timestamp (e.g. YYYY-MM-DD) or another numeric or lexicographical sortable element. The =folder_path= is searched for all files matching the name pattern =*basename*file_suffix=. The found names are sorted reverse lexicographical. The 'age_offset' element of that list is returned which is by default the first element in the list which in turn is the youngest file provided the timestamp's in the filenames are correct.
Parameters | |
basename:str | Name stem of the file's to search. |
filestr | Suffix of the file's to search. |
folderpathlib.Path | Path to the folder where to search in (default: current working dir). |
ageint | Element to use after reverse lexicographic sorting. |
Returns | |
pathlib.Path | File path relative to current working dir. |
Raises | |
FileNotFoundError | When no file was found. |
IndexError | If the 'age_offset' does not work. |
Gives the runtime as a string.
The runtime is calculated from the difference between current time and 'start_time'. Example results are "20 seconds" or "4.5 minutes".
Parameters | |
startdatetime.datetime | Timestamp of start. |
Returns | |
str | Undocumented |
int
, pieces_n: int
= None, min_max_per_piece: int
= None, min_pieces_n: int
= None) -> int
:
(source)
¶
Calculate the number of elements in one piece when a bigger list of elements is cut into pieces depending on rules.
If 'pieces_n' is given all other arguments are ignored and the result are the number of elements per piece you have to cut from your list to get the number of pieces specified by 'pieces_n'.
If 'pieces_n' is None then the number of elements per piece is calculated based on 'min_max_per_piece'. But if 'min_pieces_n' is given also then the min/max rules can be overwritten to give you as much elements per pieces to result with 'min_pieces_n.
- There is a hierarchy of the rules.
- If 'pieces_n' is given the rest of arguments are ignored.
- If 'pieces_n' is None then 'min_max_per_piece' is taken into account. If present 'min_pieces_n' is also taken into account.
Be aware that the last piece in your list can have less then the resulting number of elements per piece.
Parameters | |
totalint | x |
piecesint | y |
minint | z |
minint | a |
Returns | |
int | Number of elements one piece should have to fulfill the rules. |
Raises | |
ValueError | No rules specified with arguments. |
pathlib.Path
= None, console_level: int
= logging.INFO, console_format_str: str
= '%(log_color)s[%(levelname)s]%(reset)s %(message)s', file_level: int
= logging.DEBUG, file_format_str: str
= '%(asctime)s - %(name)s - %(levelname)s - %(message)s', file_backup_count: int
= 20, exceptional_loggers: Dict[ str, int]
= None):
(source)
¶
Setup the root logger with a console and a file handler.
The file handler is rotated for each session. The file name is based on
sys.argv[0] (the filename of the current running python script). With
exceptional_loggers it is possible to set levels to specific loggers;
e.g. matplotlib.font_manager
or PIL
which are know for annoying debug
messages.
Colorized console output is activated by default if the package colorlog is available.
Parameters | |
logpathlib.Path | Path to log file directory. |
consoleint | Log level for console (stdout) handler. |
consolestr | Format of the console log messages. |
fileint | Log level for file handler. Deactivate with None. |
filestr | Format of the file log messages. |
fileint | Keep that amount of log files. |
exceptionalDict[ | Levels for specific loggers. |
Build a string representing the application name and its version.
If a git repo is present also information about its current state are added.