Exemplo n.º 1
0
    def __init__(self, jsonObject):
        self.name = ""
        self.login = ""
        self.password = ""

        self.is_auth = False
        self.used_names = set()
        self.tables = []
        self.active_table = -1
        #   print(jsonObject)
        obj = jsonObject
        if not ("name" in obj.keys() and "login" in obj.keys()
                and "pass" in obj.keys() and "tables" in obj.keys()):
            raise FileNotFoundError
        self.name = obj["name"]
        self.login = obj["login"]
        self.password = obj["pass"]
        tbls = dict(obj["tables"])
        print("Tables", tbls)
        for e in tbls.keys():
            tmp = tbls[e]
            self.used_names.add(str(tmp["name"]))
            tbl = DataTable()
            tbl.fromJson(tmp)
            self.tables.append(tbl)
        pass
Exemplo n.º 2
0
 def __init__(self, file):
     type = {\
        'id':   'int',\
        'src': 'string',\
        'src_args': 'string',\
        'parent_id': 'int',\
        'parents': 'int',\
        'parent_dist': 'int',\
        'num_cpus': 'int',\
        'num_units': 'int',\
        'total_units': 'int',\
        'total_cpus': 'int',\
        'length': 'int',\
        'merit': 'float',\
        'gest_time': 'float',\
        'fitness': 'float',\
        'gen_born': 'int',\
        'update_born': 'int',\
        'update_dead': 'int',\
        'update_deactivated': 'int',\
        'depth': 'int',\
        'hw_type': 'int',\
        'inst_set': 'string',\
        'sequence': 'string',\
        'cells': 'string',\
        'gest_offset': 'string',\
        'lineage': 'string',\
        'phen_entropy': 'float',\
        'phen_max_fitness': 'float',\
        'task.0':'float',\
        'task.1':'float',\
        'task.2':'float',\
        'task.3':'float',\
        'task.4':'float',\
        'task.5':'float',\
        'task.6':'float',\
        'task.7':'float',\
        'task.8':'float',\
        'alignment':'string'
     }
     order = []
     fid = gz.open(file, 'rb')
     try:
         fid.readline()  # Skip first header line
         format = fid.readline().strip()  # Read format line
         for f in format.split(' '):
             if (f[0] == '#'):
                 continue
             order.append(f)
         self.dt = DataTable(file, order, type)
     finally:
         fid.close()
Exemplo n.º 3
0
def testSource(name, src, headings, data):
    heading(name)
    dt = DataTable()
    lines = split(src, '\n')
    dt.readLines(lines)
    assert [col.name() for col in dt.headings()] == headings
    i = 0
    while i < len(dt):
        match = data[i]
        if dt[i].asList() != match:
            print 'mismatch'
            print 'i        :', i
            print 'expected :', match
            print 'got      :', dt[i]
            raise AssertionError
        i = i + 1
Exemplo n.º 4
0
 def startElement(self, name, attrs):
     if (name == 'Result'):
         for attr_name in attrs.getNames():
             self.response.attributes[attr_name] = attrs.getValue(attr_name)
     if (name == 'GlobalVars'):
         for attr_name in attrs.getNames():
             self.response.params[attr_name] = attrs.getValue(attr_name)
     if (name == 'DataTable'):
         self.data_table = DataTable()
         self.data_table.set_table_name(attrs.getValue('Name'))
         self.data_table.set_table_headers(attrs.getValue('Headers'))
         for attr_name in attrs.getNames():
             if ('Name' != attr_name and 'Headers' != attr_name):
                 self.data_table.set_table_params(attr_name,
                                                  attrs.getValue(attr_name))
         self.response.tables[self.data_table.name] = self.data_table
     if (name == 'Row'):
         self.is_row = True
Exemplo n.º 5
0
def test01():
    print 'Simple tests...'

    heading('Create table')
    t = DataTable()

    heading('Headings 1')
    t = DataTable()
    t.setHeadings([
        TableColumn('name'),
        TableColumn('age:int'),
        TableColumn('rating:float')
    ])

    heading('Headings 2')
    t = DataTable()
    t.setHeadings(['name', 'age:int', 'rating:float'])

    heading('Adding and accessing data')
    a = ['John', '26', '7.2']
    b = ['Mary', 32, 8.3]
    t.append(a)
    t.append(b)
    assert t[-1].asList() == b
    assert t[-2].asDict() == {'name': 'John', 'age': 26, 'rating': 7.2}
    assert t[-1]['name'] == 'Mary'
    assert t[-2]['name'] == 'John'

    heading('Printing')
    print t

    heading('Writing file (CSV)')
    answer = '''\
name,age,rating
John,26,7.2
Mary,32,8.3
'''
    out = StringIO()
    t.writeFile(out)
    results = out.getvalue()
    assert results == answer, '\n%r\n%r\n' % (results, answer)

    heading('Accessing rows')
    for row in t:
        assert row['name'] == row[0]
        assert row['age'] == row[1]
        assert row['rating'] == row[2]
        for item in row:
            pass

    heading('Default type')
    t = DataTable(defaultType='int')
    t.setHeadings(list('xyz'))
    t.append([1, 2, 3])
    t.append([4, 5, 6])
    assert t[0]['x'] - t[1]['z'] == -5

    # Basics
    src = '''\
"x","y,y",z
a,b,c
a,b,"c,d"
"a,b",c,d
"a","b","c"
"a",b,"c"
"a,b,c"
"","",""
"a","",
'''
    headings = ['x', 'y,y', 'z']
    data = [['a', 'b', 'c'], ['a', 'b', 'c,d'], ['a,b', 'c', 'd'],
            ['a', 'b', 'c'], ['a', 'b', 'c'], ['a,b,c', '', ''], ['', '', ''],
            ['a', '', '']]
    testSource('Basics', src, headings, data)

    # Comments
    src = '''\
a:int,b:int
1,2
#3,4
5,6
'''
    headings = ['a', 'b']
    data = [
        [1, 2],
        [5, 6],
    ]
    testSource('Comments', src, headings, data)

    # Multiline records
    src = '''\
a
"""Hi
there"""
'''
    headings = ['a']
    data = [
        ['"Hi\nthere"'],
    ]
    testSource('Multiline records', src, headings, data)

    # MiddleKit enums
    src = '''\
Class,Attribute,Type,Extras
#Foo,
,what,enum,"Enums=""foo, bar"""
,what,enum,"Enums='foo, bar'"
'''
    headings = 'Class,Attribute,Type,Extras'.split(',')
    data = [
        ['', 'what', 'enum', 'Enums="foo, bar"'],
        ['', 'what', 'enum', "Enums='foo, bar'"],
    ]
    testSource('MK enums', src, headings, data)

    heading('Unfinished multiline record')
    try:
        DataTable().readString('a\n"1\n')
    except DataTableError:
        pass  # just what we were expecting
    else:
        raise Exception, 'Failed to raise exception for unfinished multiline record'
Exemplo n.º 6
0
 def get_table_for_name(self, name):
     if (name in self.tables):
         return self.tables[name]
     return DataTable()
Exemplo n.º 7
0
 def initFrames(self, pageNumber, controller):
     utilBar = UtilBar(self, pageNumber, controller)
     navBar = NavBar(self, pageNumber, controller)
     dataTable = DataTable(self, pageNumber, controller)
     self.frames = [utilBar, navBar, dataTable]