def save_data(request): result = { "error" : "", "status" : ""} print request.POST for key, value in request.POST.iteritems(): print "1", key, value if request.method == 'POST': if request.POST.get('stats', ''): logger.error(request.POST['stats']) try: stats = json.loads(request.POST['stats']) stats = Statistics(IMEI = stats['IMEI'],IMSI = stats['IMSI'],PHONE_MODEL = stats['PHONE_MODEL'],SIM_SN = stats['SIM_SN'],GSM_TYPE = stats['GSM_TYPE'],NETWORK_MCC = stats['NETWORK_MCC'],NETWORK_MNC = stats['NETWORK_MNC'],NETWORK_NAME = stats['NETWORK_NAME'],NETWORK_COUNTRY = stats['NETWORK_COUNTRY'],NETWORK_TYPE = stats['NETWORK_TYPE'],CELL_ID = stats['CELL_ID'],CELL_PSC = stats['CELL_PSC'],CELL_LAC = stats['CELL_LAC'],RSSI = stats['RSSI'],GPS = stats['GPS'],COLLECTED_TIME = stats['COLLECTED_TIME']) stats.save() # print stats.id result['status'] = 'True' result['error'] = "" try: r.rpush("check_stats",stats.id) except: result['error'] = "unable to add it to check status queque" return HttpResponse(json.dumps(result), content_type="application/json") except: result['status'] = 'False' print sys.exc_info() result['error'] = "Unexpected error:" + str(sys.exc_info()[0]) return HttpResponse(json.dumps(result), content_type="application/json") else: result['status'] = 'False' result['error'] = "Couldnt find the stats variable" return HttpResponse(json.dumps(result), content_type="application/json") else: result['status'] = 'False' result['error'] = "Using unknown request type" return HttpResponse(json.dumps(result), content_type="application/json")
def footer_link(request): if Statistics.disabled(): return '' link = '<a id="page-special-statistics" href="' + reverse( 'wouso.interface.apps.statistics.views.stats') + '">' + _( 'Live stats') + '</a>' return link
def render(cls, page, data = None): if not data: return NoRenderer.render(page) stats = Statistics.get_by_campaign_and_namespace(page.campaign, page.namespace) # todo, how to clean the type assoc to the campaign/namespace logging.info('Getting visualization for: %s' % stats.type) url = visualize.get(stats.type).get_url(page.request, data) logging.info('Redirecting to: %s' % url) if url: if DEBUG: return page.response.out.write('<img src="%s" />' % url) return page.redirect(url) page.response.set_status(500)
def add_statistics(): try: for data in request.json['country_statistics']: country = data['country'] code = data['code'] flag = data['flag'] coordinates = data['coordinates'] confirmed = data['confirmed'] deaths = data['deaths'] recovered = data['recovered'] all_states = [] for state in data['states']: states = States(key=state['key'], name=state['name'], address=state['address'], latitude=state['latitude'], longitude=state['longitude'], confirmed=state['confirmed'], deaths=state['deaths'], recovered=state['recovered']) states.save() all_states.append(states) statistics = Statistics(country=country, code=code, flag=flag, coordinates=coordinates, confirmed=confirmed, deaths=deaths, recovered=recovered, states=all_states) statistics.save() return make_response(jsonify({"success": request.json}), 201) except KeyError: abort(400)
def updateUserStatistics(account_id): try: req = request.get_json() user = User.query.filter_by(account_id=account_id).options( db.load_only("id")).first() stats = Statistics(user_id=user.id, wins=req['wins'], losses=req['losses'], score=req['score'], level=req['level']) db.session.add(stats) db.session.commit() resp = {"success": "statistics has been added successfully"} return respond(resp, 201) except: return respond({"error": "user not found"}, 404)
def get_statistics(cls, campaign, ns, path = ''): data = Statistics.get_by_campaign_and_namespace(campaign, ns) if (data and path): data = util.getattr_by_path(data, path) return data
def footer_link(request): if Statistics.disabled(): return '' link = '<a id="page-special-statistics" href="' + reverse('wouso.interface.apps.statistics.views.stats') + '">' + _('Live stats') + '</a>' return link
h_name=game['home_team']['country'] h_ball_possession = game['home_team_statistics']['ball_possession'] a_goals = game['away_team']['goals'] a_name=game['away_team']['country'] a_ball_possession = game['away_team_statistics']['ball_possession'] h_distance_covered = game['home_team_statistics']['distance_covered'] a_distance_covered = game['away_team_statistics']['distance_covered'] h_pass_accuracy = game['home_team_statistics']['pass_accuracy'] a_pass_accuracy = game['away_team_statistics']['pass_accuracy'] h_on_target = game['home_team_statistics']['on_target'] a_on_target = game['away_team_statistics']['on_target'] h_stats = Statistics(name=h_name,game = game_object, team = h_team, ball_possession =h_ball_possession, goals = h_goals, distance_covered = h_distance_covered, pass_accuracy = h_pass_accuracy, on_target = h_on_target) a_stats = Statistics(name=a_name,game = game_object, team = a_team, ball_possession =a_ball_possession, goals = a_goals, distance_covered = a_distance_covered, pass_accuracy = a_pass_accuracy, on_target = a_on_target) all_stats.append(h_stats) all_stats.append(a_stats) # db.session.add_all(all_game_objects) # db.session.commit()