def __init__(self): ModuleBase.__init__(self) Cacher.__init__(self) ChannelsBase.__init__(self) Analytics.__init__(self) socket.setdefaulttimeout(5) self.max_time_drift = int( config.plugins.seriesplugin.max_time_drift.value) * 60 self.name = "" self.begin = None self.end = None self.channel = "" self.ids = [] self.knownids = [] self.returnvalue = None self.search_depth = 0 self.now = time() today = datetime.today() self.actual_month = today.month self.actual_year = today.year
def __init__(self): ModuleBase.__init__(self) Cacher.__init__(self) ChannelsBase.__init__(self) Analytics.__init__(self) socket.setdefaulttimeout(5) self.max_time_drift = int(config.plugins.seriesplugin.max_time_drift.value) * 60 self.name = "" self.begin = None self.end = None self.channel = "" self.ids = [] self.knownids = [] self.returnvalue = None self.search_depth = 0; self.now = time() today = datetime.today() self.actual_month = today.month self.actual_year = today.year
def analyticsMeanTest(): print("Running analytics mean test") a = Analytics('beverage') a.transaction(cart) if (a.getMean() == 2): return 'pass' else: return 'false'
def analyticsTransactionTest(_type, _quantity): print("Running analytics transaction test for", _type, _quantity) a = Analytics(_type) items = a.transaction(cart) if (items == _quantity): return 'pass' else: return 'fail'
def analyticsCategoryTest(): print("Running analytics category test") a = Analytics("Baseball") cat = a.getCategory() if ("Baseball" in cat): return 'pass' else: return 'fail'
def analyticsPerSecondTest(): print("Running analytics per sec test") a = Analytics('fruit') a.transaction(cart) time.sleep(1) ps = a.catPerSecond() if (round(ps, 0) == 17): return 'pass' else: return 'false'
def start_App(sc): print("******************************************* Job Started at {} **". format(datetime.now())) Analytics().run_Analytic_Engine() print( "******************************************* Job Finished at {} **", datetime.now()) scheduler_obj.enter(int(config['Start_Delay']), int(config['Interval']), start_App, (sc, ))
def project(): pr = Processor() pr.read_data('presidential_polls.csv') pr.draw_visualization() new_df = pr.clean_prepare_data() an = Analytics(new_df) X, y, X_train, X_test, y_train, y_test = an.test_train_data() log_model, logistic_model_pred, logistic_model_prob = an.logistic_model( X_train, y_train, X_test) desc_model, decision_model_pred, decision_model_prob = an.decision_tree_model( X_train, y_train, X_test) an.cross_validation(log_model, X, y, desc_model) an.accuracy(y_test, logistic_model_pred, logistic_model_prob, decision_model_pred, decision_model_prob)
def runStrategy(self, ticker, merged): print '\nRunning strategy on ' + ticker + '..' time.sleep(2) # First, do analytics to figure out how to execute the strategy. # Return lagged correlations and (10dayMA) of those lagged correlations. analyticsObj = Analytics() s_p_r_ma = analyticsObj.getAnalytics(ticker, merged) # Second, determine the position. positionObj = Position() s_p_r_ma_pos = positionObj.getPosition(ticker, s_p_r_ma) # Third, run the strategy! # Return a performance list (with dates?) strategyObj = RunStrategy() strategyResults = strategyObj.getResults(ticker, s_p_r_ma_pos) # Fourth, determine the metrics. metricsObj = StrategyMetrics() metrics = metricsObj.getStrategyMetrics(ticker, strategyResults, s_p_r_ma_pos) return metrics
def get_total_metrics_from_org_id(self, id): org = self.get_organzation_by_id(id) analytics = Analytics() with DB.cursor() as cursor: query = "SELECT SUM(donation_amount) as total_raised, COUNT(*) as number_of_donations, COUNT(DISTINCT user_id) as number_of_pledges FROM pledge_submissions WHERE organization_id = %s" print(query) cursor.execute(query, (org.id)) result = cursor.fetchone() DB.commit() analytics.set_progress(result) analytics.set_goals(org) return analytics
from Serial import Serial from RCRFile import File from Analytics import Analytics #Don't forget to update the serial port location!! serial_port = Serial('COM8') header = ["time", "response"] data_file = File(header=header) serial_port.listen_and_log(data_file) Analytics.sr_test(data_file) data_file.close() try: while True: pass except KeyboardInterrupt: pass
SOCKET_HOST = 'http://eval.socket.nio.works' def clear_screen(): print(chr(27) + "[2J") _unused = os.system("clear") def signal_handler(signal, frame): print('\r\nShutting down... please wait.') sys.exit(0) signal.signal(signal.SIGINT, signal_handler) fruitAnalytics = Analytics("fruit") def handle_message(message, *args): """ Called whenever a message comes through the socket. Args: message (str): The message we just received *args: Any additional arguments received, likely will be empty """ parsedMessage = json.loads(message) amount = parsedMessage['amount'] cart = parsedMessage['cart'] shopper = parsedMessage['shopper']
def main(): settings = Settings() analytics = Analytics() novelty = Novelty() cmd_line_args_success = settings.update_command_line_args() if not cmd_line_args_success: return print("Settings:" + "\n".join([f"{i} : {j}" for i, j in vars(settings).items()])) hws = [ Hardware(None, i, settings.min_program_length, settings.max_program_length) for i in range(settings.pop_size) ] game = FlappyDarwin( hws, settings.ticks_per_update, settings.num_tests if settings.selection == "lexicase" else 1, (lambda: 0) if settings.fitness == "novelty" else (lambda: time())) inst_lib = generate_inst_lib(game) for hw in hws: hw.inst_lib = inst_lib [hw.generate_program() for hw in hws] best_fitness = [0] fitness_data = [] gen = 1 if settings.save_file: print(F"LOADING FROM EXISTING SAVED GP FILE: {settings.save_file}") hws, gen, gen_finished_test = load_programs(inst_lib, settings) game.generation = gen game.gen_finished_test = gen_finished_test if settings.fitness == "novelty": load_novelty_archive(novelty) while not game.QUIT_SIGNAL: print(F"Generation: {gen}") game.set_hardware(hws) game.start() for i, hw in enumerate(hws): hw.cache_fitness(game.birds[i].fitness) local_best = max(hws, key=lambda hw: min(hw.fitness)) fitness_data.append(sum(local_best.fitness) / len(local_best.fitness)) if min(local_best.fitness) > min(best_fitness): best_fitness = local_best.fitness print(local_best) print("Finished with fitness", local_best.fitness) print("____________________________") if settings.fitness == "novelty": assert settings.selection != "lexicase", "Lexicase is not compatible with Novelty." dists = novelty.select([(bird.rect.x + bird.last_frame_alive, clamp(bird.rect.y, 0, game.HEIGHT)) for bird in game.birds]) for i, hw in enumerate(hws): hw.cache_fitness(dists[i]) copy_best = local_best.copy() copy_best.traits = 0 if settings.selection == "tournament": hws = tournament(hws) elif settings.selection == "elite": hws = elite(hws, len(hws) // 2) elif settings.selection == "lexicase": hws = lexicase(hws) elif settings.selection == "roulette": hws = roulette(hws) else: raise NotImplementedError( F"Invalid Selection Scheme: {settings.selection}") [mutate(hw) for hw in hws] recombination(hws) for i, hw in enumerate(hws): hw.traits = i # Keep around the best performing from the previous generation & reset its hardware hws[0] = copy_best hws[0].traits = 0 gen += 1 if gen in {10, 50, 100, 250, 500, 1500, 2500} or not gen % 1000: save_programs(gen, hws, game.gen_finished_test) analytics.save(gen, fitness_data) fitness_data.clear() if settings.fitness == "novelty": save_novelty_archive(novelty)
def showError(handler): print(handler.getLastFriendlyError()) Analytics.sendAnalytics('AppError', handler.getLastError()) print('Press the Enter key to exit') raw_input() sys.exit(1)
from getpass import getpass, getuser from SessionHandler import SessionHandler from Analytics import Analytics def showError(handler): print(handler.getLastFriendlyError()) Analytics.sendAnalytics('AppError', handler.getLastError()) print('Press the Enter key to exit') raw_input() sys.exit(1) if __name__ == '__main__': Analytics.sendAnalytics('AppEvent', 'AppLaunch') user = raw_input('Username: '******'Contact ID: ') handler = SessionHandler() if not handler.authorize(user, password): showError(handler) print('Logged in successfully, requesting export of {}'.format(contactId)) if not handler.requestContactExport(contactId): showError(handler) print('Requested export successfully, waiting for export to be ready.') while not handler.isDownloadReady(): if not handler.checkIfExportIsReady(): showError(handler) print(