예제 #1
0
def testcase1():
    ## 2018-11-22,07:51,68.40,461,3.60,11.50,66.30,45.90,22.30,1542873060
    data_peter = {
        "measured": 72.80,
        "calcweight": 70.65,
        "unit": 'kg',
        "impedance": 478,
        "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
        "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
    }

    data_reni = {
        "measured": 49.50,
        "calcweight": 49.50,
        "unit": 'kg',
        "impedance": 495,
        "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
        "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
    }

    data = data_peter

    log.info('Calcluation based on data:{}'.format(data))
    mCalc = calcdata.CalcData(data, True)
    mi_data = mCalc.getData('string')
    print(mi_data)
예제 #2
0
def testcase1():
    variables_file = '../data/gewichtsdaten.csv'
    reader = csv.DictReader(open(variables_file, 'r'), delimiter=',')
    dict_list = []
    for line in reader:
        dict_list.append(line)

    line_count = 0
    for data in dict_list:
        # simulate the impedance from the history values
        # impedance = int((450 / 54) * float(data['wasser']))
        impedance = int((175**2) / float(data['wasser']))
        scaledata = {
            "measured": float(data['gewicht']),
            "calcweight": 70.65,
            "unit": 'kg',
            "impedance": impedance,
            "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
            "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
        }
        mCalc = calcdata.CalcData(scaledata, True)
        user = mCalc.getUserData()
        mCalc.impedance = int((user['height']**2) / float(data['wasser']))

        # get the data from the calculation
        results = mCalc.getData('full', 'data')

        log.info("Results: {}".format(results))
        line_count += 1

    print(f'Processed {line_count} lines.')
    return line_count
예제 #3
0
def main():

    dict_list = []  # list previous data
    line_count = 0  # number of lines

    scaledata = dict()  # data object for the calc module
    height = 175  # height for the user
    try:
        # file with the data from the previous scale
        # datum,zeit,gewicht,knochen,fett,wasser,muskeln,bmi,timestamp
        # 31.12.2013,12:35,77.90,3.70,21.00,59.20,40.60,25.40,1388493300
        # ....
        variables_file = '../data/peter.csv'
        reader = csv.DictReader(open(variables_file, 'r'), delimiter=',')

        # build the dict list
        for line in reader:
            dict_list.append(line)

        for data in dict_list:
            # calculate  the impedance from the history values
            impedance = (int(height)**2) / float(data['wasser'])
            dt_object = datetime.fromtimestamp(int(data['timestamp']))
            scaledata = {
                "measured": float(data['gewicht']),
                "calcweight": float(data['gewicht']) * 2.00,
                "unit": 'kg',
                "impedance": int(data['impedance']),
                "timestamp": "{} {}:00".format(data['datum'], data['zeit']),
                "scantime": "{} {}:00".format(data['datum'], data['zeit'])
            }

            log.info('Calcluation based on data:{}'.format(scaledata))

            # initialize the calc module with the data from the csv file
            mCalc = calcdata.CalcData(scaledata, True)

            # get the userdata
            mi_userdata = mCalc.getUserData()

            # calculate all miscale data
            log.info('Calcluation for user :{}, Date:{}'.format(
                mi_userdata['name'], scaledata['timestamp']))

            mi_data = mCalc.getData('alldata')
            if mCalc.ready:
                # publish data to influxdb
                datasections = {"influxdb": True}
                mCalc.publishdata(datasections)

            line_count += 1

        log.info(
            '{} previous data found, transfer finished'.format(line_count))

    except BaseException as e:
        log.error(
            f"Error {__name__}, {str(e)} line {sys.exc_info()[-1].tb_lineno}")
예제 #4
0
def doCalc(scaledata: dict = None,
           useAge: bool = False,
           useAthletic: bool = False):

    mCalc = calcdata.CalcData(scaledata, useAge)
    user = mCalc.getUserData()
    mCalc.athletic = useAthletic

    log.info(
        "User: {}\t Athletic: {} \tAge: {} \tyears Weight: {}kg \tImpedance: {}"
        .format(mCalc.user, mCalc.athletic, round(mCalc.age, 2), mCalc.weight,
                mCalc.impedance))
    results = mCalc.getData('full', 'data')
    mCalc = None

    return results
예제 #5
0
def updateInfluxDb():

    log.debug("Start Update Influxdb data")

    variables_file = '../data/peter.csv'
    reader = csv.DictReader(open(variables_file, 'r'), delimiter=',')
    dict_list = []
    for line in reader:
        dict_list.append(line)

    line_count = 0

    for data in dict_list:

        # recalc the impedance and build the measurement data
        scaledata = {
            "measured": float(data['gewicht']),
            "calcweight": float(data['gewicht']),
            "unit": 'kg',
            "impedance": data['impedance'],
            "timestamp": data['datum'] + " " + data['zeit'],
            "scantime": data['datum'] + " " + data['zeit']
        }

        log.info("Scale data: {}".format(scaledata))

        # start the calculation modul
        mCalc = calcdata.CalcData(scaledata, True)

        # get the userdata
        user = mCalc.getUserData()

        # make the calulations
        if mCalc.doCalc('full'):

            # publish data to the influxDB
            log.info("Update row{}, User{}".format(line_count, user['name']))
            mCalc.publish2Influxdb()
            mCalc.bodyScores2Influxdb()

        line_count += 1

    print(f'Processed {line_count} records to influxDB.')
    return line_count
예제 #6
0
def checkData():
    
    scaledata = {
        "measured": 68.50,
        "calcweight": 70.65,
        "unit": 'kg',
        "impedance": 543,
        "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
        "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
    }

    log.info("Calcdata: {}".format(scaledata))
    mCalc = calcdata.CalcData(scaledata, True)
    user = mCalc.getUserData()
    
    # get the data from the calculation
    results = mCalc.getData('full', 'data')
    log.info("Results: {}".format(results))
    mCalc.__savedata__()
예제 #7
0
def doCalc(scaledata, data) -> dict:

    mCalc = calcdata.CalcData(scaledata, True)
    user = mCalc.getUserData()
    mCalc.impedance = (int(user['height'])**2) / float(data['wasser'])

    # get the data from the calculation
    result = mCalc.getData('full', 'data')
    useAthletic = result['athletic']
    useAthletic = False
    # try to rescale the calculated values
    if useAthletic:

        #result['fat'] = round(result['fat'] - 8.34, 2)
        result['fat'] = round(result['fat'] * 0.6225, 2)
        result['bone'] = round(result['bone'] * 1.302, 2)
        result['water'] = round(result['water'] * 1.033, 2)
        result['muscle'] = round(result['muscle'] * 0.852, 2)
        result['visceral'] = round(result['visceral'] * 0.475, 2)

    # Körperfettanteil + Knochenmasse + Muskelmasse = 100 % der Körperzusammensetzung
    result['check'] = round(float(result['fat']) + float(result['bone']) + float(result['muscle']) + float(result['water']), 2)
    return result
예제 #8
0
def testcase2():

    xmax = 600
    ymax = 10

    data = dict()
    data['fat'] = dict()
    data['visceral'] = dict()
    data['muscle'] = dict()
    data['bone'] = dict()
    data['water'] = dict()

    for impedance in range(450, 600):
        miscale_peter = {
            "measured": 70.65,
            "calcweight": 70.65,
            "unit": 'kg',
            "impedance": impedance,
            "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
            "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
        }

        miscale_reni = {
            "measured": 50.65,
            "calcweight": 50.65,
            "unit": 'kg',
            "impedance": impedance,
            "timestamp": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S')),
            "scantime": str(datetime.today().strftime('%Y-%m-%d %H:%M:%S'))
        }
        mCalc = calcdata.CalcData(miscale_peter)
        result = mCalc.getData('full', 'data')

        y = result['fat']
        # if y>ymax: ymax = y+0.10
        data['fat'][impedance] = y

        y = result['visceral']
        # if y>ymax: ymax = y+0.10
        data['visceral'][impedance] = y

        y = result['muscle']
        # if y>ymax: ymax = y+0.10
        data['muscle'][impedance] = y

        y = result['water']
        # if y>ymax: ymax = y+0.10
        data['water'][impedance] = y

        y = result['bone']
        # if y>ymax: ymax = y+0.10
        data['bone'][impedance] = y

    # draw the grid
    fig, ax = plt.subplots(1, figsize=(8, 6))
    plt.suptitle("Testcase Body Calculator Impedance {}".format(
        result['timestamp']),
                 fontsize=12)
    plt.title("Result for User {} ({}), Years:{}, Weight:{}{}, ".format(
        result['user'], result['sex'], result['age'], result['measured'],
        result['unit'], result['timestamp']),
              fontsize=10)
    # Show the major grid lines with dark grey lines
    ax.minorticks_on()
    ax.grid(b=True, which='major', color='#666666', linestyle='-', alpha=0.75)

    # Show the minor grid lines with very faint and almost transparent grey lines
    ax.minorticks_on()
    ax.grid(b=True, which='minor', color='#999999', linestyle='-', alpha=0.1)

    # primary y:
    ax.plot(*zip(*sorted(data['fat'].items())), label='1-fat', color="red")
    ax.plot(*zip(*sorted(data['visceral'].items())),
            label='2-visceral',
            color="orange")
    ax.plot(*zip(*sorted(data['bone'].items())), label='5-bone', color="lime")
    ax.set_ylabel("1-fat, 2-visceral, 5-Bone %")
    ax.set_xlabel("Impedance (Ω)")

    # secondary y:
    ax2 = ax.twinx()
    ax2.plot(*zip(*sorted(data['muscle'].items())),
             label='3-muscle',
             color="green")
    ax2.plot(*zip(*sorted(data['water'].items())),
             label='4-water',
             color="blue")
    ax2.set_ylabel("3-Muscle, 4-Water %")

    # add legend
    lines_1, labels_1 = ax.get_legend_handles_labels()
    lines_2, labels_2 = ax2.get_legend_handles_labels()
    lines = lines_1 + lines_2
    labels = labels_1 + labels_2
    ax.legend(lines, labels, loc="center left")

    plt.savefig("impedance.png", dpi=600)
    plt.show()