@classmethod
    @custommetrics_service
    @secure_post
    def add_event_batch(cls, slug, params=None):
        # Only a validation simulation! Custom events are only tracked on the game site.
        try:
            session = cls.game_session_list.get_session(params['gameSessionId'])
        except (KeyError, TypeError):
            raise BadRequest('Invalid game session id')

        game = session.game
        if game is None:
            raise ApiException('No game with that slug')

        if slug != game.slug:
            raise BadRequest('Slug and game session do not match')

        try:
            event_batch = params['batch']
        except (TypeError, KeyError):
            raise BadRequest('Event batch missing')
        del params['batch']

        if not isinstance(event_batch, list):
            raise BadRequest('Event batch must be an array of events')

        for event in event_batch:
            try:
                event_key = event['key']
            except (TypeError, KeyError):
                raise BadRequest('Event key missing')

            try:
                event_value = event['value']
            except (TypeError, KeyError):
                raise BadRequest('Event value missing')

            try:
                event_key, event_value = _validate_event(event_key, event_value)
            except ValueError as e:
                raise BadRequest(e.message)

            try:
                event_time = float(event['timeOffset'])
            except (TypeError, KeyError):
                raise BadRequest('Event time offset missing')
            except ValueError:
                raise BadRequest('Event time offset should be a float')

            if event_time > 0:
                raise BadRequest('Event time offsets should be <= 0 to represent older events')

        # If reaches this point, assume success
        return  {'ok': True, 'data': {'msg': 'Added %d events ' \
                                             '(Simulation only - Custom events are only tracked on the game site)' %
                                             len(event_batch)}}
dataset/ETHPy150Open turbulenz/turbulenz_local/turbulenz_local/controllers/apiv1/custommetrics.py/CustommetricsController.add_event_batch/original