def get_choices(self): # print time(), 'enter get_choices' # suggest pictures with similiarity link to current if not self.mode in [Browser.BLOG,Browser.POPULAR]: choices = dict(self.img.relates) else: choices = {} # prefer pictures in pool, # prefer newest pictures for p in self.pool: boost = min(1,util.days_since(p.reviewed)/99) boost *= 1./(1+util.days_since(p.date)/5) choices[p] = choices.get(p, 0)+boost # not enough candidates? fill up with favies! # TODO: need we? #if len(choices)<10: #favies=picture.favorites() #for i in range(10-len(choices)): #p = favies.pop(0) #choices[p] = p.relates.get(self.img,0) # calculate scores for p, sim in choices.items(): score = (1+p.rating/6./10.) * sim for vote in self.new_votes: adv = p.relates.get(vote) if not adv: adv = vote.relates.get(p,0) score += vote.rating * (.1+adv/len(self.new_votes)/6./10.) choices[p] = score # return candidates ordered by highest score desc. choices = sorted(choices.items(), key=lambda t:t[1]) # print time(), 'return get_choices' return [t[0] for t in choices[::-1]]
def __init__(self, root): self.cur_imgs = [] # backup references against garbage coll. self.img_reg = {} # registry to avoid disk access self.thmb_reg = {} # thumbnail registry to avoid resize self.preview_reg = {} # preview registry to avoid resize self.mode = Browser.BROWSE self.redraw = False # set true to redraw gui self.changes = False # changes to be saved? self.new_votes = set() # keep track of new ratings self.pool=[] # TODO: selection: GUI indicator must be present for selection state, # selection must be viewable in its entirety in dedicated view mode, # selection should probably be of type set. self.selection=[] # selection for exports or queries # compare new pictures with favorites favs = picture.starred()[:10] newsies = [p for p in picture.pictures() if p.reviewed < 1] if len(newsies)>0 and len(favs)>0: print 'calculating similarities between {} new images and highest rated'.format( len(newsies)) self.new_votes = set(favs) for n in newsies: for p in favs: if n != p: sim = p.similarity(n) if sim > .6: picture.connect(n, p, sim) print 'done doing that.' # merge candidates for currentlt selected image self.merge_candidates=[] # img clusters self.clusters=[] # init img tracking self.repool() #pics = sorted(pics, key=lambda p:p.rating) # repopulate history self.hist = [] for p in picture.last_reviewed()[:50]: if util.days_since(p.reviewed)<1.5: self.hist.append(p) if p in self.pool: self.pool.remove(p) # choose image to displ if len(self.hist)<1 and len(self.pool)>0: self.choose(self.pool.pop()) # current image as Pict object self.hist = [self.img] # history of recent images elif len(self.hist)>0: self.img = self.hist[0] # self.trash # key: pict instance, value: (path, image) self.trash = {} # canvas self.cnv = tk.Canvas(root, bg="black") self.cnv.pack(side='top', fill='both', expand='yes') # put a button on the image panel to test it #self.button = tk.Button(self.cnv, text='button2') #self.button.pack(side='top') self.merge_candidates = self.merge_cand() self.display()
def short_desc(self): notes=[] if self.rating>0: notes.append('*'*self.rating) days=util.days_since(self.date) if days<7: if days<2: notes.append('new! ({} hours)'.format(int(days*24))) else: notes.append('new! ({} days)'.format(int(days))) days=int(util.days_since(self.reviewed)) if days > 31: if days < 100: notes.append('awaits review ({} days)'.format(days)) else: notes.append('awaits review!') if self.origin: notes.append(self.origin.name) if len(self.sources)>1: notes.append('found {}x'.format(len(self.sources))) return '\n'.join(notes)
def favorites(): # rating times month passed since review fav = lambda p:p.rating * (.5+util.days_since(p.reviewed)/31) return sorted(pictures(), key=fav, reverse=True)
def days_since_changed(self) -> int: return util.days_since(self.last_changed_ts())
def days_since_pushed(self) -> int: return util.days_since(self.pushed_at_ts())
def days_since_created(self) -> int: return util.days_since(self.created_at_ts())
def reviewed_imgs(self): if len(self.proper_imgs)>0: return sum([1/(1+util.days_since(p.reviewed)/31) for p in self.proper_imgs if p.reviewed > 0]) / len(self.proper_imgs) return 0.