Пример #1
0
    def test_aggregate_table(self):
        """Insert 47 datasets from ID 10 and test against this """
        _id = 10
        sampling = 1 # seconds
        src = "Profiles_060_WTH_STATIC_EL90"
        dest = "Profiles_060_WTH_STATIC_EL90_Images_1_TEST"
        con = db.connect("cube", "cube", "HDCP2")

        self.assertEqual(True, image.aggregate_table(con, _id, sampling, src, dest))
        self.cursor.execute("SELECT COUNT(img_id) FROM `Profiles_060_WTH_STATIC_EL90_Images_1_TEST`")
        total = self.cursor.fetchone()
        self.assertEqual(47, total[0])
Пример #2
0
 def test_aggregate_stitch(self):
     """Stitch 47 images (1 minute) from 2826 rows (1 sec) """
     _id = 8
     sampling = 60
     src = "Profiles_060_WTH_STATIC_EL90"
     onesec = "Profiles_060_WTH_STATIC_EL90_IM_S1_8000_JET"
     dest = "Profiles_060_WTH_STATIC_EL90_Images_60_TEST"
     con = db.connect("cube", "cube", "HDCP2")
     
     self.assertEqual(True, image.aggregate_table_stitch(con, _id, sampling, src, onesec, dest))
     self.cursor.execute("SELECT COUNT(img_id) FROM `Profiles_060_WTH_STATIC_EL90_Images_60_TEST`")
     total = self.cursor.fetchone()
     self.assertEqual(48, total[0])
Пример #3
0
    def setUp(self):
        """Setup a connection to database """
        self.db = db.connect("cube", "cube", "HDCP2")
        self.cursor = self.db.cursor()
        self.cursor.execute("DROP TABLE IF EXISTS Profiles_060_WTH_STATIC_EL90_Images_1_TEST")
        self.cursor.execute("DROP TABLE IF EXISTS Profiles_060_WTH_STATIC_EL90_Images_60_TEST")
        self.cursor.execute("""DROP TABLE IF EXISTS 
                              `Profiles_060_WTH_STATIC_EL90_Images_3600_TEST`""")
        self.cursor.execute("""CREATE TABLE 
                               Profiles_060_WTH_STATIC_EL90_Images_1_TEST (
                                   img_id int AUTO_INCREMENT, 
                                   timestamp BIGINT(20),
                                   width int,
                                   height int, 
                                   image BLOB, 
                                   P_Id int,
                                   RG_start DOUBLE(5,2),
                                   RG_end DOUBLE(5,2),
                               PRIMARY KEY (img_id), 
                               FOREIGN KEY (P_Id) 
                               REFERENCES Profiles_060_WTH_Event(Id))""")

        self.cursor.execute("""CREATE TABLE 
                               Profiles_060_WTH_STATIC_EL90_Images_60_TEST (
                                   img_id int AUTO_INCREMENT, 
                                   timestamp BIGINT(20),
                                   width int,
                                   height int, 
                                   image BLOB, 
                                   P_Id int,
                                   RG_start DOUBLE(5,2),
                                   RG_end DOUBLE(5,2),
                               PRIMARY KEY (img_id), 
                               FOREIGN KEY (P_Id) 
                               REFERENCES Profiles_060_WTH_Event(Id))""")

        self.cursor.execute("""CREATE TABLE 
                               Profiles_060_WTH_STATIC_EL90_Images_3600_TEST (
                                   img_id int AUTO_INCREMENT, 
                                   timestamp BIGINT(20),
                                   width int,
                                   height int, 
                                   image BLOB, 
                                   P_Id int,
                                   RG_start DOUBLE(5,2),
                                   RG_end DOUBLE(5,2),
                               PRIMARY KEY (img_id), 
                               FOREIGN KEY (P_Id) 
                               REFERENCES Profiles_060_WTH_Event(Id))""")

        self.db.commit()
Пример #4
0
    def test_slice_array(self):
        tablename = "Profiles_060_WTH"
        start = 1369753484783000
        end = 1369753489783000
        gate = 2500
        con = db.connect("cube", "cube", "HDCP2")

        im = image.get_image_strip(con, tablename, start, end)
        #print im
        im_a = create_opencv_image_from_stringio(im["image"])
        #print im_a
        #cv2.imwrite("./b.png", im_b)
        im_b = cv2.imread("img/b.png")
        im_new = []
        for item in im_b:
            tmp = []
            for unit in item:
                tmp.append(unit[0])
            im_new.append(tmp)
        im_b = np.asarray(im_new)
        self.assertEqual(0, mse(im_a, im_b))
Пример #5
0
from radar import db, event
import time


user = "******"
password = "******"
database = "HDCP2"
tablename = "Profiles_060_WTH"
tablename_event = tablename + "_Event"

if not event.table_event_exist(user, password, database, tablename_event):
    db = db.connect(user, password, database)
    cursor = db.cursor()
    cursor.execute("CREATE TABLE " + tablename + "_Event (Id INT PRIMARY KEY AUTO_INCREMENT, \
                                 ts_start BIGINT(20), \
                                 ts_end BIGINT(20), \
                                 az_start DECIMAL(10,4), \
                                 az_end DECIMAL(10,4), \
                                 az_rate DECIMAL(10,4), \
                                 el_start DECIMAL(10,4), \
                                 el_end DECIMAL(10,4), \
                                 el_rate DECIMAL(10,4), \
                                 az_target DECIMAL(10,4), \
                                 el_target DECIMAL(10,4), \
                                 mode VARCHAR(8), \
                                 total INT)")
    db.commit()

column_definition = {"azimuth_mean": "WTH.HYB.A.AZM.001.INST",
                     "azimuth_target": "WTH.HYB.A.AZT.001.INST",
                     "azimuth_rate": "WTH.HYB.A.AZR.001.INST",
from radar import db, image
from PIL import Image
import time

con = db.connect("cube", "cube", "HDCP2")
cursor = con.cursor()
cursor.execute("SELECT Id FROM SE90_060_WTH")

sampling = 60 # seconds
src = "SE90_060_WTH"
# NEVER DROP THIS TABLE
onesec = "SE90_060_WTH_IM_S1_8000_JET_M6"
dest = "SE90_060_WTH_IM_S1_8000_JET_M6_ST60"

"""CREATE TABLE 
       SE90_060_WTH_IM_S1_8000_JET_M6_ST60 (
           img_id int AUTO_INCREMENT, 
           timestamp BIGINT(20),
           width int,
           height int, 
           image BLOB, 
           P_Id int,
           RG_start DOUBLE(5,2),
           RG_end DOUBLE(5,2),
       PRIMARY KEY (img_id), 
       FOREIGN KEY (P_Id) 
   REFERENCES Profiles_060_WTH_Event(Id))"""

tstart = time.time()

row = cursor.fetchone()
import os.path
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))

from radar import db, image
import cv2
import numpy as np


def create_opencv_image_from_stringio(img_stream, cv2_img_flag=1):
    img_stream.seek(0)
    img_array = np.asarray(bytearray(img_stream.read()), dtype=np.uint8)
    return cv2.imdecode(img_array, cv2_img_flag)


tablename = "Profiles_060_WTH"
# 5 secs
start = 1369753484783000
end = 1369753489783000
#gate = 2500        

con = db.connect("cube", "cube", "HDCP10")

im= image.get_image_strip(con, tablename, start, end)

im_a = create_opencv_image_from_stringio(im["image"])

print im["first"], im["last"]

cv2.imwrite("./test.png", im_a)
Пример #8
0
 def test_wrong_credentials(self):
     """Raise on wrong credentials """
     self.assertRaises(OperationalError, lambda: db.connect("bla", "bla", "bla"))
Пример #9
0
 def setUp(self):
     """Setup a connection to database """
     self.db = db.connect("cube", "cube", "HDCP10")