def buy_drink(drink, payment, name): span = trace.newspan(tracer, None, 'transaction') span.set_tag('drink', drink) span.set_tag('customer', name) span.set_tag('payment', payment) res = trace.inject_in_header(tracer, span, {}) span.finish() if True: print(name + ' buys ' + drink) API.call_api(data_server, data_port, '/wip/add/' + drink, res) API.call_api(data_server, data_port, '/add/client', res) r = API.call_api(produce_server, produce_port, '/produce/' + drink, res) if r.status_code == 200: r = API.call_api(bill_server, bill_port, '/bill/' + payment + '/' + name, res) if r.status_code == 200: span.set_tag('error', False) else: span.set_tag('error', True) span.set_tag('bill', r.status_code) else: span.set_tag('error', True) response = app.response_class(response=json.dumps(res), status=r.status_code, mimetype='application/json') API.call_api(data_server, data_port, '/wip/sup/' + drink, res) return response
def produce_drink(drink): print('produce '+drink) response = app.response_class( status=404, mimetype='application/json' ) span = trace.newspan( tracer, trace.getparentspanfromheader(tracer, request), drink ) res = trace.inject_in_header(tracer, span, {}) result = API.call_api(data_server, data_port, '/state', res) decoded = result.content.decode() _state = json.loads(decoded) error = False if True: if _state['water'] <= 0: API.call_api(data_server, data_port, '/resource/add/water', res) else: if drink == 'coffee' and _state['coffee_bean'] <= 0: API.call_api(data_server, data_port, '/resource/add/' + drink, res) error = True span.set_tag('reason', 'need ' + drink) elif drink == 'tea' and _state['tea_leaf'] <= 0: API.call_api(data_server, data_port, '/resource/add/' + drink, res) error = True span.set_tag('reason', 'need '+drink) else: r = API.call_api(data_server, data_port, '/consume/water', res) if r.status_code == 200: API.call_api(data_server, data_port, '/consume/'+drink, res) time.sleep(random.randint(0, 500) / 1000) response = app.response_class( status=200, mimetype='application/json' ) print(drink + ' produced') # span.status = status.Status( response.status,'TODO') span.set_tag('error', error) span.finish() return response
def range_split(z3inst, module, num_split, order="biggest"): initial_num_split = num_split #only consider ranges of top level abstracts that are referring to the same type of concretes pairs = [] for i in z3inst.cfr_sorts.values(): glCardRange = i.numInstances - i.element.glCard[0].value + 1 if glCardRange > 1: pairs.append((i, glCardRange)) if order == "random": random.shuffle(pairs) else: pairs.sort(key=operator.itemgetter(1)) if order == "biggest": pairs.reverse() constraints = [] splitters = [] curr_count = 0 for i in pairs: (claferSort, card_range) = i splitters.append(claferSort) curr_count = curr_count + card_range if curr_count >= num_split: break if curr_count < num_split: return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed.") else: ranges = [] for i in splitters: curr_range = [] for j in range(i.element.glCard[0].value, i.numInstances + 1): left = API.createCard(API.createArg(i.element.uid, i)) right = API.createInteger(j) bc = CreateBracketedConstraints.CreateBracketedConstraints( z3inst, True) constraint = bc.generatedConstraintVisit( API.createEquals(left, right)) curr_range.append(constraint) ranges.append(curr_range) products = list(itertools.product(*ranges)) products = [[And(*list(i))] for i in products] products = condense(products, num_split) return products return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed.")
def range_split(z3inst, module, num_split, order="biggest"): initial_num_split = num_split #only consider ranges of top level abstracts that are referring to the same type of concretes pairs = [] for i in z3inst.cfr_sorts.values(): glCardRange = i.numInstances - i.element.glCard[0].value + 1 if glCardRange > 1: pairs.append((i, glCardRange)) if order == "random": random.shuffle(pairs) else: pairs.sort(key=operator.itemgetter(1)) if order == "biggest": pairs.reverse() constraints = [] splitters = [] curr_count = 0 for i in pairs: (claferSort, card_range) = i splitters.append(claferSort) curr_count = curr_count + card_range if curr_count >= num_split: break if curr_count < num_split: return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed." ) else: ranges = [] for i in splitters: curr_range = [] for j in range(i.element.glCard[0].value, i.numInstances + 1): left = API.createCard(API.createArg(i.element.uid, i)) right = API.createInteger(j) bc = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True) constraint = bc.generatedConstraintVisit(API.createEquals(left, right)) curr_range.append(constraint) ranges.append(curr_range) products = list(itertools.product(*ranges)) products = [[And(*list(i))] for i in products] products = condense(products, num_split) return products return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed." )
def consume(r): global tea_leaf, coffee_bean, water s = 200 print('consume ' + r) span = trace.newspan(tracer, trace.getparentspanfromheader(tracer, request), 'consume ' + r) res = trace.inject_in_header(tracer, span, {}) error = False if resources[r] <= 0: API.call_api( data_server, data_port, '/resource/add/' + r, res, ) s = 404 error = True else: resources[r] += -1 json_body = [{ "measurement": "rt", "tags": { "type": r }, "fields": { "resource": resources[r], "movement": -1 } }] client_influx.write_points(json_body) time.sleep(random.randint(0, 50) / 1000) print(r + ' ' + str(resources[r])) span.set_tag('error', error) res = {} response = app.response_class(response=json.dumps(res), status=s, mimetype='application/json') span.finish() return response
def divide_biggest_ranges_in_two(z3inst, module, num_split): initial_num_split = num_split pairs = [] for i in z3inst.cfr_sorts.values(): glCardRange = i.numInstances - i.element.glCard[0].value + 1 if glCardRange > 1: pairs.append((i, glCardRange)) pairs.append((i, glCardRange)) pairs.reverse() constraints = [True] try: while num_split != 1: num_split = num_split // 2 (currSort, currRange) = pairs.pop(0) left1 = API.createCard( API.createArg(currSort.element.uid, currSort)) right1 = API.createInteger(currSort.element.glCard[0].value + (currRange // 2)) bc1 = CreateBracketedConstraints.CreateBracketedConstraints( z3inst, True) constraint1 = bc1.generatedConstraintVisit( API.createLT(left1, right1)) left2 = API.createCard( API.createArg(currSort.element.uid, currSort)) right2 = API.createInteger(currSort.element.glCard[0].value + (currRange // 2)) bc2 = CreateBracketedConstraints.CreateBracketedConstraints( z3inst, True) constraint2 = bc2.generatedConstraintVisit( API.createLE(right2, left2)) newConstraints = [] for i in constraints: newConstraints.append(mAnd(i, constraint1)) for i in constraints: newConstraints.append(mAnd(i, constraint2)) constraints = newConstraints except: return safe_raise_heuristic_failure_exception( "divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") if num_split != 1: return safe_raise_heuristic_failure_exception( "divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") return constraints sys.exit( "INCOMPLETE: need to figure out what to do when run out of splits")
def drink(self): r = random.getrandbits(1) p = means_of_payment[random.getrandbits(1)] try: res = API.call_api(buy_server, buy_port, '/buy/'+drinks[r]+'/' + p + '/' + self.name, {}) print('/buy/'+drinks[r]+'/' + p + '/' + self.name+' > '+str(res)) self.energy = energy.get(drinks[r]) self.last = True except Exception as e: print(e) self.last = False
def divide_biggest_ranges_in_two(z3inst, module, num_split): initial_num_split = num_split pairs = [] for i in z3inst.cfr_sorts.values(): glCardRange = i.numInstances - i.element.glCard[0].value + 1 if glCardRange > 1: pairs.append((i, glCardRange)) pairs.append((i, glCardRange)) pairs.reverse() constraints = [True] try: while num_split != 1: num_split = num_split // 2 (currSort,currRange) = pairs.pop(0) left1 = API.createCard(API.createArg(currSort.element.uid, currSort)) right1 = API.createInteger(currSort.element.glCard[0].value + (currRange//2)) bc1 = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True) constraint1 = bc1.generatedConstraintVisit(API.createLT(left1, right1)) left2 = API.createCard(API.createArg(currSort.element.uid, currSort)) right2 = API.createInteger(currSort.element.glCard[0].value + (currRange//2)) bc2 = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True) constraint2 = bc2.generatedConstraintVisit(API.createLE(right2, left2)) newConstraints = [] for i in constraints: newConstraints.append(mAnd(i, constraint1)) for i in constraints: newConstraints.append(mAnd(i, constraint2)) constraints = newConstraints except: return safe_raise_heuristic_failure_exception("divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") if num_split != 1: return safe_raise_heuristic_failure_exception("divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") return constraints sys.exit("INCOMPLETE: need to figure out what to do when run out of splits")
def bill(payment, name): span = trace.newspan(tracer, trace.getparentspanfromheader(tracer, request), 'bill') span.set_tag('customer', name) span.set_tag('payment', payment) res = trace.inject_in_header(tracer, span, {}) res = API.call_api(data_server, data_port, '/cashin/' + payment, res) span.finish() sspan = trace.newspan(tracer, span.context, payment) time.sleep(random.randint(0, 200) / 1000) response = app.response_class(response=json.dumps({}), status=200, mimetype='application/json') sspan.finish() return response
# CORS(app) i = 0 while True: if i == 0: root = trace.newspan(tracer, None, 'root') i += 1 if i == 10: root.finish() i = 0 r = None try: # span = trace.newspan(tracer, root.context, 'pushdata') span = trace.newspan(tracer, None, 'pushdata') sspan = trace.newspan(tracer, span.context, 'ask data') res = trace.inject_in_header(tracer, span, {}) r = API.call_api(data_server, data_port, '/state', res) # print(r.content) j = json.loads(r.content.decode()) sspan.finish() sspan = trace.newspan(tracer, sspan.context, 'push tea') json_body = [{ "measurement": "coffeetea", "tags": { "type": "tea", "fill": j['fill_tea_in_progress'], }, "fields": { "resource": j['tea_leaf'], "refills": 1.0 if j['fill_tea_in_progress'] else 0.0, "wip_produce": j['tea_in_progress'], }
import p2api import pytest import requests from common import API api = API() api.connect() def test_cannot_delete_finding_chart_if_not_authenticated(): response = requests.delete(f'{api.API_URL}/obsBlocks/0/findingCharts/0') assert response.status_code == 401 def test_cannot_delete_finding_chart_of_invalid_observing_block(): ob_id = 'invalid' # invalid observing block ID index = 1 response = api.make_request( 'DELETE', f'/obsBlocks/{ob_id}/findingCharts/{index}') assert response.status_code == 400 @pytest.mark.parametrize('invalid_index', [('invalid',), (0,), (6,)]) def test_cannot_delete_invalid_finding_chart(invalid_index): ob_id = api.create_observing_block(); response = api.make_request(
# match_id = "1deb2118-557e-4945-a8e1-81ae70bf62e3" # match_id = "42f94823-1e69-423e-983a-02f0973c9534" # duo/sanhok # match_id = "1859feb8-e65e-46eb-9ef0-555082002695" # squad/sanhok # match_id = "e15b4139-38f8-4e67-a6ae-2f0c7cb02881" # erangel/squad lame # match_id = "64c6a84d-49b4-4c6c-943e-26bc8676b611" match_id = "9ff7d88c-0665-438a-9e73-c562c7eb0a46" ds = dataset.Dataset(match_id) # print(ds.get_team('eponymoose')) # plot_location_overlay(ds, ds.get_team('eponymoose')) # plot_distance_from_zone(ds) # plot_distance_from_zone_player_highlighted(ds, 'eponymoose') # plot_distance_from_zone_player_comparison(ds, 'eponymoose') # plot_distance_from_zone_player_comparison(ds) api = API() for i, (player, match) in enumerate(api.iter_player_matches('eponymoose')): ds = dataset.Dataset(match.id) try: plot_distance_from_zone_player_comparison(ds, 'eponymoose') except IndexError: print("INDEX ERROR! {}".format(i)) continue except TypeError: print("TYPE ERROR! {}".format(i)) continue