def recommend(self, objids): '''Given a system and a ids of recordings or artist, computes de recommendation following the system specification. ''' algs, errors = get_recommend_algs() recs = [] for c in self.components: if c.s_type == 'sys': rec = c.recommend(objids) elif c.s_type == 'alg': rec = getattr(algs[c.name], self.get_io_type())(objids) if len(rec) > c.limit: rec = rec[:c.limit] recs.append((rec, c.weight)) all_recs = [] last_len = -1 while len(all_recs) < self.limit and len(all_recs)>last_len: remains = self.limit - len(all_recs) last_len = len(all_recs) for r in recs: for i in r[0][:int(round(r[1] * remains))]: if i not in all_recs: all_recs.append(i) all_recs = list(all_recs)[:self.limit] ret = all_recs if self.next_sys: ret = self.next_sys.recommend(list(all_recs)[:self.limit]) return ret
def get_graphs(self): '''If type of System is alg, call get_graphs of the algorithm. ''' algs, errors = get_recommend_algs() if self.name in algs and self.s_type == 'alg': return algs[self.name].get_graphs()