Exemplo n.º 1
0
    def __init__(self):
        self.dark_archiver = Archiver(None, None)
        self.folder_encode_path = "test_dirs"
        self.folder_encode_out_path = None
        self.folder_decode_path = "out/test_dirs.dzf"
        self.folder_decode_out_path = "decode"

        self.file_encode_path = "test.txt"
    def __plot(self):

        file_name = TornadoDic.get_short_names(self.learner.LEARNER_NAME)
        pair_name = self.learner.LEARNER_NAME.title()

        up_range = numpy.max(self.__learner_error_rate_array)
        up_range = 1 if up_range > 0.75 else round(up_range, 1) + 0.25

        Plotter.plot_single(pair_name, self.__learner_error_rate_array, "Error-rate",
                            self.__project_name, self.__project_path, file_name, [0, up_range], 'upper right', 200)
        Archiver.archive_single(pair_name, self.__learner_error_rate_array,
                                self.__project_path, self.__project_name, 'Error-rate')
Exemplo n.º 3
0
    def __plot(self):

        learner_name = TornadoDic.get_short_names(self.learner.LEARNER_NAME)
        detector_name = self.drift_detector.DETECTOR_NAME
        detector_setting = self.drift_detector.get_settings()
        file_name = learner_name + "_" + detector_name + "." + detector_setting[0]

        up_range = numpy.max(self.__learner_error_rate_array)
        up_range = 1 if up_range > 0.75 else round(up_range, 1) + 0.25

        pair_name = learner_name + ' + ' + detector_name + "(" + detector_setting[1] + ")"
        Plotter.plot_single(pair_name, self.__learner_error_rate_array, "Error-rate",
                            self.__project_name, self.__project_path, file_name, [0, up_range], 'upper right', 200)
        Archiver.archive_single(pair_name, self.__learner_error_rate_array,
                                self.__project_path, self.__project_name, 'Error-rate')
Exemplo n.º 4
0
def main():
    # Clear the screen
    subprocess.call("clear", shell=True)
    config_object = Config(os.getcwd() + "/config/config.ini").raw_config_object

    try:

        """
        need to spin the threads and get all the jazz up and running
        probably need a separate config parser and starter classes...?
        """
        mic = Mic(config_object)
        camera = Camera(config_object)
        archiver = Archiver(config_object)
        mailer = Mailer(config_object)

        while True:
            mic_response = mic.send({"action": "listen"})
            print(".", end="", flush=True)

            if mic_response == mic.MIC_DONE:
                camera_res = camera.send({"action": "photos"})
                print("taking photos")
                if camera_res == camera.CAMERA_DONE:
                    archiver_res = archiver.send({"action": "archive"})
                    print("archiving...")
                    if archiver_res == archiver.ARCHIVER_DONE and archiver.zfilename is not None:
                        print("sending mail")
                        mailer_done = mailer.send({"action": "last", "last_archive_name": archiver.zfilename})
                        if mailer_done == mailer.MAILER_DONE:
                            print("...cleaning up")
                            archiver.send({"action": "clearup"})
                            print("cycle done...")

    except LookupError as e:
        print(e)
        sys.exit(2)

    except KeyboardInterrupt:
        print("keyboard interruption")
        camera.close()
        mic.close()
        archiver.close()
        mailer.close()
        sys.exit(1)
Exemplo n.º 5
0
    def refresh_data(self):
        super(AutomaticCollector, self).refresh_data()

        if self.config.collector_has_archiver():
            self.archiver = Archiver(self)
    def archive(self):

        Archiver.archive_multiple(self.pairs_names, self.er,
                                  self.__project_path, self.__project_name,
                                  'Error-rate')
        Archiver.archive_multiple(self.pairs_names, self.mu,
                                  self.__project_path, self.__project_name,
                                  'Memory Usage (Kilobytes)')
        Archiver.archive_multiple(self.pairs_names, self.rt,
                                  self.__project_path, self.__project_name,
                                  'Runtime (Milliseconds)')
        Archiver.archive_multiple(self.pairs_names, self.sc,
                                  self.__project_path, self.__project_name,
                                  'Score')
        Archiver.archive_multiple(self.pairs_names, self.learners_stats,
                                  self.__project_path, self.__project_name,
                                  'learners_stats')
        Archiver.archive_multiple(self.pairs_names, self.detectors_stats,
                                  self.__project_path, self.__project_name,
                                  'detectors_stats')
Exemplo n.º 7
0
class Runner(object):
    def __init__(self):
        self.dark_archiver = Archiver(None, None)
        self.folder_encode_path = "test_dirs"
        self.folder_encode_out_path = None
        self.folder_decode_path = "out/test_dirs.dzf"
        self.folder_decode_out_path = "decode"

        self.file_encode_path = "test.txt"

    def encode_file(self, **kwargs):
        if "file_encode_path" in kwargs:
            self.file_encode_path = kwargs["file_encode_path"]
        if "folder_encode_out_path" in kwargs:
            self.folder_encode_out_path = kwargs["folder_encode_out_path"]

        file_name = self.dark_archiver.archive_file(self.file_encode_path,
                                                    create_mode=True).name
        if self.folder_encode_out_path is None:
            out_file_path = os.path.join(
                os.path.dirname(self.file_encode_path), file_name + ".dzf")
        else:
            out_file_path = os.path.join(self.folder_encode_out_path,
                                         file_name + ".dzf")

        file_path = os.path.join("out", file_name + ".dzf")
        self._encode(file_path, out_file_path)
        return out_file_path

    def encode_folder(self, **kwargs):
        if "folder_encode_path" in kwargs:
            self.folder_encode_path = kwargs["folder_encode_path"]
        if "folder_encode_out_path" in kwargs:
            self.folder_encode_out_path = kwargs["folder_encode_out_path"]

        folder_title = self.dark_archiver.archive_folder(
            self.folder_encode_path)[0]
        file_path = os.path.join("out", folder_title + ".dzf")

        if self.folder_encode_out_path is None:
            out_file_path = os.path.join(self.folder_encode_path + ".dzf")
        else:
            out_file_path = os.path.join(self.folder_encode_out_path,
                                         folder_title + ".dzf")
        self._encode(file_path, out_file_path)
        return out_file_path

    def _encode(self, file_path, encode_out_path):
        symbols = []
        with open(file_path, "r", encoding="cp1251") as file:
            for line in file:
                symbols.extend(line)

        compressor = HuffmanCompressor(source_text=symbols)
        encoded_str = compressor.encode()

        byter = Byter()
        encoded_bytes = byter.convert_to_bytes(encoded_str)
        encoded_huffman_tree = compressor.huffman_tree_code
        encoded_count_bytes = self._convert_to_225(len(encoded_str))

        HuffmanWriter.write(encode_out_path, encoded_bytes,
                            encoded_huffman_tree, encoded_count_bytes)

    def decode_folder(self, **kwargs):
        if "folder_decode_path" in kwargs:
            self.folder_decode_path = kwargs["folder_decode_path"]
        if "folder_decode_out_path" in kwargs:
            self.folder_decode_out_path = kwargs["folder_decode_out_path"]

        start = time.time()
        file_bytes = b""
        with open(self.folder_decode_path, "rb") as file:
            next_byte = file.read(1024)
            while next_byte:
                file_bytes += next_byte
                next_byte = file.read(1024)
        end = time.time()
        print(f"Bytes was read: {end - start}")

        huffman_reader = HuffmanReader(file_bytes)
        compressor = HuffmanCompressor(
            huffman_tree_bytes=huffman_reader.tree_bytes)

        byter = Byter()
        bit_str_bytes = huffman_reader.count_bytes
        bit_str = byter.convert_to_bit_str(
            huffman_reader.code_bytes, self._convert_from_255(bit_str_bytes))

        source_str = compressor.decode(bit_str)
        source_str = source_str[:source_str.rindex(']')]
        source_str += ']}'
        folder_json = json.loads(source_str)

        self.dark_archiver.dearchive_folder(folder_json,
                                            self.folder_decode_out_path)
        with open("out/test_dirs.dzf", "w+", encoding="cp1251") as file:
            file.writelines(source_str)

    @staticmethod
    def crypt_file(file_path, key):
        text = b""
        with open(file_path, "rb") as file:
            next_byte = file.read(1)
            while next_byte:
                text += next_byte
                next_byte = file.read(1)

        code = des.encrypt(text, key)[0]
        code_bytes = code.tobytes()

        with open(file_path, "wb") as file:
            for byte in code_bytes:
                file.write(byte.to_bytes(1, "little"))

    @staticmethod
    def decrypt_file(file_path, key):
        code_bytes = b""

        with open(file_path, "rb") as file:
            next_byte = file.read()
            while next_byte:
                code_bytes += next_byte
                next_byte = file.read()

        code = bitarray()
        code.frombytes(code_bytes)
        decode_bits = des.decrypt(code, key)
        decode_bytes = decode_bits.tobytes()

        with open(file_path, "wb") as file:
            for byte in decode_bytes:
                file.write(byte.to_bytes(1, "little"))

    @staticmethod
    def _convert_to_225(num):
        num_225 = []
        while num > 0:
            num_225.append(num % 225)
            num //= 225
        return num_225

    @staticmethod
    def _convert_from_255(nums):
        res = 0
        power = 0

        for i, num in enumerate(nums):
            res += num * 225**power
            power += 1

        return res