Example #1
0
class ProgBar(object):
    
    def __init__(self,max_epoch):
        self.leaf_values = [Value(0) for i in range(1)]
        self.max_epoch = max_epoch
        self.epoch = 0
        self.test_d = {
                'Training Processing:': BarDescriptor(value=self.leaf_values[0],
                                                      type=Bar, 
                                                      kwargs=dict(max_value=self.max_epoch))
                }
        self.t = Terminal()
        self.n = ProgressTree(term=self.t)
        self.n.make_room(self.test_d)


    def incr_value(self):
        if self.epoch < self.max_epoch:
            self.leaf_values[0].value +=1
            self.epoch +=1

    def we_done(self):
        if self.epoch == self.max_epoch:
            return True
        else:
            return False

    def show_progbar(self):
        self.n.cursor.restore()
        self.incr_value()
        self.n.draw(self.test_d)
Example #2
0
class TaskGraphics:
    def __init__(self,data,num=__DEFAULT_NUM__):
        self.bind_data=[Value(0) for i in range(num)]
        #self.bind_data=data
        self.terminal=False
        self.bd_defaults=dict(type=Bar,kwargs=dict(max_value=100))
        self.indicator={}
        self.graph_data={}
        for i in range(0,num):
            task_name='task_%d'%i
            self.indicator[i]=task_name
            self.graph_data[task_name]=BarDescriptor(value=self.bind_data[i],**self.bd_defaults)
        self.__init_tree__()
        threading.Thread(target=self.invalidate,args=()).start()
    def __init_tree__(self):
        t=Terminal()
        self.n=ProgressTree(term=t)
        self.n.make_room(self.graph_data)
    def updateTask(self,id,task_name):
        old_task_name=self.indicator[id]
        if task_name == old_task_name:
            return
        self.graph_data[task_name]=self.graph_data[old_task_name]
        self.indicator[id]=task_name
        del self.graph_data[old_task_name]
    def updateValue(self,id,value):
        self.bind_data[id].value=value
    def invalidate(self):
        while not self.terminal:
            time.sleep(0.1)
            self.n.cursor.restore()
            self.n.draw(self.graph_data,BarDescriptor(self.bd_defaults))
    def stop(self):
        self.terminal=True
Example #3
0
            n_group = out_tb.createGroup(f2l_group, 'feat_%d' % int(n_img))
            n_group.img_feat = n_img
            neogeo_out = out_tb.create_carray(n_group,
                                              'neogeo_out',
                                              atom=atom,
                                              shape=neogeo_shape,
                                              filters=filters)
            obs_out = out_tb.create_carray(n_group,
                                           'obs_out',
                                           atom=atom,
                                           shape=neogeo_shape,
                                           filters=filters)
            flann_time = out_tb.create_carray(n_group,
                                              'flann_time',
                                              atom=atom,
                                              shape=times_shape,
                                              filters=filters)
            for img_num in np.arange(img_times.nrows):
                generate_obs(img_num, n_img, db_rows, obs_out, neogeo_out,
                             flann_time, flann)
                leaf_values[leaf_ii].value += 1
                if np.mod(leaf_values[leaf_ii].value, 5) == 0:
                    prog_tree.cursor.restore()
                    prog_tree.draw(test_d)
            leaf_ii += 1
            out_tb.flush()

    out_tb.close()
    dbf.close()
    f5.close()
Example #4
0
def tree():
    """Example showing tree progress view"""

    #############
    # Test data #
    #############

    # For this example, we're obviously going to be feeding fictitious data
    #   to ProgressTree, so here it is
    leaf_values = [Value(0) for i in range(6)]
    bd_defaults = dict(type=Bar, kwargs=dict(max_value=10))

    test_d = {
        "Warp Jump": {
            "1) Prepare fuel": {
                "Load Tanks": {
                    "Tank 1": BarDescriptor(value=leaf_values[0],
                                            **bd_defaults),
                    "Tank 2": BarDescriptor(value=leaf_values[1],
                                            **bd_defaults),
                },
                "Refine tylium ore":
                BarDescriptor(value=leaf_values[2], **bd_defaults),
            },
            "2) Calculate jump co-ordinates": {
                "Resolve common name to co-ordinates": {
                    "Querying resolution from baseship":
                    BarDescriptor(value=leaf_values[3], **bd_defaults),
                },
            },
            "3) Perform jump": {
                "Check FTL drive readiness":
                BarDescriptor(value=leaf_values[4], **bd_defaults),
                "Juuuuuump!":
                BarDescriptor(value=leaf_values[5], **bd_defaults)
            }
        }
    }

    # We'll use this function to bump up the leaf values
    def incr_value(obj):
        for val in leaf_values:
            if val.value < 10:
                val.value += 1
                break

    # And this to check if we're to stop drawing
    def are_we_done(obj):
        return all(val.value == 10 for val in leaf_values)

    ###################
    # The actual code #
    ###################

    # Create blessings.Terminal instance
    t = Terminal()
    # Initialize a ProgressTree instance
    n = ProgressTree(term=t)
    # We'll use the make_room method to make sure the terminal
    #   is filled out with all the room we need
    n.make_room(test_d)

    while not are_we_done(test_d):
        sleep(0.2 * random.random())
        # After the cursor position is first saved (in the first draw call)
        #   this will restore the cursor back to the top so we can draw again
        n.cursor.restore()
        # We use our incr_value method to bump the fake numbers
        incr_value(test_d)
        # Actually draw out the bars
        n.draw(test_d, BarDescriptor(bd_defaults))
    for root, dirs, files in os.walk(scan_dir, followlinks=False,
                                     topdown=True):
        dirs[:] = [d for d in dirs if d not in exclude]
        for directory_name in dirs:
            directory_name = os.path.join(root, directory_name)
            file_hash = analyze(directory_name).hexdigest()
            upsert_md5_hash(directory_name, file_hash)
            dirs_analyzed += 1
            leaf_values[0].value = dirs_analyzed

        for file_name in files:
            file_name = os.path.join(root, file_name)
            file_hash = analyze(file_name).hexdigest()
            upsert_md5_hash(file_name, file_hash)
            files_analyzed += 1
            leaf_values[1].value = files_analyzed
            if not RUNNING_IN_PYCHARM:
                n.cursor.restore()
                try:
                    n.draw(test_d, BarDescriptor(bd_defaults))
                except TypeError:
                    print(
                        "Looks like you're running in pycharm. Progressive doesn't work in its terminal."
                    )
                    print(
                        "Disable progressive by setting the environment variable RUNNING_IN_PYCHARM=1"
                    )
                    quit()

commit()
Example #6
0
def pretty(delete=False):
    import random
    from time import sleep

    from blessings import Terminal

    from progressive.bar import Bar
    from progressive.tree import ProgressTree, Value, BarDescriptor

    leaf_values = [Value(0) for i in range(1)]
    bd_defaults = dict(type=Bar, kwargs=dict(max_value=900))

    test_d = {
        "Verifying [kubeflow]": BarDescriptor(value=leaf_values[0],
                                              **bd_defaults),
        "Verifying [dkube]": BarDescriptor(value=leaf_values[0],
                                           **bd_defaults),
        "Verifying [dkube-ui]": BarDescriptor(value=leaf_values[0],
                                              **bd_defaults),
        "Verifying [argo]": BarDescriptor(value=leaf_values[0], **bd_defaults),
        "Verifying [minio]": BarDescriptor(value=leaf_values[0],
                                           **bd_defaults),
        "Verifying [efk]": BarDescriptor(value=leaf_values[0], **bd_defaults)
    }

    # We'll use this function to bump up the leaf values
    def incr_value(obj):
        for val in leaf_values:
            if val.value < 900:
                val.value += 10
                break

    # And this to check if we're to stop drawing
    def are_we_done(obj):
        return all(val.value == 900 for val in leaf_values)

    ###################
    # The actual code #
    ###################

    # Create blessings.Terminal instance
    t = Terminal()
    # Initialize a ProgressTree instance
    n = ProgressTree(term=t)
    # We'll use the make_room method to make sure the terminal
    #   is filled out with all the room we need
    n.make_room(test_d)

    monitor_freq = 0
    status = False
    while not status and not are_we_done(test_d):
        if monitor_freq >= 60:
            if not delete:
                status = monitorOnCreation()
            else:
                status = monitorOnDeletion()
            monitor_freq = 0
        # After the cursor position is first saved (in the first draw call)
        #   this will restore the cursor back to the top so we can draw again
        n.cursor.restore()
        # We use our incr_value method to bump the fake numbers
        incr_value(test_d)
        # Actually draw out the bars
        n.draw(test_d, BarDescriptor(bd_defaults))
        sleep(10)
        monitor_freq += 10
    return status
Example #7
0
def tree():
    """Example showing tree progress view"""

    #############
    # Test data #
    #############

    # For this example, we're obviously going to be feeding fictitious data
    #   to ProgressTree, so here it is
    leaf_values = [Value(0) for i in range(6)]
    bd_defaults = dict(type=Bar, kwargs=dict(max_value=10))

    test_d = {
        "Warp Jump": {
            "1) Prepare fuel": {
                "Load Tanks": {
                    "Tank 1": BarDescriptor(value=leaf_values[0], **bd_defaults),
                    "Tank 2": BarDescriptor(value=leaf_values[1], **bd_defaults),
                },
                "Refine tylium ore": BarDescriptor(
                    value=leaf_values[2], **bd_defaults
                ),
            },
            "2) Calculate jump co-ordinates": {
                "Resolve common name to co-ordinates": {
                    "Querying resolution from baseship": BarDescriptor(
                        value=leaf_values[3], **bd_defaults
                    ),
                },
            },
            "3) Perform jump": {
                "Check FTL drive readiness": BarDescriptor(
                    value=leaf_values[4], **bd_defaults
                ),
                "Juuuuuump!": BarDescriptor(value=leaf_values[5],
                                            **bd_defaults)
            }
        }
    }

    # We'll use this function to bump up the leaf values
    def incr_value(obj):
        for val in leaf_values:
            if val.value < 10:
                val.value += 1
                break

    # And this to check if we're to stop drawing
    def are_we_done(obj):
        return all(val.value == 10 for val in leaf_values)

    ###################
    # The actual code #
    ###################

    # Create blessings.Terminal instance
    t = Terminal()
    # Initialize a ProgressTree instance
    n = ProgressTree(term=t)
    # We'll use the make_room method to make sure the terminal
    #   is filled out with all the room we need
    n.make_room(test_d)

    while not are_we_done(test_d):
        sleep(0.2 * random.random())
        # After the cursor position is first saved (in the first draw call)
        #   this will restore the cursor back to the top so we can draw again
        n.cursor.restore()
        # We use our incr_value method to bump the fake numbers
        incr_value(test_d)
        # Actually draw out the bars
        n.draw(test_d, BarDescriptor(bd_defaults))
Example #8
0
n.make_room(test_d)
#n.cursor.save()
while True:
    try:
        # These three lines are usefull to debug wether to use MSB or LSB in th$
        # for the first parameter of "hx.set_reading_format("LSB", "MSB")".
        # Comment the two lines "val = hx.get_weight(5)" and "print val" and un$
        #np_arr8_string = hx.get_np_arr8_string()
        #binary_string = hx.get_binary_string()
        #print binary_string + " " + np_arr8_string
        
        # Prints the weight. Comment if you're debbuging the MSB and LSB issue.
        val_1 = hx1.get_weight(DATA_1)
        val_2 = hx2.get_weight(DATA_2)
        val_3 = hx3.get_weight(DATA_3)
        val_4 = hx4.get_weight(DATA_4)
        
        #print val
        n.cursor.restore()
        leaf_values[0].value = abs(val_1)
        leaf_values[1].value = abs(val_2)
        leaf_values[2].value = abs(val_3)
        leaf_values[3].value = abs(val_4)

        n.draw(test_d, BarDescriptor(bd_defaults))
        #hx.power_down()
        #hx.power_up()
        #time.sleep(0.1)
    except (KeyboardInterrupt, SystemExit):
        cleanAndExit()