Esempio n. 1
0
    def overview(events, tasks, tasks_done):

        # TODO sym class \u2500...
        # TODO more functions for 'left' + colors
        # TODO less code per line

        out = f'{sym.default()}{sym.CYAN}{sym.HLINE*3}[ \u001b[1mToday\'s Events{sym.default()}{sym.CYAN} ]' \
            + f'{sym.HLINE*59}{sym.default()}'
        
        if len(events) == 0:
            out += "\n   No events found for today. Use 'dl event -h' and add new events :)"
        i = 0
        for e in events:
            if e[7] < 0 and e[10] == False:
                continue
            title = Output.align_text_left(e[1], 50)
            if i == 0 or (e[7] < 0 and e[10] == True):
                out += f'\n{sym.BLUE} {sym.ARROW} {sym.default()}'
                time_left = Output.align_text_right(f'{Output.format_time(*e[7:11])}',9)
                out += f'{title} [{e[5]}] {e[3]}-{e[4]} {sym.CYAN}{time_left}{sym.default()}'
            else:
                out += f'\n{sym.BLUE} {sym.ARROW} {sym.default()}{sym.DIM}'
                time_left = Output.align_text_right(f'{Output.format_time(*e[7:10])}',9)
                out += f'{title} [{e[5]}] {e[3]}-{e[4]} {time_left}{sym.default()}'
            i += 1

        out += f'\n{sym.MAGENTA}{sym.HLINE*3}[ \u001b[1mYour Tasks{sym.default()}{sym.MAGENTA} ]' \
            + "\u2500"*63 + sym.default()

        if len(tasks) == 0 and len(tasks_done) == 0:
            out += "\n   No tasks found. Use 'dl task -h' and add new tasks ;)"

        
        for i,t in enumerate(tasks):
            title = Output.align_text_left(t[1], 48)
            weekday = Output.align_text_left(Output.int_to_days[t[2]], 3).upper()
            time_left = Output.align_text_right(f'{Output.format_time(*t[8:11])}',11)
            time_left = Output.color_time(*t[8:11], time_left)
            mark = (' ', sym.WHITE, )
            if t[8] < 0:
                mark = (sym.MISSED, sym.RED)
            out += f'\n{sym.RED} [{mark[0]}]{mark[1]} {title} [{t[4]}] ' \
                + f'{weekday} {t[3]} {time_left}{sym.default()}'

        for i,t in enumerate(tasks_done):
            title = Output.align_text_left(t[1], 48)
            weekday = Output.align_text_left(Output.int_to_days[t[2]], 3).upper()
            time_left = Output.align_text_right(f'{Output.format_time(*t[8:11])}',11)
            out += f'\n{sym.GREEN} [{sym.DONE}] {title} {sym.default()}[{t[4]}] ' \
                + sym.striken(f'{weekday} {t[3]} {time_left}') + sym.default()
        out += sym.default()
        print(out, flush=True)
Esempio n. 2
0
    def __parameters(self):
        param      = True
        var_type   = None
        identifier = None

        while param:
            param = False

            if self.__lexeme not in self.DATA_TYPES:
                self.__error("data type")
            else:
                var_type = self.__lexeme

            self.__lexeme = self.__lexic.next_lexeme()
            if self.__lexic.token() != "identifier":
                self.__error("identifier")
            else:
                identifier = self.__lexeme + "@" + self.__scope

            self.__symbol_tree.add(Symbol(
                symbol = identifier,
                _type  = var_type,
                _class = "parameter"
            ))

            self.__add_statement(var_type, "data_type", True)
            self.__add_statement(identifier, "parameter", True)
            self.__statement_end()
            self.__statement_end()

            self.__lexeme = self.__lexic.next_lexeme()
            if self.__lexeme == ",":
                param = True
                self.__lexeme = self.__lexic.next_lexeme()
Esempio n. 3
0
 def list_all(events, tasks):
     le = len(events) - 1
     lt = len(tasks) - 1
     event_head = f'{sym.CYAN} event [ID] [TITLE]{"".join(" " for _ in range(25))}' + \
         f'[FREQ] [DAY] [DATE]     [FROM - TO]{sym.default()}'
     task_head = f'\n{sym.MAGENTA} task  [ID] [TITLE]{"".join(" " for _ in range(31))}' + \
         f'[FREQ] [DAY] [DATE]     [DUE]{sym.default()}'
     out = event_head
     for i,e in enumerate(events):
         title = Output.align_text_left(e[1], 31)
         freq = Output.align_text_left(Output.char_to_freq[e[5]], 6)
         day = Output.align_text_left(Output.int_to_days[e[2]], 5)
         date = (e[6] if e[6] != None else '          ')
         if i == le:
             out += f'\n {sym.BOX2}{sym.BOX3*4} '
         else:
             out += f'\n {sym.BOX1}{sym.BOX3*4} ' 
         out += f'{Output.align_text_left(str(e[0]), 4)} {title} {freq} {day} {date} {e[3]}-{e[4]}'
     out += task_head
     for i,t in enumerate(tasks):
         title = Output.align_text_left(t[1], 37)
         freq = Output.align_text_left(Output.char_to_freq[t[4]], 6)
         day = Output.align_text_left(Output.int_to_days[t[2]], 5)
         date = (t[5] if t[5] != None else '          ')
         if i == lt:
             out += f'\n {sym.BOX2}{sym.BOX3*4} '
         else:
             out += f'\n {sym.BOX1}{sym.BOX3*4} ' 
         out += f'{Output.align_text_left(str(t[0]), 4)} {title} {freq} {day} {date} {t[3]}'
     out += sym.default()
     print(out, flush=True)
Esempio n. 4
0
    def __func_declaration(self):
        var_type   = None
        identifier = None
        main_tree  = None
        main_index = 0

        if self.__lexeme != "funcion":
            self.__error("funcion")

        self.__lexeme = self.__lexic.next_lexeme()
        if self.__lexic.token() != "identifier":
            self.__error("identifier")
        else:
            identifier               = self.__lexeme
            self.__scope             = self.__lexeme
            main_tree                = self.__current_statement
            main_index               = self.__statement_index
            self.__current_statement = NNode(data=StatementComponent(label=identifier), _id=0)
            self.__statement_index   = 0
            self.__functions.append(self.__current_statement)

        self.__lexeme = self.__lexic.next_lexeme()
        if self.__lexeme != "(":
            self.__error("(")

        self.__lexeme = self.__lexic.next_lexeme()
        if self.__lexeme != ")":
            self.__parameters() #TODO: declare parameters

        if self.__lexeme != ")":
            self.__error(")")

        self.__lexeme = self.__lexic.next_lexeme()
        if self.__lexeme != "regresa":
            self.__error("regresa")

        self.__lexeme = self.__lexic.next_lexeme()
        if self.__lexeme not in self.DATA_TYPES:
            self.__error("data type")
        else:
            var_type = self.__lexeme

        self.__symbol_tree.add(Symbol(
            symbol = identifier,
            _type  = var_type,
            _class = "function"
        ))

        self.__lexeme = self.__lexic.next_lexeme()
        self.__block()
        self.__lexeme = self.__lexic.next_lexeme()

        self.__scope = "global"
        self.__current_statement = main_tree
        self.__statement_index   = main_index
Esempio n. 5
0
    def __var_declaration(self):
        variable   = True
        var_type   = None
        identifier = None

        if self.__lexeme not in self.DATA_TYPES:
            self.__error("data type")
        else:
            var_type = self.__lexeme

        self.__add_statement(self.__lexeme, self.__lexic.token(), True)
        self.__lexeme = self.__lexic.next_lexeme()

        while variable:
            variable = False

            if self.__lexic.token() != "identifier":
                self.__error("identifier")
            else:
                identifier = self.__lexeme + "@" + self.__scope

            self.__symbol_tree.add(Symbol(
                symbol = identifier,
                _type  = var_type,
                _class = "variable"
            ))

            self.__lexeme = self.__lexic.next_lexeme()

            if self.__lexeme == ":=":
                self.__add_statement(self.__lexeme, None, True)
                self.__add_statement(identifier, "identifier")
                self.__lexeme = self.__lexic.next_lexeme()
                self.__expression()
                self.__statement_end()
            else:
                self.__add_statement(identifier, "identifier")

            if self.__lexeme == ",":
                self.__lexeme = self.__lexic.next_lexeme()
                variable = True

        self.__statement_end()
Esempio n. 6
0
def test_KB_wumpus():
    # A simple KB that defines the relevant conditions of the Wumpus World as in Fig 7.4.
    # See Sec. 7.4.3
    kb_wumpus = PropKB()

    # Creating the relevant expressions
    # TODO: Let's just use P11, P12, ... = symbols('P11, P12, ...')
    P = {}
    B = {}
    P[1, 1] = Symbol("P[1,1]")
    P[1, 2] = Symbol("P[1,2]")
    P[2, 1] = Symbol("P[2,1]")
    P[2, 2] = Symbol("P[2,2]")
    P[3, 1] = Symbol("P[3,1]")
    B[1, 1] = Symbol("B[1,1]")
    B[2, 1] = Symbol("B[2,1]")

    kb_wumpus.tell(~P[1, 1])
    kb_wumpus.tell(B[1, 1] | '<=>' | ((P[1, 2] | P[2, 1])))
    kb_wumpus.tell(B[2, 1] | '<=>' | ((P[1, 1] | P[2, 2] | P[3, 1])))
    kb_wumpus.tell(~B[1, 1])
    kb_wumpus.tell(B[2, 1])

    # Statement: There is no pit in [1,1].
    assert kb_wumpus.ask(~P[1, 1]) == {}

    # Statement: There is no pit in [1,2].
    assert kb_wumpus.ask(~P[1, 2]) == {}

    # Statement: There is a pit in [2,2].
    assert kb_wumpus.ask(P[2, 2]) is False

    # Statement: There is a pit in [3,1].
    assert kb_wumpus.ask(P[3, 1]) is False

    # Statement: Neither [1,2] nor [2,1] contains a pit.
    assert kb_wumpus.ask(~P[1, 2] & ~P[2, 1]) == {}

    # Statement: There is a pit in either [2,2] or [3,1].
    assert kb_wumpus.ask(P[2, 2] | P[3, 1]) == {}
def definitial(name, value=None):
    global GLOBAL_ENV
    GLOBAL_ENV = VariableEnv(GLOBAL_ENV, Symbol(name), value)
    return name
def test_eval_apply_lambda():
    func = LambdaExpr(cons(Symbol("a"), cons(Symbol("b"), Nil)),
                      cons(ApplyExpr(VariableExpr(Symbol("+")), cons(VariableExpr(Symbol("a")), cons(VariableExpr(Symbol("b")), Nil))), Nil))
    expr = ApplyExpr(func, cons(QuoteExpr(5), cons(QuoteExpr(2), Nil)))
    expr.evaluate(GLOBAL_ENV, AssertEqCont(7))
def test_eval_apply_primitive():
    expr = ApplyExpr(VariableExpr(Symbol("+")), cons(QuoteExpr(1), cons(QuoteExpr(2), Nil)))
    expr.evaluate(GLOBAL_ENV, AssertEqCont(3))
Esempio n. 10
0
def test_eval_lambda():
    expr = LambdaExpr(cons(Symbol("a"), cons(Symbol("b"), Nil)),
                      cons(QuoteExpr(42), Nil))
    expr.evaluate(NullEnv(), AssertInstanceCont(Function))
Esempio n. 11
0
def test_eval_constant():
    QuoteExpr(42).evaluate(NullEnv(), AssertEqCont(42))
    QuoteExpr(Symbol("foo")).evaluate(NullEnv(), AssertEqCont("foo"))
Esempio n. 12
0
def test_eval_variable():
    expr = VariableExpr(Symbol("foo"))
    expr.evaluate(VariableEnv(NullEnv(), "foo", 42), AssertEqCont(42))
Esempio n. 13
0
import numpy as np

from graph import Op
from blaze.datashape import coretypes as C
from blaze.datashape.coretypes import promote

from utils import Symbol

#------------------------------------------------------------------------
# Domain Constraint
#------------------------------------------------------------------------

Array, Table = Symbol('Array'), Symbol('Table')
one, zero, false, true = xrange(4)

ints      = set([C.int8, C.int16, C.int32, C.int64])
uints     = set([C.uint8, C.uint16, C.uint32, C.uint64])
floats    = set([C.float32, C.float64])
complexes = set([C.complex64, C.complex128])
bools     = set([C.bool_])
string    = set([C.string])

discrete   = ints | uints
continuous = floats | complexes
numeric    = discrete | continuous

array_like, tabular_like = Array, Table
indexable = set([array_like, tabular_like])

universal = set([C.top]) | numeric | indexable | string