示例#1
0
    def Weightplot(self):
        # Retrieves all the history and packages into an array.
        weighthist = self.read_weight()
        weight = []
        weight_date = []
        lastreading = ''
        for element in weighthist:
            # dateobj = datetime.datetime.fromisoformat(element['timestamp'])
            dateobj = datefromisotz(element['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y")
            # Only print one value per day to avoid artifacts in plotting.
            # if (lastreading != date_repr):
            weight_date.append(dateobj)
            weight.append(element['weight'])

        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)

        ax.plot(weight_date, weight, color="blue")

        ax.set_ylabel('kg', size=13)
        fig.autofmt_xdate()
        fig.suptitle("Weight (kg)", size=20)

        holder = io.BytesIO()
        fig.savefig(holder, format="svg")
        image = "data:image/svg+xml;base64," + \
            base64.b64encode(holder.getvalue()).decode()

        holder.close()
        return (image)
示例#2
0
    def Osatplot(self):
        # Retrieves all the history and packages into an array.
        osathist = self.read_osat()
        osat = []
        osat_date = []
        lastreading = ''
        for element in osathist:
            dateobj = datefromisotz(element['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y")
            osat_date.append(dateobj)
            osat.append(element['osat'])

        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)

        ax.plot(osat_date, osat, color="red")

        ax.set_ylabel('%', size=13)
        fig.autofmt_xdate()
        fig.suptitle("Osat (%)", size=20)

        holder = io.BytesIO()
        fig.savefig(holder, format="svg")
        image = "data:image/svg+xml;base64," + \
            base64.b64encode(holder.getvalue()).decode()

        holder.close()
        return (image)
示例#3
0
    def Glucoseplot(self):
        # Retrieves all the history and packages into an array.
        glucosehist = self.read_glucose()
        glucose = []
        glucose_date = []
        lastreading = ''
        for element in glucosehist:
            dateobj = datefromisotz(element['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y")
            # Only print one value per day to avoid artifacts in plotting.
            # if (lastreading != date_repr):
            glucose_date.append(dateobj)
            glucose.append(element['glucose'])

        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)

        ax.plot(glucose_date, glucose, color="red")

        ax.set_ylabel('mg/dl', size=13)
        fig.autofmt_xdate()
        fig.suptitle("Glucose level (mg/dl)", size=20)

        holder = io.BytesIO()
        fig.savefig(holder, format="svg")
        image = "data:image/svg+xml;base64," + \
            base64.b64encode(holder.getvalue()).decode()

        holder.close()
        return image
示例#4
0
    def HRplot(self):
        # Retrieves all the history and packages into an array.
        hrhist = self.read_hr()
        hr = []
        hr_date = []
        lastreading = ''
        for element in hrhist:
            dateobj = datefromisotz(element['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y")
            # Only print one value per day to avoid artifacts in plotting.
            if (lastreading != date_repr):
                hr_date.append(dateobj)
                hr.append(element['heart_rate'])

            lastreading = date_repr

        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)

        ax.plot(hr_date, hr, color="orange")

        ax.set_ylabel('Frequency', size=13)
        fig.autofmt_xdate()
        fig.suptitle("Heart Rate (bpm)", size=20)

        holder = io.BytesIO()
        fig.savefig(holder, format="svg")
        image = "data:image/svg+xml;base64," + \
            base64.b64encode(holder.getvalue()).decode()

        holder.close()
        return image
示例#5
0
    def getGlucose(self):
        # Extracts the latest readings from Glucose
        glucosehist = self.read_glucose()
        glucoseobj = ['', '']
        if (glucosehist):  # Enter this block if there is a history
            glucose = glucosehist[-1]  # Get the latest (newest) record
            dateobj = datefromisotz(glucose['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y - %H:%M")

            glucoseobj = [str(date_repr), str(glucose['glucose'])]
        return glucoseobj
示例#6
0
    def getOsat(self):
        # Extracts the latest readings from Osat
        osathist = self.read_osat()
        osatobj = ['', '']
        if (osathist):
            osat = osathist[-1]  # Get the latest (newest) record

            # dateobj =  datetime.datetime.fromisoformat(osat['timestamp'])
            dateobj = datefromisotz(osat['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y - %H:%M")
            osatobj = [str(date_repr), str(osat['osat'])]
        return osatobj
示例#7
0
    def getWeight(self):
        # Extracts the latest readings from Weight
        weighthist = self.read_weight()
        weightobj = ['', '']
        if (weighthist):
            weight = weighthist[-1]  # Get the latest (newest) record

            # dateobj =  datetime.datetime.fromisoformat(weight['timestamp'])
            dateobj = datefromisotz(weight['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y - %H:%M")

            weightobj = [str(date_repr), str(weight['weight'])]
        return weightobj
示例#8
0
    def getBP(self):
        # Extracts the latest readings from BP
        bphist = self.read_bp()
        hrhist = self.read_hr()
        bpobj = ['', '', '', '']  # Init to empty string to avoid undefined val
        if bphist and hrhist:
            bp = bphist[-1]  # Get the latest (newest) record
            hr = hrhist[-1]

            # dateobj =  datetime.datetime.fromisoformat(bp['timestamp'])
            dateobj = datefromisotz(bp['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y - %H:%M")

            bpobj = [
                str(date_repr),
                str(bp['systolic']),
                str(bp['diastolic']),
                str(hr['heart_rate'])
            ]

        return bpobj
示例#9
0
    def BPplot(self):
        # Retrieves all the history and packages into an array.
        bphist = self.read_bp()
        bpsys = []
        bpdia = []
        bp_date = []
        lastreading = ''
        for element in bphist:

            dateobj = datefromisotz(element['timestamp'])
            date_repr = dateobj.strftime("%a, %b %d '%y")

            # Only print one value per day to avoid artifacts in plotting.
            if (lastreading != date_repr):
                bp_date.append(dateobj)
                bpsys.append(element['systolic'])
                bpdia.append(element['diastolic'])

            lastreading = date_repr

        fig, axs = plt.subplots(2)

        # Plot both systolic and diastolic history
        axs[0].plot(bp_date, bpsys)
        axs[1].plot(bp_date, bpdia, color='teal')

        axs[0].set_ylabel('Systolic', size=13)
        axs[1].set_ylabel('Diastolic', size=13)

        fig.autofmt_xdate()
        fig.suptitle("Blood Pressure (mm Hg)", size=20)
        holder = io.BytesIO()
        fig.savefig(holder, format="svg")
        image = "data:image/svg+xml;base64," + \
            base64.b64encode(holder.getvalue()).decode()

        holder.close()
        return image