From 5eeb207e22711ddc8bf7db84feeda50276ca4a75 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 20 May 2021 10:29:15 +0100 Subject: [PATCH] Updated Adding your own checker (markdown) --- Adding-your-own-checker.md | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Adding-your-own-checker.md b/Adding-your-own-checker.md index 9248fa9..161e3eb 100644 --- a/Adding-your-own-checker.md +++ b/Adding-your-own-checker.md @@ -128,4 +128,44 @@ Like so: self.checkers.append(config(Brandon)) ``` -Finally, write some tests, run our tests with [Nox](https://nox.thea.codes/en/stable/) and make sure everything is a-okay! \ No newline at end of file +Finally, write some tests, run our tests with [Nox](https://nox.thea.codes/en/stable/) and make sure everything is a-okay! + +# Extra Info +```py +from typing import Dict, Optional + +from loguru import logger +from pywhat import identifier + +from ciphey.iface import Checker, Config, ParamSpec, T, registry + + +@registry.register +class GTestChecker(Checker[str]): + + """ + G-test of fitness, similar to Chi squared. + """ + + def check(self, text: T) -> Optional[str]: + logger.trace("Trying PyWhat checker") + returned_regexes = self.id.identify(text) + if returned_regexes["Regexes"] > 0: + return returned_regexes["Regexes"][0]["Regex Pattern"]["Name"] + return None + + def getExpectedRuntime(self, text: T) -> float: + # TODO: actually bench this + return 4e-7 * len(text) + + def __init__(self, config: Config): + super().__init__(config) + self.id = identifier.Identifier() + + @staticmethod + def getParams() -> Optional[Dict[str, ParamSpec]]: + pass + +``` + +Checkers return a string (with what it found) or None if it fails. \ No newline at end of file