예제 #1
0
 def can_move(_x, _y, _r, world):
     x, y = utils.move(_x, _y, _r)
     tx, ty = utils.move(_x, _y, _r)
     sm = []
     while world.exist(tx, ty):
         obj = world.get(tx, ty)  
         if isinstance(obj, AxisMovableBlock):
             if obj.r == 0 and (_r == 0 or _r == 180):
                 pass
             elif obj.r == 180 and (_r == 90 or _r == 270):
                 pass
             else:
                 return False, []
         if "movable" in obj.tags:
             obj2 = world.get(*utils.move(obj.x, obj.y, _r))
             if (isinstance(obj2, Mover)):
                 if obj2.r == _r:
                     c, m = Mover.can_move(obj2.x, obj2.y, obj2.r, world)
                     if not c:
                         return False, []
                     sm += m
                     return True, sm
             if obj2 == None:
                 sm.append(obj)
                 return True, sm
             elif "movable" in obj2.tags:
                 sm.append(obj)
             else:
                 return False, []
         else:
             return False, []
         tx, ty = utils.move(tx, ty, _r)
     return True, sm
예제 #2
0
def post_json_files(root):
    """
    Post json objects in a designated directory to BuildingOS.

    Params:
        root string
    """
    json_dir = defaults.json_dir(root)
    archive = defaults.json_archive(root)
    post_url = defaults.BOS_URL

    json_files = utils.get_files_in_dir(json_dir)
    if not json_files:
        utils.warn('No JSON files to process. Terminating')
        exit()

    utils.print_time('LOADER START')
    for json_file in json_files:
        print('Posting file: %s ...' % (json_file)),
        with open(json_file, 'rb') as jf:
            payload = {'data': jf}
            response = requests.post(post_url, files=payload)
            print('done')

            print('Server response: %s' % (response.text))

        utils.move(json_file, archive)

    utils.print_time('LOADER END')
예제 #3
0
def post_json_files(root):
    """
    Post json objects in a designated directory to BuildingOS.

    Params:
        root string
    """
    json_dir = defaults.json_dir(root)
    archive = defaults.json_archive(root)
    post_url = defaults.BOS_URL

    json_files = utils.get_files_in_dir(json_dir)
    if not json_files:
        utils.warn('No JSON files to process. Terminating')
        exit()

    utils.print_time('LOADER START')
    for json_file in json_files:
        print('Posting file: %s ...' % (json_file)),
        with open(json_file, 'rb') as jf:
            payload = {'data': jf}
            response = requests.post(post_url, files=payload)
            print('done')

            print('Server response: %s' % (response.text))

        utils.move(json_file, archive)

    utils.print_time('LOADER END')
예제 #4
0
    def run(self):
        if not platform.is_arch:
            return

        print_header("Setting up VNC")

        install_pkg("tigervnc", "lxde-gtk3")

        if file_exists("/etc/pam.d/tigervnc.pacnew"):
            move("/etc/pam.d/tigervnc.pacnew", "/etc/pam.d/tigervnc")

        link_files([
            [
                SCRIPT_DIR.joinpath("vncserver.users"),
                Path("/etc/tigervnc/vncserver.users"),
                True,
            ],
            [
                SCRIPT_DIR.joinpath("config"),
                Path.home().joinpath(".vnc", "config"),
                True,
            ],
        ])

        run_command("sudo systemctl enable vncserver@:1")
        run_command("sudo systemctl start vncserver@:1")
def create_json(root):
    """
    Create the json file containing reading data.

    Params:
        root string
    """
    data_dir = defaults.downloads(root)
    output_dir = defaults.json_dir(root)
    archive = defaults.data_archive(root)

    catalog = []
    data = []
    json_file = {}

    data_files = utils.get_files_in_dir(data_dir)
    if not data_files:
        utils.warn('No csv files to process. Terminating')
        exit()

    utils.print_time('PROCESSOR START')
    print('Begin JSON file generation')
    for data_file in data_files:
        with open(data_file, 'rb') as f:
            reader = csv.reader(f)
            meterId, meterName = reader.next()

            print('Processing meterId %s ...' % (meterId)),

            info = {'meterId': meterId, 'meterName': meterName}
            catalog.append(info)

            for row in reader:
                ts = row[0]
                val = float(row[1])
                reading = {'timestamp': ts,
                           'value': val,
                           'meterId': meterId}
                data.append(reading)

            print('done')
        utils.move(data_file, archive)

    json_file['datasource'] = defaults.URI
    json_file['meterCatalog'] = catalog
    json_file['readings'] = data

    print('End JSON file generation')

    curr_dt = datetime.now()
    json_fname = 'dump_%s.json' % (utils.format_dt(curr_dt))
    save_path = os.path.join(output_dir, json_fname)

    print('Writing JSON to file %s ...' % (save_path)),
    with open(save_path, 'wb') as out:
        json.dump(json_file, out)
        print('done')

    utils.print_time('PROCESSOR END')
예제 #6
0
 def tick(self, world):
     super().tick(world)
     bx, by = utils.move(self.x, self.y, (self.r - 180) % 360)
     tx, ty = utils.move(self.x, self.y, self.r)
     if world.exist(bx, by) and not world.exist(tx, ty):
         obj = world.get(bx, by)
         obj2 = obj.copy()
         obj2.x, obj2.y = tx, ty
         obj2.should_tick = False
         world.objects.append(obj2)
예제 #7
0
    def tick(self, world):
        super().tick(world)
        self.t_x = self.x
        self.t_y = self.y

        cm, sm = Mover.can_move(self.x, self.y, self.r, world)
        if not cm:
            return
                
        for o in sm:
            o.update_queue["x"], o.update_queue["y"] = utils.move(o.x, o.y, self.r)
        self.update_queue["x"], self.update_queue["y"] = utils.move(self.x, self.y, self.r)
예제 #8
0
def main(instruction):
    map = utils.create_map('data/input')
    starting_position = [0, 0]
    trees = 0

    while starting_position[0] < len(map) - 1:
        trees += utils.move(instruction, starting_position, map)
    return trees
예제 #9
0
 def tick(self, world):
     if self._die:
         self.kill()
         super().tick(world)
         return
     self.t_x = self.x
     self.t_y = self.y
     self.update_queue["x"], self.update_queue["y"] = utils.move(self.x, self.y, self.r)
     super().tick(world)