def insert_aggregate(self, house, should_commit=True):
     aggregate = Aggregate(location=house['location'], origin_dataset_id=self.origin_dataset.id)
     self.session.add(aggregate)
     if should_commit:
         self.session.commit()
     return aggregate
Beispiel #2
0
from app import app, db
from datetime import datetime
from models import Aggregate, Day, Hours
from bitcoin_api import buyHour, sellHour, buyDay, sellDay, buyMonth, sellMonth

time_h = date.hour
time_d = date.day
time_m = date.month

month = Aggregate.query.filter_by(month_number=time_m).first()

if month is None:
    # Create Month, Day, Hour
    month = Aggregate(month=date.strftime("%B"),
                      month_number=time_m,
                      average_buy=-1,
                      average_sell=-1)
    day = Day(month=date.strftime("%B"),
              month_number=time_m,
              average_buy=-1,
              average_sell=-1,
              parent_month=month,
              day_number=time_d)
    hour = Hours(hour_number=time_h, buy_price=-1, sell_price=-1, hour=day)

    db.session.add(month)
    db.session.add(day)
    db.session.add(hour)
    db.session.commit()

    buyHour(hour)
Beispiel #3
0
def creation(date, buy, sell):
    date = strptime(date, '%m/%d/%y %H:%M')
    print("%r" % date)

    time_h = date.tm_hour
    time_d = date.tm_mday
    time_m = date.tm_mon
    complete_month = 0
    complete_day = 0

    monthDict = {
        1: 'Jan',
        2: 'Feb',
        3: 'Mar',
        4: 'Apr',
        5: 'May',
        6: 'Jun',
        7: 'Jul',
        8: 'Aug',
        9: 'Sep',
        10: 'Oct',
        11: 'Nov',
        12: 'Dec'
    }

    month = Aggregate.query.filter_by(month_number=time_m).first()
    day = Day.query.filter_by(month_number=time_m).first()

    if month is None:
        # Create Month, Day, Hour
        month = Aggregate(month=monthDict[time_m],
                          month_number=time_m,
                          average_buy=-1,
                          average_sell=-1)
        day = Day(month=monthDict[time_m],
                  month_number=time_m,
                  average_buy=-1,
                  average_sell=-1,
                  parent_month=month,
                  day_number=time_d)
        hour = Hours(hour_number=time_h,
                     buy_price=buy,
                     sell_price=sell,
                     hour=day)

        db.session.add(month)
        db.session.add(day)
        db.session.add(hour)
        db.session.commit()

        complete_month = buyMonth(month)
        sellMonth(month)

    else:
        day = Day.query.filter_by(day_number=time_d, month_id=month.id).first()

        if day is None:
            day = Day(month=monthDict[time_m],
                      month_number=time_m,
                      average_buy=-1,
                      average_sell=-1,
                      parent_month=month,
                      day_number=time_d)
            hour = Hours(hour_number=time_h,
                         buy_price=buy,
                         sell_price=sell,
                         day_id=day.id)

            db.session.add(day)
            db.session.add(hour)
            db.session.commit()

            complete_day = buyDay(day)
            sellDay(day)

        else:
            hour = Hours.query.filter_by(hour_number=time_h,
                                         day_id=day.id).first()

            if hour is None:
                hour = Hours(hour_number=time_h,
                             buy_price=buy,
                             sell_price=sell,
                             day_id=day.id)

                db.session.add(hour)
                db.session.commit()