Пример #1
0
def getBreakdown():
	objId = request.args.get("obj")
	args = processArgs(request.args)
	dims = request.args.get("dims")
	if dims is None:
		return returnJSON({ "success": 0, "error": "missing 'dims' agrument; please supply a comma-separated list of dimensions to aggregate" })
	dims = dims.split(",")
	return returnJSON(statsdb.aggregateTotals(objId, args, dims))
Пример #2
0
def getAllCountries(args):
  countries = myworld_config["country_metadata"]
  ret = { "countries": [] }
  ret["overall"] = statsdb.aggregateTotals(objId, args, [ "age", "gender", "education", "country" ])
  
  for country_id in ret["overall"]["dimensions"]["country"]:
    
    argsClone = copy.deepcopy(args)
    if country_id in myworld_config["country_metadata"]:
      c = myworld_config["country_metadata"][country_id]
      argsClone["country"] = country_id
      c["id"] = country_id
    else:
      c = None

    if c is not None:
      c["stats"] = statsdb.aggregateTotals(objId, argsClone, [ "age", "gender", "education" ])
      c["segment"] = formatSegment(statsdb.getData(objId, argsClone))
      ret["countries"].append(c)

  return ret
Пример #3
0
def getMapStats(args):
  countries = myworld_config["country_metadata"]
  ret = { "countries": [], "computed_at": int(time.time()) }
  # total
  total = statsdb.getData(objId, {})
  ret["tVotes"] = total["values"]["_total"]
  # countries
  for country_id in countries:
    c = myworld_config["country_metadata"][country_id]
    c["id"] = country_id
    stats = statsdb.aggregateTotals(objId, { "country": country_id }, [ "age", "gender" ])
    c["demo"] = stats["dimensions"]
    c["tVotes"] = stats["_total"]
    c["country"] = c["id"]
    del c["id"]
    # c["segment"] = formatSegment(statsdb.getData(objId, { "country": country_id }))
    ret["countries"].append(c)    
  return ret
Пример #4
0
def getDemographics(args):
  ret = statsdb.aggregateTotals(objId, args, [ "age", "gender", "education", "country" ]);
  if "country" in ret["dimensions"]:
    ret["dimensions"]["hdi"] = aggregateDimension("hdi", ret["dimensions"]["country"])
  # ret = formatStats(ret)
  return ret