Esempio n. 1
0
def Main(out, read, Reg_no):
    f = open("symbol_temp.txt", "w")
    f.close()
    f = open("symbol_original.txt", "w")
    f.close()
    tostr = []
    # f = open('input.txt', 'r')
    # read = f.readlines()
    k = 0
    for input_exp in read:
        # print '\n\n'+input_exp
        input_exp = str(input_exp)
        # print k
        k = eval.eval(input_exp, k, tostr)
        # input_exp = raw_input('Enter the Expression : ')
        # eval.eval(input_exp)

    f.close()
    d = []

    f1 = open("inout.txt", "r")

    lines = f1.readlines()
    f1.close()
    os.system("rm inout.txt")
    for i in lines:
        i = i.split("\n")
        d.append(i[0])

    quad = []

    j = 0
    for i in d:
        quad.append(re.findall("\w+|\+|-|\*", d[j]))
        j = j + 1

    t = usage.gen(quad)
    # print t

    f = 0
    # print t
    # 	print '\n\n\n'

    # 	for i , j in t.iteritems():
    # 		for k in j:
    # 			print k[0],'\t',
    # 			print 'lu'+str(k[1]),'\t',
    # 			if k[2] == None:
    # 				print 'nnu\t',
    # 			else:
    # 				print 'nu'+str(k[2])+'\t',
    # 			print
    # 		print
    # 	print

    # 	print quad

    table.get(quad, t, out, Reg_no, tostr)
    os.system("rm symbol_temp.txt")
Esempio n. 2
0
def Main(out, read,Reg_no):
	f = open("symbol_temp.txt", "w")
	f.close()
        f = open("symbol_original.txt", "w")	
	f.close()
	tostr = []
	#f = open('input.txt', 'r')
	#read = f.readlines()
	k = 0
	for input_exp in read:
		#print '\n\n'+input_exp
		input_exp = str(input_exp)
		#print k
		k = eval.eval(input_exp, k, tostr)
	#input_exp = raw_input('Enter the Expression : ')
	#eval.eval(input_exp)
	
	f.close()
	d = []
	
	f1 = open('inout.txt' , 'r')
	
	lines = f1.readlines()
	f1.close()
	os.system('rm inout.txt')
	for i in lines:
		i = i.split('\n')
		d.append(i[0])

	quad = []

	j = 0
	for i in d:
		quad.append(re.findall('\w+|\+|-|\*', d[j]))
		j = j + 1

	t = usage.gen(quad)
	#print t

	f = 0
	#print t
#	print '\n\n\n'

#	for i , j in t.iteritems():
#		for k in j:
#			print k[0],'\t',
#			print 'lu'+str(k[1]),'\t',
#			if k[2] == None:
#				print 'nnu\t',
#			else:
#				print 'nu'+str(k[2])+'\t',
#			print
#		print
#	print

#	print quad	

	table.get(quad , t,out, Reg_no, tostr)
	os.system("rm symbol_temp.txt")
Esempio n. 3
0
def place_address(address):
    if is_internal(address):
        return INTERNAL
    if not t.has_key("ext-email-%s-campaign" % (address,)):
        return UNKNOWN
    cid = t.get("ext-email-%s-campaign" % (address,))
    if t.has_key("ext-email-%s-is-gm" % (address,)):
        return ( cid, True, None )
    return ( cid, False, t.get("ext-email-%s-character" % (address,)) )
Esempio n. 4
0
def get_attribution(full_from):
    name, sender = parseaddr(full_from)
    attribution = t.get('ext-email-%s-attribution' % (sender,))
    if attribution:
        return attribution
    if name:
        t.set_key('ext-email-%s-attribution' % (sender,), name)
        
    return name
Esempio n. 5
0
def get(stat_id, include_tables=True):
    db = mongo.get_db()
    statistic = db.statistics.find_one({'code': stat_id})
    if (not statistic) or config.bool('reload'):
        logging.info("Statistic %s not found, loading from SOAP...", stat_id)
        statistic = soap.get_statistic(stat_id)
        if not statistic: 
            return None
        tables = []
        for table in soap.find_tables_by_statistic(stat_id):
            tables.append(table)
        statistic['tables'] = tables
        statistic['description'] = load_description(stat_id)
        statistic['variables'] = [v for v in load_variables(stat_id)]
        statistic['__ts'] = datetime.utcnow()
        db.statistics.update({'code': stat_id}, statistic, upsert=True)
    import table
    for _table in statistic['tables']:
        table.get(_table.get('code'))
    return statistic
Esempio n. 6
0
def apply_generic(op, *params):
    """
    1. get the op based on the param types
    2. get the param values
    3. apply op to values
    """
    args = List(params) # convert to scheme list (exp)
    type_tags = mapp(get_type_tag, args)
    proc = get(op, type_tags)  # get supports only 2 keys (op, type); lookup(op, type)
    values = mapp(contents, args)
    vals_py = convertToPythonList(values)
    return proc(*vals_py)
Esempio n. 7
0
def m_eval_dd(exp, env):
    """
    The data-directed core evaluator.
    """
    if isSelfEvaluating(exp):
        # number, string, bool
        return exp
    elif isVariable(exp):
        # symbol
        return lookup_variable_value(exp, env)
    else:
        return get(EVAL, get_type_tag(exp))(exp, env)
Esempio n. 8
0
def sub(a, b):
    a, b, opType = prepareOperands(a, b)
    return get('sub', opType)(a, b)
Esempio n. 9
0
def campaign_gm(cid):
    """ email address, full email header, attribution"""
    gm_address = t.get_field("campaign-%s" % (str(cid),), "gm")
    gm_attribution = t.get('ext-email-%s-attribution' % (gm_address,))
    return ( gm_address, formataddr( (gm_attribution, gm_address) ), gm_attribution )
d = {
    "Ella": 39,
    "Owen": 40,
    "Fred": 44,
    "Zoe": 41,
    "Adam": 27,
    "Ceve": 37,
    "Adam": 27,
    "Ceve": 37
}
root = tbl.new_empty_root()
for k, v in d.items():
    tbl.add(root, k, v)
print("To_string: ", tbl.to_string(
    root))  # { (Adam,27) (Ceve,37) (Ella,39) (Fred,44) (Owen,40) (Zoe,41) }
print("Get(Owen):", tbl.get(root, "Owen"))  # 40
print("Get(Jonas):", tbl.get(root, "Jonas"))  # None
print("Size:", tbl.count(root))  # 6

print("Max depth:", tbl.max_depth(root))  # 3
pairs = tbl.get_all_pairs(root)
print(
    "All pairs: ", pairs
)  # [('Adam', 27), ('Ceve', 37), ('Ella', 39), ('Fred', 44), ('Owen', 40), ('Zoe', 41)]

tbl.add(root, "AA", 1)
tbl.add(root, "AAA", 2)
tbl.add(root, "AAAA", 3)
tbl.add(root, "AAAAA", 4)

print("Size:", tbl.count(root))  # 10
Esempio n. 11
0
        i = i.split('\n')
        d.append(i[0])

    quad = []

    j = 0
    for i in d:
        quad.append(re.findall('\w+|\+|-|\*', d[j]))
        j = j + 1

    print
    t = usage.gen(quad)

    f = 0
    #print t
    print '\n\n\n'

    for i, j in t.iteritems():
        for k in j:
            print k[0], '\t',
            print 'lu' + str(k[1]), '\t',
            if k[2] == None:
                print 'nnu\t',
            else:
                print 'nu' + str(k[2]) + '\t',
            print
        print
    print
    table.get(quad, t)
    #os.system("rm symbol_temp.txt")
Esempio n. 12
0
    arr = [upper, lower]
    line = random.choice(arr)
    if (line == upper):
        line = line + 1
        upper = upper + 1
    else:
        line = line - 1
        lower = lower - 1
    m = "MOVE " + str(line) + " 0" + " 0\n"
    connection.send(str.encode(m))
    print(m, end="")


while True:

    if table.get():
        mess = table.get_1_el()
        table.remove()
        print(mess)
        if "ERROR" in mess:
            print("heeeee")
            if stage == 1:
                print("ko")
                choice(ClientMultiSocket)
            else:
                print("mo")
                move(ClientMultiSocket)
        if "CONNECT" in mess:
            login_mess(ClientMultiSocket)
        elif "START" in mess:
            start_mess(ClientMultiSocket, mess)
Esempio n. 13
0
    #run_once()
    print "TIME: %s" % (time.time() - begin)


def run_once():
    import terms
    terms.load_terms()


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    #logging.getLogger('suds').setLevel(logging.ERROR)
    if sys.argv[1] == 'variables':
        import variable
        variable.all()
    elif sys.argv[1] == 'variable':
        import variable
        pprint(variable.get(sys.argv[2]))
    elif sys.argv[1] == 'table':
        import table
        pprint(table.get(sys.argv[2]))
    elif sys.argv[1] == 'statistic':
        import statistic
        pprint(statistic.get(sys.argv[2]))
    elif sys.argv[1] == 'load':
        import statistic
        statistic.all()
    elif sys.argv[1] == 'test':
        test_load()
Esempio n. 14
0
def add(a, b):
    a, b, opType = prepareOperands(a, b)
    return get('add', opType)(a, b)
Esempio n. 15
0
def make_define_from_symb(var, val):
    return get(MAKE_EXP, SYMBOL)(var, val)
Esempio n. 16
0
def make_proc_call(proc, *args):
    return get(MAKE_EXP, CALL)(proc, args)
Esempio n. 17
0
def make_define_from_lambda(var, params, body):
    # define(foo, (x y), (e1 e2 e3))
    return get(MAKE_EXP, DEF_LAMBDA)(var, params, body)
Esempio n. 18
0
 def get(self, key, sender):
     state_key = self.key(key, sender)
     if t.has_key(state_key):
         return t.get(state_key)
     else:
         return ROUTE_FIRST_STATE
Esempio n. 19
0
def mul(a, b):
    a, b, opType = prepareOperands(a, b)
    return get('mul', opType)(a, b)
Esempio n. 20
0
    
    #logging.info(table.get('12211-0104', force_reload=True))
    
    #run_once()
    print "TIME: %s" % (time.time() - begin)
    
def run_once():
    import terms
    terms.load_terms()
    
if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    #logging.getLogger('suds').setLevel(logging.ERROR)
    if sys.argv[1] == 'variables':
        import variable 
        variable.all()
    elif sys.argv[1] == 'variable':
        import variable
        pprint(variable.get(sys.argv[2]))
    elif sys.argv[1] == 'table':
        import table
        pprint(table.get(sys.argv[2]))
    elif sys.argv[1] == 'statistic':
        import statistic
        pprint(statistic.get(sys.argv[2]))
    elif sys.argv[1] == 'load':
        import statistic
        statistic.all()
    elif sys.argv[1] == 'test':
        test_load()
Esempio n. 21
0
def div(a, b):
    a, b, opType = prepareOperands(a, b)
    return get('div', opType)(a, b)
#     line = line.strip('\n')
#     key = len(line)
#      if key not in dct:
#           dct[key] = 0
#        dct[key] += 1

#for k,v in sorted(dct.items()):
#    print(f'{k}\t{v}')
start = time.time()

dct = tbl.new_empty_root()
with open(path, 'r', encoding='UTF-8') as file:
    for line in file.readlines():
        line = line.strip('\n')
        key = len(line)
        if tbl.get(dct, key) == None:
            tbl.add(dct, key, 1)
        else:
            res = tbl.get(dct, key)
            tbl.add(dct, key, res + 1)

lenght = []
count = []

for i in range(1, 60):
    if tbl.get(dct, i) is not None:
        count.append(tbl.get(dct, i))
        lenght.append(i)

lenght_x = (lenght)
y_pos = list(range(1, len(lenght) + 1))
Esempio n. 23
0
def neg(a):
    a, _, opType = prepareOperands(a)
    return get('neg', opType)(a)
Esempio n. 24
0
		i = i.split('\n')
		d.append(i[0])

	quad = []
	
	j = 0
	for i in d:
		quad.append(re.findall('\w+|\+|-|\*', d[j]))
		j = j + 1

	print
	t = usage.gen(quad)

	f = 0
	#print t
	print '\n\n\n'

	for i , j in t.iteritems():
		for k in j:
			print k[0],'\t',
			print 'lu'+str(k[1]),'\t',
			if k[2] == None:
				print 'nnu\t',
			else:
				print 'nu'+str(k[2])+'\t',
			print
		print
	print
	table.get(quad , t)
	#os.system("rm symbol_temp.txt")
Esempio n. 25
0
def rev(a):
    a, _, opType = prepareOperands(a)
    return get('rev', opType)(a)
Esempio n. 26
0
#     line = line.strip('\n')
#     key = len(line)
#      if key not in dct:
#           dct[key] = 0
#        dct[key] += 1

#for k,v in sorted(dct.items()):
#    print(f'{k}\t{v}')

dct = tbl.new_empty_root()
with open(path, 'r', encoding='UTF-8') as file:
    for line in file.readlines():
        line = line.strip('\n')
        key = line
        if len(line) > 3:
            if tbl.get(dct, key) == None:
                tbl.add(dct, key, 1)
            else:
                res = tbl.get(dct, key)
                tbl.add(dct, key, res + 1)

all_pairs = tbl.get_all_pairs(dct)


def getkey(item):
    return item[1]


all_pairs2 = sorted(all_pairs, key=getkey, reverse=True)
print(all_pairs2[0:10])
Esempio n. 27
0
if __name__ == "__main__":
    the_global_environment = setup_environment()
    x = Symbol("x")
    y = Symbol("y")
    foo = Symbol("foo")

    install_define_pkg()
    install_assignment_pkg()
    install_isquoted_pkg()
    install_if_pkg()
    install_lambda_pkg()
    install_begin_pkg()
    install_cond_pkg()
    install_call_pkg()

    t = get(EVAL, COND)
    print(t)

    # test define var val
    #exp = make_define_from_symb(x, 22)
    ##(exp)

    #m_eval_dd(exp, the_global_environment)    # updates env
    #v = m_eval(x, the_global_environment)  # looks up variable in env
    #print("define and lookup: ", v)

    # test define proc
    exp = make_define_from_lambda(foo, List(x, y), List(List(PLUS, x, y)))
    pprint(exp)
    m_eval_dd(exp, the_global_environment) # adds foo PROCEDURE to env
    t = m_eval_dd(foo, the_global_environment) # looks up foo in env