Created
August 11, 2022 07:07
-
-
Save travisbhartwell/bad743496b618aafa5dc8a17883b531e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dialysis_data.data import TreatmentLog, make_json_converter | |
from visidata import VisiData, TableSheet, Column, date | |
@VisiData.api | |
def open_dialysis(vd, p): | |
"""Dialysis Data Format""" | |
return DialysisDataSheet(p.name, source=p) | |
class DialysisDataSheet(TableSheet): | |
rowtype = "treatment logs" # rowdef: (treatment_date, weight, systolic, diastolic, heart_rate, temperature, solution, initial_drain, ultra_filtration, average_dwell) | |
columns = [ | |
Column("treatment_date", getter=lambda col, row: row.treatment_date, type=date), | |
Column("weight", getter=lambda col, row: float(row.weight.value), type=float), | |
Column( | |
"systolic", | |
getter=lambda col, row: row.blood_pressure.systolic.value, | |
type=int, | |
), | |
Column( | |
"diastolic", | |
getter=lambda col, row: row.blood_pressure.diastolic.value, | |
type=int, | |
), | |
Column("heart_rate", getter=lambda col, row: row.heart_rate.value, type=int), | |
Column( | |
"temperature", | |
getter=lambda col, row: float(row.temperature.value), | |
type=float, | |
), | |
Column("solution", getter=lambda col, row: str(row.solution), type=str), | |
Column( | |
"initial_drain", getter=lambda col, row: row.initial_drain.value, type=int | |
), | |
Column( | |
"ultra_filtration", | |
getter=lambda col, row: row.ultra_filtration.value, | |
type=int, | |
), | |
Column( | |
"average_dwell", getter=lambda col, row: str(row.average_dwell), type=str | |
), | |
] | |
def iterload(self): | |
with open(self.source) as f: | |
self.file_data = f.read() | |
json_converter = make_json_converter() | |
self.treatment_logs: list[TreatmentLog] = json_converter.loads( | |
self.file_data, list[TreatmentLog] | |
) | |
for tl in self.treatment_logs: | |
yield tl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment