Exemple #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
Exemple #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()
Exemple #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
Exemple #4
0
    def make_target(self, data, var1, var2):
        (var1, _) = var1
        (var2, _) = var2
        try:
            func_utter_ind = self.question.index("{func}")
            func_utter = self.param[func_utter_ind]
            func_target = DT.find_matched_functions(func_utter, self.func_key)
        except ValueError as e:
            print(e)
            raise FunctionNA
        # Try getting <val>
        try:
            val_ind = self.question.index("{val}")
            val = self.param[val_ind]
        except ValueError:
            val = None
            pass
        # Try getting <var_name>
        # try:
        #     var_name_ind = self.question.index("{var_name}")
        #     var_name = self.param[var_name_ind]
        #     if var_name == "":
        #         var_name = data
        # except ValueError:
        #     var_name = None
        #     pass
        target = self.make_template(data=data,
                                    func=func_target,
                                    var1=var1,
                                    var2=var2,
                                    val=val)

        return target
 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
 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()
 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
class Handler(handler.ContentHandler):

    """ Constructs a SAX handler for Majestic SEO's API data """

    def __init__(self, response):
        self.response = response
        self.data_table = None
        self.is_row = False
        self.row = ""

    """ Parses the start element """

    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

    """ Parses the data within the elements """

    def characters(self, chrs):
        if self.is_row:
            self.row += chrs

    """ Parses the end element """

    def endElement(self, name):
        if "Row" == name:
            self.data_table.set_table_row(self.row)
            self.is_row = False
            self.row = ""
class Handler(handler.ContentHandler):
    """ Constructs a SAX handler for Majestic SEO's API data """
    def __init__(self, response):
        self.response = response
        self.data_table = None
        self.is_row = False
        self.row = ''

    """ Parses the start element """

    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

    """ Parses the data within the elements """

    def characters(self, chrs):
        if (self.is_row):
            self.row += chrs

    """ Parses the end element """

    def endElement(self, name):
        if ('Row' == name):
            self.data_table.set_table_row(self.row)
            self.is_row = False
            self.row = ''
Exemple #10
0
import DataTable as DT
import Question as QS
"""
# {0}: functions using one variable
# {1}: preposition: ["of", "of the"]
# {2}: "var"
# {3}: data_op
"""
Q0_param = {
    0:
    DT.dict_to_list(DT.Functions["1var" + "data"]) +
    DT.dict_to_list(DT.Functions["1var"]),
    1:
    DT.Grammar["preposition"],
    2:
    "<var1>",
    3:
    DT.CommonWords["data_op"],
}
Q0 = QS.Questions(num_param=4,
                  func_key=["1var" + "data", "1var"],
                  question=["{func}", "{prep}", "{var1}", "{data_op}"],
                  param_detail=Q0_param,
                  template_ver="v1")
"""
# {0}: functions using one dataset
# {1}: preposition: ["of", "of the"]
# {2}: data
"""
Q1_param = {
    0:
Exemple #11
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'
Exemple #12
0
class AvidaData:

   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()
      
   def __getitem__(self,descr):
      return self.dt[descr]           
  
   def table(self):
      return self.dt.table()

   def columns(self):
      return self.dt.columns()

   def rows(self):
      return self.dt.rows()
      
   def rearrange(self,ndx):
      for k,v in self.dt.col.items():
         self.dt.col[k] = v[ndx]
      return
 def get_table_for_name(self, name):
     if (name in self.tables):
         return self.tables[name]
     return DataTable()
Exemple #14
0
class AvidaData:
    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()

    def __getitem__(self, descr):
        return self.dt[descr]

    def table(self):
        return self.dt.table()

    def columns(self):
        return self.dt.columns()

    def rows(self):
        return self.dt.rows()

    def rearrange(self, ndx):
        for k, v in self.dt.col.items():
            self.dt.col[k] = v[ndx]
        return
Exemple #15
0
import pickle
from dash.dependencies import Input, Output, State

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets = external_stylesheets)
paysim = pd.read_csv('ps_tf_co_sample.csv')
# ps_tf = pd.read_csv('ps_tf.csv')
# ps_co = pd.read_csv('ps_co.csv')

app.layout = html.Div(children = [
    html.Center(html.H1('Paysim')),
    dcc.Tabs(value = 'tabs', id = 'tabs-1', children = [
        # Prediction_tf.Tab_Prediction_tf(),
        # Prediction_co.Tab_Prediction_co(),
        DataTable.Tab_DataTable(paysim),
        dcc.Tab(label = 'Fraud Detection for CASH_OUT Transaction', value = 'tab-empat', children = [
            html.Div(children = [
                html.Div(children = [
                    html.P('Total Hour of Transaction:'),
                    dcc.Input(id = 'co-input-hour', type = 'number', value = '')
                ], className = 'col-3'),
                html.Div(children = [
                    html.P('Amount of Transaction:'),
                    dcc.Input(id = 'co-input-trx', type = 'number', value = '')
                ], className = 'col-3'),
                html.Div(children = [
                    html.P('Old Original Account Balance: '),
                    dcc.Input(id = 'co-input-old-amt-org', type = 'number', value = '')
                ], className = 'col-3'),
                html.Div(children = [
Exemple #16
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]