コード例 #1
0
 def put_in_child(node):
     # placing the overwrite logic within "propagate" makes this
     # decision point more explicit and avoids hidden behavior where
     # the decision to overwrite is imposed in the library.
     permission = (overwrite
                   or not is_null(node.contents.get(child_key, None)))
     if permission:
         value = get_from_parent(node.parent)
         if value is not None:
             put(child_key)(node, value)
コード例 #2
0
 def __call__(self, node, arr):
     unique = tuple(set(Functor.make_hashable(arr)))
     unique = tuple(u for u in unique if u is not None)
     unique = {
         0: lambda x: None,
         1: lambda x: x[0]
     }.get(len(unique), lambda x: x)(unique)
     return put(self.key)(node, unique)
コード例 #3
0
 def __call__(self, node, arr):
     result = tuple(x for x in Functor.flatten(arr) if x is not None)
     # check if result is a single value
     if len(result) == 1:
         return None
     # check if result is the same as arr
     try:
         if np.all(np.asarray(arr) == np.asarray(result)):
             return None
     except:
         pass
     return put(self.key)(node, result)
コード例 #4
0
 def __call__(self, node, arr):
     return put(self.key)(node, Functor.std(arr))
コード例 #5
0
 def __call__(self, node, arr):
     return put(self.key)(node, Functor.minimum(arr))
コード例 #6
0
ファイル: example.py プロジェクト: csm-adapt/karon
 def put_in_child(node):
     if overwrite or (child_key not in node.contents):
         value = get_from_parent(node.parent)
         if value is not None:
             put(child_key)(node, value)
コード例 #7
0
ファイル: example.py プロジェクト: csm-adapt/karon
    return func


reader = ExcelIO(build=build,
                 mechanical=mechanical,
                 porosity=porosity,
                 default=generic)

nodes = reader.load(os.path.join('..', 'tests', 'data', 'example.xlsx'))

lineage = generate_tree(get_nodeid=get('name'),
                        get_parent=get('parent name'),
                        cmp=strcmp(str.lower, str.strip))(nodes)
aggregator = aggregate(get("modulus (GPa)"),
                       reduce=lambda node, arr: put("average modulus")
                       (node, mean(arr)))
propagator = propagate("spot size (um)")

for root in lineage:
    aggregator(root)
    propagator(root)

to_dataframe(nodes).to_excel('output.xlsx', index=False)

##### OO-based example #####
# class Example(object):
#     _uid_key: str
#     _parent_key: str
#
#     def __init__(self, uid: str, parent: str):
#         """