How to use dupe2 method in assertpy

Best Python code snippet using assertpy_python

posematch.py

Source:posematch.py Github

copy

Full Screen

1import bpy2from bpy.props import (CollectionProperty,3 FloatProperty,4 StringProperty,5 PointerProperty,6 BoolProperty,7 IntProperty,8 EnumProperty)9from bpy.types import PropertyGroup10from mathutils import Vector, Matrix11from .utils import (bbox_diagonal,12 bbox_from_diagonal,13 bbox_rig,14 bbox_rig_vector,15 global_bbox,16 AddHipLocator)17def cull_matches(self, context):18 scene = context.scene19 matches = [o for o in scene.objects20 if "match_action" in o.keys()21 and o["match"] > scene.pose_match.match22 and o.parent["Matches"] == scene.pose_match.rig]23 for ob in matches:24 ob.parent = None25 ob.animation_data_clear()26 ob.use_fake_user = False27 scene.objects.unlink(ob)28 if ob.users == 0:29 bpy.data.objects.remove(ob)30prop_dic = {"name": StringProperty()}31SceneRigs = type("SceneRigs", (PropertyGroup,), prop_dic)32bpy.utils.register_class(SceneRigs)33bpy.types.Scene.rigs = CollectionProperty(type=SceneRigs)34prop_dic = {"b1": FloatProperty(min=0, max=3.2, unit='ROTATION'),35 "name": StringProperty()36 }37BoneRot = type("BoneRot", (PropertyGroup,), prop_dic)38bpy.utils.register_class(BoneRot)39method = EnumProperty(40 name="Pose Match Method",41 description="Choose Way to Match Poses",42 items=(('BBOX', "Bound Box", "Compare Bounding Boxes (Fastest)"),43 ('BONE_DRIVER',44 "Bone Drivers",45 "Set Up Bone Drivers"),46 ('BONE_DRIVER_VIS',47 "Visual Bone Drivers",48 "Set Up Bone Drivers"),49 ),50 default='BBOX',51 )52func = EnumProperty(53 name="Driver Method",54 description="Calculate Using",55 items=(('SUM', "Sum", "Minimise sum of drivers"),56 ('AVERAGE', "Average", "Minimise average of drivers"),57 ('MAX', "Maximum", "Minimimise Maximum"),58 ),59 default='MAX',60 )61driver_var_type = EnumProperty(62 name="Compare",63 description="Choose Way to Match Poses",64 items=(('ROTATION_DIFF',65 "Rotational Difference",66 "Compare the Rotational Difference of bones"),67 ('LOC_DIFF',68 "Bone Distance",69 "Compare the distance between Bones"),70 ),71 default='LOC_DIFF',72 )73prop_dic = {"match": FloatProperty(min=0.0,74 max=30.0,75 default=10.0,76 description="Match Tolerance, lower = better match",77 options={'SKIP_SAVE'},78 update=cull_matches),79 "matches": IntProperty(min=2, max=10, default=10, step=2),80 "use_delta_loc": BoolProperty(default=False),81 "delta_loc": FloatProperty(min=-1.0, default=0.1, unit='LENGTH'),82 "rig": StringProperty(),83 "dupe": StringProperty(),84 "action1": StringProperty(),85 "action2": StringProperty(),86 "method": method,87 "func": func,88 "driver_var_type": driver_var_type,89 "name": StringProperty(),90 "pause": BoolProperty(default=False),91 "percent": IntProperty(default=0, min=0, max=100),92 "timers": IntProperty(min=0, default=0),93 }94PoseMatch = type("PoseMatch", (PropertyGroup,), prop_dic)95bpy.utils.register_class(PoseMatch)96bpy.types.Scene.bones = CollectionProperty(type=BoneRot)97bpy.types.Scene.pose_match = PointerProperty(type=PoseMatch)98class PoseMatchPanel(bpy.types.Panel):99 """Creates a Panel in the scene context of the properties editor"""100 bl_label = "Pose Matching"101 bl_idname = "SCENE_PT_layout"102 bl_space_type = 'VIEW_3D'103 bl_region_type = 'TOOLS'104 bl_category = "BVH"105 @classmethod106 def poll(cls, context):107 if context.object is None:108 return False109 if context.object.type == 'ARMATURE':110 return True111 def draw(self, context):112 context.region.tag_redraw()113 layout = self.layout114 scene = context.scene115 pm = scene.pose_match116 if pm.timers and pm.method.endswith("_VIS"):117 bones = scene.bones118 col = layout.column(align=True)119 col.scale_y = 0.4120 #tot = 0121 for b in bones:122 #row = layout.row()123 #row.scale_y = 0.5124 #tot += b.b1125 col.prop(b, "b1", slider=True, text=b.name)126 # show a percent slider for how far127 if pm.timers:128 row = layout.row()129 row.scale_y = 0.4130 #row.alert = True131 row.prop(scene.pose_match, "percent", slider=True, text="%")132 layout.operator("wm.modal_timer_operator")133 layout.operator("object.simple_operator")134 layout.prop(scene.pose_match, "match")135 layout.prop(scene.pose_match, "rig")136 layout.prop(scene.pose_match, "matches")137 layout.prop(scene.pose_match, "delta_loc")138 layout.prop(scene.pose_match, "action1")139 arm = context.object.data140 #arm = scene.objects.get(scene.pose_match.rig).data141 layout.prop_search(scene.pose_match,142 "action1",143 arm,144 "actions",145 icon='ACTION',146 text="Action1")147 layout.prop(scene.pose_match, "action2")148 layout.prop_search(scene.pose_match,149 "action2",150 arm,151 "actions",152 icon='ACTION',153 text="Action2")154 layout.prop(scene.pose_match, "timers")155 layout.prop(scene.pose_match, "method")156 layout.prop(scene.pose_match, "func")157 layout.prop(scene.pose_match, "driver_var_type")158 layout.prop(scene.pose_match, "pause", toggle=True)159 if "tot" in scene.keys():160 layout.prop(scene, '["tot"]')161 #layout.label("TOT: %3.1f" % tot)162 #if tot < 10:163 #print("under 10 at frame:", scene.frame_current, " (", tot, ")")164def bone(op, scene):165 if scene.pose_match.pause:166 return False167 bones = scene.bones168 # offer selection of169 # visual drivers all bones170 # same but grouped171 # single all encompassing driver using SUM172 ob = op.rig173 action = ob.animation_data.action174 dupe = op.dupe175 #ob = scene.objects.get("16_01")176 #dupe = scene.objects.get("16_01.001")177 strip = op.strip178 tot = 100000179 if strip.action.name == ob.animation_data.action.name:180 if abs(scene.frame_current - strip.action_frame_end) >= 20:181 if scene.pose_match.method == 'BBOX':182 tot = (bbox_rig_vector(ob) - op.dupe_bbox).length183 if scene.pose_match.method == 'BONE_DRIVER':184 tot = scene["tot"]185 if scene.pose_match.method == 'BONE_DRIVER_VIS':186 tot = sum([b.b1 for b in scene.bones])187 if tot < scene.pose_match.match:188 #print("TOT:", tot)189 #op.wait = True190 # look for matches within small distance191 h = ob.pose.bones['Hips']192 loc = h.location193 sf = ob.scale.x194 if scene.pose_match.delta_loc > 0:195 matches = [m for m in op.mt.children196 if m.users > 0197 #and m["action_frame"] in list(range(af-5, af+1))198 and (m.pose.bones["Hips"].location - loc).length199 < scene.pose_match.delta_loc / sf]200 if len(matches):201 #print("LEN MATCHES", len(matches))202 #print(matches)203 matches.sort(key=lambda x: x["match"])204 # delete all but the best205 if matches[0]["match"] < tot:206 return False207 #print(matches)208 for o in matches:209 #print("del", o.name, o["action_frame"], o["match_frame"])210 o.parent = None211 scene.objects.unlink(o)212 #o["match"] = scene.pose_match.match213 dupe2 = dupe.copy()214 dupe2.hide = False215 dupe2.hide_select = False216 # remove custom props217 for prop in dupe2.keys():218 del dupe2[prop]219 scene.objects.link(dupe2)220 dupe2.name = "[%06.3f]" % tot221 af = int(strip.action_frame_start)222 mf = scene.frame_current223 dupe2["match"] = tot224 dupe2["action_frame"] = af225 dupe2["action"] = strip.action.name226 dupe2["match_action"] = action.name227 dupe2["match_frame"] = mf228 dupe2.parent = op.mt229 hips = dupe2.pose.bones['Hips']230 #loc = AddHipLocator(dupe2, hips)231 #scene.update()232 #print("adding hiploc")233 #print("setting hips on ", dupe2.name)234 for c in hips.constraints:235 hips.constraints.remove(c)236 hips.matrix_basis = h.matrix_basis.copy()237 #hips.matrix = h.matrix.copy()238 dupe2.animation_data_clear()239 '''240 hips.keyframe_insert('location', options={'INSERTKEY_VISUAL'})241 dupe2.rotation_mode = 'QUATERNION'242 hips.keyframe_insert('rotation_quaternion',243 options={'INSERTKEY_VISUAL'})244 # code to add a hip locator instead of armature copy245 loc = AddHipLocator(ob, h)246 loc.matrix_local = loc.matrix_world247 for c in loc.constraints:248 loc.constraints.remove(c)249 print(scene.frame_current, ":", tot)250 op.wait = False251 # remove matches that are similar to current252 matches = [m for m in op.mt.children253 if m.users > 0254 #and m["action_frame"] in list(range(af-5, af+1))255 and m["match_frame"] in list(range(mf-1, mf+1))256 ]257 if len(matches) > 1:258 print("LEN MATCHES", len(matches))259 #print(matches)260 matches.sort(key=lambda x: x["match"])261 # delete all but the best262 matches.pop(0)263 #print(matches)264 for o in matches:265 print("del", o.name, o["action_frame"], o["match_frame"])266 o.parent = None267 scene.objects.unlink(o)268 #o["match"] = scene.pose_match.match269 '''270 # keep list to 10 matches271 matches = [m["match"]272 for m in op.mt.children273 if m.users > 0274 ]275 #print("LEN MATCHES", len(matches))276 keep = scene.pose_match.matches277 if len(matches) > keep:278 matches.sort()279 #print("10th", matches[keep - 1])280 scene.pose_match.match = matches[keep - 1]281 #op.mt.name = "Matches (%s)" % len(op.mt.children)282 # if at end frame then click up the NLA283 # QUICK HACK TO CHECK284 if scene.frame_current >= int(action.frame_range[1] / 2):285 #bpy.ops.wm.redraw_timer(type='DRAW_WIN')286 scene.pose_match.percent = 100 * strip.action_frame_start / action.frame_range.length287 strip.action_frame_end += 1288 strip.action_frame_start += 1289 scene.frame_set(action.frame_range[0])290 if scene.pose_match.method == 'BBOX':291 op.dupe_bbox = bbox_rig_vector(dupe)292 if strip.action_frame_start > strip.action.frame_range[1]:293 scene.pose_match.pause = True294def set_up_simulation(operator, scene):295 #operator = operator.__class__296 # set up the action lists297 # put rna checking in the poll method. (both ops)298 operator.rig = rig = scene.objects.active299 scene.pose_match.rig = rig.name300 #print("RIG", rig)301 if rig is None:302 # ABORT303 pass304 arm = rig.data305 actions = arm.actions306 #print(actions)307 action = rig.animation_data.action308 dupe = rig.copy()309 scene.objects.link(dupe)310 dupe["dupe"] = True311 dupe.hide = True312 dupe.hide_select = True313 scene.pose_match.dupe = dupe.name314 #del dupe.data["bvh_import_settings"]315 #remove the actions list from dupe316 dupe["actions"] = []317 dupe.animation_data.action = None318 dupetrack = dupe.animation_data.nla_tracks.new()319 dupetrack.name = "DupeTrack"320 # QUICK HACK TO CHECK321 if scene.pose_match.action1 == scene.pose_match.action2:322 start = action.frame_range[1] / 2323 else:324 start = action.frame_range[0]325 action = bpy.data.actions.get(scene.pose_match.action2)326 dupestrip = dupetrack.strips.new("DupeStrip", 1, action)327 dupestrip.name = "DupeStrip"328 dupestrip.action_frame_start = dupestrip.action_frame_end = int(start)329 dupestrip.scale = 1.0330 scene.pose_match.rig = rig.name331 scene.pose_match.action1 = rig.animation_data.action.name332 scene.pose_match.action2 = dupestrip.action.name333 operator.dupe = dupe334 operator.strip = dupestrip335 for bg in scene.bones:336 bg.driver_remove('b1')337 for bg in scene.bones:338 scene.bones.remove(0)339 if "tot" in scene.keys():340 scene.driver_remove('["tot"]')341 if scene.pose_match.method.startswith('BONE_DRIVER'):342 # ignore the parent bone and zlb's343 bones = [b for b in rig.pose.bones344 if b.parent is not None345 ]346 # remove old drivers347 if scene.pose_match.method == 'BONE_DRIVER_VIS':348 for b in bones:349 #pb = ob.pose.bones.get(b["bvh"])350 bg = scene.bones.add()351 bg.name = b.name352 d = bg.driver_add("b1").driver353 v = d.variables.get("bone1", d.variables.new())354 v.name = b.name355 v.type = scene.pose_match.driver_var_type356 # double boner357 v.targets[0].id = rig358 v.targets[0].bone_target = b.name359 v.targets[1].id = dupe360 v.targets[1].bone_target = b.name361 d.expression = "abs(%s)" % v.name362 elif scene.pose_match.method == 'BONE_DRIVER':363 scene["tot"] = 0.0364 tot_driver = scene.driver_add('["tot"]').driver365 tot_driver.type = scene.pose_match.func366 for b in bones:367 #pb = ob.pose.bones.get(b["bvh"])368 bg = scene.bones.add()369 bg.name = b.name370 d = tot_driver371 v = d.variables.get("bone1", d.variables.new())372 v.name = b.name373 v.type = scene.pose_match.driver_var_type374 # double boner375 v.targets[0].id = rig376 v.targets[0].bone_target = b.name377 v.targets[1].id = dupe378 v.targets[1].bone_target = b.name379 # get the angle between them380 #print(angle)381 # add copy transforms constraint382 con = dupe.pose.bones["Hips"].constraints.new(type='COPY_TRANSFORMS')383 con.target = rig384 con.subtarget = "Hips"385 scene.frame_set(1)386 if scene.pose_match.method == 'BBOX':387 operator.dupe_bbox = bbox_rig_vector(dupe)388 return True389def get_holder_empty(scene, key):390 obs = [mt for mt in scene.objects391 if mt.data is None392 and "Matches" in mt.keys()393 and mt["Matches"] == key]394 if len(obs):395 return obs[0]396 mt = bpy.data.objects.new("%s (Pose Match)" % key, None)397 mt["Matches"] = key # number of matches398 return scene.objects.link(mt).object399class ModalTimerOperator(bpy.types.Operator):400 """Operator which runs its self from a timer"""401 bl_idname = "wm.modal_timer_operator"402 bl_label = "Modal Timer Operator"403 _timer = None404 wait = False405 def modal(self, context, event):406 scene = context.scene407 if event.type in {'ESC'} or scene.pose_match.pause:408 return self.cancel(context)409 if self.wait:410 return {'PASS_THROUGH'}411 if event.type == 'TIMER':412 scene = context.scene413 bone(self, scene)414 scene.frame_set(scene.frame_current + 1)415 return {'PASS_THROUGH'}416 def execute(self, context):417 scene = context.scene418 if not scene.pose_match.timers:419 set_up_simulation(self, scene)420 else:421 scene.pose_match.timers = 0422 self.rig = scene.objects.get(scene.pose_match.rig)423 self.dupe = scene.objects.get(scene.pose_match.dupe)424 self.dupe_bbox = bbox_rig_vector(self.dupe)425 dad = self.dupe.animation_data426 self.strip = dad.nla_tracks["DupeTrack"].strips["DupeStrip"]427 wm = context.window_manager428 scene.pose_match.timers += 1429 #holder empty430 #mt.location = (0,0,0)431 self.mt = get_holder_empty(scene, self.rig.name)432 self._timer = wm.event_timer_add(0.01, context.window)433 wm.modal_handler_add(self)434 return {'RUNNING_MODAL'}435 def cancel(self, context):436 scene = context.scene437 scene.pose_match.timers -= 1438 if scene.pose_match.timers == 0:439 scene.pose_match.pause = False440 if scene.objects.get(self.dupe.name):441 scene.objects.unlink(self.dupe)442 wm = context.window_manager443 wm.event_timer_remove(self._timer)444 return {'CANCELLED'}445class PoseMatch(bpy.types.Operator):446 """Operator to do the matching non modal"""447 bl_idname = "object.simple_operator"448 bl_label = "Simple Object Operator"449 @classmethod450 def poll(cls, context):451 return context.active_object is not None452 def execute(self, context):453 scene = context.scene454 scene.pose_match.pause = False455 scene.frame_set(1)456 #holder empty457 set_up_simulation(self, scene)458 self.mt = get_holder_empty(scene, self.rig.name)459 action = self.rig.animation_data.action460 while not scene.pose_match.pause:461 bone(self, scene)462 scene.frame_set(scene.frame_current + 1)463 # clean up464 if scene.objects.get(self.dupe.name):465 scene.objects.unlink(self.dupe)466 return {'FINISHED'}467def register():468 bpy.utils.register_class(PoseMatchPanel)469 bpy.utils.register_class(ModalTimerOperator)470 bpy.utils.register_class(PoseMatch)471def unregister():472 bpy.utils.unregister_class(PoseMatchPanel)473 bpy.utils.unregister_class(ModalTimerOperator)...

Full Screen

Full Screen

day 3 solution.py

Source:day 3 solution.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2with open("input.txt", 'r') as f:3 nums = [line for line in f.readlines()]4nums = [i.strip('\n') for i in nums]5nums_dupe1 = nums6nums_dupe2 = nums7empty = []8for i in range(len(nums[0])):9 counter = 010 for j in range(len(nums)):11 if int(nums[j][i]) == 1:12 counter+=113 else:14 counter-= 115 16 if counter >0:17 empty.append(1)18 else:19 empty.append(0)20 21 22binary = ''.join([str(i) for i in empty])23binary2 = binary.replace("1", "2").replace("0", "1").replace("2", "0")24print(int(binary,2))25print(int(binary2,2))26print(int(binary,2) * int(binary2,2))27#part 228empty2 = []29for i in range(len(nums_dupe1[0])):30 counter = 031 for j in range(len(nums_dupe1)):32 if int(nums_dupe1[j][i]) == 1:33 counter+=134 else:35 counter-= 136 if len(nums_dupe1) == 1:37 break38 if counter >= 0:39 nums_dupe1 = [x for x in nums_dupe1 if x[i] == '1']40 if counter < 0:41 nums_dupe1 = [x for x in nums_dupe1 if x[i] == '0']42print(nums_dupe1)43 44for i in range(len(nums_dupe2[0])):45 counter = 046 for j in range(len(nums_dupe2)):47 if int(nums_dupe2[j][i]) == 1:48 counter+=149 else:50 counter-= 151 if len(nums_dupe2) == 1:52 break53 if counter >= 0:54 nums_dupe2 = [x for x in nums_dupe2 if x[i] == '0']55 if counter < 0:56 nums_dupe2 = [x for x in nums_dupe2 if x[i] == '1']57print(nums_dupe2)58x1 =(int(nums_dupe1[0],2))59x2 =(int(nums_dupe2[0],2))60print(x1*x2)61 ...

Full Screen

Full Screen

diff.py

Source:diff.py Github

copy

Full Screen

1def diff(str1, str2):2 list_for_strings1 = []3 list_for_strings2 = []4 list_for_strings3 = []5 list_for_strings4 = []6 dupe1 = str17 dupe2 = str28 reverse1 = str1[::-1]9 reverse2 = str2[::-1]10 duper1 = str1[::-1]11 duper2 = str2[::-1]12###########################################################13 for i in dupe1:14 if i in dupe2:15 list_for_strings1.append(dupe2[dupe2.index(i)])16 dupe2 = dupe2[dupe2.index(i) + 1 : ]17 18 for i in str2:19 if i in str1:20 list_for_strings2.append(str1[str1.index(i)])21 str1 = str1[str1.index(i) + 1 : ]22 for i in duper2:23 if i in duper1:24 list_for_strings3.append(duper1[duper1.index(i)])25 duper1 = duper1[duper1.index(i) + 1 : ]26 for i in reverse1:27 if i in reverse2:28 list_for_strings4.append(reverse2[reverse2.index(i)])29 reverse2 = reverse2[reverse2.index(i) + 1 : ]30##########################################################31 common = []32 for i in list_for_strings1:33 if i in list_for_strings2 and i in list_for_strings3 and i in list_for_strings4:34 common.append(i)35 common = list(set(common))36 common.sort()37 return common38 39# print(diff('abcddef', 'vdfaddwf'))40# print(diff('friends', 'afraid'))41# print(diff('delicious', 'indiginous'))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful