def __init__(self, sDBPath): """Constructor of the AnalysisDataGenerator class Note: Please define the `DB_PATH` in the config.py or pass the path of the SQLite as parameter Args: sDBPath (str): Path to the SQLite database. """ if sDBPath is None: raise Exception("Path to SQL-Database has to be defined") tw = Twizzle(sDBPath) dfChallenges = pd.DataFrame(tw.get_challenges()) if dfChallenges.empty: raise Exception("currently there are no challenges defined yet") dfTests = pd.DataFrame(tw.get_tests()) if dfTests.empty: raise Exception("currently no test have been run yet") dfChallenges = dfChallenges.drop( labels=["originalImages", "comparativeImages", "targetDecisions"], axis=1) dfTests = pd.merge(dfTests, dfChallenges, how="inner", left_on="challenge", right_on="challenge") self.dataframe = dfTests
class TestRunner(object): """ TestRunner - creates a multi threaded environment for running tests """ def __init__(self, sDBPath, lNrOfThreads=2): """Constructor of a TestRunner class Note: Please define the `DB_PATH` in the config.py or pass the path of the SQLite as parameter Args: sDBPath (str): Path to the SQLite database. lNrOfThreads (int): number of threads to use for the tests """ if sDBPath is None: raise Exception("Path to SQL-Database has to be defined") if lNrOfThreads <= 0: raise Exception("lNrOfThreads has to be grater then 0") self.tw = Twizzle(sDBPath) self.oPool = ThreadPool(processes=lNrOfThreads) self.aTaskPoolThreads = [] self.lock = Lock() def run_test_async(self, sChallengeName, fnCallback, dicCallbackParameters={}): """add test run to threadpool Args: sChallengeName (str): name of the challenge that should be tested fnCallback (function): test wrapper function that should be called dicCallbackParameters (:obj:): Dictionary of parameters for fnCallback Returns: None """ pThread = self.oPool.apply_async( self.tw.run_test, (sChallengeName, fnCallback, dicCallbackParameters)) self.aTaskPoolThreads.append(pThread) def wait_till_tests_finished(self): """block execution till all threads are done""" # catch threads ready for pThread in self.aTaskPoolThreads: dicTest = pThread.get() self.tw.save_test_threadsafe(dicTest, self.lock) def get_tests(self): """get all tests defined""" return self.tw.get_tests()
def __init__(self, sDBPath, lNrOfThreads=2): """Constructor of a TestRunner class Note: Please define the `DB_PATH` in the config.py or pass the path of the SQLite as parameter Args: sDBPath (str): Path to the SQLite database. lNrOfThreads (int): number of threads to use for the tests """ if sDBPath is None: raise Exception("Path to SQL-Database has to be defined") if lNrOfThreads <= 0: raise Exception("lNrOfThreads has to be grater then 0") self.tw = Twizzle(sDBPath) self.oPool = ThreadPool(processes=lNrOfThreads) self.aTaskPoolThreads = [] self.lock = Lock()
@attack_challenge_group.menu(title="Scale (uniform)") def attack_scale_uniform(): print("I am scale (uniform)") attack_challenge_creator(scale_uniform_hook) @attack_challenge_group.menu(title="Scale (nonuniform)") def attack_scale_nonuniform(): print("I am scale (nonuniform)") attack_challenge_creator(scale_nonuniform_hook) @attack_challenge_group.menu(title="Contrast") def attack_contrast(): print("I am contrast") attack_challenge_creator(contrast_hook) @attack_challenge_group.menu(title="Gamma") def attack_gamma(): print("I am gamma") attack_challenge_creator(gamma_hook) if __name__ == '__main__': db_path = input("Enter the path of the database: ") tw = Twizzle(db_path) climenu.run()
from twizzle import Twizzle if __name__ == "__main__": sDBPath = "test.db" tw = Twizzle(sDBPath) sChallengeName = "image_hashing_challenge_print_scan_1" aOriginals = [ "_img/p1.png", "_img/p2.png", "_img/p3.png", "_img/p1.png", "_img/p1.png", "_img/p2.png", "_img/p2.png", "_img/p3.png", "_img/p3.png" ] aComparatives = [ "_img/p1_S.png", "_img/p3.png", "_img/p3_S.png", "_img/p2.png", "_img/p3.png", "_img/p1.png", "_img/p3.png", "_img/p1.png", "_img/p2.png" ] aTargetDecisions = [ True, False, True, False, False, False, False, False, False ] dicMetadata = { "printer": "DC783", "paper": "recycled paper", "print_dpi": 300 } tw.add_challenge(sChallengeName, aOriginals, aComparatives, aTargetDecisions, dicMetadata)