示例#1
0
def device():
    addr = int(request.args.get('addr'))

    d = directory.Directory(conn, addr)
    d.read()

    return render_template("device.html", d=d, addr=addr)
示例#2
0
def main(file_name, algorithm, iterations, population_size, phenotype_coding):
    """Main function.

    Function is used for connecting the main parts of a project. Firstly, it
    calls deletion of before created image directories. Then it calls file
    reading method and so gets parsed objects from it. It creates new task
    with given information and runs it using selected evolutionary algorithm.
    Lastly, it calls printing information of overall best instance to output.

    Args:
        file_name: A string, indicating name of a file, which will be read.
        algorithm: A NiaPy algorithm, indicating evolutionary algorithm
        that will be used.
        iterations: An integer, indicating number of repetitions.
        population_size: An integer, indicating number of instances that will
        be created inside one generation.
        phenotype_coding: An enum type, indicating which genotype-to-phenotype
        coding will be used in evaluation.

    Returns:
        Method does not return anything.
    """

    directory.Directory().delete_directories()
    objects = file.File.read('../datasets/' + file_name)

    task = Task(D=len(objects[1]), nFES=iterations, benchmark=evaluation.Evaluation(
        objects, iterations, population_size, phenotype_coding), optType=OptimizationType.MINIMIZATION)
    alg = algorithm(seed=randint(1000, 10000), task=task, NP=population_size)

    result, fitness = alg.run()
    print_result(evaluation.Evaluation.find_overall_best_instance(fitness))
示例#3
0
def block():
    addr = int(request.args.get('addr'))
    slot = int(request.args.get('slot'))
    idx = int(request.args.get('idx'))

    if idx in (14, ):
        idx += 100

    d = directory.Directory(conn, addr)
    b = d.read_block(slot, idx)
    print(b)

    params = OrderedDict()

    # Physical block
    if b.block_obj == 1:
        params["Manufacturer"] = man[unpack(
            ">H", conn.readparam(addr, slot, idx + 10))[0]]
        params["Device ID"] = conn.readparam(addr, slot, idx + 11).decode()

    # Function block
    if b.block_obj == 2:
        data = conn.readparam(addr, slot, idx + 10)
        params["Out"], params["Status"] = unpack(">fB", data)
        params["Unit"] = conn.readparam(addr, slot, idx + 35).decode()

    # Transducer block
    if b.block_obj == 3:
        if b.parent_class == 1:
            params["Out"], params["Status"] = unpack(
                ">fB",
                conn.readparam(addr, slot, idx + TRIMMED_VALUE, cached=False))
            params["Unit"] = units[unpack(
                ">H", conn.readparam(addr, slot, idx + SENSOR_UNIT))[0]]
        if b.parent_class == 2:
            params["Out"], params["Status"] = unpack(
                ">fB",
                conn.readparam(addr, slot, idx + PRIMARY_VALUE, cached=False))
            params["Unit"] = units[unpack(
                ">H", conn.readparam(addr, slot, idx + PRIMARY_VALUE_UNIT))[0]]

    return render_template("block.html",
                           slot=slot,
                           idx=idx,
                           o=objects[b.block_obj],
                           b=b,
                           addr=addr,
                           params=params)
示例#4
0
    def run(self):
        # open dir and get oldest file with the given extension
        dir = directory.Directory(os, self.import_dir, ['jpg', 'jpeg'])
        self.imagefile = dir.get_oldest_file()

        # open image
        scan = scanner.Scanner(self.imagefile.name)
        self.remove_image()
        informations = scan.scan()

        # load board_id and cards
        mapping = mapper.Mapper(informations)
        board_id = mapping.board_id
        cards = mapping.get_cards()

        # create board
        current_board = board.Board(board_id, cards)
        # write baord to json
        current_board.export_json(self.export_dir)
示例#5
0
import directory
import landing
import sess
import widgets
import plugins
import importer

app = Flask(__name__)

#app.debug = True
app.register_blueprint(api.bp)
app.register_blueprint(cache.cachebp)
app.register_blueprint(render.renderbp)

i = importer.importotron(importer.mods)
d = directory.Directory("examples", "export")
api.d = d
render.d = d
cache.d = d
widgets.d = d

app.secret_key = os.environ["CQPARTS_SECURE"]
app.session_interface = sess.SessionCollection(d.store)


# don't cache
@app.after_request
def add_header(response):
    response.headers["Cache-Control"] = "no-store"
    #    app.logger.error(session)
    return response
 def setUp(self):
     self.d = directory.Directory()
 def setUp(self):
     self.d = directory.Directory()
     self.d.add_number('name', '111.111.1111')
示例#8
0
    def run_parser(self, callback=None):
        """
        Parse post office directory

        callback - function to be executed after each page parse
        """

        # read meta data
        self.directory = directory.Directory(self.dir_path)

        if self.directory.town == None:
            return None

        if self.db:
            self.db.set_directory(self.directory, self.commit)

        # create checker object
        entry_checker = checker.EntryChecker(self.directory, self.config)
        print 'Parsing %s for %s\n' % (self.directory.town,
                                       self.directory.year)

        # get list of files to parse
        self._get_listing()

        for page in self.directory.pages:

            print '\nParsing %s ' % page.path

            lines = self._fix_line_returns(self._parse_page(page,
                                                            entry_checker))

            if self.verbose:
                self._print_page(lines)

            for line in lines:
                # fix OCR problems with global replaces
                line = entry_checker.clean_up_global(line)

                # create entry with cleanup line
                pod_entry = directory.Entry(line)

                if pod_entry.valid():
                    # again, clean up valid entries
                    entry_checker.clean_up(pod_entry)

                    # geo encode address if encoder set up
                    if self.geoencoder:
                        entry_checker.geo_encode(self.geoencoder, pod_entry)

                self._print_entry(pod_entry)
                page.entries.append(pod_entry)

            # envoke callback function for a page
            if callback:
                callback(self.directory, page)

            # commit page to database
            if self.db and self.commit:
                self.db.commit(page)

        return self.directory
示例#9
0
#!/usr/bin/env python
" rebuild  the directory"

import directory
import inspect
import os

d = directory.Directory("cqparts", "export")

l = d.treeiter("/cqparts/export")
for i in l:
    if i.is_leaf:
        print(i.name)
        d.params(i.info()["path"][1:])
        i.built = True
        d.store.upsert(i)
示例#10
0
 def setUp(self):
     self.d = directory.Directory()
     self.d.add_number('Rick', '404.452.5202')
示例#11
0
            jpeg_file = files.JPEGFile(mapped_df, general_df, output_df,
                                       output_name)
            jpeg_file.output()

            pdf_file = files.PDFFile(mapped_df, general_df, output_df,
                                     output_name)
            pdf_file.output()

            txt_file = files.TXTFile(mapped_df, general_df, output_df,
                                     output_name)
            txt_file.output()

            # Create directory and move files
            directory = dir.Directory(output_name, raw_data_df.get_name(),
                                      excel_file.get_name(),
                                      jpeg_file.get_name(),
                                      pdf_file.get_name(), txt_file.get_name())
            directory.create()

            repeat = input('Do you want to process another CSV? (y/n): ')
        except FileNotFoundError as not_found:
            print('No such file:', not_found.filename)
            repeat = input('Do you want to process another CSV? (y/n): ')
        except PermissionError as per_error:
            print('Cannot access', per_error.filename,
                  'as it is currently being used.')
            repeat = input('Do you want to process another CSV? (y/n): ')
        except TypeError:
            print(
                'Type mismatch! Please make sure your configuration file is compatible with the CSV.'
            )