def create_feature(): url = base_url + '/features' feature = { "key": key, "project_id": project_id, "archived": False, "description": description, "environments": { "Production": { "rollout_rules": [{ "audience_ids": [audience_id], "enabled": False, "percentage_included": 100 }] } }, "variables": [{ "default_value": "false", "key": variable_key, "type": "string", "archived": False, "description": variable_description }] } et.print_request_details('POST', url, feature, headers) r = requests.post(url, data=json.dumps(feature), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return j['id'], j['variables'][0]['id']
def update_feature(id, variable_id): url = base_url + '/features/' + str(id) feature = { "key": key + '_updated', "project_id": project_id, "archived": False, "description": description + '_updated', "environments": { "Production": { "rollout_rules": [{ "audience_ids": [audience_id], "enabled": True, "percentage_included": 1000 }] } }, "variables": [{ "id": variable_id, "default_value": "true", "key": variable_key + '_updated', "type": "string", "archived": True, "description": variable_description + '_updated' }] } et.print_request_details('PATCH', url, feature, headers) r = requests.patch(url, data=json.dumps(feature), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return j['id']
def update_audience(id): url = base_url + '/audiences/' + str(id) audience = { "project_id": project_id, "archived": False, "conditions": '["and", ["or", ["or", {"name": "' + custom_audience_attribute + '", "type": "custom_attribute", "value": "full stack value"}], ["or", {"name": "' + custom_audience_attribute + '", "type": "custom_attribute", "value": "val 2"}]]]', "description": "Using a Full Stack attribute", "is_classic": False, "name": name + '_updated', "segmentation": False } et.print_request_details('PATCH', url, audience, headers) r = requests.patch(url, data=json.dumps(audience), headers=headers) j = r.json() et.print_response_details(r.status_code, j)
def pause_experiment(id): url = base_url + '/experiments/' + str(id) + '?action=pause' experiment = {} et.print_request_details('PATCH', url, experiment, headers) r = requests.patch(url, data=json.dumps(experiment), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return r.json()
def update_project(id): url = base_url + '/projects/' + str(id) project = { 'name': name + "_updated", 'confidence_threshold': 0.9, 'description': description + "_updated", 'platform': 'custom', 'sdks': ['python'], 'status': 'active', } et.print_request_details('PATCH', url, project, headers) r = requests.patch(url, data=json.dumps(project), headers=headers) j = r.json() et.print_response_details(r.status_code, j)
def create_project(): url = base_url + '/projects' project = { 'name': name, 'confidence_threshold': 0.9, 'description': description, 'platform': 'custom', 'sdks': ['python'], 'status': 'active', } et.print_request_details('POST', url, project, headers) r = requests.post(url, data=json.dumps(project), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return r.json()['id']
def update_attribute(id): url = base_url + '/attributes/' + str(id) attribute = { 'key': key + '_updated', 'project_id': project_id, 'archived': False, 'description': description + ' - updated', 'name': name + ' - updated', } et.print_request_details('PATCH', url, attribute, headers) r = requests.patch(url, data=json.dumps(attribute), headers=headers) j = r.json() et.print_response_details(r.status_code, j)
def update_group(id): url = base_url + '/groups/' + str(id) group = { 'project_id': project_id, 'archived': False, 'description': 'A new group updated', 'name': name + ' updated', 'entities': [{ "id": experiment_id, "kind": "Experiment", "weight": 5000 }] } et.print_request_details('PATCH', url, group, headers) r = requests.patch(url, data=json.dumps(group), headers=headers) j = r.json() et.print_response_details(r.status_code, j)
def create_attribute(): url = base_url + '/attributes' attribute = { 'key': key, 'project_id': project_id, 'archived': False, 'description': 'A new attribute', 'name': name, } et.print_request_details('POST', url, attribute, headers) r = requests.post(url, data=json.dumps(attribute), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return j['id']
def create_group(): url = base_url + '/groups' group = { 'project_id': project_id, 'archived': False, 'description': 'A new group', 'name': name, 'entities': [{ "id": experiment_id, "kind": "Experiment", "weight": 5000 }] } et.print_request_details('POST', url, group, headers) r = requests.post(url, data=json.dumps(group), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return r.json()['id']
def create_experiment(): url = base_url + '/experiments' experiment = { 'project_id': project_id, 'type': 'a/b', 'description': description, 'holdback': 5000, 'archived': False, 'key': key, "metrics": [{ "aggregator": "unique", "event_id": event_id, "scope": "visitor", "winning_direction": "increasing" }], "multivariate_traffic_policy": "full_factorial", "variations": [{ "weight": 10000, "archived": False, "description": "blabla", "key": variation_key }] } if feature_id: experiment['feature_id'] = feature_id if len(variable_values) > 0: experiment['variations'][0]['variable_values'] = variables et.print_request_details('POST', url, experiment, headers) r = requests.post(url, data=json.dumps(experiment), headers=headers) j = r.json() et.print_response_details(r.status_code, j) return (j['id'], j['variations'][0]['variation_id'])
def update_experiment_2(id, variation_id): url = base_url + '/experiments/' + str(id) + '' experiment = { 'project_id': project_id, 'type': 'a/b', 'description': description + "_updated_2", 'holdback': 5000, 'archived': False, 'key': key + "_updated_2", "metrics": [{ "aggregator": "unique", "event_id": event_id, "scope": "visitor", "winning_direction": "increasing" }], "multivariate_traffic_policy": "full_factorial", "variations": [{ "weight": 10000, "archived": False, "description": "blabla_2", "key": variation_key + '_updated_2', "variation_id": variation_id }] } if feature_id: experiment['feature_id'] = feature_id if len(variable_values) > 0: experiment['variations'][0]['variable_values'] = variables experiment['variations'][0]['feature_enabled'] = True et.print_request_details('PATCH', url, experiment, headers) r = requests.patch(url, data=json.dumps(experiment), headers=headers) j = r.json() et.print_response_details(r.status_code, j)
def create_result(): url = base_url + '/experiments/' + str(experiment_id) + '/results' et.print_request_details('GET', url, {}, headers) r = requests.get(url, headers=headers) print r.text j = r.json() et.print_response_details(r.status_code, j) url = base_url + '/experiments/' + str(experiment_id) + '/timeseries' et.print_request_details('GET', url, {}, headers) r = requests.get(url, headers=headers) j = r.json() et.print_response_details(r.status_code, j) url = base_url + '/export/experiments/' + str( experiment_id) + '/results/csv' et.print_request_details('GET', url, {}, headers) r = requests.get(url, headers=headers) et.print_response_details(r.status_code, {}) print(r.text)