def __init__(self, filename):
     self._text = yaml.safe_load(open(filename, 'r'))
     data = FileReader(self._text)
     data.read()
     self._original_instructions = data.get_original_instructions()
     self._special_instructions = data.get_special_instructions()
     self._video_list = data.get_video_list()
     self._names = data.get_names()
Exemplo n.º 2
0
  def _read(self):
    cluster_indexes = dict()
    distances = dict()
    count = 0
    start = time.time()
    reader = FileReader(self._input_file, 64, self._process)
    for ci, ds, c in reader.read():
      distances.update(ds)
      count += c
      for x in ci:
        if x not in cluster_indexes:
          cluster_indexes[x] = np.array(ci[x], dtype="int64")
        else:
          cluster_indexes[x] = np.append(cluster_indexes[x], ci[x])

    assert count == len(distances), \
      "ids count: {}, record count: {}".format(
        len(distances), count)
    print("Read data done, read {} records, elapsed: {}".format(
      count, time.time() - start))
    return cluster_indexes, distances, count
Exemplo n.º 3
0
    def _read(self):
        cluster_indexes = dict()
        distances = dict()
        count = 0
        start = time.time()
        reader = FileReader(self._input_file, 64, self._process)
        for ci, ds, c in reader.read():
            distances.update(ds)
            count += c
            for x in ci:
                if x not in cluster_indexes:
                    cluster_indexes[x] = np.array(ci[x], dtype="int64")
                else:
                    cluster_indexes[x] = np.append(cluster_indexes[x], ci[x])

        assert count == len(distances), \
          "ids count: {}, record count: {}".format(
            len(distances), count)
        print("Read data done, read {} records, elapsed: {}".format(
            count,
            time.time() - start))
        return cluster_indexes, distances, count
Exemplo n.º 4
0
def main():
    conf = Config()
    users = []

    fr = FileReader()
    users = fr.read('in.txt')

    log.header("USERS FROM FILE")
    users_list = []
    for user in users:
        log.info("name: {} email: {} forbidden: {}".format(
            user.name, user.email, [u.name for u in user.forbidden]))
        users_list.append(user)

    # "Normales Wichteln" and "Schrottwichteln"
    perms_normal = bfs(users_list)

    if len(perms_normal) < 1:
        log.fail("No allowed perms found ('Normales Wichteln').")
        sys.exit(1)

    log.header("PERFECT MATCHINGS NORMAL")
    log.info("Found {} perfect matchings for normal wichteln.".format(
        len(perms_normal)))

    rnd = random.randint(0, len(perms_normal) - 1)

    perm_normal = perms_normal[rnd]

    # forbid the matches from "Normales Wichteln"
    for (user, match) in perm_normal:
        user.forbid(match)

    perms_schrott = bfs(users_list)

    if len(perms_schrott) < 1:
        log.fail("No allowed perms found ('Schrott-Wichteln').")
        sys.exit(1)

    log.header("PERFECT MATCHINGS SCHROTT")
    log.info("Found {} perfect matchings for schritt wichteln.".format(
        len(perms_schrott)))

    rnd = random.randint(0, len(perms_schrott) - 1)

    perm_schrott = perms_schrott[rnd]

    log.header("CHOSEN PERM Normal")
    for (paira, pairb) in perm_normal:
        log.info("{} -> {}".format(paira.name, pairb.name))

    log.header("CHOSEN PERM Schrott")
    for (paira, pairb) in perm_schrott:
        log.info("{} -> {}".format(paira.name, pairb.name))

    if conf.mail_enabled:
        mail = Mail(conf)
        for user in users_list:
            mail.send_mail(
                user.email, conf.mail_subject,
                "Hallo {}, \r\ndein normaler Wichtelpartner ist {}.\r\n "
                "Desweiteren ist dein Schrottwichtelpartner {}.\r\n"
                "Viel Spaß,\r\ndein Wichtelmagic System\r\n".format(
                    user.name,
                    get_matching(perm_normal, user).name,
                    get_matching(perm_schrott, user).name))
        mail.quit()
        log.info("mails sent")

def test_bounding_box_volume(bounding_box_volume):
    # Bounding box volume should be same as volume for cube
    assert np.abs(bounding_box_volume - 8) < 10e-3, "Bounding box volume test failed"


def test_bounding_box_ratio(bounding_box_ratio):
    # Ratio should be 1 since bounding box is cube
    assert np.abs(bounding_box_ratio - 1) < 10e-3, "Bouding box ratio test failed"


def test_diameter(diameter):
    # Cube is already convex so diameter just dist of opposing corners
    dist = np.linalg.norm(np.array([-1, -1, -1]) - np.array([1, 1, 1]))
    assert np.abs(dist - diameter) < 10e-3, "Dimateter test failed"


if __name__ == '__main__':
    # cube. off is a 2x2x2 cube
    path = Path(r"data/cube.off")
    reader = FileReader()
    vertices, element_dict, info = reader.read(path)
    shape = Shape(vertices, element_dict, info)
    feature_dict = extract_features(shape,n_bins=10,n_samples=1e+6)
    test_volume(feature_dict['volume'])
    test_surface_area(feature_dict['surface_area'])
    test_bounding_box_volume(feature_dict['bounding_box_volume'])
    test_bounding_box_ratio(feature_dict['bounding_box_ratio'])
    test_diameter(feature_dict['diameter'])
Exemplo n.º 6
0
    # the uncompressor
    uncompressor = be_scan.uncompressor_t()

    # scan buffer intervals from the file reader
    while file_reader.more():

        # scan stream
        status = scanner.scan_stream(file_reader.stream_offset,
                                     file_reader.previous, file_reader.current)
        if status:
            raise ValueError(status)

        consume_top_level_artifacts(scanner)

        # next
        file_reader.read()

        # runtime status
        file_reader.print_status(args.verbose)

    # capture any remaining open artifacts
    status = scanner.scan_final(file_reader.stream_offset,
                                file_reader.previous, file_reader.current)
    if status:
        raise ValueError(status)

    consume_top_level_artifacts(scanner)

    print("# Done.")
def test():

    path = Path(r"data\\test.ply")

    reader = FileReader()
    print(reader.read(path))
Exemplo n.º 8
0
import sys

from file_reader import FileReader
from game import Game
from game_consts import WHITE, BLACK, EMPTY, ILLEGAL_MOVE_ERROR, STATUS_OK, STATUS_ERROR, INCOMPLETE_GAME_ERROR

if __name__ == "__main__":
    filename = ""
    if len(sys.argv) >= 2:
        filename = sys.argv[1]
    else:
        print("Error, filename is required")
        exit(1)

    moves = FileReader.read(filename)

    game = Game()

    result = game.play(moves)

    if result[0] == STATUS_OK:
        if result[1] == WHITE:
            print("first")
        elif result[1] == BLACK:
            print("second")
        elif result[1] == EMPTY:
            print("draw")
    elif result[0] == STATUS_ERROR:
        if result[1] == ILLEGAL_MOVE_ERROR:
            print("line {} illegal move".format(result[2]))
        elif result[1] == INCOMPLETE_GAME_ERROR:
Exemplo n.º 9
0
import argparse
from file_reader import FileReader
from perceptron import Perceptron

parser = argparse.ArgumentParser(description = 'This script processes data in the \
                                 data folder through the perceptron.')

parser.add_argument('-n', '--learnRate', action='store', help='Specify the learning rate of the perceptron.', required=True)

args = parser.parse_args()

n = float(args.learnRate)

reader = FileReader()
reader.read()
features = reader.get_features()
labels = reader.get_labels()

perceptron = Perceptron(features, labels, n)
perceptron.train()
Exemplo n.º 10
0
from file_reader import FileReader
from os.path import exists


strings = ['Hello', 'goodbye', 'you_suck']
fr1 = FileReader(strings, 'test_file1.txt')
fr2 = FileReader([''], 'test_file2.txt')

def check_file_exists():
    return fr1.exists() and fr2.exists()

def print_information():
    print fr1.contents
    print fr1.cfile
    print fr2.cfile

'''
    Check the files existstance
'''
if check_file_exists():
    fr1.open()
    fr1.read()
    fr2.open()
    print_information()
    fr2.write(fr1.contents)
else:
    print 'One of the files were not found'