def select_videoType(self): """ Select video type and write into config file :return: """ type = self.chooseVideoType.currentText() C.set_config_file("global setting", "default_video_source", type)
def start_detect(self): """ Deal with detect prepare job :return: """ if not hp.dir_exist(C.DEFAULT_RESULT_PATH): self.statusbar.showMessage('No my_dataset/ exist!Use 快速部署 first.') return self.statusBrowser.clear() self.progressBar.reset() if self.mode == 'image' and self.image_mode == 'single': # only predict by one zebra when image is only single self.chooseZebraCombo.setCurrentIndex(0) if not self.image_path == '': self.do_detect() self.statusBar().showMessage('single image predict success') else: self.statusbar.showMessage('Choose image first') elif self.mode == 'image' and self.image_mode == 'directory': self.do_detect() self.statusBar().showMessage('open up result path success') self.open_up_desktop_files(C.DEFAULT_RESULT_PATH) elif self.mode == 'video': # change videoType as soon as possible self.select_videoType() C.read_config_file() if self.chooseVideoType.currentText() == 'video_file': base_path = C.DEFAULT_VIDEO_PATH if self.chooseZebraCombo.currentText() == 'one_zebra': self.tag = 'people' self.video_source = base_path + self.tag + '.mp4' self.chooseZebraCombo.setCurrentIndex(0) self.showFrame() elif self.chooseZebraCombo.currentText() == 'tri_zebra' or \ self.chooseZebraCombo.currentText() == 'rec_zebra': print('Read people video first...') self.tag = 'people' self.video_source = base_path + self.tag + '.mp4' self.showFrame() print('Read cars video then...') self.tag = 'cars' self.video_source = base_path + self.tag + '.mp4' self.showFrame() elif self.chooseVideoType.currentText() == 'camera': # only support one zebra for now self.tag = 'people' self.video_source = 0 self.showFrame() self.do_detect() self.statusBar().showMessage('open up result path success') self.open_up_desktop_files(C.DEFAULT_RESULT_PATH)
def populate_config(conn: Connection, config: Config): """ This function is responsible for adding the already present courses to the config. THIS FUNCTION MUTATES THE config PARAM :param conn: DB connection :param config: Moodle configuration """ rows = get_config_courses(conn, config.id) # Create the courses and populate each one # TODO test this code for row in rows: course = Course.create_from_db(row) # Create the sections and populate each one rows_sections = get_course_sections(conn, config.id, course.id) for r_section in rows_sections: section = Section.create_from_db(r_section) # Add the LinkableContents section.modules = __get_linkablecontents(conn, config.id, section.id, True) # Create the modules, populate each one and add them to the section rows_modules = get_section_modules(conn, config.id, section.id) for r_module in rows_modules: module = Module.create_from_db(r_module) # Add the LinkableContents module.contents = __get_linkablecontents( conn, config.id, module.id, False) # Add the Files rows_files = get_module_files(conn, config.id, module.id) for r_file in rows_files: module.add_content( File.create_file_or_linkablecontent(r_file)) # Add the module to the section section.add_module(module) # Add the section to the course course.add_section(section) # Add the course to the config config.add_course(course)
def first_run() -> (list, Connection): """ This function is launched when the app starts and makes sure that everything is properly setup. If everything ran correctly, it returns the token. Otherwise it stops the application. """ conn = create_connection() db_configs = read_configs(conn) # Create the state and the config objects and populate them with their data state = [] for db_config in db_configs: config = Config.create_from_db(db_config) populate_config(conn, config) # Get the token token = login(config) if token != UNABLE_TO_LOGIN: config.token = token else: logging.error(ERROR_STRINGS[token]) sys.exit(-1) # Check if the userid is still the same, if it isn't update in the DB userid = get_site_info(config) config.userid = userid # Check if the userid was correctly set if config.userid == userid: # Update to the new userid update_config_userid(conn, config.id, userid) state.append(config) return state, conn
def __init__(self, **kwargs): super().__init__(**kwargs) self.screens = {} self.available_screens = {} Active.cl = ClientList Active.confList = Config() Active.qrList = list() Active.scanList = list() Active.scan_task = TaskScan() Active.qr_task = TaskQR() Active.conf_task = TaskConfig()
def __init__(self): self._config = Config() self._worker_manager = DefaultWorkerManager(self._config, self._config.db_name) if self._get_num_current_workers() < self._config.min_workers: self._worker_manager.set_workers_available( self._config.min_workers) try: while True: time.sleep(10) self.do_some_work() except KeyboardInterrupt: # return gracefully. pass
def __add_new_courses(conn: Connection, state: Config, courses: Dict[int, str]) -> list: """ This function is responsible for finding new courses, adding them to the DB and downloading them if the user wants :param state: The current moodle state :param courses: List of all the courses. The id is the key, and the shortname the value :return: A list of the new courses ids """ # Check for new courses and store them new_courses = __check_courses_differences(state, courses.keys()) # Add the new courses to the state and stored them in the DB for c_id in new_courses: # Create the course and populate ir course = Course(c_id, courses[c_id], state.default_action == "download") content = get_course_contents(state, c_id) course.read_json_contents(content) state.add_course(course) # DB insert_course(conn, course, state.id) # Download the courses or notify if state.default_action == 'notify': # Notify logging.warning( "New courses were found, please check which contents you want to download." ) elif state.default_action == 'download': # Download logging.info("Downloading") for course_key in state.courses: course = state.courses[course_key] download_course(course, state) return new_courses
from server.EventProcessor import EventProcessor from server.DefaultComputeManager import DefaultComputeManager from server.DefaultWorkerManager import DefaultWorkerManager from storage.DatabaseStorage import DatabaseStorage from celery.task.control import discard_all from model.Config import Config from flask import session, redirect, url_for, \ render_template, flash import json from utils import DBUtil app = Flask(__name__, template_folder="web/templates", static_folder="web/static") config = Config() SECRET_KEY = config.secret_key app.config.from_object(__name__) kv_storage = DatabaseStorage(config.db_name) worker_manager = DefaultWorkerManager(config, config.db_name) comp_manager = DefaultComputeManager(worker_manager,kv_storage, config) @app.route('/interface', methods=['GET']) def web_interface(): return send_file("interface.html") @app.route("/job", methods=['POST', 'GET']) def create_job(): user_params = UserParameters()
def post(self): times = [] data = [] ##### 设置安全cookie 和权限标记cookie self.Username = self.get_secure_cookie("Username") self.Flag = self.get_secure_cookie("Flag") self.set_secure_cookie("Username", self.Username, expires_days=None) self.set_secure_cookie("Flag", self.Flag, expires_days=None) ts = time.strftime('%Y-%m-%d', time.localtime(time.time())) #print ts ####设置时间段#### stime = "000001" etime = "010000" ####前后台交互定义 self.selectp = self.get_argument('selectp') self.selectc = self.get_argument('selectc') self.time = self.get_argument('time') #print self.time if self.selectp == '0' or self.selectc == '0' or self.time == '': ####查询为空上传值 times = [0] data = [0] devname = '查无数据' content = '' time_data = '' ##### 设置安全cookie 和权限标记cookie self.Username = self.get_secure_cookie("Username") self.Flag = self.get_secure_cookie("Flag") self.set_secure_cookie("Username", self.Username, expires_days=None) self.set_secure_cookie("Flag", self.Flag, expires_days=None) ts = time.strftime('%Y-%m-%d', time.localtime(time.time())) self.render('charts.html', times=times, data=data, content=content, devname=devname, time_data=time_data, ts=ts, Username=self.Username, User_Flag=self.Flag) else: ####提取时间信息#### time_data = self.time time_s = time_data.replace('-', '') time_url = "start=%sT%s&end=%sT%s" % (time_s, stime, time_s, etime) ####提取设备名称和编号#### sp_url = self.selectp sc_url = self.selectc ####提取IP变量 Block_Name = 'StoneRestful' Block_Value = 'rest_url' config = Config() ip_address = config.Read_Config(1, Block_Name, Block_Value) defined = "%s/v1.0/stonefab/0001/hsdata/device/%s/%s?%s" % ( ip_address, sp_url, sc_url, time_url) defined_url = defined.encode("utf-8") ####获取JSON数据 urlJsonApi = UrlJsonApi() getvalue = urlJsonApi.url_method(1, defined_url) ####提取数据####a是总数据 b是时间数据 c是列表数据 a = json.loads(getvalue) b = a['times'] c = a['data'] ####设备列表 content = a['content'] ####设备名称 devname = a['devname'] ####图表X轴数据 for a1 in b: times.append(a1) print times ########################## ####图表Y轴数据 for a2 in c: data.append(a2) print data ####处理数据传到前台#### self.render('charts.html', a1=a1, a2=a2, times=times, data=data, content=content, devname=devname, time_data=time_data, ts=ts, Username=self.Username, User_Flag=self.Flag)
runner_path = dirname(abspath(__file__)) def get_path(relative_path): return abspath(join(runner_path, relative_path)) # COLLECT GLOBAL INFORMATION FROM SOURCES ##################################### # VERSION with open(get_path('../VERSION'), 'r') as version_file: version = version_file.read().replace('\n', '').strip() # CONFIG config_path = get_path('config') config = Config(directory=config_path) # DOWNLOADS downloads_path = get_path('../build') downloads_files = [ f for f in listdir(downloads_path) if isfile(join(downloads_path, f)) ] # NEWS news_path = get_path('news') news = NewsCollection(directory=news_path) # SETUP FLASK ENGINE ########################################################## app = Flask(__name__)