コード例 #1
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def bloodsugar():
    db_class = mod_dbconn.Database()

    email = request.args.get("email")
    sql = "SELECT bloodsugar FROM db.bloodsugar order by idx desc limit 10"
    row = db_class.executeAll(sql)

    return jsonify(row)
コード例 #2
0
def supply_desc(p_id):
    # 상세페이지 조회하는 함수
    db_class = mod_dbconn.Database()
    sql = """SELECT *
                FROM taxocr.t_provider
                WHERE p_id = %s"""
    desc_dict = db_class.executeAll(sql, args=p_id)
    return desc_dict
コード例 #3
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def readCarb():
    db_class = mod_dbconn.Database()

    email = request.args.get("email")

    sql = "SELECT * FROM db.carb WHERE email=" + email
    row = db_class.executeAll(sql)

    return jsonify(row)
コード例 #4
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def deleteInsulin():
    idx = request.args.get("idx")

    db_class = mod_dbconn.Database()

    sql = "DELETE FROM db.insulin WHERE idx=" + idx
    row = db_class.executeAll(sql)
    db_class.commit()

    return jsonify(row)
コード例 #5
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def readInsulin():

    email = request.args.get("email")

    db_class = mod_dbconn.Database()

    sql = "SELECT * FROM db.insulin WHERE email=" + email
    row = db_class.executeAll(sql)

    return jsonify(row)
コード例 #6
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def addInsulin():

    email = request.form['email']
    insulin = request.form['value']
    fDate = request.form['fDate']

    db_class = mod_dbconn.Database()
    '''
    sql = "INSERT INTO db.insulin (insulin, email, fDate) VALUES(" + insulin + ", \'" + email + "\', \'" + fDate + "\')"
    row = db_class.executeAll(sql)
    print(sql)
    db_class.commit()
    '''
    sql = "SELECT * FROM db.features WHERE email = \'" + email + "\' and fDate >= \'" + fDate + "\' ORDER BY fDate DESC"
    print(sql)
    row = db_class.executeAll(sql)

    #x = 투여량, insulin
    #t = 마지막 투여로부터 지난 시간, fDate - curDate
    for i in row:
        curDate = i.get('fDate')
        x = float(insulin)
        date_time_obj = datetime.strptime(fDate, '%Y-%m-%d %H:%M:%S')
        diff = curDate - date_time_obj
        t = diff.seconds / 60
        print(t)
        print("인슐린량")
        print(x)

        input = x * ((0.0008 * x + 0.028) * (0.0008 * x + 0.028)) * 2 * t * (
            2.7**0.09 * t) / (t * t + (0.0008 * x + 0.028) *
                              (0.0008 * x + 0.028)) * (t * t +
                                                       (0.0008 * x + 0.028) *
                                                       (0.0008 * x + 0.028))
        print(insulin.__class__)
        print(curDate.__class__)

        sql = "UPDATE db.features SET insulin = " + str(
            input) + " WHERE fDate = \'" + str(
                curDate) + "\' and email = \'" + email + "\'"
        print(sql)

        row = db_class.executeAll(sql)
        db_class.commit()

    return jsonify(row)
コード例 #7
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def addCarb():

    email = request.form['email']
    carb = request.form['value']
    fDate = request.form['fDate']

    db_class = mod_dbconn.Database()
    '''
    sql = "INSERT INTO db.carb (carb, email, fDate) VALUES(" + carb + ", \'" + email + "\', \'" + fDate + "\')"
    row = db_class.executeAll(sql)
    print(sql)
    db_class.commit()
    '''
    sql = "SELECT * FROM db.features WHERE email = \'" + email + "\' and fDate >= \'" + fDate + "\' ORDER BY fDate DESC"
    print(sql)
    row = db_class.executeAll(sql)

    #x = 투여량, insulin
    #t = 마지막 투여로부터 지난 시간, fDate - curDate
    for i in row:
        curDate = i.get('fDate')
        v = float(carb)
        date_time_obj = datetime.strptime(fDate, '%Y-%m-%d %H:%M:%S')
        diff = curDate - date_time_obj
        t = diff.seconds / 60
        print(t)

        if t >= 0 and t < 30:
            input = (t - 1) / 15 + math.exp(-t)
        elif t >= 30 and t < 30 + (5.5 * v - 2) / 240:
            input = 2 + math.exp(-t)
        elif 30 + (5.5 * v - 2) / 240 <= t and t < 60 + (5.5 * v - 2) / 240:
            input = -0.0015 * v + math.exp(-t) - 0.06 * t + 4.06
        else:
            input = math.exp(-t)

        sql = "UPDATE db.features SET carb = " + str(
            input) + " WHERE fDate = \'" + str(
                curDate) + "\' and email = \'" + email + "\'"
        print(sql)

        row = db_class.executeAll(sql)
        db_class.commit()

    return jsonify(row)
コード例 #8
0
from app import mod_dbconn

year_='2010' # 이거 웹에서 받아올거라 변수 여기서 선언 안되어있어도 됨(?)
db_class = mod_dbconn.Database()

# 세금 데이터----------------------------------------
def taxdata(year_):
    taxsql = """SELECT SUM(t_bill.b_cost_tax)
                FROM t_bill
                WHERE YEAR(t_bill.b_date) = %s""" 

    taxrow = db_class.executeOne(taxsql, year_)
    taxdata = int(taxrow["SUM(t_bill.b_cost_tax)"])

    return taxdata

# Doughnut graph------------------------------------
def doughnutGraph(year_):
    labels = [] # 그래프 x축: 회사명
    data = [] #그래프 y축 : 거래 금액
    temp = [] # 디비에서 빼온 것 잠깐 담을 리스트
    temp2 = [] # 위와 동일
    temptuple = [] # 위와 동일

    sql = """SELECT t_provider.p_corp_name as p_corp_name,
            SUM(t_bill.b_cost_total) as b_cost_total_sum
            FROM t_provider, t_bill
            WHERE t_provider.p_id = t_bill.FK_p_id AND YEAR(t_bill.b_date) = %s
            GROUP BY FK_p_id
            ORDER BY SUM(t_bill.b_cost_total) DESC"""
    row = db_class.executeAll(sql, year_)
コード例 #9
0
ファイル: __init__.py プロジェクト: CBMteam/CBM_Flask
def user():
    email = request.form['email']
    #email = request.args.get("email")

    print(email)

    db_class = mod_dbconn.Database()

    sql = "SELECT id, cycle, bloodsugar, carb, insulin FROM db.features WHERE email=\"" + email + "\"ORDER BY fDate DESC LIMIT 1301"
    row = db_class.executeAll(sql)

    train_df = DataFrame(row)

    print(train_df)
    print(train_df.shape)

    train_df = train_df.sort_values(['id', 'cycle'])

    # Data Labeling - generate column RUL (Remaining Useful Life or Time to Failure)
    rul = pd.DataFrame(train_df.groupby('id')['cycle'].max()).reset_index()
    rul.columns = ['id', 'max']
    train_df = train_df.merge(rul, on=['id'], how='left')
    train_df['RUL'] = train_df['max'] - train_df['cycle']
    train_df.drop('max', axis=1, inplace=True)

    print("러벨링")
    print(train_df.shape)

    # MinMax normalization (from 0 to 1)
    train_df['cycle_norm'] = train_df['cycle']
    cols_normalize = train_df.columns.difference(
        ['id', 'cycle', 'RUL', 'label1', 'label2', 'label3'])
    min_max_scaler = preprocessing.MinMaxScaler()
    norm_train_df = pd.DataFrame(min_max_scaler.fit_transform(
        train_df[cols_normalize]),
                                 columns=cols_normalize,
                                 index=train_df.index)
    join_df = train_df[train_df.columns.difference(cols_normalize)].join(
        norm_train_df)
    train_df = join_df.reindex(columns=train_df.columns)

    print("노말라이제이션")
    print(train_df.shape)

    train_df[train_df["id"] == 1].tail()

    max_batch_len = train_df['id'].value_counts().max()
    train_cols = ['bloodsugar', 'carb', 'insulin'] + ['cycle_norm']
    test_cols = ["RUL"]

    xhat = pad_engines(train_df, train_cols, 1301)

    print(xhat)
    print(xhat.shape)

    #(1301, 4)
    print(xhat.shape)

    #xhat = np.zeros((1, 1301, 4))
    y_pred = model.predict(xhat)

    print(y_pred.shape)
    print(y_pred[-1].shape)

    #tte = {
    #'tte': json.dumps(str(y_pred[-1].flatten()[-1]))
    #'tte':str(y_pred[-1].flatten()[-1])
    #}

    return str(y_pred[-1].flatten()[-1])