Example #1
0
def write_val(addr,data,op=1):
	'@FUNCTION=write_val\n'\
	'@SYNTAX=write_val(addr,data)\n'\
	'@DESCRIPTION=Write a value to address provided.\n\n'\
	'@EXAMPLES=To write data 0x50 at 0x2c, enter address 0x2C and Data\n'\
	'0x50 and hit enter.\n\n'\
	'@SEEALSO='
	wb = Gnumeric.workbooks()[0] 
	s  = wb.sheets()[1]

	write_path = "/tmp/pipe.in"
	read_path = '/tmp/pipe.out'
	wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)
	rf = os.open(read_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)

	msg = str(op) + "," + str(addr) + "," + str(data)
	os.write(wf,msg)

	time.sleep(3)

	val = os.read(rf, 4)
	val = str(val,encoding='latin-1')

	# return 'successful'
	if val == '\x00\x01':
		return 'Successful'
	else:
		return 'Not Successful'
Example #2
0
def api_list_companies(industry, sector, bourse, cell):
    wbs = g.workbooks()
    wb = wbs[0]
    sheet = wb.sheets()[0]

    col = g.functions['column']
    row = g.functions['row']

    URL = SERVER + urllib2.quote(
        '/api/list/%s/%s/company_list/%s' %
        (industry.replace("/", "_"), sector.replace("/", "_"), bourse))

    # return URL
    info = urllib2.urlopen(URL).read()

    for i, data in enumerate(info.split(',')):
        sheet.cell_fetch(int(col(cell)) - 1,
                         i + int(row(cell)) - 1).set_text(data)

    while True:
        i = i + 1
        the_t = sheet.cell_fetch(int(col(cell)) - 1,
                                 i + int(row(cell)) - 1).get_rendered_text()
        # print i, the_t
        sheet.cell_fetch(int(col(cell)) - 1,
                         i + int(row(cell)) - 1).set_text('')
        if the_t == '':
            break

    return industry + ',' + sector + str(len(info.split(',')))
def write_val(addr, data, op=1):
    '@FUNCTION=write_val\n'\
    '@SYNTAX=write_val(addr,data)\n'\
    '@DESCRIPTION=Write a value to address provided.\n\n'\
    '@EXAMPLES=To write data 0x50 at 0x2c, enter address 0x2C and Data\n'\
    '0x50 and hit enter.\n\n'\
    '@SEEALSO='
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]

    write_path = "/tmp/pipewrite.in"
    read_path = '/tmp/pipewrite.out'
    wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)

    msg = str(op) + "," + str(addr) + "," + str(data)
    os.write(wf, msg)

    time.sleep(2)
    rf = os.open(read_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)
    val = os.read(rf, 1)
    # val = str(val,encoding='latin-1')
    # resp = val.from_bytes(val,byteorder='big',signed=False)
    # return 'successful'
    # if len(val) == 2:
    # 	if ord(val[0]) == 1:
    # 		return 'Successful'
    # 	else:
    # 		return str(val)
    # else:
    if ord(val) == 1:
        return 'Successful'
    else:
        return "Not Successful"
def check(addr):
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]
    col = Gnumeric.functions['column']
    rw = Gnumeric.functions['row']
    colnum = col(addr)
    rownum = rww(addr)
    print('Col: ', colnum, ' Row: ', rownum)
Example #5
0
def api_list_industry(cell):
    wbs = g.workbooks()
    wb = wbs[0]
    sheet = wb.sheets()[0]

    col = g.functions['column']
    row = g.functions['row']

    URL = SERVER + '/api/list/industry_list'
    info = urllib2.urlopen(URL).read()

    for i, data in enumerate(info.split(',')):
        sheet.cell_fetch(int(col(cell)) - 1,
                         i + int(row(cell)) - 1).set_text(data)
def read_val(address):
    '@FUNCTION=read_val\n'\
    '@SYNTAX=read_val(addr)\n'\
    '@DESCRIPTION= Read a value address provided.\n\n'\
    '@EXAMPLES=To read data from 0x2C, enter address 0x2C\n'\
    'and hit enter.\n\n'\
    '@SEEALSO='
    global flag
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]
    address = str(address)
    mm = Aval_mm()
    if flag == True:
        mm.open_fifos()
        flag = False
    resp = mm.read(address)
    return resp
Example #7
0
def api_list_sector(industry, cell):
    wbs = g.workbooks()
    wb = wbs[0]
    sheet = wb.sheets()[0]

    col = g.functions['column']
    row = g.functions['row']

    URL = SERVER + urllib2.quote('/api/list/%s/sector_list' %
                                 (industry.replace("/", "_")))
    # return URL
    info = urllib2.urlopen(URL).read()

    for i, data in enumerate(info.split(',')):
        sheet.cell_fetch(int(col(cell)) - 1,
                         i + int(row(cell)) - 1).set_text(data)

    return industry
Example #8
0
def get_field(cell_range):
	global n1,m1,m2,wb,s
	col  = Gnumeric.functions['column']   
	rw  = Gnumeric.functions['row'] 
	wb = Gnumeric.workbooks()[0] 
	s  = wb.sheets()[0]
	columns = col(cell_range)
	rows = rw(cell_range)
	n1 = int(rows) -1
	if len(str(columns)) == 3:
		m1 = int(columns)-1
		m2 = m1
	else:
		m1 = int(columns[0][0])-1;m2 = int(columns[-1][0])-1
	ar = []
	for val in range(m1,m2+1):
		cell = s[val,n1]
		num = cell.get_value()
		ar.append(num)
	return ar
def read_val(addr, op=0):
    '@FUNCTION=read_val\n'\
    '@SYNTAX=read_val(addr)\n'\
    '@DESCRIPTION= Read a value address provided.\n\n'\
    '@EXAMPLES=To read data from 0x2C, enter address 0x2C\n'\
    'and hit enter.\n\n'\
    '@SEEALSO='
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]
    wr_path = "/tmp/pipewrite.in"
    rd_path = '/tmp/piperead.out'
    wrt = os.open(wr_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)

    msg = str(op) + "," + str(addr)
    os.write(wrt, msg)

    # time.sleep(3)
    rd = os.open(rd_path, os.O_RDONLY)
    val = os.read(rd, 4)
    val = val.encode()
    val = unpack(">I", val)
    return str(hex(val[0]))
def write_val(address, wdata):
    '@FUNCTION=write_val\n'\
    '@SYNTAX=write_val(addr,data)\n'\
    '@DESCRIPTION=Write a value to address provided.\n\n'\
    '@EXAMPLES=To write data 0x50 at 0x2c, enter address 0x2C and Data\n'\
    '0x50 and hit enter.\n\n'\
    '@SEEALSO='
    global flag
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]
    addr = int(address, 16)
    # print(addr)
    data = int(wdata, 16)
    mm = Aval_mm()
    if flag == True:
        mm.open_fifos()
        flag = False
    resp = mm.write(address, data)
    if resp == True:
        return "Write Successful"
        # time.sleep(100)
    else:
        return "Write Failed"
Example #11
0
import Gnumeric
wb = Gnumeric.workbooks()[1]
s = wb.sheets()[0]
f = lambda x: s[x,75].get_value()
kas_2_data = [f(i) for i in range(15,19)]
f2 = lambda j : [s[i,j].get_value() for i in range(25,29)]
matrix = [f2(j) for j in range(1,187)]
import numpy
from rpy import r
dist_ls = [numpy.average((numpy.array(matrix[i])-kas_2_data)*(numpy.array(matrix[i])-kas_2_data)) for i in range(len(matrix))]
from sets import Set
good_index_set = Set(range(186))
bad_index_set = Set([1, 8, 9, 17, 102, 104, 108, 119, 139, 140, 154, 157, 177, 180])

good_index_set = good_index_set - bad_index_set
dist_ls = [numpy.average((numpy.array(matrix[i])-kas_2_data)*(numpy.array(matrix[i])-kas_2_data)) for i in list(good_index_set)]
dist_ls_argsort = numpy.argsort(dist_ls)
dist_ls_argsort[0]

numpy.average((numpy.array(matrix[51])-kas_2_data)*(numpy.array(matrix[41])-kas_2_data))
def func_secmax(gRange):
    '@FUNCTION=PY_SUM2\n'\
    '@SYNTAX=PY_SUM2(range)\n'\
    '@DESCRIPTION=Adds a range of numbers together,'\
    'without calling built-in SUM.\n\n'\
    '@EXAMPLES=To add values in A1 to A5, just type them in:\n'\
    '    py_sum(a1:a5)\n'\
    '@SEEALSO='
    col = Gnumeric.functions['column']
    rw = Gnumeric.functions['row']

    write_path = "/tmp/pipe.in"
    read_path = "/tmp/pipe.out"

    columns = col(gRange)
    rows = rw(gRange)
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[0]
    i = 0
    ar = []
    if len(str(rows)) == 3:
        n1 = int(rows) - 1
        n2 = n1
    else:
        n1 = int(rows[0][0]) - 1
        n2 = int(rows[-1][0]) - 1

    if len(str(columns)) == 3:
        m1 = int(columns) - 1
        m2 = m1
    else:
        m1 = int(columns[0][0]) - 1
        m2 = int(columns[-1][0]) - 1

    for r in range(n1, n2 + 1):
        for c in range(m1, m2 + 1):
            cell = s[c, r]
            val = cell.get_value()
            ar.append(val)
            i += 1
    list1 = ar
    mx = max(list1[0], list1[1])
    secondmax = min(list1[0], list1[1])
    n = len(list1)
    for i in range(2, n):
        if list1[i] > mx:
            secondmax = mx
            mx = list1[i]
        elif list1[i] > secondmax and mx != list1[i]:
            secondmax = list1[i]
        else:
            if secondmax == mx:
                secondmax = list1[i]

    #
    wf = os.open(write_path, os.O_SYNC | os.O_CREAT | os.O_RDWR)
    rf = None
    msg = str(secondmax)
    os.write(wf, msg)
    print("sent msg: ", msg)
    # 	if rf is None:
    #     rf = os.open(read_path, os.O_RDONLY)

    # s = os.read(rf, 1024)
    # if len(s) != 0:
    # 	print ("\n")
    # else:
    # 	os.write(wf, 'exit')
    # 	os.close(rf)
    # os.close(wf)
    return secondmax
def exit_sim():
    wb = Gnumeric.workbooks()[0]
    s = wb.sheets()[1]
    mm = Aval_mm()
    mm.ctrl_command()