def stats_to_matrix(pair_stats, authors={}): result_stats = [] pairs = ramda.to_pairs(pair_stats) _pair_list = ramda.reduce(stats_to_matrix_prep, [], pairs) pair_list = ramda.reduce(lambda acc, cur: [*acc, *cur], [], _pair_list) authors_emails = sorted(ramda.uniq(ramda.pluck(0, pair_list))) for author_a in [*authors_emails]: author_a_pair_stats = [] for author_b in [*authors_emails]: if author_a == author_b: author_a_pair_stats.append(None) else: stat = ramda.find( lambda pair: pair[0] == author_a and pair[1] == author_b, pair_list) author_a_pair_stats.append(stat[2]) result_stats.append({ 'author': authors.get(author_a, {}), 'matrix': author_a_pair_stats, }) return result_stats
def add_links(self, coll): list(map(lambda pair: self.add_link(pair[0], pair[1]), (r.to_pairs(coll)))) return self
def get_hrefs(self): return f.reduce(lambda acc, x: {**acc, x[0]: r.cond([[r.pipe(type, r.equals(dict)), r.prop("href")], [r.pipe(type, r.equals(list)), r.map(r.prop('href'))]], x[1])}, r.to_pairs(self.links), {})
def add_properties(self, coll): list(map(lambda pair: self.add_property(pair[0], pair[1]), (r.to_pairs(coll)))) return self
def apply_to_resource(self, coll, fn): return r.reduce(fn, self, r.to_pairs(coll))
def add_resources(self, coll): if not r.is_empty(coll): list(map(lambda pair: self.add_resource(pair[0], pair[1]), (r.to_pairs(coll)))) return self