Ejemplo n.º 1
0
 def __init__(self, args={}):
     super().__init__("div")
     self.parent = getitem(args, "parent", None)
     for arg in SCHEMA_DEFAULT_ARGS:
         self[arg[0]] = getitem(args, arg[0], arg[1])
     self.childs = []
     for childarg in self.childsarg:
         childarg["parent"] = self
         child = Schema(childarg)
         self.childs.append(child)
     self.build()
Ejemplo n.º 2
0
    def run(self):
        """Add each section to `self.commands` and write html."""
        add = self.add_text
        add(nl * 2)
        sections = [s for s in self.sections if s is not None]

        for section in sections:
            # print ("section", section)
            match = re.match(cmdpat, section, re.VERBOSE)
            if match:
                match = list(filter(None, match.groups()))
                cmd   = match[1]
                arg   = getitem(match, 2)
                if cmd == 'q':
                    break
                if cmd == 'p': cmd = "pause"
                if cmd.isdigit() and not arg:
                    arg = cmd
                    cmd = "pause"

                if cmd == "pause":
                    arg = arg or default_pause
                if cmd == "note":
                    arg = "Note: " + arg
                self.commands.append(dict(cmd=cmd, arg=arg))
            else:
                add(section)

        add(nl*3 + endmsg + nl*2)
        self.write_html()
        print("%s written.." % self.name)
Ejemplo n.º 3
0
    def full_display(self):
        """Redraw all cells."""
        for l in self:
            log(l, self[l])

        for loc in self:
            item = getitem(self[loc], -1, Item("empty"))

            if not self.show_vertices:
                # do not show vertice, vertice would only be on top if cell is empty
                if item.kind == "vertice":
                    item = Item("empty")
            # log('drawing at', loc.y-1, loc.x-1)
            self.scr.addstr(loc.y-1, loc.x-1, str(item), curses.color_pair(item.color))
        self.display()
Ejemplo n.º 4
0
    def play(self):
        print(nl * 2)
        for section_num, section in enumerate1(self.sections):

            if re.match(cmdpat, section):
                section = section.split()
                cmd, arg = section[0], getitem(section, 1)

                if cmd == ":pause": self.pause(arg, section_num)
                elif cmd == ":clear": print(nl * screensep)
                elif cmd == ":type": self.typeblock = True

            else:
                self.display(section.lstrip(nl))

        print(nl * 2, "----- END -----", nl * 2)
Ejemplo n.º 5
0
Archivo: tmovies.py Proyecto: Voder/PBE
    def play(self):
        print(nl * 2)
        for section_num, section in enumerate1(self.sections):

            if re.match(cmdpat, section):
                section  = section.split()
                cmd, arg = section[0], getitem(section, 1)

                if   cmd == ":pause" : self.pause(arg, section_num)
                elif cmd == ":clear" : print(nl * screensep)
                elif cmd == ":type"  : self.typeblock = True

            else:
                self.display(section.lstrip(nl))

        print(nl*2, "----- END -----", nl*2)
Ejemplo n.º 6
0
def main_gen_results_set_on_fold(experiment, named_data_sets, data_set_name, variation_name, fold_num):
    experiment_obj = get_experiment_obj(experiment)
    named_data_sets_obj = get_named_data_sets_obj(named_data_sets)
    named_data_sets_dict = dict(named_data_sets_obj)
    data_set_generator = named_data_sets_dict[data_set_name]
    l_experiment, data_info_generator = get_exp_ds_pair(experiment_obj, data_set_generator)
    named_experiment_variations = l_experiment.named_experiment_variations
    named_experiment_variations_dict = dict(named_experiment_variations)
    
    data_info = data_info_generator()
    variation = named_experiment_variations_dict[variation_name]
    evaluator = l_experiment.get_selection_strategy_evaluator(data_info, variation)
    
    training_test_tuples = l_experiment.training_test_sets_extractor(data_info.data, data_info.oracle)
    training_test_tuple = getitem(training_test_tuples, fold_num)
    
    return evaluator.generate_results(*training_test_tuple)
Ejemplo n.º 7
0
    def run(self):
        add = self.add_text
        add(nl * 2)

        for section in self.sections:

            if re.match(cmdpat, section):
                section  = section.split()
                cmd, arg = section[0][1:], getitem(section, 1)
                if cmd == "pause":
                    arg = arg or default_pause
                self.commands.append((cmd, arg))
            else:
                add(section)

        add(nl*3 + endmsg + nl*2)
        self.write_html()
Ejemplo n.º 8
0
    def run(self):
        add = self.add_text
        add(nl * 2)

        for section in self.sections:

            if re.match(cmdpat, section):
                section = section.split()
                cmd, arg = section[0][1:], getitem(section, 1)
                if cmd == "pause":
                    arg = arg or default_pause
                self.commands.append((cmd, arg))
            else:
                add(section)

        add(nl * 3 + endmsg + nl * 2)
        self.write_html()
Ejemplo n.º 9
0
    def los_update(self, beings):
        """Update line-of-sight data."""
        visible = set()
        if beings and not isinstance(beings, list):
            beings = [beings]

        for being in (beings or []):
            visible = los.los(being.loc, 6, self)
            # log("visible", visible)
            for loc in visible:
                ls = self.get_last_seen(loc)
                item = getitem(self[loc], -1, Item("empty"))

                itype = 'bug'
                if ls.kind == itype and item.kind != itype:
                    log("moved party FROM loc", loc)
                if ls.kind != itype and item.kind == itype:
                    log("moved party TO loc", loc)
                self.last_seen[loc.x][loc.y] = item
        return visible
Ejemplo n.º 10
0

class Flashcards(object):
    def __init__(self, fname):
        self.cards = list()
        with open(fname) as fp:
            for line in fp:
                if line.strip():
                    self.cards.append(Card(line))

    def run(self):
        right = cards = total = 0

        while True:
            cards   = cards or shuffled(copy(self.cards))
            percent = (right/total*100.0) if total else 0
            stat    = status % (right, total, percent)

            right += int( cards.pop().draw(stat) )
            total += 1


if __name__ == "__main__":
    fname = getitem(sys.argv, 1, default=cards_fn)
    if not exists(fname):
        print("Error: %s could not be found" % fname)
        sys.exit()

    try                      : Flashcards(fname).run()
    except KeyboardInterrupt : sys.exit()
Ejemplo n.º 11
0
class Flashcards(object):
    def __init__(self, fname):
        self.cards = list()
        with open(fname) as fp:
            for line in fp:
                if line.strip():
                    self.cards.append(Card(line))

    def run(self):
        right = cards = total = 0

        while True:
            cards = cards or shuffled(copy(self.cards))
            percent = (right / total * 100.0) if total else 0
            stat = status % (right, total, percent)

            right += int(cards.pop().draw(stat))
            total += 1


if __name__ == "__main__":
    fname = getitem(sys.argv, 1, default=cards_fn)
    if not exists(fname):
        print("Error: %s could not be found" % fname)
        sys.exit()

    try:
        Flashcards(fname).run()
    except KeyboardInterrupt:
        sys.exit()
Ejemplo n.º 12
0
 def add(self, n=1):
     self.points = max(0, self.points + n)
     self.level  = 1 + self.points // 10
     self.rank   = getitem(ranks, self.level // levels_per_rank, default=ranks[-1])
Ejemplo n.º 13
0
 def blocked(self, loc):
     """Is location blocked?"""
     item = getitem(self[loc], -1)
     return item and item.block
Ejemplo n.º 14
0
 def blocked2(self, path):
     """Is location blocked?"""
     for loc in path:
         item = getitem(self[loc], -1)
         if item and item.block:
             return True
Ejemplo n.º 15
0
 def blocked(self, loc):
     """Is location blocked?"""
     item = getitem(self[loc], -1)
     return item and item.block
Ejemplo n.º 16
0
 def blocked2(self, path):
     """Is location blocked?"""
     for loc in path:
         item = getitem(self[loc], -1)
         if item and item.block:
             return True