def statView(): args = {k: v for k, v in request.args.iteritems()} col = args.pop("col", "name") moe = args.pop("moe", False) truncate = int(args.pop("truncate", 0)) if moe == "False": moe = False dataset = args.pop("dataset", False) if dataset == "False": dataset = False return jsonify(stat(args, col=col, dataset=dataset, moe=moe, truncate=truncate))
def statView(): args = {k: v for k, v in request.args.iteritems()} col = args.pop("col", "name") moe = args.pop("moe", False) truncate = int(args.pop("truncate", 0)) if moe == "False": moe = False dataset = args.pop("dataset", False) if dataset == "False": dataset = False return jsonify( stat(args, col=col, dataset=dataset, moe=moe, truncate=truncate))
def statView(): args = {k: v for k, v in request.args.iteritems()} col = args.pop("col", "name") moe = args.pop("moe", False) truncate = int(args.pop("truncate", 0)) if moe == "False": moe = False dataset = args.pop("dataset", False) if dataset == "False": dataset = False order = args.get("order", False) required = args.get("required").split(",") if order and order not in required: required.append(order) if col != "name" and col != "id" and col not in required: required.append(col) args["required"] = ",".join(required) return jsonify(stat(args, col=col, dataset=dataset, moe=moe, truncate=truncate))
def top(self, **kwargs): """str: A text representation of a top statistic or list of statistics """ attr_type = kwargs.get("attr_type", self.attr_type) dataset = kwargs.get("dataset", False) moe = kwargs.pop("moe", False) truncate = int(kwargs.pop("truncate", 0)) # create a params dict to use in the URL request params = {} # set the section's attribute ID in params attr_id = kwargs.get("attr_id", False) if attr_type != self.attr_type and attr_id and "top" in attr_id: l, o = attr_id.split(":") attr_id = self.top(**{ "col": "id", "order": o, "sort": "desc", "limit": l[3:], "show": attr_type })["value"] child = kwargs.get("child", False) if attr_id == False: if child: kwargs["prefix"] = kwargs.get("prefix", True) where = self.children(**kwargs) if kwargs["prefix"] is True: pre = kwargs.pop("prefix") if len(where) > 0: params["where"] = "{}:{}".format(self.attr_type, where) attr_id = "" if attr_id == False: attr_id = self.id(**kwargs) params[attr_type] = attr_id # get output key from either the value in kwargs (while removing it) or 'name' col = kwargs.pop("col", "name") data_only = kwargs.pop("data_only", False) if child: kwargs["sumlevel"] = self.sumlevel(**kwargs) for k in ["attr_type", "attr_id", "child", "dataset"]: if k in kwargs: del kwargs[k] # add the remaining kwargs into the params dict params = dict(params.items()+kwargs.items()) # set default params params["year"] = params.get("year", "latest") params["limit"] = params.get("limit", 1) params["show"] = params.get("show", attr_type) params["sumlevel"] = params.get("sumlevel", "all") if "sumlevel" in params["sumlevel"]: params["sumlevel"] = params["sumlevel"].replace("sumlevel", self.sumlevel()) if "naics_level" in params and "sumlevel" in params["naics_level"]: params["naics_level"] = params["naics_level"].replace("sumlevel", self.sumlevel()) if "soc_level" in params and "sumlevel" in params["soc_level"]: params["soc_level"] = params["soc_level"].replace("sumlevel", self.sumlevel()) params = param_format(params) if "force" not in params and params["required"] == "": col_maps = COLMAP.keys() col_maps += ["-".join(c) for c in list(combinations(col_maps, 2))] # extra allowed values for 'col' col_maps += ["id", "name", "ratio"] if col not in col_maps: params["required"] = col elif "order" in params: params["required"] = params["order"] if moe and "force" not in params: params["required"] += ",{}".format(moe) # make the API request using the params return stat(params, col=col, dataset=dataset, data_only=data_only, moe=moe, truncate=truncate)
def top(self, **kwargs): """str: A text representation of a top statistic or list of statistics """ attr_type = kwargs.get("attr_type", self.attr_type) dataset = kwargs.get("dataset", False) moe = kwargs.pop("moe", False) truncate = int(kwargs.pop("truncate", 0)) # create a params dict to use in the URL request params = {} # set the section's attribute ID in params attr_id = kwargs.get("attr_id", False) if attr_type != self.attr_type and attr_id and "top" in attr_id: l, o = attr_id.split(":") attr_id = self.top(**{ "col": "id", "order": o, "sort": "desc", "limit": l[3:], "show": attr_type })["value"] child = kwargs.get("child", False) if attr_id == False: if child: kwargs["prefix"] = kwargs.get("prefix", True) where = self.children(**kwargs) if kwargs["prefix"] is True: pre = kwargs.pop("prefix") if len(where) > 0: params["where"] = "{}:{}".format(self.attr_type, where) attr_id = "" if attr_id == False: attr_id = self.id(**kwargs) params[attr_type] = attr_id # get output key from either the value in kwargs (while removing it) or 'name' col = kwargs.pop("col", "name") data_only = kwargs.pop("data_only", False) if child: kwargs["sumlevel"] = self.sumlevel(**kwargs) for k in ["attr_type", "attr_id", "child", "dataset"]: if k in kwargs: del kwargs[k] # add the remaining kwargs into the params dict params = dict(params.items()+kwargs.items()) # set default params params["limit"] = params.get("limit", 1) params["show"] = params.get("show", attr_type) params["sumlevel"] = params.get("sumlevel", "all") if "sumlevel" in params["sumlevel"]: params["sumlevel"] = params["sumlevel"].replace("sumlevel", self.sumlevel()) if "naics_level" in params and "sumlevel" in params["naics_level"]: params["naics_level"] = params["naics_level"].replace("sumlevel", self.sumlevel()) if "soc_level" in params and "sumlevel" in params["soc_level"]: params["soc_level"] = params["soc_level"].replace("sumlevel", self.sumlevel()) params = param_format(params) if "force" not in params and params["required"] == "": col_maps = COLMAP.keys() col_maps += ["-".join(c) for c in list(combinations(col_maps, 2))] # extra allowed values for 'col' col_maps += ["id", "name", "ratio"] if col not in col_maps: params["required"] = col elif "order" in params: params["required"] = params["order"] if moe and "force" not in params: params["required"] += ",{}".format(moe) # make the API request using the params return stat(params, col=col, dataset=dataset, data_only=data_only, moe=moe, truncate=truncate)