Example #1
0
def update(stockno,stockname,openp,close,high,low,volumn,amount,trade_day):
    #
    dbw.update('stock_base_infos',
        stock_name=stockname,
        open=openp,close=close,high=high,low=low,volumn=volumn,amount=amount,trade_date=trade_day,
        last_update=web.SQLLiteral('NOW()'),
        where="stock_no=$stockno",vars=locals())
Example #2
0
def import_rows(rows):
    date = rows[0].date
    for r in rows:
        candle = r.candle_2
        results = check_exist(date, r.stock_no)
        pk_id = insert_row(date,
                           r.stock_no) if not results else results[0].pk_id
        dbw.update('stock_daily',
                   open=r.open_price,
                   close=r.close_price,
                   high=r.high_price,
                   low=r.low_price,
                   volume=r.volume,
                   amount=r.amount,
                   last_close=r.last_close,
                   high_low=r.high_low,
                   close_open=r.close_open,
                   open_last_close=r.open_last_close,
                   jump_rate=r.jump_rate,
                   price_rate=r.raise_drop_rate,
                   high_rate=r.high_rate,
                   low_rate=r.low_rate,
                   hig_low_rate=r.high_rate - r.low_rate,
                   range_1=candle[0],
                   range_2=candle[1],
                   range_3=candle[2],
                   last_update=web.SQLLiteral('NOW()'),
                   where='pk_id=$pk_id',
                   vars=locals())
Example #3
0
def update(stock_no,date,raise_drop,raise_drop_rate,volume_updown,volume_updown_rate):
    dbw.update('stock_daily_records',
        raise_drop = raise_drop,
        raise_drop_rate = raise_drop_rate,
        volume_updown = volume_updown,
        volume_updown_rate = volume_updown_rate,
        where="stock_no=$stock_no and date=$date",vars=locals())
Example #4
0
def get_access_token(user_id,device_no,device_type,os_type,channel,version): 
    result = list(dbr.select('user_devices',
        what="user_id,device_no,access_token,device_type,os_type",
        where="user_id=$user_id and device_no=$device_no",vars=locals()))

    access_token = generate_access_token()
    if not result:
        dbw.insert('user_devices',user_id=user_id,device_no=device_no, 
        device_type=device_type,os_type=os_type,
        access_token=access_token,
        channel=channel,
        version=version,
        creation_date=web.SQLLiteral('now()'),
        last_update=web.SQLLiteral('now()'))

        result = list(dbr.select('user_devices',
        what="user_id,device_no,access_token,device_type,os_type",
        where="user_id=$user_id and device_no=$device_no",vars=locals()))
    else:
        dbw.update('user_devices',
            device_no=device_no, 
            device_type=device_type,os_type=os_type,
            access_token=access_token,
            channel=channel,
            version=version,
            last_update=web.SQLLiteral('now()'),
            where="user_id=$user_id and device_no=$device_no",vars=locals())
        result[0].access_token = access_token 
    
    return load_user(result[0].user_id)
Example #5
0
def import_rows(rows):
    for r in rows:
        stock_no = r.stock_no
        dbw.update('stock_base_infos',
            open=r.open_price,close=r.close_price,high=r.high_price,low=r.low_price,volumn=r.volume,amount=r.amount,trade_date=r.date,
            lclose=r.last_close,prate=r.raise_drop_rate,candle=r.candle,
            last_update=web.SQLLiteral('NOW()'),
            where="stock_no=$stock_no",vars=locals())
Example #6
0
def update(stock_no, date, raise_drop, raise_drop_rate, volume_updown,
           volume_updown_rate):
    dbw.update('stock_daily_records',
               raise_drop=raise_drop,
               raise_drop_rate=raise_drop_rate,
               volume_updown=volume_updown,
               volume_updown_rate=volume_updown_rate,
               where="stock_no=$stock_no and date=$date",
               vars=locals())
Example #7
0
def update(pk_id, result):
    dbw.update('stock_base_infos',
               days_count_5=result.days_count_5,
               trend_5=result.trend_5,
               trend_3=result.trend_3,
               prate_3=result.prate_3,
               prate_5=result.prate_5,
               ratetrend_date=web.SQLLiteral('NOW()'),
               where='pk_id=$pk_id',
               vars=locals())
Example #8
0
def update(pk_id, result):
    dbw.update(
        "stock_base_infos",
        days_count_5=result.days_count_5,
        trend_5=result.trend_5,
        trend_3=result.trend_3,
        prate_3=result.prate_3,
        prate_5=result.prate_5,
        ratetrend_date=web.SQLLiteral("NOW()"),
        where="pk_id=$pk_id",
        vars=locals(),
    )
Example #9
0
def import_rows(rows):
    date = rows[0].date 
    for r in rows:
        candle = r.candle_2
        results = check_exist(date,r.stock_no)
        pk_id = insert_row(date,r.stock_no) if not results else results[0].pk_id
        dbw.update('stock_daily',
            open=r.open_price,close=r.close_price,high=r.high_price,low=r.low_price,volume=r.volume,amount=r.amount,last_close=r.last_close,
            high_low = r.high_low, close_open = r.close_open, open_last_close = r.open_last_close, 
            jump_rate=r.jump_rate, price_rate=r.raise_drop_rate, high_rate = r.high_rate, low_rate = r.low_rate, hig_low_rate =  r.high_rate -  r.low_rate,
            range_1=candle[0],range_2=candle[1],range_3=candle[2],
            last_update = web.SQLLiteral('NOW()'),
            where='pk_id=$pk_id',vars=locals())
Example #10
0
def update(stockno, stockname, openp, close, high, low, volumn, amount,
           trade_day):
    #
    dbw.update('stock_base_infos',
               stock_name=stockname,
               open=openp,
               close=close,
               high=high,
               low=low,
               volumn=volumn,
               amount=amount,
               trade_date=trade_day,
               last_update=web.SQLLiteral('NOW()'),
               where="stock_no=$stockno",
               vars=locals())
Example #11
0
def update_sogou_idf(term, count, idf):
    return dbw.update(tname,
                      sogou_ix_count=count,
                      sogou_idf=idf,
                      sogou_last_get=web.SQLLiteral('now()'),
                      where="term=$term",
                      vars=locals())
Example #12
0
def computeLastClosePrice(records):
    count = len(records)
    for i in range(0, count):
        if (count - i) == 1:
            break
        last_close = records[i + 1].close
        open_last_close = records[i].open - records[i + 1].close
        high_low = records[i].high - records[i].low
        close_open = records[i].close - records[i].open
        price_rate = (records[i].close - last_close) / last_close
        high_rate = (records[i].high - last_close) / last_close
        low_rate = (records[i].low - last_close) / last_close
        high_low_rate = high_rate - low_rate
        candle = comm.get_candle_2(records[i].open, records[i].close,
                                   records[i].high, records[i].low)
        range_1 = candle[0]
        range_2 = candle[1]
        range_3 = candle[2]

        jump_rate = open_last_close / last_close
        jump_level = 0
        if jump_rate * 100 >= 2:
            jump_level = 3
        elif jump_rate * 100 >= 0 and jump_rate * 100 < 2:
            jump_level = 2
        elif jump_rate * 100 < 0:
            jump_level = 1
        else:
            jump_level = 50

        pk_id = records[i].pk_id
        dbw.update('stock_daily',
                   high_low=high_low,
                   last_close=last_close,
                   open_last_close=open_last_close,
                   close_open=close_open,
                   price_rate=price_rate,
                   high_rate=high_rate,
                   low_rate=low_rate,
                   hig_low_rate=high_low_rate,
                   range_1=range_1,
                   range_2=range_2,
                   range_3=range_3,
                   jump_level=jump_level,
                   jump_rate=jump_rate,
                   where="pk_id=$pk_id",
                   vars=locals())
Example #13
0
def import_rows(rows):
    for r in rows:
        stock_no = r.stock_no
        dbw.update('stock_base_infos',
                   open=r.open_price,
                   close=r.close_price,
                   high=r.high_price,
                   low=r.low_price,
                   volumn=r.volume,
                   amount=r.amount,
                   trade_date=r.date,
                   lclose=r.last_close,
                   prate=r.raise_drop_rate,
                   candle=r.candle,
                   last_update=web.SQLLiteral('NOW()'),
                   where="stock_no=$stock_no",
                   vars=locals())
Example #14
0
def import_date_sums(str_date):
    sql = '''SELECT 'all' as stock_plate,count(*) as stock_count,
        avg(open_price) as open,avg(high_price) as high,avg(low_price) as low,avg(close_price) as close,avg(volume) as volume,avg(amount) as amount
        FROM `stock_daily_records` where date='%s' ''' % (str_date)
    #rows = dbr.query(sql)
    #insert_date_sum(str_date,rows)

    sql = '''SELECT stock_market_no as stock_plate,count(*) as stock_count,
        avg(open_price) as open,avg(high_price) as high,avg(low_price) as low,avg(close_price) as close,avg(volume) as volume,avg(amount) as amount
        FROM `stock_daily_records` where date='%s' and stock_market_no is not null group by stock_market_no''' % (str_date)
    rows = dbr.query(sql)
    insert_date_sum(str_date,rows)

    sql = '''SELECT stock_market_no as stock_plate,count(*) as stock_count
        FROM `stock_daily_records` where date='%s' and stock_market_no is not null and raise_drop>0 group by stock_market_no  ''' % (str_date)
    rows = dbr.query(sql)
    for r in rows:
        stock_plate = r.stock_plate
        dbw.update('date_sums',price_up_count=r.stock_count, where="trade_date=$str_date and stock_plate=$stock_plate",vars=locals())
    dbw.query("update date_sums set price_up_percent=price_up_count/stock_count where trade_date='%s'" % (str_date) )
Example #15
0
def get_access_token(user_id, device_no, device_type, os_type, channel,
                     version):
    result = list(
        dbr.select('user_devices',
                   what="user_id,device_no,access_token,device_type,os_type",
                   where="user_id=$user_id and device_no=$device_no",
                   vars=locals()))

    access_token = generate_access_token()
    if not result:
        dbw.insert('user_devices',
                   user_id=user_id,
                   device_no=device_no,
                   device_type=device_type,
                   os_type=os_type,
                   access_token=access_token,
                   channel=channel,
                   version=version,
                   creation_date=web.SQLLiteral('now()'),
                   last_update=web.SQLLiteral('now()'))

        result = list(
            dbr.select(
                'user_devices',
                what="user_id,device_no,access_token,device_type,os_type",
                where="user_id=$user_id and device_no=$device_no",
                vars=locals()))
    else:
        dbw.update('user_devices',
                   device_no=device_no,
                   device_type=device_type,
                   os_type=os_type,
                   access_token=access_token,
                   channel=channel,
                   version=version,
                   last_update=web.SQLLiteral('now()'),
                   where="user_id=$user_id and device_no=$device_no",
                   vars=locals())
        result[0].access_token = access_token

    return load_user(result[0].user_id)
Example #16
0
def update_date_sum(date, data, plate=0):
    rows = list(
        dbr.select('date_sum_infos',
                   where="date=$date and plate=$plate",
                   vars=locals()))
    if len(rows) == 0:
        dbw.insert('date_sum_infos',
                   date=date,
                   plate=plate,
                   create_date=web.SQLLiteral("NOW()"),
                   last_update=web.SQLLiteral("NOW()"))
    dbw.update(
        'date_sum_infos',
        total_count=data.total_count,
        price_up_count=data.price_up_count,
        volumn_up_count=data.volumn_up_count,
        price_up_percent=data.price_up_percent,
        volumn_up_percent=data.volumn_up_percent,
        #  price_raise_sum = data.price_raise_sum,
        where="date=$date and plate=$plate",
        vars=locals())
Example #17
0
def computeLastClosePrice(records):
    count = len(records)
    for i in range(0,count):
        if (count-i) == 1:
            break
        last_close = records[i+1].close
        open_last_close = records[i].open - records[i+1].close
        high_low = records[i].high - records[i].low
        close_open = records[i].close - records[i].open
        price_rate = (records[i].close - last_close)/last_close
        high_rate = (records[i].high - last_close)/last_close
        low_rate = (records[i].low - last_close)/last_close
        high_low_rate = high_rate - low_rate
        candle = comm.get_candle_2(records[i].open,records[i].close,records[i].high,records[i].low)
        range_1 = candle[0]
        range_2 = candle[1]
        range_3 = candle[2]

        jump_rate = open_last_close / last_close 
        jump_level = 0
        if jump_rate*100>=2:
            jump_level = 3
        elif jump_rate*100>=0 and jump_rate*100<2:
            jump_level = 2
        elif jump_rate*100<0:
            jump_level = 1
        else:
            jump_level = 50  

        pk_id = records[i].pk_id
        dbw.update('stock_daily',high_low=high_low,last_close=last_close,open_last_close=open_last_close,
            close_open = close_open,
            price_rate=price_rate,high_rate=high_rate,low_rate=low_rate,hig_low_rate=high_low_rate,
            range_1 = range_1,range_2 = range_2,range_3 = range_3,
            jump_level = jump_level, jump_rate=jump_rate,
            where="pk_id=$pk_id",vars=locals())
Example #18
0
def update_a(term,**kv):
	return dbw.update(tname,where="term=$term",vars=locals(),**kv)
Example #19
0
def update_a(term, **kv):
    return dbw.update(tname, where="term=$term", vars=locals(), **kv)
Example #20
0
def update(term, count, idf=0):
    return dbw.update(tname,
                      count=count,
                      idf=idf,
                      where="term=$term",
                      vars=locals())
Example #21
0
def update_code_status(pk_id, status):
    dbw.update(tname,
               code_status=status,
               last_update=web.SQLLiteral('now()'),
               where="pk_id=$pk_id",
               vars=locals())
Example #22
0
def update(pkid, gua64):
    dbw.update('stock_base_infos',
               gua64=gua64,
               where="pk_id=$pkid",
               vars=locals())
Example #23
0
def update_trend3(trade_date,stock_no,trend3):
    dbw.update('stock_daily',trend_3=trend3,where="trade_date=$trade_date and stock_no=$stock_no",vars=locals())
Example #24
0
def update1(pk_id,**kv):
    return dbw.update(table_name,last_update=web.SQLLiteral('now()'),where='pk_id=$pk_id ',vars=locals(),**kv)
Example #25
0
def update(pk_id,**kv):
    dbw.update('stock_daily_records',where='pk_id=$pk_id',vars=locals(),**kv)
Example #26
0
def update(pkid,gua64):
    dbw.update('stock_base_infos',
        gua64=gua64,         
        where="pk_id=$pkid",vars=locals())
Example #27
0
def update_code_status(pk_id,status):
    dbw.update(tname,
        code_status=status, last_update=web.SQLLiteral('now()'),
        where="pk_id=$pk_id",
        vars=locals())
Example #28
0
def update(term,count,idf=0):
	return dbw.update(tname,count=count,idf=idf,where="term=$term",vars=locals())
Example #29
0
def update_sogou_idf(term,count,idf):
	return dbw.update(tname,sogou_ix_count=count,sogou_idf=idf,sogou_last_get=web.SQLLiteral('now()'),
		where="term=$term",vars=locals())
Example #30
0
def update_daily(stock_no,date,gua64):
    dbw.update('stock_daily_records',
        gua64=gua64,         
        where="stock_no=$stock_no and date=$date",vars=locals())
Example #31
0
def update_trend3(trade_date, stock_no, trend3):
    dbw.update('stock_daily',
               trend_3=trend3,
               where="trade_date=$trade_date and stock_no=$stock_no",
               vars=locals())
Example #32
0
def update_daily(stock_no, date, gua64):
    dbw.update('stock_daily_records',
               gua64=gua64,
               where="stock_no=$stock_no and date=$date",
               vars=locals())