def make_structures_dto(roles_dict: dict[Role, set[Structure]]) -> list[dict]: def reverse_dict(d: dict) -> dict[Any, list]: result: dict[Any, list] = {} for k, l in d.items(): for v in l: result[v] = result.get(v, []) result[v].append(k) return result def make_structure_dto(structure): role_set = {role.value for role in structures_to_roles[structure]} role_set -= {"Membre", "Membre affilié"} if "Membre affecté" in role_set or "Membre rattaché" in role_set: role_set.add("Membre") role_set -= {"Membre affecté", "Membre rattaché"} roles = sorted(role_set) structure_dto = { "name": structure.sigle_ou_nom, "id": structure.id, "roles": ", ".join(roles), "depth": structure.depth, } return structure_dto structures_to_roles = reverse_dict(roles_dict) structures = sort_by_name(structures_to_roles.keys()) structures_dto = r.pipe(r.map(make_structure_dto), r.filter(lambda s: s["roles"]))(structures) structures_dto.sort(key=lambda x: x["depth"]) return structures_dto
def __init__(self, headers: List[str], items: List[Row] = [], rows: List[any] = []): self.headers = headers if (len(items) > 0): self.rows = list(map(lambda row: dict(zip(headers, row)), items)) if(len(rows) > 0): self.rows = rows
def blad_srednikwadratowy(edges, functions): result = [] for edge, wspolczynniki in zip(edges, functions): f = lambda x: wspolczynniki[0] * x + wspolczynniki[1] errors = R.map(lambda x: (f(x[0]) - x[1])**2)(edge[1:-1]) result.append(0 if len(errors) < 1 else sum(errors) / len(errors)) return result
def __train(self, data: Table): features = R.filter(lambda i: i != 'rating', data.headers) labels = self.__get_labels(data.rows) guess = mode(labels) if len(set(labels)) == 1 or len(features) == 0: return Tree(value=guess) scores = R.map(lambda feature: self.__get_feature_score(feature, data), features) top_feature = R.head( R.sort(lambda a, b: b['score'] - a['score'], scores))['feature'] headers = R.filter(lambda feature: feature != top_feature, data.headers) yes_set = data.filter(top_feature, 'y').pick_columns(headers) no_set = data.filter(top_feature, 'n').pick_columns(headers) right = self.__train(yes_set) left = self.__train(no_set) return Tree(value=top_feature, left=left, right=right)
def track_pairing(self, *coauthors): coauthor_emails = ramda.map(lambda _coauthor: _coauthor.get('email'), coauthors) pairs = itertools.combinations(coauthor_emails, 2) for pair in pairs: _a, _b = pair _a = ramda.find(lambda a: a.get('email') == _a, coauthors) _b = ramda.find(lambda a: a.get('email') == _b, coauthors) self._pairs.append((Author(**_a), Author(**_b)))
def make_stats(lines, attrs): result = {} for attr in attrs: series = pd.Series([getattr(line, attr) for line in lines]) result[attr] = r.map( format_float, [ series.mean(), series.median(), series.std(), series.min(), series.max(), series.sum(), ], ) return result
def get_stats(**args): check_permission() args2 = {} for arg_name, arg_value in args.items(): if not arg_value: continue if isinstance(arg_value, List): value = r.map(lambda x: x["value"], arg_value) elif isinstance(arg_value, Dict): value = arg_value["value"] else: value = arg_value args2[arg_name] = value user = get_current_profile() return get_stats2(user, **args2)
def make_duree_traitement_stats(query): def duree_traitement(line): if line.date_soumission and line.date_finalisation: dt = line.date_finalisation - line.date_soumission days = dt.days + dt.seconds / SECONDS_IN_DAY return days else: return None lines = query.all() series = pd.Series([duree_traitement(line) for line in lines]) return r.map( format_float, [ series.mean(), series.median(), series.std(), series.min(), series.max(), series.sum(), ], )
import ramda as R from migen_axi.interconnect import axi4 get_name = R.head get_width = R.nth(1) get_direction = R.nth(-1) get_names = R.map(get_name) def get_item_by_name(name): return R.find(R.compose(R.equals(name), get_name)) def test_axi4config(): dut = axi4.Axi4Config(16, 32, use_region=False) assert dut.addr_width == 16 assert dut.data_width == 32 assert dut.use_ar_user is False assert dut.use_aw_user is False assert dut.use_w_user is False assert dut.use_b_user is False assert dut.use_arw_user is False assert dut.arw_user_width == -1 assert dut.byte_per_word == 4 def test_axi4_aw(): cfg = axi4.Axi4Config(16, 32, use_region=False) dut = axi4.axi4_aw(cfg, 0) assert len(dut) == 9 assert "region" not in get_names(dut)
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), {})
# Problemy z: (7,15) nazwa_pliku = "set{}/{}.png".format(set_nr, img_nr) print(nazwa_pliku) im = io.imread(nazwa_pliku) # im2 = copy.deepcopy(im) edges1 = feature.canny(im) edges = break_edges(edges1) functions = edges_to_functions(edges) errors = blad_srednikwadratowy(edges, functions) print(errors) # angles_between_functions(functions) neighbour_angles = angles_with_neighbouring_functions(functions) print(neighbour_angles) neighbour_angles_sum = R.map(sum, neighbour_angles) print(neighbour_angles_sum) max_index = lambda my_list: R.reduce( lambda acc, x: acc if acc[1] >= x[1] else x, [0, 0], R.zip(range(len(my_list)), my_list)) e = max_index(errors) print(e) a = max_index(neighbour_angles_sum) print(a) #wg błędów index_podstawy = (e[0] + 2) % 4 print('wg błędów', index_podstawy, functions[index_podstawy]) [a1, _] = functions[index_podstawy]
def pick_columns(self, headers: List[str]): if len(difference(headers, self.headers)) > 0: raise Exception('Invalid headers.') new_rows = map(lambda row: pick(headers, row), self.rows) return Table(headers=headers, rows=new_rows)
def __get_labels(self, set): return R.map(lambda i: 'like' if i['rating'] >= 0 else 'nah', set)