Best Python code snippet using pyatom_python
cardMagic.py
Source:cardMagic.py
1typ=02if typ==0:3 import first.father as father4 import first.Database as database5 import first.cardMoreServent as moreS6 import first.buff as buff7 import first.cardGround as ground8 import first.cardMoreServent9 import first.cardServent10else:11 import father as father12 import Database as database13 import cardMoreServent as moreS14 import buff15 import cardGround as ground16import random17import re18import copy19def selectCards(ty,storage,haveUsed=[]):20 arr=[]21 for i in storage:22 if i.typeCard==ty and not(i in haveUsed):23 arr.append(i)24 return (arr[random.randint(0,len(arr)-1)]) if len(arr)!=0 else False25class sweeping(father.magic):26 name='sweeping'27 narrate='对ææéä»é æ1ç¹ä¼¤å®³'28 def __init__(self) -> None:29 super().__init__()30 self.cost=['w']31 def ability(self, MyMaster, Master, selectIndex=None):32 for i in MyMaster.cardGround:33 i.live-=134 for ii in Master.cardGround:35 ii.live-=136class NaturalSelect(father.magic):37 name='NaturalSelect'38 narrate='ä½¿ä½ çéä»+1+1'39 def __init__(self) -> None:40 super().__init__()41 self.cost=['g','g']42 self.buffNar=buff.NaturalSelect()43 def ability(self, MyMaster, Master, selectIndex=None):44 for i in MyMaster.cardGround:45 i.buff.append(self.buffNar)46class BigClever(father.magic):47 name='BigClever'48 narrate='æ½ä¸¤å¼ ç'49 def __init__(self) -> None:50 super().__init__()51 self.allCost=352 def ability(self, MyMaster, Master, selectIndex=None):53 MyMaster.getCard(2)54class GodPower(father.magic):55 name='GodPower'56 narrate='ææ»ä¸ä¸ªéä»ï¼èªå·±æ¢å¤4ç¹è¡é'57 selectMode='osa'58 def __init__(self) -> None:59 super().__init__()60 self.allCost=261 self.cost=['w','w']62 def ability(self, MyMaster, Master, selectIndex=None):63 selectIndex.live-=999964 MyMaster.live+=465class ancientTsunami(father.magic):66 name='ancientTsunami'67 narrate='æ¶çææéä»'68 69 def __init__(self) -> None:70 super().__init__()71 self.cost=['bl' for i in range(7)]72 def ability(self, MyMaster, Master, selectIndex=None):73 for i in MyMaster.cardGround.copy():74 i.dieth(MyMaster,Master)75 for ii in Master.cardGround.copy():76 ii.dieth(Master,MyMaster)77class Mecha(father.magic):78 name='Mecha'79 narrate='éæ©ä¸ä¸ªéä»ï¼ä½¿å
¶ +5+5'80 selectMode='osm'81 def __init__(self) -> None:82 super().__init__()83 self.cost=['g' for i in range(3)]84 self.allCost=285 self.buffNar=buff.Mecha()86 def ability(self, MyMaster, Master, selectIndex=None):87 selectIndex.buff.append(self.buffNar)88class Healing(father.magic):89 name='Healing'90 narrate='éæ©ä¸ä¸ªè§è²ï¼æ¢å¤4è¡'91 selectMode='oaa'92 def __init__(self) -> None:93 super().__init__()94 self.cost=['w' for i in range(2)]95 def ability(self, MyMaster, Master, selectIndex=None):96 selectIndex.live+=497class Cannon(father.magic):98 name='Cannon'99 narrate='éæ©ä¸ä¸ªè§è²ï¼é æ5ç¹ä¼¤å®³'100 selectMode='oaa'101 def __init__(self) -> None:102 super().__init__()103 self.cost=['r' for i in range(3)]104 def ability(self, MyMaster, Master, selectIndex=None):105 selectIndex.live-=5106class FlameThrower(father.magic):107 name='FlameThrower'108 narrate='对ææææ¹éä»é æ4ç¹ä¼¤å®³'109 def __init__(self) -> None:110 super().__init__()111 self.cost=['bl' for i in range(4)]112 def ability(self, MyMaster, Master, selectIndex=None):113 for i in Master.cardGround:114 i.live-=4115class FireBall(father.magic):116 name='FireBall'117 narrate='对ä¸ä¸ªéä»é æ2ç¹ä¼¤å®³ï¼æ½ä¸å¼ ç'118 selectMode='oaa'119 def __init__(self) -> None:120 super().__init__()121 self.cost=['r' for i in range(2)]122 def ability(self, MyMaster, Master, selectIndex=None):123 selectIndex.live-=2124 MyMaster.getCard(1)125class SoulExplosion(father.magic):126 name='SoulExplosion'127 narrate='éæ©ä¸ä¸ªéä»ï¼é æ4ç¹ä¼¤å®³ï¼æº¢åºçä¼¤å®³ä¼ ç»èªå·±'128 selectMode='osa'129 def __init__(self) -> None:130 super().__init__()131 self.cost=['bk' for i in range(2)]132 def ability(self, MyMaster, Master, selectIndex=None):133 selectIndex.live-=4134 if selectIndex.Rlive()<0:135 MyMaster.live+=selectIndex.Rlive()136class NaturalGift(father.magic):137 name='NaturalGift'138 narrate='è·å¾5ç§å°'139 def __init__(self) -> None:140 super().__init__()141 self.allCost=2142 def ability(self, MyMaster, Master, selectIndex=None):143 MyMaster.cardHand+=[ground.Forest(),ground.Flame(),ground.Dark(),ground.Light(),ground.Ocean()]144class Blasphemy(father.magic):145 name='Blasphemy'146 narrate='对ææéä»é æ1ç¹ä¼¤å®³ï¼å¦ææéä»æ»äº¡ï¼å次éæ¾è¯¥æ³æ¯'147 def __init__(self) -> None:148 super().__init__()149 self.allCost=1150 self.cost=['bk' for i in range(2)]151 def ability(self, MyMaster, Master, selectIndex=None):152 check=False153 for i in MyMaster.cardGround.copy():154 i.live-=1155 if i.Rlive()<=0:156 check=True157 i.dieth(MyMaster, Master)158 for ii in Master.cardGround.copy():159 ii.live-=1160 if ii.Rlive()<=0:161 check=True162 ii.dieth(MyMaster, Master)163 if check==True:164 self.ability(MyMaster, Master)165class SpellOverload(father.magic):166 167 name='SpellOverload'168 narrate='æ¶èææå°ï¼æ¯æ¶èä¸ä¸ªå°ï¼å¬å¤ä¸ä¸ª1-1çå¹½çµ'169 def __init__(self) -> None:170 super().__init__()171 self.cost=['g']172 def ability(self, MyMaster, Master, selectIndex=None):173 for i in MyMaster.termGround:174 for ii in range(i):175 MyMaster.cardGround.append(moreS.Phantom())176 MyMaster.termGround=[0,0,0,0,0]177class StageAComeback(father.magic):178 name='StageAComeback'179 narrate='å¤æ´»æææ»è¿çéä»'180 def __init__(self) -> None:181 super().__init__()182 self.cost=['bk' for i in range(9)]183 def ability(self, MyMaster, Master, selectIndex=None):184 r=re.compile(r"'.+'")185 cop=MyMaster.tomb.copy()186 random.shuffle(cop)187 for i in cop:188 print(type(i))189 servent=eval((r.findall(str(type(i)))[0]).replace("'",'')+'()')190 MyMaster.cardGround.append(servent)191class Greed(father.magic):192 name='Greed'193 narrate='æ½ä¸å¼ çï¼å¦æççæ³å大äº4ï¼æ£1æ»´è¡åæ½ä¸å¼ '194 def __init__(self) -> None:195 super().__init__()196 self.allCost=1197 self.cost=['bk']198 def ability(self, MyMaster, Master, selectIndex=None):199 get=MyMaster.getCard(1)200 if len(get)>0:201 getArr=get[0]202 if len(getArr.Rcost(MyMaster, Master))+getArr.allCost>4:203 self.ability(MyMaster, Master)204 MyMaster.live-=1205class Lifemanship(father.magic):206 name='Lifemanship'207 narrate='ææéä»è·å¾å²é'208 def __init__(self) -> None:209 super().__init__()210 self.cost=['r' for i in range(3)]211 def ability(self, MyMaster, Master, selectIndex=None):212 for i in MyMaster.cardGround.copy():213 i.sleep=False214class SummonSandworm(father.magic):215 name='SummonSandworm'216 narrate='对ææ¹ææéä»é æ4ç¹ä¼¤å®³ï¼ææ¹ææéä»+2æ»å»å'217 def __init__(self) -> None:218 super().__init__()219 self.cost=['r' for i in range(4)]220 self.allCost=3221 self.buffNar=buff.SummonSandworm()222 def ability(self, MyMaster, Master, selectIndex=None):223 for i in Master.cardGround.copy():224 i.live-=4225 for ii in MyMaster.cardGround.copy():226 ii.buff.append(self.buffNar)227class Reinforce(father.magic):228 name='Reinforce'229 narrate='ä»çåºéå¬å¤2个éä»ï¼ææéä»+1æ»å»å'230 def __init__(self) -> None:231 super().__init__()232 self.cost=['r' for i in range(6)]233 self.allCost=3234 self.buffNar=buff.Reinforce()235 def ability(self, MyMaster, Master, selectIndex=None):236 count=0237 for i in range(2):238 get=selectCards('servent',MyMaster.cardStorage)239 if get!=False:240 MyMaster.cardGround.append(get)241 MyMaster.cardStorage.remove(get)242 for ii in MyMaster.cardGround:243 ii.buff.append(self.buffNar)244class ElementAgitation(father.magic):245 name='ElementAgitation'246 narrate='å¬å¤2个2-1çå°ç«è'247 def __init__(self) -> None:248 super().__init__()249 self.cost=['r' for i in range(2)]250 def ability(self, MyMaster, Master, selectIndex=None):251 MyMaster.cardGround.append(moreS.SmallFire())252 MyMaster.cardGround.append(moreS.SmallFire())253class ForestCover(father.magic):254 name='ForestCover'255 narrate='æ¯æä¸å¼ æçï¼å¬å¤ä¸ä¸ª2-2çæ è'256 def __init__(self) -> None:257 super().__init__()258 self.cost=['g' for i in range(3)]259 self.allCost=1260 def ability(self, MyMaster, Master, selectIndex=None):261 for i in range(len(MyMaster.cardHand)):262 MyMaster.cardGround.append(moreS.Sapling())263class DiffusePlague(father.magic):264 name='DiffusePlague'265 narrate='å¬å¤1-5çç²è«ï¼ç´å°ææ¹éä»æ°éçäºææ¹éä»æ°é'266 def __init__(self) -> None:267 super().__init__()268 self.cost=['bl' for i in range(4)]269 self.allCost=2270 def ability(self, MyMaster, Master, selectIndex=None):271 if len(MyMaster.cardGround)<len(Master.cardGround):272 for i in range(len(Master.cardGround)-len(MyMaster.cardGround)):273 MyMaster.cardGround.append(moreS.Beetle())274 else:275 MyMaster.cardGround.append(moreS.Beetle())276class WorldTreePower(father.magic):277 name='WorldTreePower'278 narrate='åæ¹åºä¸éä»åçåºéçéä»+5+5'279 def __init__(self) -> None:280 super().__init__()281 self.cost=['g' for i in range(8)]282 self.allCost=2283 self.buffNar=buff.WorldTreePower()284 def ability(self, MyMaster, Master, selectIndex=None):285 for i in MyMaster.cardGround:286 i.buff.append(self.buffNar)287 for ii in MyMaster.cardStorage:288 if ii.typeCard=='servent':289 ii.buff.append(self.buffNar)290class RainAndDew(father.magic):291 name='RainAndDew'292 narrate='+8+8åé
ç»ææéä»'293 def __init__(self) -> None:294 super().__init__()295 self.cost=['g' for i in range(4)]296 self.allCost=2297 self.buffNar=buff.RainAndDew()298 def ability(self, MyMaster, Master, selectIndex=None):299 for i in range(8):300 if len(MyMaster.cardGround)!=0:301 MyMaster.cardGround[random.randint(0,len(MyMaster.cardGround)-1)].buff.append(self.buffNar)302class ForestSpore(father.magic):303 name='ForestSpore'304 narrate='对ææææ¹éä»-1-1ï¼å¯¹åæ¹éä»+1+1'305 def __init__(self) -> None:306 super().__init__()307 self.cost=['g' for i in range(3)]308 self.allCost=2309 self.buffNar=buff.ForestSpore()310 def ability(self, MyMaster, Master, selectIndex=None):311 for i in Master.cardGround:312 i.power-=1313 i.live-=1314 for ii in MyMaster.cardGround:315 ii.buff.append(self.buffNar)316class ExploreUnknow(father.magic):317 name='ExploreUnknow'318 narrate='æ½ä¸¤å¼ çï¼å¦ææ½å°ççæ¯æ³æ¯åå¬å¤1个2-2对æ è'319 def __init__(self) -> None:320 super().__init__()321 self.cost=['g' for i in range(3)]322 self.allCost=1323 def ability(self, MyMaster, Master, selectIndex=None):324 get=MyMaster.getCard(2)325 for i in get:326 if i.typeCard=='magic':327 MyMaster.cardGround.append(moreS.Sapling())328class GodGrace(father.magic):329 name='GodGrace'330 narrate='å¤æ´»ä¸ä¸ªéä»'331 def __init__(self) -> None:332 super().__init__()333 self.cost=['w' for i in range(2)]334 def ability(self, MyMaster, Master, selectIndex=None):335 if len(MyMaster.tomb)>0:336 r=re.compile(r"'.+'")337 getServent=MyMaster.tomb[random.randint(0,len(MyMaster.tomb)-1)]338 servent=eval((r.findall(str(type(getServent)))[0]).replace("'",'')+'()')339 MyMaster.cardGround.append(servent)340class HolyLightDispel(father.magic):341 name='HolyLightDispel'342 narrate='对ææ¹éä»é æ2ç¹ä¼¤å®³ï¼å¯¹ææ¹éä»æ¢å¤2ç¹çå½å¼'343 def __init__(self) -> None:344 super().__init__()345 self.cost=['w' for i in range(4)]346 def ability(self, MyMaster, Master, selectIndex=None):347 for i in Master.cardGround:348 i.live-=2349 for ii in MyMaster.cardGround:350 ii.live+=2351class HolyBlessing(father.magic):352 name='HolyBlessing'353 narrate='éæ©ä¸ä¸ªåæ¹éä»ï¼ä½¿å
¶çå½ç¿»å'354 selectMode='osm'355 def __init__(self) -> None:356 super().__init__()357 self.cost=['w' for i in range(1)]358 self.allCost=2359 def ability(self, MyMaster, Master, selectIndex=None):360 selectIndex.live+=selectIndex.Rlive(MyMaster, Master)361 selectIndex.iniLive+=selectIndex.Rlive(MyMaster, Master)362class PuppetPossess(father.magic):363 name='PuppetPossess'364 narrate='å¤æ´»ä¸ä¸ªéä»ï¼å
¶çå½åæ»å»åå为1'365 def __init__(self) -> None:366 super().__init__()367 self.cost=['w' for i in range(3)]368 self.allCost=1369 def ability(self, MyMaster, Master, selectIndex=None):370 r=re.compile(r"'.+'")371 cop=MyMaster.tomb.copy()372 random.shuffle(cop)373 print(cop)374 for i in range(3 if len(cop)>3 else len(cop)):375 376 servent=eval((r.findall(str(type(cop[i])))[0]).replace("'",'')+'()')377 servent.live=1378 servent.power=1379 MyMaster.cardGround.append(servent)380class HolySmite(father.magic):381 name='HolySmite'382 narrate='对ä¸ä¸ªéä»é æ3ç¹ä¼¤å®³'383 selectMode='osa'384 def __init__(self) -> None:385 super().__init__()386 self.cost=['w']387 def ability(self, MyMaster, Master, selectIndex=None):388 selectIndex.live-=3389class Opportunity(father.magic):390 name='Opportunity'391 narrate='æ½ä¸¤å¼ çï¼å¦ææ¯éä»çåæ¢å¤ä¸ç¹çå½'392 def __init__(self) -> None:393 super().__init__()394 self.cost=['w' for i in range(3)]395 def ability(self, MyMaster, Master, selectIndex=None):396 get=MyMaster.getCard(2)397 for i in get:398 if i.typeCard=='servent':399 MyMaster.live+=3400class HeavyRain(father.magic):401 name='HeavyRain'402 narrate='æ½ä¸¤å¼ çï¼å¦æè´¹ç¨å°äº5å对ææææ¹éä»é æ1ç¹ä¼¤å®³'403 def __init__(self) -> None:404 super().__init__()405 self.cost=['bl' for i in range(3)]406 self.allCost=1407 def ability(self, MyMaster, Master, selectIndex=None):408 get=MyMaster.getCard(2)409 for i in get:410 if len(i.cost)+i.allCost<5:411 for ii in Master.cardGround:412 ii.live-=1413class AbyssDoor(father.magic):414 name='AbyssDoor'415 narrate='æ¶çåºä¸ææéä»ï¼å¬å¤ä¸ä¸ªææéä»å±æ§æ»åçæªç©'416 def __init__(self) -> None:417 super().__init__()418 self.cost=['bl' for i in range(8)]419 self.allCost=2420 def ability(self, MyMaster, Master, selectIndex=None):421 power=0422 live=0423 for i in MyMaster.cardGround.copy():424 power+=i.Rpower(MyMaster, Master)425 live+=i.Rlive(MyMaster, Master)426 i.dieth(MyMaster,Master)427 for ii in Master.cardGround.copy():428 power+=ii.Rpower(Master,MyMaster)429 live+=ii.Rlive(Master,MyMaster)430 ii.dieth(Master,MyMaster)431 servent=moreS.Cthulhu()432 servent.live+=live433 servent.iniLive+=live434 servent.power+=power435 servent.iniPower+=power436 MyMaster.cardGround.append(servent)437class LifeDrain(father.magic):438 name='LifeDrain'439 narrate="é æ2ç¹ä¼¤å®³ï¼ä¸ºææ¹è±éæ¢å¤2ç¹çå½"440 selectMode='oaa'441 def __init__(self) -> None:442 super().__init__()443 self.cost=['bk' for i in range(3)]444 def ability(self, MyMaster, Master, selectIndex=None):445 selectIndex.live-=2446 MyMaster.live+=2447class InterimAdjustment(father.magic):448 name='InterimAdjustment'449 narrate="为èªå·±æ¢å¤5ç¹çå½å¼ï¼æ½ä¸å¼ ç"450 def __init__(self) -> None:451 super().__init__()452 self.cost=['w' for i in range(3)]453 def ability(self, MyMaster, Master, selectIndex=None):454 MyMaster.live+=5455 MyMaster.getCard(1)456class DoubleShot(father.magic):457 name='DoubleShot'458 narrate="对ææ¹éæºä¸¤ä¸ªéä»é æ2ç¹ä¼¤å®³"459 def __init__(self) -> None:460 super().__init__()461 self.allCost=3462 def ability(self, MyMaster, Master, selectIndex=None):463 used=[]464 for i in range(2):465 get=selectCards('servent',Master.cardGround,used)466 if get!=False:467 used.append(get)468 get.live-=2469class InnerFire(father.magic):470 name='InnerFire'471 narrate="使ä¸ä¸ªéä»çæ»å»åçäºçå½å¼"472 selectMode='osa'473 def __init__(self) -> None:474 super().__init__()475 self.cost=['w' for i in range(1)]476 self.buffNar=buff.InnerFire()477 def ability(self, MyMaster, Master, selectIndex=None):478 self.buffNar.buffType[0][1]=selectIndex.Rlive()-selectIndex.Rpower()479 selectIndex.buff.append(self.buffNar)480class UrgentRecruitment(father.magic):481 name='UrgentRecruitment'482 narrate="å°ä½ æççå¤å¶æ¾å
¥çåº"483 def __init__(self) -> None:484 super().__init__()485 self.allCost=3486 def ability(self, MyMaster, Master, selectIndex=None):487 for i in MyMaster.cardHand:488 MyMaster.cardStorage.append(copy.deepcopy(i))489class OceanCultivation(father.magic):490 name='OceanCultivation'491 narrate="å ä¸ç¹Ocean并æ½ä¸å¼ ç"492 def __init__(self) -> None:493 super().__init__()494 self.cost=['bl' for i in range(3)]495 def ability(self, MyMaster, Master, selectIndex=None):496 MyMaster.groundList[1]+=1497 MyMaster.getCard(1)498class Scheming(father.magic):499 name='Scheming'500 narrate="éæ©ä¸ä¸ªéä»ï¼æå
¶ä¸å¼ çå¤å¶å¡å
¥çåº"501 selectMode='osa'502 def __init__(self) -> None:503 super().__init__()504 self.cost=['bl' for i in range(2)]505 def ability(self, MyMaster, Master, selectIndex=None):506 for i in range(3):507 MyMaster.cardStorage.append(copy.deepcopy(selectIndex))508class SecretBlessings(father.magic):509 name='SecretBlessings'510 narrate="ä½ å¡çéææçççè´¹ç¨å
¨é¨åæå
¨æ¯åæ1è"511 def __init__(self) -> None:512 super().__init__()513 self.cost=['bl' for i in range(7)]514 def ability(self, MyMaster, Master, selectIndex=None):515 for i in MyMaster.cardStorage:516 i.allCost=0517 i.cost=['bl']518class Mimicry(father.magic):519 name='Mimicry'520 narrate="触åææéä»ç亡è¯"521 def __init__(self) -> None:522 super().__init__()523 self.allCost=3524 def ability(self, MyMaster, Master, selectIndex=None):525 for i in MyMaster.cardGround:526 i.WangYu(MyMaster, Master)527class SellYourSoul(father.magic):528 name='SellYourSoul'529 narrate="ææ»ä½ çä¸ä¸ªéä»ï¼æ¯å¦å¤ä¸ä¸ªéä»+4+4"530 selectMode='osm'531 def __init__(self) -> None:532 super().__init__()533 self.cost=['bk' for i in range(2)]534 self.buffNar=buff.SellYourSoul()535 def ability(self, MyMaster, Master, selectIndex=None):536 selectIndex.dieth(MyMaster,Master)537 if len(MyMaster.cardGround)!=0:538 MyMaster.cardGround[random.randint(0,len(MyMaster.cardGround))].buff.append(self.buffNar)539class ForestPlot(father.magic):540 name='ForestPlot'541 narrate="æ¶çåºä¸ææéä»ï¼å°åºä¸çéä»åæ2-2çæ è"542 def __init__(self) -> None:543 super().__init__()544 self.cost=['g' for i in range(3)]545 self.allCost=1546 def ability(self, MyMaster, Master, selectIndex=None):547 for i in Master.cardGround.copy():548 i.dieth(Master,MyMaster)549 Master.cardGround.append(moreS.Sapling())550 for ii in MyMaster.cardGround.copy():551 ii.dieth(MyMaster,Master)552 MyMaster.cardGround.append(moreS.Sapling())553class DarkestOfDays(father.magic):554 name='DarkestOfDays'555 narrate="ææ»ä½ çä¸ä¸ªéä»ï¼æ¯ææåæ¹éä»+1+1"556 selectMode='osm'557 def __init__(self) -> None:558 super().__init__()559 self.cost=['bk' for i in range(1)]560 self.buffNar=buff.DarkestOfDays()561 def ability(self, MyMaster, Master, selectIndex=None):562 selectIndex.dieth(MyMaster,Master)563 for i in MyMaster.cardGround:...
activeLearning.py
Source:activeLearning.py
1# -*- coding: utf-8 -*-2"""3Created on Thu Jan 17 15:04:40 201945@author: Unclered6"""7# ç¨ä¸»å¨å¦ä¹ çæ¹å¼æ¥å¢å æ°æ®æä¸æ è®°89import numpy as np10import random11from math import log1213def randomSelect(restImages,restLabels,numIncre,inputSize=2500,numClass=35):14 # éæºéåä¸å®æ°éçæ ·æ¬å ä¸æ è®°15 number = restImages.shape[0]16 indexList = range(number)17 selectIndex = random.sample(indexList, numIncre) # ä»indexListä¸è·å¾ç´¢å¼ä¸ç¸åçnumIncre个å
ç´ 18 increImages = np.zeros([numIncre,inputSize])19 increLabels = np.zeros([numIncre,numClass])20 for i in range(numIncre):21 increImages[i,:] = restImages[selectIndex[i],:]22 increLabels[i,:] = restLabels[selectIndex[i],:]23 minIndex = np.argsort(selectIndex)24 maxIndex = minIndex[::-1]25 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº26 for i in range(numIncre):27 select = maxIndex[i]28 restImages = np.delete(restImages,selectIndex[select],axis=0)29 restLabels = np.delete(restLabels,selectIndex[select],axis=0)30 return increImages, increLabels, restImages, restLabels3132def leastProb(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):33 # è·å¾æ大æ¦çä¸æ¬¡å¤§æ¦ççå·®å¼ï¼å·®å¼æå°ç就认为æ¯æ没æä¿¡å¿çãå°±å å
¥è¿æ¥34 number = restImages.shape[0]35 increImages = np.zeros([numIncre,inputSize])36 increLabels = np.zeros([numIncre,numClass])37 maxValueList = []38 maxIndex = np.argmax(restProb, axis=1)#æ大å¼ç´¢å¼39 for i in range(number):40 maxValueList.append(restProb[i,maxIndex[i]])41 selectList = np.argsort(maxValueList)#ä»å°å°å¤§æåº42 selectIndex = selectList[:numIncre]#æ¾å¯»æå°çå ä¸ªæ° 43 for i in range(numIncre):44 increImages[i,:] = restImages[selectIndex[i],:]45 increLabels[i,:] = restLabels[selectIndex[i],:]46 minIndex = np.argsort(selectIndex)47 maxIndex = minIndex[::-1]48 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº49 for i in range(numIncre):50 select = maxIndex[i]51 restImages = np.delete(restImages,selectIndex[select],axis=0)52 restLabels = np.delete(restLabels,selectIndex[select],axis=0)53 return increImages, increLabels, restImages, restLabels, maxValueList5455def entropySelect(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):56 # ç¨çµå¼æ¥éåéè¦ææ è®°çæ°æ®57 number = restImages.shape[0]58 entropyList = []59 increImages = np.zeros([numIncre,inputSize])60 increLabels = np.zeros([numIncre,numClass])61 for i in range(number):62 # ç»æåè·å¾ä¸ä¸ªä¿¡æ¯çµå表63 entropy = 064 for j in range(numClass):65 # è·å¾æ¯ä¸ä¸ªæ°æ®çä¿¡æ¯çµ66 entropy += restProb[i,j] * log(restProb[i,j], 2)67 entropyList.append(entropy) 68 selectList = np.argsort(entropyList) # ä»å°å°å¤§æåº69 selectIndex = selectList[:numIncre] # æ¾å¯»æå°çå ä¸ªæ° 70 for i in range(numIncre):71 increImages[i,:] = restImages[selectIndex[i],:]72 increLabels[i,:] = restLabels[selectIndex[i],:]73 minIndex = np.argsort(selectIndex)74 maxIndex = minIndex[::-1]75 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº76 for i in range(numIncre):77 select = maxIndex[i]78 restImages = np.delete(restImages,selectIndex[select],axis=0)79 restLabels = np.delete(restLabels,selectIndex[select],axis=0)80 return increImages, increLabels, restImages, restLabels8182 83def marginSample(restImages,restLabels,restProb,numIncre,inputSize=2500,numClass=35):84 # è·å¾æ大æ¦çä¸æ¬¡å¤§æ¦ççå·®å¼ï¼å·®å¼æå°ç就认为æ¯æ没æä¿¡å¿çãå°±å å
¥è¿æ¥85 number = restImages.shape[0]86 increImages = np.zeros([numIncre,inputSize])87 increLabels = np.zeros([numIncre,numClass])88 maxValueList = []89 maxIndex = np.argmax(restProb, axis=1)#æ大å¼ç´¢å¼90 for i in range(number):91 maxValueList.append(restProb[i,maxIndex[i]])92 restProb[i,maxIndex[i]] = 093 nextIndex = np.argmax(restProb, axis=1) # 次大å¼ç´¢å¼94 diffValueList = [maxValueList[i] - restProb[i,nextIndex[i]] for i in range(number)]95 selectList = np.argsort(diffValueList) # ä»å°å°å¤§æåº96 selectIndex = selectList[:numIncre] # æ¾å¯»æå°çå ä¸ªæ° 97 for i in range(numIncre):98 increImages[i,:] = restImages[selectIndex[i],:]99 increLabels[i,:] = restLabels[selectIndex[i],:]100 minIndex = np.argsort(selectIndex)101 maxIndex = minIndex[::-1]102 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº103 for i in range(numIncre):104 select = maxIndex[i]105 restImages = np.delete(restImages,selectIndex[select],axis=0)106 restLabels = np.delete(restLabels,selectIndex[select],axis=0)107 return increImages, increLabels, restImages, restLabels, diffValueList108109def CSmarginSample(restImages,restLabels,restProb,numIncre,numGallery=25,inputSize=2500,numClass=35):110 # è·å¾æ大æ¦çä¸æ¬¡å¤§æ¦ççå·®å¼ï¼å·®å¼æå°ç就认为æ¯æ没æä¿¡å¿çãå°±å å
¥è¿æ¥111 # 对差å¼ä¹æéãåç±»æé为1ï¼giæé为2ï¼igæé为5ï¼æè
giä¸igæéç¸åä¼æ´å¥½ï¼112 # æ¯ç«ä¹ä¸ä¸å®æ¯åç±»æ£ç¡®ï¼åªè¦å¯è½åç±»é误就å åæ´å¥½113 # ä¿¡æ¯çµçè¯ï¼ç®æµä¹æ代价ææä¿¡æ¯çµï¼114 number = restImages.shape[0]115 increImages = np.zeros([numIncre,inputSize])116 increLabels = np.zeros([numIncre,numClass])117 maxValueList = []118 maxIndex = np.argmax(restProb, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«119 for i in range(number):120 maxValueList.append(restProb[i,maxIndex[i]])121 restProb[i,maxIndex[i]] = 0122 nextIndex = np.argmax(restProb, axis=1) # 次大å¼ç´¢å¼ï¼ä¹å°±æ¯æ¬¡å¤§å¼ç±»å«123 diffValueList = [maxValueList[i] - restProb[i,nextIndex[i]] for i in range(number)]124 for i in range(number):125 if maxIndex[i] < numGallery and nextIndex[i] >= numGallery:126 diffValueList[i] = diffValueList[i] * 0.5 # giç代价127 elif maxIndex[i] >= numGallery and nextIndex[i] < numGallery:128 diffValueList[i] = diffValueList[i] * 0.25 # igç代价129 selectList = np.argsort(diffValueList) # ä»å°å°å¤§æåº130 selectIndex = selectList[:numIncre] # æ¾å¯»æå°çå ä¸ªæ° 131 for i in range(numIncre):132 increImages[i,:] = restImages[selectIndex[i],:]133 increLabels[i,:] = restLabels[selectIndex[i],:]134 minIndex = np.argsort(selectIndex)135 maxIndex = minIndex[::-1]136 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº137 for i in range(numIncre):138 select = maxIndex[i]139 restImages = np.delete(restImages,selectIndex[select],axis=0)140 restLabels = np.delete(restLabels,selectIndex[select],axis=0)141 return increImages, increLabels, restImages, restLabels, diffValueList142 143def EQB(restImages,restLabels,restProb1,restProb2,restProb3,numIncre,numGallery=25,inputSize=2500,numClass=35): 144 number = restImages.shape[0]145 increImages = np.zeros([numIncre,inputSize])146 increLabels = np.zeros([numIncre,numClass])147 label1 = np.argmax(restProb1, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«148 label2 = np.argmax(restProb2, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«149 label3 = np.argmax(restProb3, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«150 entropy = [] # ä¾æ¬¡è®¡ç®æ¯ä¸ªæ ·æ¬ç交åçµï¼å è´å·è¿æ ·å°±å¯ä»¥åæå°151 for i in range(number):152 N={}153 Hbag = 0154 label = [label1[i],label2[i],label3[i]]155 # å¶ä½ç±»å«å表156 for j in label:157 if j not in N:158 N[j] = 1159 else:160 N[j] += 1161 # 计ç®çµ162 for key,value in N.items():163 P = value/3164 Hbag += P * log(P,10)165 entropy.append(Hbag)166 selectList = np.argsort(entropy) # ä»å°å°å¤§æåº167 selectIndex = selectList[:numIncre] # æ¾å¯»æå°çå ä¸ªæ° 168 # print(selectIndex) 169 for i in range(numIncre):170 increImages[i,:] = restImages[selectIndex[i],:]171 increLabels[i,:] = restLabels[selectIndex[i],:]172 minIndex = np.argsort(selectIndex)173 maxIndex = minIndex[::-1]174 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº175 for i in range(numIncre):176 select = maxIndex[i]177 restImages = np.delete(restImages,selectIndex[select],axis=0)178 restLabels = np.delete(restLabels,selectIndex[select],axis=0)179 return increImages, increLabels, restImages, restLabels180181def CSEQB(restImages,restLabels,restProb1,restProb2,restProb3,numIncre,numGallery=25,inputSize=2500,numClass=35): 182 number = restImages.shape[0]183 increImages = np.zeros([numIncre,inputSize])184 increLabels = np.zeros([numIncre,numClass])185 label1 = np.argmax(restProb1, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«186 label2 = np.argmax(restProb2, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«187 label3 = np.argmax(restProb3, axis=1) # æ大å¼ç´¢å¼ï¼ä¹å°±æ¯ç±»å«188 entropy = [] # ä¾æ¬¡è®¡ç®æ¯ä¸ªæ ·æ¬ç交åçµï¼å è´å·è¿æ ·å°±å¯ä»¥åæå°189 for i in range(number):190 key=[]191 value=[]192 Hbag = 0193 label = [label1[i],label2[i],label3[i]]194 # å¶ä½ç±»å«å表195 for j in label:196 if j not in key:197 key.append(j)198 value.append(1)199 else:200 keyIndex=key.index(j)201 value[keyIndex] = value[keyIndex] + 1202 keyLabel = [m-numGallery+0.5 for m in key]203 # 计ç®çµ204 if len(key) == 3:205 if keyLabel[0] * keyLabel[1] * keyLabel[2] < 0:206 if keyLabel[0]<0 and keyLabel[1]<0 and keyLabel[2]<0:207 Hbag=4208 else:209 Hbag=1210 else:211 if keyLabel[0]>0 and keyLabel[1]>0 and keyLabel[2]>0:212 Hbag=3213 else:214 Hbag=2215 elif len(key) == 2:216 if keyLabel[0] * keyLabel[1] < 0:217 Hbag=5218 else:219 Hbag=6220 elif len(key) == 1:221 Hbag=7222 entropy.append(Hbag)223 selectList = np.argsort(entropy) # ä»å°å°å¤§æåº224 print(entropy[:25])225 selectIndex = selectList[:numIncre] # æ¾å¯»æå°çå ä¸ªæ° 226 # print(selectIndex) 227 for i in range(numIncre):228 increImages[i,:] = restImages[selectIndex[i],:]229 increLabels[i,:] = restLabels[selectIndex[i],:]230 minIndex = np.argsort(selectIndex)231 maxIndex = minIndex[::-1]232 # æ ¹æ®ç´¢å¼å é¤æ°æ®ä¸å®è¦ååºå é¤ãå¦åæ°æ®éåå°ï¼ç´¢å¼ä¸åæ¯åæ¥çç´¢å¼äº233 for i in range(numIncre):234 select = maxIndex[i]235 restImages = np.delete(restImages,selectIndex[select],axis=0)236 restLabels = np.delete(restLabels,selectIndex[select],axis=0)237 return increImages, increLabels, restImages, restLabels238 239 240 241 242 243 244 245 246 247 248
...
self_fieldsetting.py
Source:self_fieldsetting.py
1# -*- coding: utf-8 -*-2import kivy3kivy.require('1.11.0') # replace with your current kivy version !4import sys5import os6sys.path.append(os.path.join(os.path.dirname(__file__), ".." + os.sep + "sbase" + os.sep))7from kivy.lang import Builder8from kivy.uix.recycleview import RecycleView9from kivy.uix.recycleview.views import RecycleDataViewBehavior10from kivy.uix.label import Label11from kivy.properties import BooleanProperty12from kivy.uix.recycleboxlayout import RecycleBoxLayout13from kivy.uix.behaviors import FocusBehavior14from kivy.uix.recycleview.layout import LayoutSelectionBehavior15from kivy.uix.boxlayout import BoxLayout16from kivy.uix.floatlayout import FloatLayout17from kivy.uix.popup import Popup18from kivy.properties import ObjectProperty19import sconsts as CONSTS20import sutil21from selements import SLabel, SButton, SConfirmLayout, SDirSelectDialog22with open(os.path.join(os.path.dirname(__file__), "self_fieldsetting.kv"), encoding = "utf-8") as f:23 Builder.load_string(f.read())24class FieldSettingRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):25 ''' Adds selection and focus behaviour to the view. '''26class FieldSettingLabel(RecycleDataViewBehavior, Label):27 ''' Add selection support to the Label '''28 index = None29 selected = BooleanProperty(False)30 selectable = BooleanProperty(True)31 def refresh_view_attrs(self, rv, index, data):32 ''' Catch and handle the view changes '''33 self.index = index34 return super(FieldSettingLabel, self).refresh_view_attrs(35 rv, index, data)36 def on_touch_down(self, touch):37 ''' Add selection on touch down '''38 if super(FieldSettingLabel, self).on_touch_down(touch):39 return True40 if self.collide_point(*touch.pos) and self.selectable:41 return self.parent.select_with_touch(self.index, touch)42 def apply_selection(self, rv, index, is_selected):43 ''' Respond to the selection of items in the view. '''44 self.selected = is_selected45 if is_selected:46 rv.isSelectDict[index] = rv.data[index].get('text')47 else:48 rv.isSelectDict.pop(index, None)49 50class FieldSettingRV(RecycleView):51 52 isSelectDict = {}53 54 def __init__(self, **kwargs):55 super(FieldSettingRV, self).__init__(**kwargs)56 #self.data = [{'text': str(x)} for x in range(100)]57class SFieldSetting(BoxLayout):58 rightrv_id = ObjectProperty(None)59 ensurebtn_id = ObjectProperty(None)60 closebtn_id = ObjectProperty(None)61 sysConfDict = {}62 fieldSeqList = None63 kwargs = {}64 65 def __init__(self, refDict, **kwargs):66 super(SFieldSetting, self).__init__(**kwargs)67 self.app = refDict.get(CONSTS.S_APP)68 self.sysConfDict = self.app.confDict.get(CONSTS.SYS_CONF_DICT)69 70 filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")71 alist = sutil.getListFromFile(filePath)72 idDict = {}73 self.nameDict = {}74 seqList = []75 for astr in alist:76 tmpList = astr.strip().split(",")77 if len(tmpList) < 2:78 continue79 if tmpList[0] == "_SEQ_":80 seqList = tmpList[1].strip().split("|")81 else:82 idDict[tmpList[0]] = tmpList[1]83 self.nameDict[tmpList[1]] = tmpList[0]84 85 for seqId in seqList:86 adict = {}87 adict["text"] = idDict.get(seqId, "")88 self.rightrv_id.data.append(adict)89 def toUp(self):90 isSelectDict = self.rightrv_id.isSelectDict91 if len(isSelectDict) != 1:92 return93 94 selectIndex = list(isSelectDict.keys())[0]95 if selectIndex == 0:96 return97 adict = {}98 adict['text'] = isSelectDict.get(selectIndex)99 self.rightrv_id.data.pop(selectIndex)100 self.rightrv_id.data.insert(selectIndex - 1, adict)101 self.rightrv_id.layout_manager.selected_nodes = [selectIndex - 1]102 103 def toDown(self):104 isSelectDict = self.rightrv_id.isSelectDict105 if len(isSelectDict) != 1:106 return107 108 selectIndex = list(isSelectDict.keys())[0]109 if selectIndex == (len(self.rightrv_id.data) - 1):110 return111 adict = {}112 adict['text'] = isSelectDict.get(selectIndex)113 self.rightrv_id.data.pop(selectIndex)114 self.rightrv_id.data.insert(selectIndex + 1, adict)115 self.rightrv_id.layout_manager.selected_nodes = [selectIndex + 1]116 117 def toTop(self):118 isSelectDict = self.rightrv_id.isSelectDict119 if len(isSelectDict) != 1:120 return121 122 selectIndex = list(isSelectDict.keys())[0]123 if selectIndex == 0:124 return125 adict = {}126 adict['text'] = isSelectDict.get(selectIndex)127 self.rightrv_id.data.pop(selectIndex)128 self.rightrv_id.data.insert(0, adict)129 self.rightrv_id.layout_manager.selected_nodes = [0]130 131 def toBottom(self):132 isSelectDict = self.rightrv_id.isSelectDict133 if len(isSelectDict) != 1:134 return135 136 selectIndex = list(isSelectDict.keys())[0]137 if selectIndex == (len(self.rightrv_id.data) - 1):138 return139 adict = {}140 adict['text'] = isSelectDict.get(selectIndex)141 self.rightrv_id.data.pop(selectIndex)142 self.rightrv_id.data.append(adict)143 self.rightrv_id.layout_manager.selected_nodes = [len(self.rightrv_id.data) - 1]144 145 def saveData(self):146 filePath = os.path.join(os.path.dirname(__file__), ".." + os.sep + "conf" + os.sep + "stkfields_setting.ini")147 alist = sutil.getListFromFile(filePath) 148 with open(filePath, 'w', encoding = 'utf-8') as f:149 for tmpStr in alist:150 tmpList = tmpStr.strip().split(",")151 if len(tmpList) < 2:152 astr = tmpStr + "\n"153 f.write(astr)154 continue155 if tmpList[0] == "_SEQ_":156 aFieldId = None157 self.fieldSeqList = []158 astr = "_SEQ_,"159 for aDict in self.rightrv_id.data:160 aFieldId = self.nameDict.get(aDict.get("text"))161 astr += aFieldId + "|"162 self.fieldSeqList.append(aFieldId)163 astr = astr[0:-1] + "\n"164 else:165 astr = tmpStr + "\n" ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!