Esempio n. 1
0
def getSegmentComparison(args):
  ret = {}
  ret["total"] = formatSegment( statsdb.getData(objId, {}) )
  ret["gender1"] = formatSegment( statsdb.getData(objId, processArgs({ "gender": 1 }) ) )
  ret["gender2"] = formatSegment( statsdb.getData(objId, processArgs({ "gender": 2 }) ) )
  ret["ageGroup1"] = formatSegment( statsdb.getData(objId, processArgs({ "age": "1,20" }) ) )
  ret["ageGroup2"] = formatSegment( statsdb.getData(objId, processArgs({ "age": "35,50" }) ) )
  ret["ageGroup3"] = formatSegment( statsdb.getData(objId, processArgs({ "age": "65" }) ) )
  ret["hdi1"] = formatSegment( statsdb.getData(objId, processArgs({ "hdi": 1 }) ) )
  ret["hdi2"] = formatSegment( statsdb.getData(objId, processArgs({ "hdi": 2 }) ) )
  ret["hdi3"] = formatSegment( statsdb.getData(objId, processArgs({ "hdi": 3 }) ) )
  ret["hdi4"] = formatSegment( statsdb.getData(objId, processArgs({ "hdi": 4 }) ) )
  for k in ret:
    ret[k]["tVotes"] = ret[k]["_total"]
    for r in ret[k]["rankings"]:
      r["id"] = r["pri_id"]
      del r["pri_id"]
    ret[k]["rankings"] = sorted(ret[k]["rankings"], key=lambda x: x["count"], reverse=True)
  ret["computed_at"] = int(time.time())
  return ret
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
def getData():
	objId = request.args.get("obj")
	args = processArgs(request.args)
	return returnJSON(statsdb.getData(objId, args))
Esempio n. 5
0
def getSegment(args):
  ret = statsdb.getData(objId, args)
  ret = formatSegment(ret)
  return ret