Exemple #1
0
def post_basic():
    if request.method == 'GET':
        if 'query' in request.args:
            search = request.args['query']
            p = Parser(dir_search.basic(search))
            p.parse()
            return jsonify(p.results)
        return "Error: No search query provided. Please provide one."
    elif request.method == 'POST':
        search = request.form['search']
        p = Parser(dir_search.basic(search))
        p.parse()
        print(p.results)
        return jsonify(p.results)
Exemple #2
0
def post_advanced():
    first = None
    last = None
    id = None
    email = None
    if 'first' in request.form:
        first = request.form['first']
    if 'last' in request.form:
        last = request.form['last']
    if 'id' in request.form:
        id = request.form['id']
    if 'email' in request.form:
        email = request.form['email']
    if not any([first, last, id, email]):
        return "Error: No search query provided. Please provide one."
    p = Parser(dir_search.advanced(first, last, id, email))
    p.parse()
    return jsonify(p.results)
Exemple #3
0
    orderManager = OrderManager()
    order_idx = 4 + nb_warehouse*2
    nb_orders = int(parser.get_line(order_idx)[0])
    for i in range(nb_orders):
        coords = parser.get_line(order_idx + 1 + i*3)
        x = coords[1]
        y = coords[0]
        products_needed = parser.get_line(order_idx + 3 + i*3)
        #print("x {0} / y {1} / pro_len {2}".format(x, y, len(products_needed)))
        orderManager.add_order(i, x, y, products_needed)

    return warehouseManager, orderManager, droneManager


if __name__ == "__main__":
    file = sys.argv[1] if len(sys.argv) > 1 else 'busy_day'
    if not file.endswith('.in'):
        file_name = file + '.in'
    else:
        file_name = file
    input_fn = 'input2016-{0}'.format(file_name)
    input = os.path.join(INPUT_FILE_DIR, input_fn)
    p = Parser(input)
    p.parse()

    warehouseManager, orderManager, droneManager = create_model(p)
    simu(droneManager, orderManager, warehouseManager)
    output_file = 'output2016-{0}.out'.format(file)
    nb_lines = droneManager.write_output(output_file)
    print("{0} lines has been printed to {1}".format(nb_lines, output_file))
Exemple #4
0
def get_basic(search):
    p = Parser(dir_search.basic(search))
    p.parse()
    return jsonify(p.results)
class HashCodeParser:
    def __init__(self, file_name):
        self.parser = Parser(file_name)
        self.nb_lines = 0
        self.nb_columns = 0
        self.matrix = []

    def parse(self):
        self.parser.parse()
        self.nb_lines = self.parser.size - 1
        self.nb_columns = self.parser.get(0, 1)
        self.generate_matrix()

    def generate_matrix(self):
        self.matrix = []
        for i in range(1, len(self.parser.lines)):
            self.matrix.append(self.parser.lines[i])

    '''
    line_idx and column_idx are 0-based. First value at 0
    If value at given indices doesn't exist : returns None
    '''
    def get(self, line_idx, column_idx):
        return self.parser.get(line_idx + 1, column_idx)

    '''
    0-based index
    '''
    def get_column(self, column_idx):
        col = []
        if column_idx >= self.nb_columns:
            return col
        for line in self.parser.lines[1:]:
            if len(line) > column_idx:
                col.append(line[column_idx])
        return col

    '''
    0-based index
    '''
    def get_line(self, line_idx):
        return self.parser.lines[line_idx + 1] if line_idx < self.nb_lines else []

    '''
    0-based index
    end parameter is excluded
    Ex : [1, 4] : returns columns 1, 2 and 3
    '''
    def get_columns(self, start=0, end=None):
        if end is None:
            end = self.nb_columns
        while start < end:
            yield(self.get_column(start))
            start += 1

    '''
    0-based index
    end parameter is excluded
    Ex : [1, 4] : returns lines 1, 2 and 3
    '''
    def get_lines(self, start=0, end=None):
        if end is None:
            end = self.nb_lines
        while start < end:
            yield(self.get_line(start))
            start += 1

    def coherence_test(self):
        if self.nb_lines == 0:
            raise RuntimeError('You must parse before calling the coherence test')

        theoretical_line_nb = self.parser.get(0, 0)
        if theoretical_line_nb != self.nb_lines and theoretical_line_nb == len(self.parser.lines) - 1:
            raise SyntaxError('File should have {0} lines, but got {1}'.format(theoretical_line_nb, self.nb_lines))

        first_line_len = len(self.parser.lines[0])
        theoretical_first_line_nb = 2
        if first_line_len != theoretical_first_line_nb:
            raise SyntaxError('First line not the right size ({0} instead of {1})'.format(first_line_len,
                                                                                          theoretical_first_line_nb))

        for row in self.parser.lines[1:]:
            if len(row) != self.nb_columns:
                raise SyntaxError('Row {0} is not long enough ({1} instead of {2} columns)'.format(row,
                                                                                                   len(row),
                                                                                                   self.nb_columns))
class HashCodeParser:
    def __init__(self, file_name):
        self.parser = Parser(file_name)
        self.nb_lines = 0
        self.nb_columns = 0
        self.matrix = []

    def parse(self):
        self.parser.parse()
        self.nb_lines = self.parser.size - 1
        self.nb_columns = self.parser.get(0, 1)
        self.generate_matrix()

    def generate_matrix(self):
        self.matrix = []
        for i in range(1, len(self.parser.lines)):
            self.matrix.append(self.parser.lines[i])

    '''
    line_idx and column_idx are 0-based. First value at 0
    If value at given indices doesn't exist : returns None
    '''

    def get(self, line_idx, column_idx):
        return self.parser.get(line_idx + 1, column_idx)

    '''
    0-based index
    '''

    def get_column(self, column_idx):
        col = []
        if column_idx >= self.nb_columns:
            return col
        for line in self.parser.lines[1:]:
            if len(line) > column_idx:
                col.append(line[column_idx])
        return col

    '''
    0-based index
    '''

    def get_line(self, line_idx):
        return self.parser.lines[line_idx +
                                 1] if line_idx < self.nb_lines else []

    '''
    0-based index
    end parameter is excluded
    Ex : [1, 4] : returns columns 1, 2 and 3
    '''

    def get_columns(self, start=0, end=None):
        if end is None:
            end = self.nb_columns
        while start < end:
            yield (self.get_column(start))
            start += 1

    '''
    0-based index
    end parameter is excluded
    Ex : [1, 4] : returns lines 1, 2 and 3
    '''

    def get_lines(self, start=0, end=None):
        if end is None:
            end = self.nb_lines
        while start < end:
            yield (self.get_line(start))
            start += 1

    def coherence_test(self):
        if self.nb_lines == 0:
            raise RuntimeError(
                'You must parse before calling the coherence test')

        theoretical_line_nb = self.parser.get(0, 0)
        if theoretical_line_nb != self.nb_lines and theoretical_line_nb == len(
                self.parser.lines) - 1:
            raise SyntaxError('File should have {0} lines, but got {1}'.format(
                theoretical_line_nb, self.nb_lines))

        first_line_len = len(self.parser.lines[0])
        theoretical_first_line_nb = 2
        if first_line_len != theoretical_first_line_nb:
            raise SyntaxError(
                'First line not the right size ({0} instead of {1})'.format(
                    first_line_len, theoretical_first_line_nb))

        for row in self.parser.lines[1:]:
            if len(row) != self.nb_columns:
                raise SyntaxError(
                    'Row {0} is not long enough ({1} instead of {2} columns)'.
                    format(row, len(row), self.nb_columns))