📄 statistics.py
字号:
# Written by Edward Keyes# see LICENSE.txt for license informationfrom time import timefrom copy import copytrue = 1false = 0class Statistics: def __init__(self, upmeasure, downmeasure, connecter, httpdl, rerequest): self.upmeasure = upmeasure self.downmeasure = downmeasure self.connecter = connecter
self.httpdl = httpdl self.downloader = connecter.downloader self.picker = connecter.downloader.picker self.storage = connecter.downloader.storage self.torrentmeasure = connecter.downloader.totalmeasure self.rerequest = rerequest self.upTotal = 0.0 self.downTotal = 0.0 self.shareRating = 0.0 self.numSeeds = 0 self.numOldSeeds = 0 self.numCopies = 0.0 self.numCopies2 = 0.0 self.numPeers = 0 self.last_failed = 1 self.external_connection_made = 0 self.piecescomplete = None def set_dirstats(self, info_files, numpieces, piece_length): self.piecescomplete = 0 self.filelistupdated = true self.bgalloc_wasactive = false self.filepieces = {} self.filepieces2 = {} self.filecomplete = {} self.fileinplace = {} start = 0L for i in range(len(info_files)): self.filepieces[i] = [] self.filepieces2[i] = [] l = info_files[i]['length'] if l == 0: self.filecomplete[i] = true self.fileinplace[i] = true else: self.filecomplete[i] = false self.fileinplace[i] = false for piece in range(int(start/piece_length), int((start+l-1)/piece_length)+1): self.filepieces[i].append(piece) self.filepieces2[i].append(piece) start += l def update(self): self.upTotal = self.upmeasure.get_total() self.downTotal = self.downmeasure.get_total() self.last_failed = self.rerequest.last_failed if self.connecter.external_connection_made: self.external_connection_made = 1 if self.downTotal > 0: self.shareRating = float(self.upTotal)/self.downTotal else: if self.upTotal == 0: self.shareRating = 0.0 else: self.shareRating = -1.0 self.downloader = self.connecter.downloader self.picker = self.downloader.picker self.torrentmeasure = self.downloader.totalmeasure self.torrentRate = self.torrentmeasure.get_rate() self.torrentTotal = self.torrentmeasure.get_total() self.numSeeds = 0 for download in self.downloader.downloads: if download.unhave == 0: self.numSeeds+=1 self.numOldSeeds = self.downloader.num_disconnected_seeds() self.numPeers = len(self.downloader.downloads)-self.numSeeds self.numCopies = -self.numSeeds for i in range(len(self.picker.crosscount)): if self.picker.crosscount[i]==0: self.numCopies+=1 else: self.numCopies+=1-float(self.picker.crosscount[i])/self.picker.numpieces break self.numCopies2 = -self.numSeeds for i in range(len(self.picker.crosscount2)): if self.picker.crosscount2[i]==0: self.numCopies2+=1 else: self.numCopies2+=1-float(self.picker.crosscount2[i])/self.picker.numpieces break self.numSeeds += self.httpdl.seedsfound if self.numPeers==0: self.percentDone = 0.0 else: self.percentDone = 100.0*(float(self.picker.totalcount)/self.picker.numpieces-self.numSeeds)/self.numPeers if self.piecescomplete is not None: if ( self.piecescomplete != self.picker.numgot or self.bgalloc_wasactive or self.storage.bgalloc_active ) : self.piecescomplete = self.picker.numgot self.bgalloc_wasactive = self.storage.bgalloc_active self.filelistupdated = true for i in range(len(self.filecomplete)): if not self.filecomplete[i]: newlist = [] for piece in self.filepieces[i]: if not self.storage.have[piece]: newlist.append(piece) self.filepieces[i] = newlist if not newlist: self.filecomplete[i] = true if self.filecomplete[i] and not self.fileinplace[i]: while self.filepieces2[i]: piece = self.filepieces2[i][-1] if self.storage.places[piece] != piece: break del self.filepieces2[i][-1] if not self.filepieces2[i]: self.fileinplace[i] = true
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -