def reset_temp(): if os.path.isdir(temp_dir_path): Log.info("Temp directory reset...") shutil.rmtree(temp_dir_path) time.sleep(1) os.mkdir(temp_dir_path)
def download(server: FTP, from_path: str, to_dir_path: str): Log.info("Downloading {:s}@{:s} to {:s}@local...".format( from_path, server.host, to_dir_path)) if 0 < len(to_dir_path) and to_dir_path[-1] != "/": raise ValueError("target does not end in '/'.") source_dir, source_file = os.path.split(from_path) if len(source_file) < 1: target_dir_path = to_dir_path + from_path if not to_dir_path == "./": if os.path.isdir(target_dir_path): raise IOError("directory {:s}@local already exists".format( target_dir_path)) if not debug and not target_dir_path == "./": os.mkdir(target_dir_path) contents = get_server_contents(server, from_path) for each_element in sorted(contents): download(server, each_element, target_dir_path) elif not debug: with open(to_dir_path + source_file, mode="wb") as file: server.retrbinary("RETR {:s}".format(from_path), file.write)
def centre_schedule_update(self, check_asserts="true"): self.click_element('//*[@id="remarks"]') self.tab(reverse="true").send_inputs("Inactive", dropdown="true") self.tab(reverse="true").send_inputs("AM") time.sleep(1) self.tab(reverse="true").send_inputs("00") time.sleep(1) self.tab(2, reverse="true").send_inputs("04") time.sleep(2) self.tab(2, reverse="true").send_inputs("Hindi", clear="true") time.sleep(2) self.click_element() self.tab(reverse="true").send_inputs("Monday", dropdown="true") time.sleep(2) self.click_element(XPATH.BUTTON_SAVE_CENTRE_SCHEDULE) if check_asserts == "true": Log.info("\tTEST for GAWLA CENTRE , WEEK 5 Schedule\n") self.click_element(XPATH.SCREEN_LINK_ROW1_COL6) self._assert.test_element_value_xpath(XPATH.CENTRE_LOOKUP_FIELD, "Gawla") self._assert.test_dropdown_value_xpath(XPATH.WEEK_LOOKUP_FIELD, "Week 5") self._assert.test_dropdown_value_xpath(XPATH.WEEKDAY_LOOKUP_FIELD, "Monday") self._assert.test_element_value_xpath(XPATH.LANGUAGE_LOOKUP_FIELD, "Hindi") self._assert.test_element_value_xpath(XPATH.TIME, "09:30:00.000") self._assert.test_dropdown_value_xpath(XPATH.STATUS, "Inactive") self.click_element(XPATH.CLOSE_BUTTON)
def centre_update(self): self.click_element(XPATH.CURRENT_DOCUMENT_LOOKUP_FIELD) self.tab(2, reverse="true").send_inputs("789", clear="true") self.tab(reverse="true").send_inputs("12", clear="true") self.tab(reverse="true").send_inputs("Update", clear="true") self.tab(reverse="true").send_inputs("Non-Agricultural", dropdown="true") self.tab(reverse="true").send_inputs("Rented", dropdown="true") self.tab(reverse="true").send_inputs("School", dropdown="true") self.tab(reverse="true").send_inputs("Remarks: Update Testing", clear="true") self.press_button(constants.BUTTON_SAVE, self._tab) alert_text = self.get_element_value_xpath(XPATH.ALERT, by="text") Log.info("\tALERT: " + alert_text + "\n") self._assert.test_element_value_xpath(XPATH.CENTRE_LOOKUP_FIELD, self.search_input) self._assert.test_element_value_xpath( XPATH.DUTY_ALLOCATION_AREA_LOOKUP_FIELD, "Karnataka") self._assert.test_element_value_xpath(XPATH.REMARKS_LOOKUP_FIELD, "Remarks: Update Testing") self._assert.test_dropdown_value_xpath(XPATH.LAND_TYPE_LOOKUP_FIELD, "School") self._assert.test_dropdown_value_xpath( XPATH.OWNERSHIP_TYPE_LOOKUP_FIELD, "Rented") self._assert.test_dropdown_value_xpath( XPATH.NATURE_OF_LAND_LOOKUP_FIELD, "Non-Agricultural") self._assert.test_element_value_xpath(XPATH.LAND_EXTENT_LOOKUP_FIELD, "Update") self._assert.test_element_value_xpath(XPATH.LONGITUDE_LOOKUP_FIELD, "12") self._assert.test_element_value_xpath(XPATH.LATITUDE_LOOKUP_FIELD, "789")
def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.cInstance = c_instance self._suppress_send_midi = True self.endpoint = None Log.set_logger(self.log_message) Log.set_log_level(Log.LOG_WARN) Log.set_log_network(True) Log.write("-----------------------") Log.write("ShowtimeBridge starting") Log.write("Python version " + sys.version) Log.info(sys.version) # Network endpoint self.endpoint = LiveNetworkEndpoint() self.endpoint.set_song_root_accessor(LiveUtils.getSong) LiveWrapper.set_endpoint(self.endpoint) # Midi clock to trigger incoming message check self.clock = LoopingEncoderElement(0, 119) self.refresh_state() self._suppress_send_midi = False
def upload(server: FTP, from_path: str, to_dir_path: str): Log.info("Uploading {:s}@local to {:s}@{:s}...".format( from_path, to_dir_path, server.host)) if 0 < len(to_dir_path) and to_dir_path[-1] != "/": raise ValueError("target does not end in '/'.") source_dir, source_file = os.path.split(from_path) if len(source_file) < 1: target_dir_path = to_dir_path + from_path if not to_dir_path == "./": if dir_exists(server, target_dir_path): raise IOError("directory {:s}@{:s} already exists".format( target_dir_path, server.host)) if not debug and not to_dir_path == "./": server.mkd(target_dir_path) contents = get_local_contents(from_path) for each_element in sorted(contents): upload(server, each_element, target_dir_path) elif not debug: with open(from_path, mode="rb") as file: server.storbinary("STOR {:s}".format(to_dir_path + source_file), file)
def test_values(self, expected_value, actual_value): if not actual_value == expected_value: message = "EXPECTED VALUE IS: " + expected_value + " HOWEVER ACTUAL VALUE IS: " + actual_value Log.info(message) assert False, (message) else: Log.info("\tThe expected value and actual value matches: " + actual_value)
def event_received(self, event): self.requestLock = True # Lock the request loop Log.info("Received method " + event.subject[2:]) Log.info("Args are:" + str(event.msg)) try: self.incomingActions[event.subject](event.msg) except KeyError: Log.error("Nothing registered for incoming action " + event.subject)
def test_if_element_selected(self, xpath): element = self.get_element_from_xpath(xpath, constants.WAIT_FOR_PRESENCE) if not element.is_selected(): message = "\tElement was not selected" Log.info(message) assert False, message else: Log.info("\tElement was selected")
def load_config(config_path: str) -> Tuple[Dict[str, str], Dict[str, str]]: Log.info("Reading config from {:s}...".format(config_path)) with open(config_path, mode="r") as file: config = json.load(file) log_path = config["log_path"] Log.info("Setting logging output to {:s}...".format(log_path)) Log.log_path = log_path return config["remote_ftp"], config["local_ftp"]
def delete(server: FTP, file_path: str): Log.info("Deleting {:s}@{:s}...".format(file_path, server.host)) if debug or len(file_path) < 1: return file_dir, file_name = os.path.split(file_path) if len(file_name) < 1 and 0 < len(file_dir): server.rmd(file_path) else: server.delete(file_path)
def validate_same_day_duty(self, preacher_id, duty_date): Log.info("\nValidating Duties for Preacher ID: " + str(preacher_id) + " for date: " + str(duty_date)) duty_date_list = [] for roaster_obj in roaster_list: if roaster_obj.preacher_id == preacher_id and roaster_obj.duty_date == duty_date: duty_date_list.append(roaster_obj.duty_date) if len(duty_date_list) != 1: Log.error("\t Test failed, the preacher has been allotted " + len(duty_date_list) + " duties on date: " + str(duty_date)) else: Log.info("\t Validation successful, the preacher has been allotted only one duty for date: " + str(duty_date))
def get_features(self, root_info, name, cache_dir='_cache', logging=False): filename = os.path.join(cache_dir, name + '.pickle') if os.path.isfile(filename): if logging: Log.info('dump', 'Reading from {0}'.format(filename)) return self.read_from_local(filename) info = self._extract_fearutes( root_info['mat_home'], root_info['keys']) if not os.path.isdir(cache_dir): os.mkdir(cache_dir) self.dump_to_local(filename, info) return info
def check_for_duplicates(data_a, data_b, label=''): matched_elements = np.asarray([], dtype=int) for i in range(len(data_a)): for j in range(len(data_b)): if i != j and np.array_equal(data_a[i], data_b[j]): matched_elements = np.append(matched_elements, i) break if len(matched_elements) == 0: Log.info('Array checker', label + 'No dublicates found......OK!') else: Log.warning('Array ckecker', label + 'Duplicates found, check dataset!!') Log.info('Array checker', 'Duplicates: {0}'.format(matched_elements))
def get_test_sets(anls, data): train, test, labels_train, labels_test = anls.do_split(data['features'], data['labels'], test=0.5) dev = {'features': train, 'labels': labels_train} valid = {'features': test, 'labels': labels_test} Log.info( 'split', 'Normal - {0}; MCI - {1}; AD - {2}'.format( len(labels_train[labels_train == 0]), len(labels_train[labels_train == 1]), len(labels_train[labels_train == 2]))) return dev, valid
def main(): config_path = "credentials.json" while True: time.sleep(60) try: remote_config, local_config = load_config(config_path) with FTP(remote_config["url"]) as remote_ftp, FTP( local_config["url"]) as local_ftp: login_server(remote_ftp, remote_config) login_server(local_ftp, local_config) move(remote_ftp, "", local_ftp, "") except Exception as e: Log.info(str(e))
def validate_preacher_details(self, roaster_obj): Log.info("\nValidating Preacher Details for Preacher ID: " + str(roaster_obj.preacher_id) + " , language: " + roaster_obj.language) db_conn = DBBase() cursor = db_conn.execute_query((DBConstants.PREACHER_LANGUAGE).replace('$preacher_id', str(roaster_obj.preacher_id)).replace('$language', roaster_obj.language)) preacher_obj = None if cursor is not None: row = cursor.fetchone() db_conn.close(cursor) if row is not None: preacher_obj = PreacherDTO(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]) self.match_values('Active', preacher_obj.status, "ensuring the preacher assigned is in active status") self.match_values(roaster_obj.sewadar_name, preacher_obj.sewadar_name, "for sewadar name in roaster duty and preacher details") else: Log.error("Test failed, the preacher at id: " + str(roaster_obj.preacher_id) + " doesn't use the language: " + roaster_obj.language) else: Log.error("Unable to Open cursor")
def search(self, choice_no, check_asserts="true", input_value="Week 4"): super(Centre, self).search(choice_no, clear="true") self.send_inputs(input_value, XPATH.SCREENFIELD_INPUT, clear="true") self.click_element(XPATH.SCREEN_LINK_ROW1_COL6) if check_asserts == "true": Log.info("\tTEST for GAWLA CENTRE , WEEK 4 Schedule\n") self._assert.test_element_value_xpath(XPATH.CENTRE_LOOKUP_FIELD, "Gawla") self._assert.test_dropdown_value_xpath(XPATH.WEEK_LOOKUP_FIELD, "Week 4") self._assert.test_dropdown_value_xpath(XPATH.WEEKDAY_LOOKUP_FIELD, "Monday") self._assert.test_element_value_xpath(XPATH.LANGUAGE_LOOKUP_FIELD, "Hindi") self._assert.test_element_value_xpath(XPATH.TIME, "15:00:00.000") self._assert.test_dropdown_value_xpath(XPATH.STATUS, "Inactive") self.click_element(XPATH.CLOSE_BUTTON)
def validate_centre_schedule(self, roaster_obj): Log.info("\nValidating Centre details for Centre ID: " + str(roaster_obj.centre_id) + " , week: " + roaster_obj.week + " , weekday: " + roaster_obj.weekday) db_conn = DBBase() query = (DBConstants.CENTRE_ID_QUERY).replace('$centre_id', str(roaster_obj.centre_id)).replace('$weeknum', roaster_obj.week).replace('$weekday', roaster_obj.weekday) cursor = db_conn.execute_query(query) if cursor is not None: row = cursor.fetchone() db_conn.close(cursor) if row is not None: centre_obj = CentreDTO(row[0], row[1], row[2], row[3], row[4], row[5]) self.match_values('Active', centre_obj.status, "ensuring the details of centre are in active status") self.match_values(roaster_obj.centre_name, centre_obj.centre_name, "for centre name in roaster duty and centre schedule") self.match_values(roaster_obj.time, centre_obj.time, "for time details in roaster duty and centre schedule") self.match_values(roaster_obj.language, centre_obj.language, "for language in roaster duty and centre schedule") else: Log.error("Test failed, the language of centre and scheduled roaster for mentioned week, weekday and time doesn't match") else: Log.error("Unable to Open cursor")
def send_message(self, message, args): args = args if args else {} retries = 5 success = False Log.info("Publishing message " + str(message)) while retries > 0: try: self.publish(message, args) success = True except Pyro.errors.ConnectionClosedError, e: Log.error(e) Log.error( "Rebinding to server. {0} retries left.".format(str(retries))) self.adapter.rebindURI() retries -= 1 if success: break
def check_heartbeat(self): """Check if we've received a UDP heartbeat from a remote UDP endpoint""" if NetworkEndpoint.current_milli_time() > self.lastPeerHeartbeatTime + UDPEndpoint.HEARTBEAT_TIMEOUT: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.info("Heartbeat timeout") # Verify we're still talking to the same server if self.heartbeatID and self.lastReceivedHeartbeatID != self.heartbeatID: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.network( "Last heartbeat ID: %s. New heartbeat ID: %s" % (self.lastReceivedHeartbeatID, self.heartbeatID)) self.heartbeatID = self.lastReceivedHeartbeatID if self.connectionStatus == NetworkEndpoint.PIPE_DISCONNECTED: for callback in self.closingCallbacks: callback() return self.connectionStatus == NetworkEndpoint.PIPE_CONNECTED
def centre_schedule_insert(self, check_asserts): self.click_element(XPATH.CS_INSERT) time.sleep(2) self.tab().send_inputs("Week 3", dropdown="true", wait=constants.WAIT_FOR_PRESENCE_AND_CLICKABLE) time.sleep(2) self.tab().send_inputs("Friday", dropdown="true", wait=constants.WAIT_FOR_PRESENCE_AND_CLICKABLE) time.sleep(1) self.tab().send_inputs("Kannada", clear="true", wait=constants.WAIT_FOR_PRESENCE_AND_CLICKABLE) self.click_element() time.sleep(1) self.tab(1).send_inputs("01:30", clear="true") self.get_element().send_keys("PM") time.sleep(1) self.tab().send_inputs("Inactive", dropdown="true", wait=constants.WAIT_FOR_PRESENCE_AND_CLICKABLE) time.sleep(1) self.tab().send_inputs("Centre Schedule Insert Test", clear="true") time.sleep(3) self.click_element(XPATH.BUTTON_SAVE_CENTRE_SCHEDULE) if check_asserts == "true": self.click_search_button(self._tab) self.send_inputs("Week 3", XPATH.SCREENFIELD_INPUT, clear="true") self.click_element(XPATH.SCREEN_LINK_ROW1_COL6) Log.info("\tTEST for GAWLA CENTRE , WEEK 3 Schedule\n") self._assert.test_element_value_xpath(XPATH.CENTRE_LOOKUP_FIELD, "Gawla") self._assert.test_dropdown_value_xpath(XPATH.WEEK_LOOKUP_FIELD, "Week 3") self._assert.test_dropdown_value_xpath(XPATH.WEEKDAY_LOOKUP_FIELD, "Friday") self._assert.test_element_value_xpath(XPATH.LANGUAGE_LOOKUP_FIELD, "Kannada") self._assert.test_element_value_xpath(XPATH.TIME, "19:00:00.000") self._assert.test_dropdown_value_xpath(XPATH.STATUS, "Inactive") self.click_element(XPATH.CLOSE_BUTTON)
def check_heartbeat(self): """Check if we've received a UDP heartbeat from a remote UDP endpoint""" if NetworkEndpoint.current_milli_time( ) > self.lastPeerHeartbeatTime + UDPEndpoint.HEARTBEAT_TIMEOUT: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.info("Heartbeat timeout") # Verify we're still talking to the same server if self.heartbeatID and self.lastReceivedHeartbeatID != self.heartbeatID: self.connectionStatus = NetworkEndpoint.PIPE_DISCONNECTED Log.network("Last heartbeat ID: %s. New heartbeat ID: %s" % (self.lastReceivedHeartbeatID, self.heartbeatID)) self.heartbeatID = self.lastReceivedHeartbeatID if self.connectionStatus == NetworkEndpoint.PIPE_DISCONNECTED: for callback in self.closingCallbacks: callback() return self.connectionStatus == NetworkEndpoint.PIPE_CONNECTED
def _move(from_server: FTP, from_path: str, to_server: FTP, to_dir_path: str): Log.info("Moving {:s}@{:s} to {:s}@{:s}...".format(from_path, from_server.host, to_dir_path, to_server.host)) if 0 < len(to_dir_path) and not to_dir_path[-1] == "/": raise ValueError("target does not end in '/'.") from_dir, from_file = os.path.split(from_path) if 0 < len(from_file): download(from_server, from_path, temp_dir_path) temp_file_path = temp_dir_path + from_file upload(to_server, temp_file_path, to_dir_path) if debug: return Log.info("Removing temp file {:s}".format(temp_file_path)) os.remove(temp_file_path) else: if to_dir_path == from_path == "./": final_path = "./" else: final_path = to_dir_path + from_path if 0 < len(final_path) and not final_path == "./": if dir_exists(to_server, final_path): raise IOError("directory {:s}@{:s} already exists".format( final_path, to_server.host)) if not debug: to_server.mkd(final_path[:-1] if final_path[-1] == "/" else final_path) contents = get_server_contents(from_server, from_path) for each_element in sorted(contents): _move(from_server, each_element, to_server, final_path) delete(from_server, from_path)
def centre_insert(self, check_asserts): self.send_inputs(self.search_input, XPATH.CENTRE_LOOKUP_FIELD, clear="true") self.click_select_button(self._tab) self.tab(4) if not self.is_element_active(XPATH.REMARKS_LOOKUP_FIELD): self.tab() self.send_inputs("Remarks: Insert Testing", clear="true") self.tab().send_inputs("Land", dropdown="true") self.tab().send_inputs("Leased", dropdown="true") self.tab().send_inputs("Agricultural", dropdown="true") self.tab().send_inputs("Insert", clear="true") self.tab().send_inputs("123", clear="true") self.tab().send_inputs("456", clear="true") self.press_button(constants.BUTTON_SAVE, self._tab) alert_text = self.get_element_value_xpath(XPATH.ALERT, by="text") Log.info("\tALERT: " + alert_text + "\n") if not "Success" in alert_text: check_asserts = "false" if check_asserts == "true": self._assert.test_element_value_xpath(XPATH.CENTRE_LOOKUP_FIELD, self.search_input) if self.is_element_active(XPATH.DUTY_ALLOCATION_AREA_LOOKUP_FIELD): self._assert.test_element_value_xpath( XPATH.DUTY_ALLOCATION_AREA_LOOKUP_FIELD, "Karnataka") self._assert.test_element_value_xpath(XPATH.REMARKS_LOOKUP_FIELD, "Remarks: Insert Testing") self._assert.test_dropdown_value_xpath( XPATH.LAND_TYPE_LOOKUP_FIELD, "Land") self._assert.test_dropdown_value_xpath( XPATH.OWNERSHIP_TYPE_LOOKUP_FIELD, "Leased") self._assert.test_dropdown_value_xpath( XPATH.NATURE_OF_LAND_LOOKUP_FIELD, "Agricultural") self._assert.test_element_value_xpath( XPATH.LAND_EXTENT_LOOKUP_FIELD, "Insert") self._assert.test_element_value_xpath(XPATH.LONGITUDE_LOOKUP_FIELD, "123") self._assert.test_element_value_xpath(XPATH.LATITUDE_LOOKUP_FIELD, "456")
def mix_data(self, data_dict, keys, logging=False, test=None): step = len(keys) // 2 features, labels = data_dict[keys[0]], data_dict[keys[step]] for key in range(1, step): features = np.concatenate((features, data_dict[keys[key]])) labels = np.concatenate((labels, data_dict[keys[key + step]])) X_train, X_test, y_train, y_test = self.do_split( features, labels, test) if logging: Log.info( 'split', 'Train size - {0}; Test size - {1}'.format( len(y_train), len(y_test))) Log.info( 'split', 'Train:: Normal - {0}; MCI - {1}; AD - {2}'.format( len(y_train[y_train == 0]), len(y_train[y_train == 1]), len(y_train[y_train == 2]))) Log.info( 'split', 'Test:: Normal - {0}; MCI - {1}; AD - {2}'.format( len(y_test[y_test == 0]), len(y_test[y_test == 1]), len(y_test[y_test == 2]))) out_dict = { 'train': { 'features': X_train, 'labels': y_train }, 'test': { 'features': X_test, 'labels': y_test } } return out_dict
def _get_precision_reall(self, true_labels, predicted): from sklearn.metrics import precision_score, recall_score, f1_score precision = precision_score(predicted, true_labels, average='macro') recall = recall_score(predicted, true_labels, average='macro') f_score = f1_score(true_labels, predicted, average='macro') Log.info('Validation', 'Precision {0}'.format(precision)) Log.info('Validation', 'Recall {0}'.format(recall)) Log.info('Validation', 'F1 score {0}'.format(f_score)) return f_score
def toString(self): Log.info("Duty Details:") Log.info("\n\r\tDuty Chart Id: " + str(self._dutychart_id) + "\t\t\tCentre Id: " + str(self._centre_id) + "\t\tCentre Name: " + str(self._centre_name) + "\t\tPreacher Id: " + str(self._preacher_id) + "\tSewadar Name: " + str(self._sewadar_name)) Log.info("\n\r\tDuty Date: " + str(self._duty_date) + "\t\tWeek: " + str(self._week) + "\t\tWeekday: " + str(self._weekday)[:3] + "\t\t\tTime: " + str(self._time) + "\tLanguage: " + str(self._language))
def _get_classifier(self, type, k=3): if type.lower() == 'knn': Log.info('Model info', 'Nearest Neighbor Classifier has been selected') clf = KNeighborsClassifier(n_neighbors=k, algorithm='kd_tree') elif type.lower() == 'svm': Log.info('Model info', 'Support vector machine has been selected') tuned_param = { 'C': [0.1, 10, 10, 50, 100], 'gamma': [0.001, 0.01, 0.1, 0.2] } clf = GridSearchCV(SVC(kernel='rbf', decision_function_shape='ovr', random_state=0, probability=True), tuned_param, cv=5) elif type.lower() == 'lin_svm': Log.info('Model info', 'Linear Support Vector machine has been selected') clf = OneVsRestClassifier(LinearSVC(random_state=0, C=5)) elif type.lower() == 'lgr': Log.info('Model info', 'Logistic regression has been selected') tuned_param = { 'C': [0.01, 0.1, 10, 10, 100, 200], 'solver': ['newton-cg', 'lbfgs'] } f1_scorer = make_scorer(f1_score, pos_label='0') clf = GridSearchCV(LogisticRegression(), param_grid=tuned_param, cv=5) elif type.lower() == 'xgb': tuned_param = { 'max_depth': [5], 'n_estimators': [20, 300], 'learning_rate': [0.01, 0.4], 'silent': [1.0], 'gamma': [0.01, 0.1, 0.5] } model = xgb.XGBClassifier(seed=42, objective='multi:softmax') clf = GridSearchCV(model, param_grid=tuned_param, cv=5) return clf
def validate_preacher_leaves(self, roaster_obj): duty_date = roaster_obj.duty_date Log.info("\nValidating Preacher Leaves for Preacher ID: " + str(roaster_obj.preacher_id) + " for duty date: " + str(duty_date)) db_conn = DBBase() cursor = db_conn.execute_query((DBConstants.PREACHER_LEAVES).replace('$preacher_id', str(roaster_obj.preacher_id))) i = 0 if cursor is not None: for row in cursor.fetchall(): i = i + 1 from_date = row[1] till_date = row[2] Log.info("\tPreacher is on leave from date: " + str(from_date) + " till date: " + str(till_date)) if from_date<=duty_date and duty_date<=till_date: Log.error("The Duty date: " + duty_date + " is during preacher leave period from date: " + str(from_date) + " till date: " + str(till_date)) else: Log.info("The duty date doesn't fall under the leave period from date: " + str(from_date) + " till date: " + str(till_date)) db_conn.close(cursor) if i==0 : Log.info("Validation not needed, the preacher has not applied for any leaves") else: Log.error("Unable to Open cursor")
def load_list(self): db_conn = DBBase() cursor = db_conn.execute_query(DBConstants.ROASTER_QUERY) if cursor is not None: for row in cursor.fetchall(): roaster_obj = RoasterDTO(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9]) roaster_list.append(roaster_obj) db_conn.close(cursor) Log.info("\n\r ROASTER TESTING ") #for roaster_obj in roaster_list: if roaster_obj is not None: Log.info("\n\r*********************START OF RECORD**************************") roaster_obj.toString() self.validate(roaster_obj) Log.info("\n\r*********************END OF RECORD****************************\n\r")
def mix_data(data, keys, logging=False, test_frac=0.1): """ Method to pack all data and split it in the train and test sets Output forma is dict with – "train" and "test" fields """ assert isinstance(data, dict), 'Data has to be a dictionary' assert isinstance(keys, list), 'Keys has to be a list' step = len(keys) // 2 features, labels = data[keys[0]], data[keys[step]] for key in range(1, step): features = np.concatenate((features, data[keys[key]])) labels = np.concatenate((labels, data[keys[key + step]])) X_train, X_test, y_train, y_test = train_test_split(features, labels, test_size=test_frac, random_state=42) if logging: Log.info( 'split', 'Train size - {0}; Test size - {1}'.format(len(y_train), len(y_test))) Log.info( 'split', 'Train:: Normal - {0}; MCI - {1}; AD - {2}'.format( len(y_train[y_train == 0]), len(y_train[y_train == 1]), len(y_train[y_train == 2]))) Log.info( 'split', 'Test:: Normal - {0}; MCI - {1}; AD - {2}'.format( len(y_test[y_test == 0]), len(y_test[y_test == 1]), len(y_test[y_test == 2]))) out_dict = { 'train': { 'features': X_train, 'labels': y_train }, 'test': { 'features': X_test, 'labels': y_test } } return out_dict
def __init__(self, c_instance): ControlSurface.__init__(self, c_instance) with self.component_guard(): self.cInstance = c_instance self._suppress_send_midi = True Log.set_logger(self.log_message) Log.set_log_level(Log.LOG_WARN) Log.write("-----------------------") Log.write("ShowtimeBridge starting") Log.info(sys.version) self.initPyroServer() # Register methods to the showtimebridge server wrapperClasses = PyroWrapper.__subclasses__() wrapperClasses.append(PyroWrapper) for cls in wrapperClasses: cls.clear_instances() cls.register_methods() for action in cls.incoming_methods().values(): Log.info("Adding %s to incoming callbacks" % action.methodName) self.subscriber.add_incoming_action(action.methodName, cls, action.callback) self.publisher.register_to_showtime(action.methodName, action.methodAccess, action.methodArgs) for action in cls.outgoing_methods().values(): Log.info("Adding %s to outgoing methods" % action.methodName) self.publisher.register_to_showtime(action.methodName, action.methodAccess) # Midi clock to trigger incoming message check self.clock = PyroEncoderElement(0, 119) # Create the root wrapper PyroSong.add_instance(PyroSong(getSong())) self.refresh_state() self._suppress_send_midi = False
def event(self, event): self.requestLock = True # Lock the request loop Log.info("Received method " + event.subject[2:]) Log.info("Args are:" + str(event.msg)) self.incomingSubscriptions[event.subject]["function"](event.msg)
def build_midi_map(self, midi_map_handle): Log.info("Building midi map...") ControlSurface.build_midi_map(self, midi_map_handle)