+ 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()
+ 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 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_bayes (dbMySQL.py)", str(type(inst)),str(inst)+traceback.format_exc(),log_level=200)
+ 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)
+ def update_db_to93(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ db[1].execute("\
+ ALTER TABLE timeline ADD epgtitle VARCHAR(100),\
+ ADD epgbtime DATETIME,\
+ ADD epgetime DATETIME,\
+ ADD epgduplicate TINYINT DEFAULT 0,\
+ ADD epgchange TINYINT DEFAULT 0")
+ db[1].execute("\
+ ALTER TABLE in_status ADD version TINYINT")
+ self.close_db(db)
+ self.change_version_in_status("93")
+ def update_db_93to94(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ db[1].execute("\
+ ALTER TABLE timeline ADD counter TINYINT DEFAULT -1")
+ self.close_db(db)
+ self.change_version_in_status("94")
+ def update_db_94to95(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ db[1].execute("\
+ ALTER TABLE timeline ADD epgexp VARCHAR(200)")
+ self.close_db(db)
+ self.change_version_in_status("95")
+ def update_db_95to96(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ self.close_db(db)
+ self.change_version_in_status("96")
+ def update_db_96to98(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ self.close_db(db)
+ self.change_version_in_status("98")
+ def update_db_98to100(self):
+ ###ここで前のepg_chをバックアップしてchtxtの変換をする必要がある。
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ db[1].execute("\
+ UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT(CONCAT(epg_ch.ch,'_'),epg_ch.csch) WHERE NOT (substring(epg_ch.bctype,1,2) = 'bs' OR substring(epg_ch.bctype,1,2) = 'cs')")
+ db[1].execute("\
+ UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('BS_',epg_ch.ch) WHERE substring(epg_ch.bctype,1,2) = 'bs'")
+ db[1].execute("\
+ UPDATE timeline INNER JOIN epg_ch ON timeline.chtxt=epg_ch.chtxt SET timeline.chtxt=CONCAT('CS_',epg_ch.csch) WHERE substring(epg_ch.bctype,1,2) = 'cs'")
+ try:
+ db[1].execute("\
+ ALTER TABLE epg_ch DROP ontv")
+ except:
+ ""
+ db[1].execute("\
+ ALTER TABLE epg_ch ADD logo0 BLOB,\
+ ADD logo1 BLOB,\
+ ADD logo2 BLOB,\
+ ADD logo3 BLOB,\
+ ADD logo4 BLOB,\
+ ADD logo5 BLOB\
+ ")
+ db[1].execute("\
+ ALTER TABLE in_auto_jbk_key ADD auto TINYINT DEFAULT 0")
+ db[1].execute("\
+ ALTER TABLE in_auto_jbk_key ADD opt VARCHAR(20) DEFAULT \"\"")
+ self.close_db(db)
+ self.change_installed_in_status()#チャンネルスキャンをさせる
+ self.change_version_in_status("100")
+ def update_db_100to101(self):
+ db = self.connect_db()
+ self.drop_in_settings()
+ self.new_in_settings()
+ self.new_epg_ch()
+ try:
+ db[1].execute("\
+ ALTER TABLE timeline ADD epgcategory VARCHAR(100)\
+ ")
+ except:
+ ""