def start_basic_analyzer_action(request): if request.method == "POST": accountGuid = request.POST.get('accountselection', '') botGuid = request.POST.get('botselection', '') timeFrameToTest = request.POST.get('timeframetotest', 1440) botGuidSplit = botGuid.split(':') botType = botGuidSplit[0] botGuid = botGuidSplit[1] config = ConfigManager.get_or_create_config() markets = HaasManager.get_all_markets_for_guid(accountGuid) HistoryRetrievalManager.reset_retrieval_info() HistoryRetrievalManager.set_retrieval_info(accountGuid, len(markets)) HistoryRetrievalManager.mark_started() BasicAnalysisManager.set_account_guid(accountGuid) BasicAnalysisManager.set_bot_guid(botGuid) BasicAnalysisManager.set_time_frame_in_minutes(int(timeFrameToTest)*2) if botType == "CB": BasicAnalysisManager.set_is_custom_bot(True) download_history_for_all_markets_task(config.haasIp, config.haasPort, config.haasSecret, accountGuid, int(timeFrameToTest)*2) return redirect('/analyzer/basic') else: print("derp") return redirect('/')
def calculate_clothing(ids_csv, feels_csv, gender_csv, name_csv, color_csv, lat, lon): # takes in a person list and returns a # dict of clothing for each person id_array = ids_csv.split(',') feel_ary = feels_csv.split(',') gender_ary = gender_csv.split(',') name_ary = name_csv.split(',') color_ary = color_csv.split(',') if len(feel_ary) != len(gender_ary) != len(name_ary) != len(color_ary) != len(id_array): # status HTTP_400_BAD_REQUEST return {"message": "people values do not match"}, 400 #setup the people objects to loop through people = create_people(id_array, feel_ary, gender_ary, name_ary, color_ary) #get weather and time of day weather = WeatherManager.get_weather(WeatherFetch.NORMAL, lat, lon) if "error" not in weather and "weather_time" in weather: time_of_day = get_time_of_day(weather["weather_time"], weather["sunrise_time"], weather["sunset_time"]) #get intensities intensity_data = ConfigManager.get_intensity_config_data() results = calculate(people, intensity_data, weather, time_of_day) return results else: return weather, 500 #weather just holds the error at this point not the actual weather
def calculate_items(adjusted_temperature, gender, intensity, conditions, time_of_day): """ Actually does the calculating""" clothing_config = ConfigManager.get_clothing_config_data() clothes = {} for bodyPart in clothing_config: #print("--" + bodyPart + "--") for item in clothing_config[bodyPart]: if item["min_temp"] <= adjusted_temperature <= item["max_temp"]: if "gender" in item: if item["gender"] == gender: #print(item["title"] + " added with special gender!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break elif "intensity" in item: if item["intensity"].find(intensity) > -1: # print(item["title"] + " added with special intensity!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break elif "conditions" in item: if item["conditions"].find(conditions) > -1: #print(item["title"] + " added with special conditions!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break elif "special" in item: if item["special"] == "sunny": if conditions.find("Clear") > -1 and time_of_day == "day": # print(item["title"] + " added with special special sunny!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break elif item["special"] == "not_rain": if conditions.find("Rain") == -1: # print(item["title"] + " added with special special not_rain!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break elif item["special"] == "singlet": if intensity == "race": clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break else: # print(item["title"] + " added normally!") clothes[bodyPart] = item["title"] clothes[bodyPart + "_name"] = item["name"] break return clothes
def get_bodyparts(): # returns list of body parts that have clothing associated data = {} ary = [] clothingConfig = ConfigManager.get_clothing_config_data() if "error" not in clothingConfig: for bodypart in clothingConfig: ary.append( bodypart) data["data"] = ary return data return {"error": "Error getting bodyparts"}, 500
def get_all_clothing(): # read config and return clothing titles # UI can use this to build stuff if it needs it clothingConfig = ConfigManager.get_clothing_config_data() if "error" not in clothingConfig: data = {} info = {} for bodypart in clothingConfig: for clothing in clothingConfig[bodypart]: info[clothing["name"]] = {} info[clothing["name"]]["bodypart"] = bodypart info[clothing["name"]]["title"] = clothing["title"] data["data"] = info return data return {"error": "Error getting all clothing"}, 500
def get_weather_from_api(lat, lon): json_results = "" error_text = "" apiConfig = ConfigManager.get_api_config_data() if not "error" in apiConfig: try: weather_req_url = apiConfig["weather_req_url"] % ( apiConfig["weather_api_token"], lat, lon, apiConfig["weather_lang"], apiConfig["weather_unit"], apiConfig["weather_exclude_list"]) request = requests.get(weather_req_url) if request.status_code == 200: json_results = json.loads(request.text) else: ErrorManager.log_error( "WeatherManager.get_weather_from_api: request.status_code - " + str(request.status_code) + " | Responce - " + str(request.json())) json_results = { "error": "Error Getting Weather from open weather." } except HTTPError as http_err: error_text = f"HTTP Error Could not get weather:{http_err}" except ConnectionError as http_con_err: error_text = f"HTTP Connection Pool Error Could not get weather:{http_con_err}" except json.JSONDecodeError as err: error_text = f'JSON Decoding error occurred: {err}' except KeyError as key_err: error_text = f'JSON key error occurred: {key_err}' except Exception as err: error_text = f'Unknown error occurred: {err}' else: error_text = apiConfig["error"] if error_text != "": ErrorManager.log_error("WeatherManager.get_weather_from_api: " + error_text) json_results = {"error": "Error connecting to open weather."} return json_results
def basic_analyzer_view(request): config = ConfigManager.get_or_create_config() history = HistoryRetrievalManager.get_or_create_history_retrieval_model() basicAnalysis = BasicAnalysisManager.get_or_create_basic_analysis_run_model() context = {'accounts': HaasManager.get_all_accounts(), 'customBots': HaasManager.get_all_custom_bots(), 'tradeBots': HaasManager.get_all_trade_bots(), 'history': HistoryRetrievalManager.get_or_create_history_retrieval_model(), 'basicAnalysis': BasicAnalysisManager.get_or_create_basic_analysis_run_model() } if history.completed == True and basicAnalysis.started == False: basicAnalysis.started = True context['basicAnalysis'] = basicAnalysis markets = HaasManager.get_all_markets_for_guid(basicAnalysis.accountGuid) BasicAnalysisManager.set_total_to_retrieve(len(markets)) BasicAnalysisManager.mark_started() backtest_all_markets_with_bot(config.haasIp, config.haasPort, config.haasSecret, basicAnalysis.accountGuid, basicAnalysis.botGuid, basicAnalysis.timeFrameInMinutes, "", basicAnalysis.isCustomBot) return render(request, 'authed/basic_analyzer.html', context)
def save_settings_action(request): context = {} if request.method == "POST": haasIp = request.POST.get('haasip', '') haasPort = request.POST.get('haasport', 0) haasSecret = request.POST.get('haassecret', '') numConcurrentTask = request.POST.get('numconcurrenttest', 0) ConfigManager.set_haas_configuration(haasIp, haasPort, haasSecret) ConfigManager.set_num_concurrent_test(numConcurrentTask) if HaasManager.quick_test_haas_creds(haasIp, haasPort, haasSecret): context = {'success': True, 'config': ConfigManager.get_or_create_config()} HaasManager.init_haas_manager(haasIp, haasPort, haasSecret) else: context = {'success': False, 'config': ConfigManager.get_or_create_config()} return render(request, 'authed/settings.html', context) else: return redirect('/settings')
def setitngs_view(request): context = {'config': ConfigManager.get_or_create_config()} return render(request, 'authed/settings.html', context)
def startup(): configModel = ConfigManager.get_or_create_config() HaasManager.init_haas_manager(configModel.haasIp, configModel.haasPort, configModel.haasSecret)