示例#1
0
def update_output(date):
    """计算总产量"""
    db = Session()
    obj = PreprocessDayDataArtificial
    # for varieties in DAY_VARIEYIES_DICT.keys():
    for varieties in ['cu', 'al', 'pb', 'zn']:
        symbol = get_symbol(varieties, key='total_output')
        init_vals = init_output_import(db, varieties, date)
        res = cal_total_output(varieties, date, **init_vals)
        if res:
            logging.debug('保存(总产量), 品类: %s, 时间: %s, 值: %s ' %
                          (varieties, date, res))
            save_symbol_data(db, res, date, symbol=symbol, obj=obj)
            db.commit()
    db.close()
示例#2
0
def newdata(dic):
    session = Session()
    ndata = Argentina(date=dic['date'],
                      cases=dic['casos'],
                      deaths=dic['muertes'],
                      recovered=dic['recuperados'],
                      terapy=dic['terapia'],
                      testsNegative=dic['testsNegatives'],
                      tests=dic['tests'],
                      discardedNegatives=dic['negativosDescarte'],
                      dailyCases=dic['casosDiarios'],
                      dailyTestNegative=dic['testNegativosDiarios'],
                      imported=dic['casosImportados'],
                      contactCase=dic['contactoEstrecho'],
                      communitary_Transmission=dic['trasmisionComunitaria'])
    session.add(ndata)
    session.commit()
    session.flush()
    session.close()
示例#3
0
def update_or_create_symbol(symbol, vals):
    from models.models import Symbol, Session
    """更新或删除symbol表"""
    db = Session()
    now = str(datetime.now())[:19]
    symbol_objs = db.query(Symbol).filter(Symbol.symbol == symbol).all()
    if symbol_objs:
        obj = symbol_objs[0]
        for key in vals:
            obj.updated_at = now
            setattr(obj, key, vals[key])
        if len(symbol_objs) > 1:
            for index in range(1, len(symbol_objs)):
                db.delete(symbol_objs[index])
    else:
        new_obj = Symbol(**vals)
        new_obj.updated_at = now
        db.add(new_obj)
    db.commit()
    db.close()
示例#4
0
def postgres_demo():
    """ Example use of setting and retrieving a postgres record.
    """
    drop_tables()
    create_tables()

    # Create a database session
    s = Session()

    print('*' * 50)
    print('Creating departments ...')
    departments = (('Produce', 'Healthy stuff!'),
                   ('Bakery', 'Breads and goodies'), ('Deli',
                                                      'Meats, cheeses, etc'))
    for department in departments:
        d = Departments(name=department[0], description=department[1])
        s.add(d)
        s.commit()
        print('Added: {}'.format(department[0]))

    print('*' * 50)

    print('Creating products ...')
    products = ((1, 'Apple', 1.99, 'Delicious Apple'), (1, 'Banana', 3.49,
                                                        'Bunch of Bananas'),
                (2, 'Bread', 3.99, 'Loaf of whole wheat'), (3, 'Cheddar', 2.79,
                                                            'Sliced cheddar'))
    for product in products:
        p = Products(department_id=product[0],
                     name=product[1],
                     price=product[2],
                     description=product[3])
        s.add(p)
        s.commit()
        print('Added: {}'.format(product[1]))

    print('*' * 50)
    res = s.query(Products).join(Departments).all()
    print('Result of outer join:')
    for r in res:
        print('{} | {} | {}'.format(r.name, r.department.name, r.price))
示例#5
0
def deleteCase(id):
    session = Session()
    session.query(Argentina).filter(Argentina.date == id).delete()
    session.commit()
    session.flush()
    session.close()
示例#6
0
def updatedata(dic, id):
    session = Session()
    session.query(Argentina).filter(Argentina.date == id).update(dic)
    session.commit()
    session.flush()
    session.close()