def init_tables(self):
		db = self.db
		# person group table
		pgSchema = [Field('gid', 'CHAR(255)', True, True, None),
					Field('name', 'TEXT', True, False, None),
					Field('user_data', 'TEXT', False, False, None)]
		self.tables['PersonGroup'] = Table(db, 'PersonGroup', pgSchema)

		# person table
		pSchema =  [Field('pid', 'CHAR(255)', True, True, None),
					Field('name', 'TEXT', True, False, None),
					Field('alias', 'TEXT', True, False, None),
					Field('gid', 'CHAR(255)', True, False, ForeignKey(self.tables['PersonGroup'].name, 'gid'))]
		self.tables['Person'] = Table(db, 'Person', pSchema)

		# face table
		fSchema =  [Field('fid', 'CHAR(255)', True, True, None),
					Field('image', 'TEXT', True, False, None),
					Field('pid', 'CHAR(255)', True, False, ForeignKey(self.tables['Person'].name, 'pid'))]
		self.tables['Face'] = Table(db, 'Face', fSchema)

		# event table
		eSchema = [Field('name', 'TEXT', True, False, None),
					Field('description', 'TEXT', True, False, None),
					Field('timestamp', 'BIGINT', True, False, None)]
		self.tables['Event'] = Table(db, 'Event', eSchema)

		# clockin table
		cSchema =  [Field('timestamp', 'BIGINT', True, False, None),
					Field('eid', 'INT', True, False, ForeignKey(self.tables['Event'].name, 'id')),
					Field('pid', 'CHAR(255)', True, False, ForeignKey(self.tables['Person'].name, 'pid'))]
		self.tables['ClockIn'] = Table(db, 'ClockIn', cSchema)
예제 #2
0
    def test_persist(self):
        dbms: DBMS = DBMS()

        db1: Database = dbms.create_database('db1')
        table1 = Table('table1', ['c1', 'c2'], ColumnTypes([int, str]))
        table1.append_row([1, '1'])
        table1.append_row([2, '2'])
        table2 = Table('table2', ['c1', 'c2'], ColumnTypes([str, int]))
        table2.append_row(['1', 1])
        table2.append_row(['2', 2])
        table3 = Table('table3', ['c1', 'c3'], ColumnTypes([int, int]))
        table3.append_row([1, 1])
        table3.append_row([1, 2])
        table3.append_row([2, 1])
        table3.append_row([2, 2])
        db1.add_table(table1)
        db1.add_table(table2)
        db1.add_table(table3)

        db2: Database = dbms.create_database('db2')
        table3 = Table('table3', ['c1', 'c2'], ColumnTypes([Char, Color]))
        table3.append_row([Char('a'), Color('#ffffff')])
        table3.append_row([Char('b'), Color('#aaaaaa')])
        table4 = Table('table4', ['c1', 'c2'], ColumnTypes([Color, Char]))
        table4.append_row([Color('#ffffff'), Char('a')])
        table4.append_row([Color('#ffffff'), Char('a')])
        db2.add_table(table3)
        db2.add_table(table4)

        dbms.persist()
        DBMS.load()
        for database_name in dbms.get_databases_names():
            for table_name, table in dbms.get_database(
                    database_name)._tables.items():
                print(table.to_json())
예제 #3
0
 def test_01_blank_tables(self):
     # start with two tables that will be empty
     t1 = Table()
     t2 = Table()
     # the result of the cartesian product of two empty tables
     # should iteslf be an empty table
     result = squeal.cartesian_product(t1, t2)
     # we'll know it's an empty table if its dictionary is empty
     result_dict = result.get_dict()
     expected = {}
     self.assertEqual(result_dict, expected,
                      "product of two empty tables should be empty")
예제 #4
0
 def test_03_blank_table_second(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # set table 2
     table_2.set_dict({'t2.title': ['CSCA', '08']})
     # the result should return 0 row, and titles of t2
     result = squeal.cartesian_product(table_1, table_2)
     # we'll know it's an empty table if its dictionary is empty
     # but t2 has title, so we should return its title
     result_dict = result.get_dict()
     expected = {'t2.title': []}
     self.assertEqual(result_dict, expected,
                      '''if one table is empty, result should be empty,
                      and return another tables' title''')
예제 #5
0
    def test_join(self):
        table1 = Table('table1', ['c1', 'c2'], ColumnTypes([int, int]))
        table1.append_row([1, 2])
        table1.append_row([1, 4])
        table1.append_row([2, 3])
        table2 = Table('table2', ['c1', 'c3'], ColumnTypes([int, str]))
        table2.append_row([1, 'str1'])
        table2.append_row([2, 'str2'])

        table3 = table1.join(table2, 'c1')

        rows_data = list(map(lambda x: x.data, table3.rows))
        self.assertTrue([1, 2, 'str1'] in rows_data)
        self.assertTrue([1, 4, 'str1'] in rows_data)
        self.assertTrue([2, 3, 'str2'] in rows_data)
예제 #6
0
파일: tests.py 프로젝트: Raumo0/ByFlyPy
 def setUp(self):
     try:
         os.remove(self.FILENAME)
     except Exception as e:
         pass
     self._table = Table(self.FILENAME)
     self.db_manage = DBManager(self._table)
예제 #7
0
 def test_04_blank_row_second(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # table 1 has no row only titles, but table 2 has
     table_1.set_dict({'t1.title': []})
     table_2.set_dict({'t2.title': ['CSCA', '08']})
     # the result of the cartesian product of a table without any row
     # it should return no row
     result = squeal.cartesian_product(table_1, table_2)
     # if there is no row for one table, then result should be no row
     result_dict = result.get_dict()
     expected = {'t2.title': [], 't1.title': []}
     self.assertEqual(result_dict, expected,
                      '''if one table has no row, product should be empty,
                      but it has all the title names''')
예제 #8
0
 def test_06_two_blank_rows(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # two tables both have no row
     table_1.set_dict({'t1.title': []})
     table_2.set_dict({'t2.title': []})
     # the result of the cartesian product of a table without any row
     # it should return no row
     result = squeal.cartesian_product(table_1, table_2)
     # if there is no row for one table, then result should be no row
     result_dict = result.get_dict()
     expected = {'t2.title': [], 't1.title': []}
     self.assertEqual(result_dict, expected,
                      '''if two tables has no row, then there is no row
                      to return but title names''')
예제 #9
0
 def test_07_normal_cases(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # set two tables
     table_1.set_dict({'CSC': ['A08', 'A67'], 'MAT': ['A31', 'A23']})
     table_2.set_dict({'c.A08': ['term work', 'term tests', 'final']})
     result = squeal.cartesian_product(table_1, table_2)
     # get the result dict of cartesian product
     result_dict = result.get_dict()
     expected = {'MAT': ['A31', 'A31', 'A31', 'A23', 'A23', 'A23'],
                 'c.A08': ['term work', 'term tests', 'final', 'term work',
                           'term tests', 'final'],
                 'CSC': ['A08', 'A08', 'A08', 'A67', 'A67', 'A67']}
     self.assertEqual(result_dict, expected,
                      '''your cartesian product must get something
                      wrong''')
    def setUp(self):
        t1, t2, t3 = Table(), Table(), Table()
        t1.set_dict({
            'a.str': ['one', 'two', 'three', 'one'],
            'a.val': ['1', '2', '3', '1'],
            'a.a': ['1', '2', '3', '4']
        })
        t2.set_dict({
            'b.str': ['one', 'two', 'three', 'one'],
            'b.b': ['1', '2', '3', '3'],
            'b.val': ['1', '2', '3', '1']
        })
        t3.set_dict({'c.c': ['1', '2'], 'c.val': ['100', '200']})

        self.db = {'tablea': t1, 'tableb': t2, 'tablec': t3}

        self.dbo = Database()
        self.dbo.set_dict(self.db)
예제 #11
0
 def test_08_normal_test(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # set two tables
     table_1.set_dict({'m.A31': ['homework', 'midterm', 'final']})
     table_2.set_dict({'c.A08': ['term work', 'term tests', 'final']})
     result = squeal.cartesian_product(table_1, table_2)
     # get the result dict of cartesian product
     result_dict = result.get_dict()
     expected = {'m.A31': ['homework', 'homework', 'homework', 'midterm',
                           'midterm', 'midterm', 'final', 'final', 'final'],
                 'c.A08': ['term work', 'term tests', 'final', 'term work',
                           'term tests', 'final', 'term work',
                           'term tests', 'final']}
     self.assertEqual(result_dict, expected,
                      '''your cartesian product must get something
                      wrong''')
예제 #12
0
 def start(self, index):
     """
     爬虫启动入口
     :param index: 对应表的结尾序号
     """
     domains = Table(index).get_unexplored_domain()  # 获取需要爬取的域名
     re_link = re.compile('/data/whoishistory/\d')
     source = 'openwhois'
     for domain in domains:
         self.get_whowas(self.domain_format(domain))
예제 #13
0
 def test_11_normal_test(self):
     # initialize two tables
     table_1 = Table()
     table_2 = Table()
     # set two tables
     table_1.set_dict({'a': ['1', '2', '3', '4']})
     table_2.set_dict({'b': ['10', '11', '12'], 'c': ['99', '98', '97']})
     result = squeal.cartesian_product(table_2, table_1)
     # get the result dict of cartesian product
     result_dict = result.get_dict()
     expected = {'a': ['1', '2', '3', '4', '1', '2', '3', '4', '1', '2',
                       '3', '4'],
                 'b': ['10', '10', '10', '10', '11', '11', '11', '11',
                       '12', '12', '12', '12'],
                 'c': ['99', '99', '99', '99', '98', '98', '98', '98',
                       '97', '97', '97', '97']}
     self.assertEqual(result_dict, expected,
                      '''your cartesian product must get something
                      wrong''')
예제 #14
0
    def test_to_json(self):
        table = Table('table', ['column'], ColumnTypes([str]))
        database = Database('database')
        database.add_table(table)

        self.assertEqual(
            {
                'name': 'database',
                'tables': {
                    'table': table.to_json()
                }
            }, database.to_json())
예제 #15
0
 def seakEntity(self, entity: Entity, forceUpdate: bool = False):
     if (entity.getName()
             not in self._entitesALreadyFormated.keys()) | forceUpdate:
         self._entity = entity
         self._tableEncours = Table()
         self._recupDatas()
         self._decoupeComment()
         self._entitesALreadyFormated[entity.getName()] = self._entity
         self._tablesAlreadyDone[entity.getName()] = self._tableEncours
     else:
         self._entity = self._entitesALreadyFormated[entity.getName()]
         self._tableEncours = self._tablesAlreadyDone[entity.getName()]
         self._recupDataWithCopieEntity(entity)
예제 #16
0
def joinTable(from_tables):
    for table in from_tables:
        if table not in db.tables:
            print "Error:", table, " does not exist"
            exit()
    if len(from_tables) == 2:
        obj1 = db.tables[from_tables[0]]
        obj2 = db.tables[from_tables[1]]
        columns = (obj1.columns) + (obj2.columns)
        obj3 = Table("result", columns)
        data = []
        for row1 in obj1.data:
            for row2 in obj2.data:
                data.append(row1 + row2)
        obj3.update_data(data)
    elif len(from_tables) == 1:
        obj3 = db.tables[from_tables[0]]
    else:
        print "Error: This Engine Don't support operation on more than 2 tables"
        exit()
    return obj3
예제 #17
0
 def _decoupeComment(self):
     lfichier = len(self._lines)
     ln = 0
     commentStarted = False
     findEntity = "# @ORM/" + baseCommandeAnnotation[0] + "="
     self._entity.clearAttibutes()
     while ln < lfichier:
         self._actualLine = self._lines[ln]
         if self._fieldEncours:
             if preFormatLineAnnotation(self._actualLine)[0:1] == '_':
                 vals = preFormatLineAnnotation(
                     self._actualLine)[1:].split(":")
                 self._entity.addAttributeToListAttributes(vals[0])
                 if self._fieldEncours.key == "PRI":
                     self._entity.setPrimaryKey(vals[0])
                     self._tableEncours.setPrimaryKey(
                         self._nameMysqlFieldEncours)
         if self.isLineContain(stToContain=findEntity,
                               addPreCarShort=False):
             self._tableEncours = Table()
             self._tableEncours.fieldsName = []
             self._tableEncours.name = preFormatLineAnnotation(
                 self._actualLine)[18:]
         if self.isLineContain(startAnnotationFormat, False):
             commentStarted = True
             self._fieldEncours = FieldTable()
             ln += 1
             self._actualLine = self._lines[ln]
         if commentStarted:
             while not self.isLineContain(startAnnotationFormat, False):
                 self._actualLine = self._lines[ln]
                 if self.isLineContain("# @ORM/", False):
                     self._commandAnnotationEntity()
                 ln += 1
                 self._actualLine = self._lines[ln]
             self._tableEncours.fields[
                 self._fieldEncours.name] = self._fieldEncours
             self._tableEncours.fieldsName.append(self._fieldEncours.name)
             commentStarted = False
         ln += 1
예제 #18
0
 def post(self):
     """New Table"""
     table = Table(id=str(uuid.uuid4()), **api.payload)
     save(table)
     return table, 201
예제 #19
0
# Created by Marsify, 2019

import discord
from discord.ext import commands
import random
import config
import rules_and_sets as rns
from database import Table

rules = Table('rules', rns.rule_list)
sets = Table('sets', rns.set_list)

rules.delete_table()
sets.delete_table()

rules.create_table()
sets.create_table()


# Generates a random list of sets and rules based on the specified mode. Used when spinning the wheel.
def generate(mode):
    # Return values
    rule_list = []
    set_list = []
    # Entries from database
    rule_values = []
    set_values = []

    # 'Standard' mode has a separate method of set generation.
    if mode == 'standard':
        rule_values = rules.get_values(1)
예제 #20
0
import numpy as np
import vision
from PIL import Image
from database import Column, Integer, Float, String, Boolean
from database import Model, CRUDMixin, ForeignKey, Table
from database import relationship, backref
from vision.track.interpolation import LinearFill
from meta_table import video_evaluation_association_table

import config

logger = logging.getLogger("vatic.models")

boxes_attributes = Table(
    "boxes2attributes", Column("box_id", Integer, ForeignKey("boxes.id")),
    Column("attribute_id", Integer, ForeignKey("attributes.id")))


class Video(Model, CRUDMixin):
    __tablename__ = "videos"

    id = Column(Integer, primary_key=True)
    slug = Column(String(250), index=True)
    width = Column(Integer)
    height = Column(Integer)
    totalframes = Column(Integer)
    location = Column(String(250))
    skip = Column(Integer, default=0, nullable=False)
    perobjectbonus = Column(Float, default=0)
    completionbonus = Column(Float, default=0)
예제 #21
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from database import Column, Integer, Float, String, Boolean
from database import Model, ForeignKey, Table
from database import relationship, backref

video_evaluation_association_table = Table(
    'video_evaluation_association',
    Column('evaluation_sets_id', Integer, ForeignKey('evaluation_sets.id')),
    Column('videos_id', Integer, ForeignKey('videos.id')))

classifier_evaluation_association_table = Table(
    'classifier_evaluation_association',
    Column('evaluation_sets_id', Integer, ForeignKey('evaluation_sets.id')),
    Column('classifiers_id', Integer, ForeignKey('classifiers.id')))

video_classifier_association_table = Table(
    'video_classifier_association',
    Column('videos_id', Integer, ForeignKey('videos.id')),
    Column('classifiers_id', Integer, ForeignKey('classifiers.id')))
예제 #22
0
파일: tests.py 프로젝트: Raumo0/ByFlyPy
 def test_cant_create_table(self):
     table = Table(self.FILENAME)
     with mock.patch.object(table, '_connection') as mock_connection:
         mock_connection.execute = mock.Mock(side_effect=ValueError("1"))
         with self.assertRaises(ErrorDatabase):
             table.create_table_if_not_exists()
예제 #23
0
파일: tests.py 프로젝트: Raumo0/ByFlyPy
 def test_wrong_db_file(self):
     with mock.patch.object(database.db,
                            'connect',
                            side_effect=IOError("1")):
         with self.assertRaises(ErrorDatabase):
             table = Table(self.FILENAME)
예제 #24
0
 def _getTables(self):
     self.cursor.execute("SHOW TABLES")
     for c in self.cursor:
         self.tablesNames.append(c[0])
         self.tables[c[0]] = Table(name=c[0])
예제 #25
0
import time
import sqlite3
from database import Integer, String, Column, Table

DB_FN = 'hits.db'
db = sqlite3.connect(DB_FN)

Hits = Table(
    'hits',
    db,
    Column('ip', String()),
    Column('localip', String()),
    Column('epoch', Integer()),
    Column('request', String()),
)

Hits.create()


def insert(ip, localip, request):
    now = int(time.time())
    Hits.insert([[ip, localip, now, request]])