def assign2col(uid, colid, cids): db = dbcon.connect_torndb() dbutil.update_collection_user(db, colid, uid) for cid in cids: dbutil.update_collection(db, colid, cid) db.close()
def merge_collection(colfrom, colto): db = dbcon.connect_torndb() cids = [ item.companyId for item in db.query( 'select companyId from collection_company_rel where collectionId=%s ' 'and (active is null or active="Y");', colfrom) ] for cid in cids: dbutil.update_collection(db, colto, cid) db.close()
def update_collection_from_topic(tpid, colid): db = dbcon.connect_torndb() cids = [ item.companyId for item in db.query( 'select * from topic_company where topicId=%s and ' '(active is null or active="Y");', tpid) ] for cid in cids: dbutil.update_collection(db, colid, cid, 0.5, "Y") time.sleep(0.05) db.close()
def update_collection_from_list(listid, colid): db = dbcon.connect_torndb() cids = [ item.companyId for item in db.query( 'select companyId from mylist_company_rel where mylistId=%s ' 'order by createTime asc;', listid) ] for cid in cids: dbutil.update_collection(db, colid, cid, 0.5, "Y") time.sleep(0.05) db.close()
def convertion(oid=1): db = dbcon.connect_torndb() deals = db.query( 'select distinct deal.id as did, deal.companyId from deal, deal_user_rel where dealId=deal.id and ' 'deal.organizationId=%s and deal_user_rel.type=23030 and deal.status>19000;', oid) for deal in deals: if db.get( 'select type from deal_user_rel where dealId=%s ' 'order by createTime limit 1;', deal.did).type == 23030: dbutil.update_collection(db, 612, deal.companyId) # dbutil.update_collection_user(db, 612, 19) db.close()
def insertcol(): db = dbcon.connect_torndb() cids = [int(line.strip()) for line in open('cachs/ai.candidates.ids')] dups = [ db.get('select id from company where code=%s;', line.strip()).id for line in open('cachs/ai.dup') ] for cid in cids: if cid in dups: continue dbutil.update_collection(db, 327, cid, user=19) dbutil.update_collection_user(db, 327, 19) db.close()
def update_collection(colid, results, in_flask=True, update=False): # update collecion # scorer = RankScorer() update_counts = 0 db = dbcon.connect_torndb() if results.get('company'): # dbutil.clear_collection(db, colid) cids = [ db.get('select id from company where code=%s', code).id for code in results.get('company').get('data') ] # remove old companies that are no longer in this collection if update: olds = dbutil.get_collection_companies(db, colid) remove = [old for old in olds if old not in cids] dbutil.clear_collection(db, colid, True, remove) dbutil.set_collection_process_status(db, colid, 0) # time.sleep(0.0002) cids.reverse() for cid in cids: update_counts += dbutil.update_collection(db, colid, cid) # dbutil.update_collection(db, colid, cid, scorer.score(db, cid)) dbutil.set_collection_process_status(db, colid) db.close() if in_flask: return make_response(jsonify({'success': True})) if in_flask: dbutil.clear_collection(db, colid) db.close() return make_response(jsonify({'success': False})) return update_counts
def update_list(listname, colid): db = dbcon.connect_torndb() path = os.path.join( os.path.split(os.path.realpath(__file__))[0], 'template/%s' % listname) cids = [line.strip() for line in codecs.open(path, encoding='utf-8')] cids.reverse() for line in cids: # code, sortv = line.split('#')[0], round(float(line.split('#')[2]), 2) cid = line.strip() # try: # cid = db.get('select id from company where code=%s', code).id # # cid = db.get('select id from company where id=%s;', code).id # except Exception, e: # print code, e # continue dbutil.update_collection(db, colid, cid, 0.5, "Y") time.sleep(0.001) db.close()
def dump(): db = dbcon.connect_torndb() mongo = dbcon.connect_mongo() uids = [ c.userId for c in db.query( 'select userId from user_organization_rel where organizationId=51;' ) ] colids = [] for uid in uids: colid = db.get('select id from collection where name=%s', 'investor2check_%s' % uid).id colids.append(colid) daichuli = 1783 for colid in colids: cids = [ c.cid for c in db.query( 'select companyId cid from collection_company_rel ' 'where collectionId=%s', colid) ] for cid in cids: alias = [ item.name for item in db.query( 'select * from company_alias ' 'where companyId=%s and type=12010 ' 'and (active is null or active="Y");', cid) ] if len(list(mongo.info.gongshang.find({'name': { '$in': alias }}))) > 1: db.execute( 'delete from collection_company_rel where collectionId=%s and companyId=%s', colid, cid) dbutil.update_collection(db, daichuli, cid) db.close()
except Exception, e: download = [int(x) for x in list(df.download)] return sum(download)/len(download) if aspect == 'growth': df = df.sort_values(by='date', ascending=False) return round(((df.iloc[0].download - df.iloc[-1].download) / df.iloc[-1].download) * 100, 4) if __name__ == '__main__': print __file__ # mongo = dbcon.connect_mongo() # evaluate_download(mongo, 16010, [u'com.leho.mag.food']) # mongo.close() # summary_android_all() if sys.argv[1] == 'test': ds = DownloadScorer() print ds.update(sys.argv[2], sys.argv[3]) elif sys.argv[1] == 'androidsummary': for update in summary_android_all(): print 'updated', update[0] elif sys.argv[1] == 'sourceall': source_android_all() elif sys.argv[1] == 'androidrank': db = dbcon.connect_torndb() for cid, score in black_android_all().iteritems(): dbutil.update_collection(db, 8, cid, score) db.close()