Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/api_separation'
Browse files Browse the repository at this point in the history
  • Loading branch information
jabb1123 committed Jan 18, 2017
2 parents 6dc8a54 + b4024d7 commit c9c3b37
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 63 deletions.
27 changes: 4 additions & 23 deletions application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ class Organizer(object): # TODO: Phase out.
def __init__(self):
super(Organizer, self).__init__()


class MainGUI(QtGui.QMainWindow):

def __init__(self):
super(MainGUI, self).__init__()
self.ui = Ui_TransportationSafety()
self.ui.setupUi(self)
self.newp = pm.ProjectWizard(self)
self.api = capi.CloudWizard('server','192.168.1.1')
self.api = capi.CloudWizard('server',None,'192.168.1.1')

# Experimenting with organizational objects
self.feature_tracking = Organizer()
Expand Down Expand Up @@ -200,33 +199,15 @@ def images_exist(self, folder):
return True
return False


def upload(self):
project_name = ac.CURRENT_PROJECT_PATH.split('/')[-1].strip('/')
homography_path = os.path.join(ac.CURRENT_PROJECT_PATH, "homography")

video_extn = ac.CURRENT_PROJECT_VIDEO_PATH.split('.')[-1]

files = {
'homography/aerial.png': open(os.path.join(homography_path, "aerial.png"), 'rb'),
'homography/camera.png': open(os.path.join(homography_path, "camera.png"), 'rb'),
'homography/homography.txt': open(os.path.join(homography_path, "homography.txt"), 'rb'),
'project_name.cfg': open(os.path.join(ac.CURRENT_PROJECT_PATH, project_name + ".cfg"), 'rb'),
'tracking.cfg': open(os.path.join(ac.CURRENT_PROJECT_PATH, "tracking.cfg"), 'rb'),
'.temp/test/test_object/object_tracking.cfg': open(os.path.join(ac.CURRENT_PROJECT_PATH, ".temp/test/test_object/object_tracking.cfg"), 'rb'),
".temp/test/test_feature/feature_tracking.cfg": open(os.path.join(ac.CURRENT_PROJECT_PATH, ".temp/test/test_feature/feature_tracking.cfg"), 'rb'),
# TODO(rlouie): do video uploading request in a streaming way
'video.%s'%video_extn : open(ac.CURRENT_PROJECT_VIDEO_PATH, 'rb')
}
r = requests.post('http://localhost:8888/upload', files=files)

# for the run button
def run(self):
"""
Runs TrafficIntelligence trackers and support scripts.
"""
# create test folder
self.upload()
self.api.upload()

return

i = raw_input("")

Expand Down
3 changes: 0 additions & 3 deletions application/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

class AppConfig(object):
PROJECT_DIR = None
TI_INSTALL_DIR = None
# TODO: Link CURRENT_PROJECT_* with a @property.setter which automatically sets all from one, (e.g., set all using just folder dir)
CURRENT_PROJECT_PATH = None # Path to base of currently open project's folder
CURRENT_PROJECT_NAME = None
CURRENT_PROJECT_CONFIG = None # Path
Expand All @@ -20,7 +18,6 @@ def load_application_config(cls):
config_parser = SafeConfigParser()
config_parser.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".application"))
cls.PROJECT_DIR = config_parser.get("info", "default_project_dir")
cls.TI_INSTALL_DIR = config_parser.get("info", "ti_install_dir")

# TODO: class method for writing to application config file

Expand Down
82 changes: 45 additions & 37 deletions application/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
import os
import pickle
import uuid
import requests

def CloudWizard(api_type,project_path,*arg):
print arg
if api_type == 'server':
print "SERVER"
return TrafficCloud_Server(project_path,arg[0])
if api_type == 'local':
print "LOCAL"
return TrafficCloud_Local(project_path)

class TrafficCloud_Abstract:

def __init__(self,project_path):
def CloudWizard(ip_addr,*arg):
return TrafficCloud(ip_addr)
class TrafficCloud:
def __init__(self,ip_addr):
#TODO: Needs to be done in sync with server
# not a uuid creation
self._ids = self.readIds()
self.project_path = project_path
self._ids[self.project_path] = uuid.uuid4()
self._writeIds()
#self._ids = self.readIds()
#self.project_path = project_path
#self._ids[self.project_path] = uuid.uuid4()
#self._writeIds()
if ip_addr == 'localhost':
self.server_ip = '127.0.0.1'
else:
self.server_ip = ip_addr


def _initializeIds(self):
with open('.IDdict','wb') as blank_dict_file:
Expand All @@ -44,7 +42,32 @@ def _writeIds(self):
return self._initializeIds()

def uploadFiles(self, types, paths, callback):
raise NotImplementedError("uploadFiles not yet implemented")
project_name = ac.CURRENT_PROJECT_PATH.strip('/').split('/')[-1]
homography_path = os.path.join(ac.CURRENT_PROJECT_PATH, "homography")

video_extn = ac.CURRENT_PROJECT_VIDEO_PATH.split('.')[-1]

with open(os.path.join(homography_path, "aerial.png"), 'rb') as hg_aerial,\
open(os.path.join(homography_path, "camera.png"), 'rb') as hg_camera,\
open(os.path.join(homography_path, "homography.txt"), 'rb') as hg_txt,\
open(os.path.join(ac.CURRENT_PROJECT_PATH, project_name + ".cfg"), 'rb') as cfg_prname,\
open(os.path.join(ac.CURRENT_PROJECT_PATH, "tracking.cfg"), 'rb') as cfg_track,\
open(os.path.join(ac.CURRENT_PROJECT_PATH, ".temp/test/test_object/object_tracking.cfg"), 'rb') as test_obj,\
open(os.path.join(ac.CURRENT_PROJECT_PATH, ".temp/test/test_feature/feature_tracking.cfg"), 'rb') as test_track,\
open(ac.CURRENT_PROJECT_VIDEO_PATH, 'rb') as video:

files = {
'homography/aerial.png': hg_aerial,
'homography/camera.png': hg_camera,
'homography/homography.txt': hg_txt,
'project_name.cfg': cfg_prname,
'tracking.cfg': cfg_track,
'.temp/test/test_object/object_tracking.cfg': test_obj,
".temp/test/test_feature/feature_tracking.cfg": test_track,
'video.%s'%video_extn : video
}
r = requests.post("http://" + self.server_ip + '/upload',files = files)
print r.text;

def testFeatureAnalysis(self, config, frames, callback):
raise NotImplementedError("testFeatureAnalysis not yet implemented")
Expand All @@ -70,27 +93,12 @@ def getStatus(self, callback):
def generateDefaultConfig(self, callback):
raise NotImplementedError("generateDefaultConfig not yet implemented")

class TrafficCloud_Local(TrafficCloud_Abstract):
def __init__(self,project_path):
TrafficCloud_Abstract.__init__(self, project_path)


class TrafficCloud_Server(TrafficCloud_Abstract):
def __init__(self,project_path,s_ip):
TrafficCloud_Abstract.__init__(self, project_path)
if s_ip == 'localhost':
self.server_ip = '127.0.0.1'
else:
self.server_ip = s_ip

#FOR TESTING PURPOSES ONLY
if __name__ == '__main__':
server = CloudWizard('server',"/project/path/server",'192.168.1.1')
local_server = CloudWizard('server',"/project/path/local_server",'localhost')
local = CloudWizard('local',"/project/path/local")
remote = CloudWizard('10.7.90.25')
local = CloudWizard('localhost')
#server = TrafficCloud_Server("/project/path/goes/ahere","localhost")
print server.server_ip
print server.readIds()
print local_server.server_ip
print local_server.readIds()
print remote.server_ip
print remote.readIds()
print local.server_ip
print local.readIds()

0 comments on commit c9c3b37

Please sign in to comment.