def testFilter(catfilename, torrentpath): readCategorisationFile(catfilename) # print 'Install_dir is %s' % execpath c = Category.getInstance(execpath, None) total = p**n = fn = fp = 0 for tfilename, isporn in tdict.items(): torrent = getMetainfo(os.path.join(torrentpath, tfilename)) name = torrent['info']['name'] cat = c.calculateCategory(torrent, name) fporn = (cat == ['xxx']) total += 1 p**n += int(isporn) if isporn == fporn: if DEBUG: print (isporn, fporn), 'good', name elif isporn and not fporn: fn += 1 print 'FALSE NEGATIVE' showTorrent(os.path.join(torrentpath, tfilename)) elif not isporn and fporn: fp += 1 print 'FALSE POSITIVE' showTorrent(os.path.join(torrentpath, tfilename)) print """ Total torrents: %(total)d XXX torrents: %(p**n)d Correct filtered: %(good)d False negatives: %(fn)d False positives: %(fp)d """ % {'total': total, 'p**n': p**n, 'fn': fn,'fp':fp,'good':total-fn-fp}
def testFilter(catfilename, torrentpath): readCategorisationFile(catfilename) #print 'Install_dir is %s' % execpath c = Category.getInstance(execpath, None) total = p**n = fn = fp = 0 for tfilename,isporn in tdict.items(): torrent = getMetainfo(os.path.join(torrentpath,tfilename)) name = torrent['info']['name'] cat = c.calculateCategory(torrent, name) fporn = (cat == ['xxx']) total+= 1 p**n += int(isporn) if isporn == fporn: if DEBUG: print (isporn, fporn), 'good', name elif isporn and not fporn: fn+=1 print 'FALSE NEGATIVE' showTorrent(os.path.join(torrentpath,tfilename)) elif not isporn and fporn: fp +=1 print 'FALSE POSITIVE' showTorrent(os.path.join(torrentpath,tfilename)) print """ Total torrents: %(total)d XXX torrents: %(p**n)d Correct filtered: %(good)d False negatives: %(fn)d False positives: %(fp)d """ % {'total':total, 'p**n':p**n, 'fn':fn,'fp':fp,'good':total-fn-fp}
def showTorrent(path): torrent = getMetainfo(os.path.join(path)) name = torrent['info']['name'] print '------------------------------' print '\tfiles :' files_list = [] __size_change = 1024 try: # the multi-files mode for ifiles in torrent['info']["files"]: files_list.append((ifiles['path'][-1], ifiles['length'] / float(__size_change))) except KeyError: # single mode files_list.append((torrent['info']["name"], torrent['info']['length'] / float(__size_change))) for fname, fsize in files_list: print'\t\t%s\t%d kb' % (fname, fsize) print 'Torrent name: %s' % name print '\ttracker:%s' % torrent['announce'] print '------------------------------'
def showTorrent(path): torrent = getMetainfo(os.path.join(path)) name = torrent["info"]["name"] print "------------------------------" print "\tfiles :" files_list = [] __size_change = 1024 try: # the multi-files mode for ifiles in torrent["info"]["files"]: files_list.append((ifiles["path"][-1], ifiles["length"] / float(__size_change))) except KeyError: # single mode files_list.append((torrent["info"]["name"], torrent["info"]["length"] / float(__size_change))) for fname, fsize in files_list: print "\t\t%s\t%d kb" % (fname, fsize) print "Torrent name: %s" % name print "\ttracker:%s" % torrent["announce"] print "------------------------------"
def showTorrent(path): torrent = getMetainfo(os.path.join(path)) name = torrent['info']['name'] print '------------------------------' print '\tfiles :' files_list = [] __size_change = 1024 try: # the multi-files mode for ifiles in torrent['info']["files"]: files_list.append((ifiles['path'][-1], ifiles['length'] / float(__size_change))) except KeyError: # single mode files_list.append((torrent['info']["name"],torrent['info']['length'] / float(__size_change))) for fname, fsize in files_list: print'\t\t%s\t%d kb' % (fname, fsize) print 'Torrent name: %s' % name print '\ttracker:%s' % torrent['announce'] print '------------------------------'
def testFilter(catfilename, torrentpath): readCategorisationFile(catfilename) # print 'Install_dir is %s' % execpath c = Category.getInstance(execpath, None) total = p**n = fn = fp = 0 for tfilename, isporn in tdict.items(): torrent = getMetainfo(os.path.join(torrentpath, tfilename)) name = torrent["info"]["name"] cat = c.calculateCategory(torrent, name) fporn = cat == ["xxx"] total += 1 p**n += int(isporn) if isporn == fporn: if DEBUG: print (isporn, fporn), "good", name elif isporn and not fporn: fn += 1 print "FALSE NEGATIVE" showTorrent(os.path.join(torrentpath, tfilename)) elif not isporn and fporn: fp += 1 print "FALSE POSITIVE" showTorrent(os.path.join(torrentpath, tfilename)) print """ Total torrents: %(total)d XXX torrents: %(p**n)d Correct filtered: %(good)d False negatives: %(fn)d False positives: %(fp)d """ % { "total": total, "p**n": p**n, "fn": fn, "fp": fp, "good": total - fn - fp, }