+ beforenumf=beforenum
+ beforenum=str(beforenum)
+ db = self.connect_db()
+ for i,j in list.items():
+ retl=(i,chtxt,"0",str(Decimal(j)/beforenumf),beforenum,str(j),beforenum)
+ db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \
+ VALUES (%s,%s,%s,%s)\
+ ON DUPLICATE KEY UPDATE \
+ ratio_all=CONVERT((ratio_all*%s+%s)/%s,DECIMAL(32,14))",retl)
+ self.close_db(db)
+ def change_ratio_rec_reduce_in_auto_bayes_key(self,chtxt,beforenum,newnum):
+ beforenum=str(beforenum)
+ newnum=str(newnum)
+ db = self.connect_db()
+ db[1].execute("\
+ UPDATE in_auto_bayes_key SET ratio_rec=CONVERT(ratio_rec*%s/(%s+%s),DECIMAL(32,14)) WHERE chtxt=%s AND NOT (keychar=\"NUM\")",(beforenum,newnum,beforenum,chtxt)\
+ )
+ self.close_db(db)
+ def change_ratio_rec_in_auto_bayes_key(self,key,chtxt,beforenum,addnum):
+ db = self.connect_db()
+ beforenumf=beforenum
+ beforenum=str(beforenum)
+ db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \
+ VALUES (%s,%s,%s,%s)\
+ ON DUPLICATE KEY UPDATE \
+ ratio_rec=CONVERT((ratio_rec*%s+%s)/%s,DECIMAL(32,14))",(key,chtxt,str(Decimal(addnum)/beforenumf),"0",beforenum,chtxt,key))
+ self.close_db(db)
+ def change_multi_ratio_rec_in_auto_bayes_key(self,chtxt,beforenum,list):#self,key,chtxt,beforenum,addnum):
+ beforenumf=beforenum
+ beforenum=str(beforenum)
+ db = self.connect_db()
+ for i,j in list.items():
+ retl=(i,chtxt,str(Decimal(j)/beforenumf),"0",beforenum,str(j),beforenum)
+ db[1].execute("INSERT INTO in_auto_bayes_key (keychar,chtxt,ratio_rec,ratio_all) \
+ VALUES (%s,%s,%s,%s)\
+ ON DUPLICATE KEY UPDATE \
+ ratio_rec=CONVERT((ratio_rec*%s+%s)/%s,DECIMAL(32,14))",retl)
+ self.close_db(db)
+ def select_by_key_in_auto_bayes_key(self,key,chtxt):
+ db = self.connect_db()
+ dbexe = db[1].execute("\
+ SELECT keychar,chtxt,ratio_rec,ratio_all \
+ FROM in_auto_bayes_key \
+ WHERE keychar = %s AND chtxt = %s", \
+ (key,chtxt))
+ dls = []
+ if dbexe > 0:
+ dls = db[1].fetchall()
+ self.close_db(db)
+ if len(dls)>0:
+ return dls[0]
+ else:
+ return dls
+
+ def new_auto_timeline_keyword(self):
+ db = self.connect_db()
+ try:
+ db[1].execute('\
+ CREATE TABLE auto_timeline_keyword \
+ (\
+ id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\
+ chtxt VARCHAR(40),\
+ title VARCHAR(100),\
+ btime DATETIME,\
+ etime DATETIME,\
+ UNIQUE uni (chtxt,title,btime,etime)\
+ )')
+ except:
+ ""
+ def add_auto_timeline_keyword(self,chtxt="", title="", btime="", etime=""):
+ db = self.connect_db()
+ db[1].execute('\
+ INSERT IGNORE into auto_timeline_keyword \
+ (chtxt,title,btime,etime) \
+ values (%s,%s,%s,%s)', \
+ (chtxt, title, btime, etime))
+ ##db.commit()
+ self.close_db(db)
+ def delete_old_auto_timeline_keyword(self, dhour):
+ db = self.connect_db()
+ db[1].execute("\
+ DELETE FROM auto_timeline_keyword \
+ WHERE \
+ btime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR )")
+ self.close_db(db)
+ def new_auto_timeline_bayes(self):
+ db = self.connect_db()
+ try:
+ db[1].execute('\
+ CREATE TABLE auto_timeline_bayes \
+ (\
+ id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,\
+ chtxt VARCHAR(40),\
+ title VARCHAR(100),\
+ btime DATETIME,\
+ etime DATETIME,\
+ point INT,\
+ UNIQUE uni (chtxt,title,btime,etime)\
+ )')
+ except:
+ ""
+ def add_auto_timeline_bayes(self,chtxt="", title="", btime="", etime="",point=""):
+ db = self.connect_db()
+ db[1].execute('\
+ INSERT IGNORE into auto_timeline_bayes \
+ (chtxt,title,btime,etime,point) \
+ values (%s,%s,%s,%s,%s)', \
+ (chtxt, title, btime, etime,point))
+ self.close_db(db)
+ def delete_old_auto_timeline_bayes(self, dhour):
+ db = self.connect_db()
+ db[1].execute("\
+ DELETE FROM auto_timeline_bayes \
+ WHERE \
+ btime < DATE_SUB(now(),INTERVAL " + dhour + " HOUR )")
+ self.close_db(db)