示例#1
0
def write_date():
    _results=get_udemy()

    sub = _results['subscribers']
    rev = _results['reviews']
    date=datetime.date.today()

    row = Data(date=date, subscribers=subscribers, reviews=reviews)

    db_session.add(row)
    db_session.commit()
示例#2
0
def write_data():
    #     新規データの読み込み
    _results = get_udemy_info()
    # 書き込むデータ
    date = datetime.date.today()
    subscribers = _results['n_subscribers']
    reviews = _results['n_reviews']

    row = Data(date=date, subscribers=subscribers, reviews=reviews)

    db_session.add(row)
    db_session.commit()
示例#3
0
def read_data():
    from assets import models
    df = pd.read_csv('assets/data.csv')
    date = datetime.datetime.strptime(df.iloc[0, 0], '%Y/%m/%d').date()
    for index, _df in df.iterrows():
        date = datetime.datetime.strptime(_df['date'], '%Y/%m/%d').date()
        row = models.Data(date=date,
                          subscribers=_df['subscribers'],
                          reviews=_df['reviews'])
        db_session.add(row)
        # print(date)
    db_session.commit()
示例#4
0
def update_data():
    #スクレイピングデータの読込み
    _results = get_info()

    #DBに書き込むデータ
    date = datetime.date.today()  #datetime形式
    subscribers = _results['n_subscribers']
    reviews = _results['n_reviews']

    row = Data(date=date, subscribers=subscribers, reviews=reviews)

    db_session.add(row)
    db_session.commit()
示例#5
0
def write_data():

    # get_udemy_info関数内のresults内のデータを見るための準備(新規のデータ)
    _results = get_udemy_info()

    # 書き込むデータ
    date = datetime.date.today()
    subscribers = _results['n_subscribers']
    reviews = _results['n_reviews']

    row = Data(date=date, subscribers=subscribers, reviews=reviews)
    db_session.add(row)
    db_session.commit()
示例#6
0
def write_data():
  #df = pd.read_csv("./data.csv")

  #新規データ
  _results = get_udemy_info()

  #書き込みデータ
  date = datetime.date.today()
  subscribers = _results["n_subscribers"]
  reviews = _results["n_reviews"]
  
  #データベースに追加
  row = Data(date=date , subscribers=subscribers,reviews=reviews)
  db_session.add(row)
  db_session.commit()
示例#7
0
def write_data():
    # df = pd.read_csv('assets/data.csv')
    # 新規のデータ
    _results = get_udemy_info()

    # 書き込むデータ
    date = datetime.date.today()
    subscribers = _results['n_subscribers']
    reviews = _results['n_reviews']

    # results = pd.DataFrame([[date, subscribers, reviews]], columns=['date', 'subscribers', 'reviews'])

    # df = pd.concat([df, results])
    # df.to_csv('assets/data.csv', index=False)

    row = Data(date=date, subscribers=subscribers, reviews=reviews)

    db_session.add(row)
    db_session.commit()
示例#8
0
def predict_nextday():

    # 価格情報を取得しデータフレームに格納
    today_data = db_session.query(Data).all()[-1]
    today_data.real_price = get_price()  # 上書き(上書きする前はNoneになっている)
    db_session.add(today_data)
    db_session.commit()

    # windowを作成し標準化
    window = 5
    data_five = db_session.query(Data).all()[-window:]
    input_will = []

    for price in data_five:
        input_will.append(price.real_price)

    input_will = np.array(input_will).reshape(1, window, 1)
    input_mean = np.mean(input_will)
    input_std = np.std(input_will)
    sta_input = (input_will - input_mean) / input_std

    # 学習済みモデルを取得
    with open("lstm_model.pickle", "rb") as f:
        model = pickle.load(f)

    # 翌日の価格を予測、標準化してあるので元に戻す
    future_price = model.predict(sta_input)
    future_price = future_price.reshape(-1)
    future_price = future_price * input_std + input_mean
    future_price = float(future_price)

    # 翌日の日付を取得
    today = db_session.query(Data).all()[-1].date
    next_day = today + timedelta(days=1)

    # 翌日の日付、予測した価格をデータベースに格納
    row = Data(date=next_day, real_price=None, pred_price=future_price)
    db_session.add(row)
    db_session.commit()
示例#9
0
from assets.database import db_session
from assets.database import init_db
from assets.models import Data
import datetime

init_db()

#create
date = datetime.date.today()
row1 = Data(date=date, subscribers=6500, reviews=210)
row2 = Data(date=date, subscribers=1500, reviews=220)
db_session.add(row1)
db_session.add(row2)
db_session.commit() #commitでデータベースに保存

#read
read1 = db_session.query(Data).all()[0].subscribers

#update
datum = db_session.query(Data).all()[0]
datum.subscribers = 1000
db_session.add(datum)
db_session.commit()

#dalete
datum = db_session.query(Data).filter_by(subscribers=1000).one()
db_session.delete(datum)
db_session.commit()
#全削除
#Data.query.delete()
print(db_session.query(Data).all())