+ def select_by_time_keyword_auto_suggest_epg_timeline(self,keyword,btime,etime):
+ db = self.connect_db()
+ dbexe = "\
+ SELECT \
+ epg_ch.chtxt,title,start,stop,exp,longexp,category \
+ FROM epg_timeline \
+ INNER JOIN epg_ch \
+ WHERE epg_ch.chtxt=epg_timeline.channel \
+ AND \
+ epg_ch.visible=1 \
+ AND \
+ start >= %s \
+ AND \
+ stop <= %s \
+ AND \
+ ( \
+ ( title LIKE \'%%"+keyword+"%%\' ) \
+ OR \
+ ( exp LIKE \'%%"+keyword+"%%\' ) \
+ OR \
+ ( longexp LIKE \'%%"+keyword+"%%\' ) \
+ )"
+ dbcmd = db[1].execute(dbexe,(btime, etime))
+ retall = []
+ if dbcmd > 0:
+ retall = db[1].fetchall()
+ self.close_db(db)
+ return retall
+ def new_in_auto_bayes_key(self):
+ db = self.connect_db()
+ try:
+ db[1].execute('CREATE TABLE in_auto_bayes_key \
+ (\
+ keychar VARCHAR(10),\
+ chtxt VARCHAR(20),\
+ ratio_rec DECIMAL(32,14),\
+ ratio_all DECIMAL(32,14),\
+ UNIQUE unibayeskey(keychar,chtxt)\
+ )')
+ db[1].execute('CREATE INDEX keycharindex ON in_auto_bayes_key(keychar)')
+ except Exception, inst:
+ if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
+ recdblist.addCommonlogEX("Error", "new_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+ self.close_db(db)
+
+ def add_in_auto_bayes_key(self,key,chtxt,ratio_rec,ratio_all):
+ db = self.connect_db()
+ ratio_rec=str(ratio_rec)
+ ratio_all=str(ratio_all)
+ db[1].execute('\
+ INSERT IGNORE INTO in_auto_bayes_key \
+ (keychar,chtxt,ratio_rec,ratio_all) \
+ values (%s,%s,%s,%s)',\
+ (key,chtxt,ratio_rec,ratio_all))
+ self.close_db(db)
+ def add_num_in_auto_bayes_key(self,chtxt,add_rec_num,add_all_num):
+ db = self.connect_db()
+ add_rec_num=str(add_rec_num)
+ add_all_num=str(add_all_num)
+ db[1].execute("\
+ UPDATE in_auto_bayes_key SET ratio_rec=CONVERT(ratio_rec+%s,DECIMAL(32,14)),ratio_all=CONVERT(ratio_all+%s,DECIMAL(32,14)) WHERE keychar=\"NUM\" AND chtxt=%s",\
+ (add_rec_num,add_all_num,chtxt))
+ self.close_db(db)
+ def change_in_auto_bayes_key(self,key,chtxt,new_ratio_rec,new_ratio_all):
+ """
+ """
+ db = self.connect_db()
+ db[1].execute("\
+ UPDATE in_auto_bayes_key SET ratio_rec=%s,ratio_all=%s WHERE keychar=%s AND chtxt=%s",(str(new_ratio_rec),str(new_ratio_all),key,chtxt)\
+ )
+ self.close_db(db)
+ def change_ratio_all_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_all=CONVERT(ratio_all*%s/(%s+%s),DECIMAL(32,14)) WHERE chtxt=%s AND NOT (keychar=\"NUM\")",(beforenum,newnum,beforenum,chtxt)\
+ )
+ self.close_db(db)
+ def change_ratio_all_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_all=CONVERT((ratio_all*%s+%s)/%s,DECIMAL(32,14))",(key,chtxt,"0",str(Decimal(addnum)/beforenumf),beforenum,chtxt,key))
+ self.close_db(db)
+ def change_multi_ratio_all_in_auto_bayes_key(self,chtxt,beforenum,list):
+ """
+ list={key:addnum}のリスト
+ """
+ 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)
+ try:
+ 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)
+ except Exception, inst:
+ if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
+ recdblist.addCommonlogEX("Error", "change_multi_ratio_all_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+ 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)
+ try:
+ 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)
+ except Exception, inst:
+ if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
+ recdblist.addCommonlogEX("Error", "change_multi_ratio_rec_in_auto_bayes_key (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+ 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 Exception, inst:
+ if not ((type(inst)==MySQLdb.ProgrammingError and inst[0]==1007)or(type(inst)==MySQLdb.OperationalError and inst[0]==1050)):
+ recdblist.addCommonlogEX("Error", "new_auto_timeline_keyword (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+ 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()