def collect_data(windows, currencies): p = Pricing() n = 0 for window in windows: for instr in currencies: p.history(instr, window, collection=True) n += 1 print("% i CSVs downloaded" % n)
def __init__(self, item): # general self.groupName = item['groupName'] self.cpu = item['cpu'] self.memory = item['memory'] # pricing self.region = item['region'] self.launchType = item['launchType'] self.osType = item['osType'] # duration self.startedAt = item['startedAt'] self.stoppedAt = item['stoppedAt'] self.runTime = item['runTime'] self.pricing = Pricing('AmazonEC2')
def __init__(self) -> None: self.DB_HOST = os.environ.get('DB_HOST') self.DB_USER = os.environ.get('DB_USER') self.DB_PASS = os.environ.get('DB_PASS') self.DB_NAME = os.environ.get('DB_NAME') self.FUNCTION_NAME = os.environ.get('FUNCTION_NAME', '') self.db = None self.db_c = None self.connect_db() # Analysis attributes self.report = request.args.get('report', 'home') # objects self.performance = Performance(self.db_c, self.FUNCTION_NAME) self.pricing = Pricing(self.db_c, self.FUNCTION_NAME) self.weekend_vs_weekdays = WeekendVsWeekdays(self.db_c, self.FUNCTION_NAME)
class Buy: def __init__(self): self.pricing = Pricing() self.create_order = CreateOrder() def execute(self, params): instrument = params['instrument'] take_profit_percentage = params['take_profit'] stop_loss_percentage = params['stop_loss'] bid, ask = self.pricing.get_prices(instrument) params_create_order = {} params_create_order['instrument'] = instrument params_create_order['take_profit'] = ask * (1 + take_profit_percentage) params_create_order['stop_loss'] = ask * (1 - stop_loss_percentage) params_create_order['units'] = 1 return self.create_order.execute(params_create_order)
class Task: """ A Task class for each item in DynamoDB table """ def __init__(self, item): # general self.groupName = item['groupName'] self.cpu = item['cpu'] self.memory = item['memory'] # pricing self.region = item['region'] self.launchType = item['launchType'] self.osType = item['osType'] # duration self.startedAt = item['startedAt'] self.stoppedAt = item['stoppedAt'] self.runTime = item['runTime'] self.pricing = Pricing('AmazonEC2') def duration(self, meter_start, meter_end, now): mRuntime = 0.0 return mRuntime def update_pricing_dict(self, key, ec2_cpu, ec2_mem, ec2_cost): pass def split_cost_by_weight(self, pricing_key, runTime, ec2_cpu2mem_weight=0.5): # Split EC2 cost bewtween memory and weights cpu_charges = ((float(self.cpu)) / 1024.0 / pricing_key['cpu']) * ( float(pricing_key['cost']) * ec2_cpu2mem_weight) * (runTime / 60.0 / 60.0) mem_charges = ( (float(self.memory)) / 1024.0 / pricing_key['memory']) * ( float(pricing_key['cost']) * (1.0 - ec2_cpu2mem_weight)) * (runTime / 60.0 / 60.0) return (mem_charges, cpu_charges) def cost_of_ec2task(self, runTime): global pricing_dict global region_table pricing_key = '_'.join( ['ec2', self.region, self.launchType, self.osType]) if pricing_key not in pricing_dict: (ec2_cpu, ec2_mem, ec2_cost) = self.pricing.ec2_pricing( region=region_table[self.region], instance_type=self.launchType, tenancy='Shared', ostype=self.osType) self.update_pricing_dict(pricing_key, ec2_cpu, ec2_mem, ec2_cost) (mem_charges, cpu_charges) = self.split_cost_by_weight(pricing_dict[pricing_key], runTime) return (mem_charges, cpu_charges) def get_datetime_start_end(self, now, month, days, hours): pass
import os from yhat import Yhat, YhatModel from pricing import Pricing class MarketingSearchAPI(YhatModel): REQUIREMENTS = ["pandas==0.15.2", "numpy"] def execute(self, data): result = p.predict(data) return result p = Pricing() username = os.environ["USERNAME"] apikey = os.environ["APIKEY"] endpoint = os.environ["OPS_ENDPOINT"] print "%s:%s:%s" % ( username, apikey, endpoint, ) yh = Yhat(username, apikey, endpoint) yh.deploy("RelayRidesPricing", MarketingSearchAPI, globals(), sure=True)
def __init__(self): self.pricing = Pricing() self.create_order = CreateOrder()
class Analysis: """ This class is responsible for managing and showing some basic metrics and also links for plots generated on demand. It can be served either by Waitress + Flask, or it can also be served as a plain python app. It is also ready to run in GCP Cloud Function. """ def __init__(self) -> None: self.DB_HOST = os.environ.get('DB_HOST') self.DB_USER = os.environ.get('DB_USER') self.DB_PASS = os.environ.get('DB_PASS') self.DB_NAME = os.environ.get('DB_NAME') self.FUNCTION_NAME = os.environ.get('FUNCTION_NAME', '') self.db = None self.db_c = None self.connect_db() # Analysis attributes self.report = request.args.get('report', 'home') # objects self.performance = Performance(self.db_c, self.FUNCTION_NAME) self.pricing = Pricing(self.db_c, self.FUNCTION_NAME) self.weekend_vs_weekdays = WeekendVsWeekdays(self.db_c, self.FUNCTION_NAME) def connect_db(self): # DB Connection self.db = MySQLdb.connect(host=self.DB_HOST, db=self.DB_NAME, user=self.DB_USER, passwd=self.DB_PASS) # Setting to use dictionaries instead of tuples (default) self.db_c = self.db.cursor(MySQLdb.cursors.DictCursor) def route(self): """Based on the report GET/query string parameter, routes and returns a specific function Returns: response, http code """ if self.report == 'home': return self.home() elif self.report == 'performance': return self.performance_analysis() elif self.report == 'pricing': return self.pricing_analysis() elif self.report == 'weekend-vs-weekdays': return self.weekend_vs_weekdays_analysis() return f"Oops... I didn't find anything here... <a href='/{self.FUNCTION_NAME}'>Go back to home</a>?", 404 def home(self): return render_template( 'home.html', summary=self.get_summary(), performance_links=self.performance.get_reports_links(), pricing_links=self.pricing.get_reports_links(), weekend_vs_weekdays_links=self.weekend_vs_weekdays. get_reports_links(), ) def get_summary(self): query = """ SELECT min(datetime) as first_date, max(datetime) as last_date, datediff(max(datetime),min(datetime)) duration_days, count(id) as tests_executed, sum(http_reqs_count) as total_request, ROUND(sum(data_received_count)/1e+9,2) as downloaded_gb, ROUND(sum(data_sent_count)/1e+9,2) as uploaded_gb, count(distinct(csp)) as caas_tested, csp FROM metrics WHERE csp != 'docker' """ # total self.db_c.execute(query) total = self.db_c.fetchall() # per csp self.db_c.execute(query + " GROUP BY csp") csps = self.db_c.fetchall() total_csps = {} for item in csps: total_csps[item['csp']] = item return {'total': total[0], 'csp': total_csps} def performance_analysis(self): cpu = request.args.get('cpu', None) memory = request.args.get('memory', None) factorial = request.args.get('factorial', None) type_of_app = request.args.get('app', None) avg_only = bool(int(request.args.get('avg_only', False))) all_in_one = bool(int(request.args.get('all_in_one', False))) if all_in_one: diagrams = [ self.performance.get_diagram(type_of_app, cpu, memory, '10', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '1000', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '10000', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '32000', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '43000', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '50000', avg_only), self.performance.get_diagram(type_of_app, cpu, memory, '60000', avg_only), ] html = '' for item in diagrams: html += item return html return self.performance.get_diagram(type_of_app, cpu, memory, factorial, avg_only) def pricing_analysis(self): pricing_scenario = request.args.get('scenario', None) if pricing_scenario == 'crossing': return self.pricing.get_crossing_diagram() elif pricing_scenario == 'pricing_factorial_60000': return self.pricing.get_pricing_based_on_factorial_60000_execution_time( ) else: return self.pricing.get_diagram(pricing_scenario) def weekend_vs_weekdays_analysis(self): type = request.args.get('type', None) return self.weekend_vs_weekdays.get_diagram_app_execution_time(type)