Beispiel #1
0
class UpdateFluc(Dbbase):
    def __init__(self):
        super(UpdateFluc, self).__init__()
        self.table = 'fluctuation'
        self.latest_update = ''
        self.dbstatistic = Dbstatistic()
        self.exist = False

    def _check_result(self, code):
        self.execute("select * from {} where code = '{}'".format(self.table, code))
        result = self.cursor.fetchall()
        if not result:
            self.exist = False
            return ''
        self.exist = True
        return result[0][2]

    def update_table(self, code, exist):
        latest_date = get_market_date(1)
        five_days_gao = get_market_date(5)
        twenty_days_ago = get_market_date(20)
        half_years_ago = get_market_date(120)
        year_ago = get_market_date(240)
        fluctuation_lastday = self.dbstatistic.cal_fluc(start=latest_date, end=latest_date)
        fluctuation_lastweek = self.dbstatistic.cal_fluc(start=five_days_gao, end=latest_date)
        fluctuation_lastmonth = self.dbstatistic.cal_fluc(start=twenty_days_ago, end=latest_date)
        fluctuation_halfyear = self.dbstatistic.cal_fluc(start=half_years_ago, end=latest_date)
        fluctuation_lastyear = self.dbstatistic.cal_fluc(start=year_ago, end=latest_date)
        fluctuation_total = self.dbstatistic.cal_fluc(start=START_DATE, end=latest_date)
        end = self.dbstatistic.code_last_trading_day
        if exist:
            self.execute("update fluctuation set end = '{}',".format(end) +
                         "fluctuation_total = {},".format(fluctuation_total) +
                         "fluctuation_lastyear = {},".format(fluctuation_lastyear) +
                         "fluctuation_halfyear= {},".format(fluctuation_halfyear) +
                         "fluctuation_lastmonth = {},".format(fluctuation_lastmonth) +
                         "fluctuation_lastweek = {},".format(fluctuation_lastweek) +
                         "fluctuation_lastday = {} where code = '{}'".format(fluctuation_lastday, code)
                         )
        else:
            self.execute("insert into fluctuation values(" +
                         "'{}', '{}', '{}', {}, {}, {}, {}, {}, {})".
                         format(code, START_DATE, end, fluctuation_total, fluctuation_lastyear,
                                fluctuation_halfyear, fluctuation_lastmonth,
                                fluctuation_lastweek, fluctuation_lastday))
        self.conn.commit()

    def run_update(self):
        for code in market_index_list + code_list.keys():
            self.dbstatistic.initialize(code)
            end_date = self._check_result(code)
            if get_market_date(1) == end_date:
                continue
            self.update_table(code, exist=self.exist)
Beispiel #2
0
 def __init__(self):
     super(UpdateFluc, self).__init__()
     self.table = 'fluctuation'
     self.latest_update = ''
     self.dbstatistic = Dbstatistic()
     self.exist = False
Beispiel #3
0
class UpdateFluc(Dbbase):
    def __init__(self):
        super(UpdateFluc, self).__init__()
        self.table = 'fluctuation'
        self.latest_update = ''
        self.dbstatistic = Dbstatistic()
        self.exist = False

    def _check_result(self, code):
        self.execute("select * from {} where code = '{}'".format(
            self.table, code))
        result = self.cursor.fetchall()
        if not result:
            self.exist = False
            return ''
        self.exist = True
        return result[0][2]

    def update_table(self, code, exist):
        latest_date = get_market_date(1)
        five_days_gao = get_market_date(5)
        twenty_days_ago = get_market_date(20)
        half_years_ago = get_market_date(120)
        year_ago = get_market_date(240)
        fluctuation_lastday = self.dbstatistic.cal_fluc(start=latest_date,
                                                        end=latest_date)
        fluctuation_lastweek = self.dbstatistic.cal_fluc(start=five_days_gao,
                                                         end=latest_date)
        fluctuation_lastmonth = self.dbstatistic.cal_fluc(
            start=twenty_days_ago, end=latest_date)
        fluctuation_halfyear = self.dbstatistic.cal_fluc(start=half_years_ago,
                                                         end=latest_date)
        fluctuation_lastyear = self.dbstatistic.cal_fluc(start=year_ago,
                                                         end=latest_date)
        fluctuation_total = self.dbstatistic.cal_fluc(start=START_DATE,
                                                      end=latest_date)
        end = self.dbstatistic.code_last_trading_day
        if exist:
            self.execute(
                "update fluctuation set end = '{}',".format(end) +
                "fluctuation_total = {},".format(fluctuation_total) +
                "fluctuation_lastyear = {},".format(fluctuation_lastyear) +
                "fluctuation_halfyear= {},".format(fluctuation_halfyear) +
                "fluctuation_lastmonth = {},".format(fluctuation_lastmonth) +
                "fluctuation_lastweek = {},".format(fluctuation_lastweek) +
                "fluctuation_lastday = {} where code = '{}'".format(
                    fluctuation_lastday, code))
        else:
            self.execute("insert into fluctuation values(" +
                         "'{}', '{}', '{}', {}, {}, {}, {}, {}, {})".format(
                             code, START_DATE, end, fluctuation_total,
                             fluctuation_lastyear, fluctuation_halfyear,
                             fluctuation_lastmonth, fluctuation_lastweek,
                             fluctuation_lastday))
        self.conn.commit()

    def run_update(self):
        for code in market_index_list + code_list.keys():
            self.dbstatistic.initialize(code)
            end_date = self._check_result(code)
            if get_market_date(1) == end_date:
                continue
            self.update_table(code, exist=self.exist)
Beispiel #4
0
 def __init__(self):
     super(UpdateFluc, self).__init__()
     self.table = 'fluctuation'
     self.latest_update = ''
     self.dbstatistic = Dbstatistic()
     self.exist = False