def predef_log_reg(): leap_predef = leap_fn.PredefinedFunction(computation_msgs_pb2.AlgoCodes.LOG_REG) selector = { "type": codes.DEFAULT, "useLocalData": True } leap_predef.selector = selector return leap_predef
def predef_mean_selector_sql(): leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.MEAN_ALGO) selector = { "type": codes.DEFAULT, "filter": "[pain_past3backpain] = 1 and [yrbirth] < 1960" } leap_predef.selector = selector return leap_predef
def predef_count_selector(): leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.COUNT_ALGO_RC) selector = { "type": codes.DEFAULT, "filter": "[pain_past3backpain] = 1 and [yrbirth] < 1931" } leap_predef.selector = selector return leap_predef
def predef_count_selector_sql(): leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.COUNT_ALGO_RC_QUERY) selector = { "type": codes.SQL, "sql_func": "count", "sql_options": { "project_id": 13, "filter": { 'pain_past3backpain': "= 1", 'yrbirth': "< 1931" } } } leap_predef.selector = selector return leap_predef
def predef_max_selector_sql(): leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.MAX_ALGO_RC) selector = { "type": codes.SQL, "sql_func": "max", "sql_options": { "project_id": 13, "filter": { 'pain_past3backpain': "= 1", 'yrbirth': "< 1931" }, "field": "yrbirth" } } leap_predef.selector = selector return leap_predef
def post(self, request, format=None): leap_predef = None print("Inside post") request = {"dp": False} if request["dp"]: leap_predef = leap_fn.PrivatePredefinedFunction( codes.PRIVATE_SITE_COUNT_ALGO, epsilon=1, delta=0) else: print("Gonna call leap api") leap_predef = leap_fn.PredefinedFunction(codes.COUNT_ALGO) print("Running non dp leap") selector = "[age] > 50 and [bmi] < 25" leap_predef.selector = selector dist_leap = leap.DistributedLeap(leap_predef) print(dist_leap.get_result()) return Response(status=status.HTTP_200_OK)
def post(self, request, format=None): leap_predef = None body = json.loads(request.body) if body['dp']: leap_predef = leap_fn.PrivatePredefinedFunction( computation_msgs_pb2.AlgoCodes.PRIVATE_SITE_COUNT_ALGO, epsilon=1, delta=0) else: leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.COUNT_ALGO) leap_predef.selector = body['selector'] dist_leap = leap.DistributedLeap(leap_predef) sites = body['sites'] result = dist_leap.get_result(sites) return HttpResponse(result)
import sys sys.path.append("../") import api.leap as leap import api.leap_fn as leap_fn from proto import computation_msgs_pb2 if __name__ == "__main__": leap_predef = leap_fn.PredefinedFunction(computation_msgs_pb2.AlgoCodes.COUNT_ALGO) selector = "[age] > 50 and [bmi] < 25" leap_predef.selector = selector dist_leap = leap.DistributedLeap(leap_predef) result = dist_leap.get_result() print(result)
def quantile_exp(): leap_predef = leap_fn.PredefinedFunction(codes.QUANTILE_ALGO) selector = "" leap_predef.selector = selector return leap_predef
def predef_count_exp(): leap_predef = leap_fn.PredefinedFunction(codes.COUNT_ALGO) selector = "[age] > 50 and [bmi] < 25" leap_predef.selector = selector return leap_predef
def predef_count_selector(): leap_predef = leap_fn.PredefinedFunction( computation_msgs_pb2.AlgoCodes.COUNT_ALGO_RC) selector = {"type": "default", "useLocalData": False} leap_predef.selector = selector return leap_predef
def quantile_exp(): leap_predef = leap_fn.PredefinedFunction(computation_msgs_pb2.AlgoCodes.QUANTILE_ALGO) selector = "" leap_predef.selector = selector return leap_predef
import sys sys.path.append("../") import api.leap as leap import api.leap_fn as leap_fn import api.codes as codes if __name__ == "__main__": leap_predef = leap_fn.PredefinedFunction(codes.COUNT_ALGO) selector = "[age] > 50 and [bmi] < 25" leap_predef.selector = selector dist_leap = leap.DistributedLeap(leap_predef) result = dist_leap.get_result() print(result)