예제 #1
0
파일: obd.py 프로젝트: rqroz/obd-dashboard
    def process_sensor_params(self, data: dict):
        """
        Process data receive from TORQUE.
        If identifies that the data is composed by keys identifying sensor specs, will register such specs in the DB.
        Sensors currently considered are described in <app.constants.obd.CarSensorID>.

        Args:
            - data (dict): Data to be processed.
        """
        LOGGER.info('Receiving sensor data from TORQUE', **data)
        has_non_value_keys = any(
            filter(
                re.compile(f'.*(unit|user).*', re.IGNORECASE).match,
                data.keys()))
        if has_non_value_keys:
            LOGGER.info(
                'Will ignore request since it\'s related to sensor params')
            return

        user = self._resolve_user(data)
        LOGGER.info(
            f'Request is attached to {user.first_name} {user.last_name}',
            user_id=user.id)
        session = SessionController(user_id=user.id).get_or_create(
            data['session'])
        LOGGER.info('Resolved session to proceed', **session.to_dict())

        car_state = CarState.create_from_torque(self.db_session, session, data)
        if car_state:
            LOGGER.info('Created Car State', **car_state.to_dict())
            self.db_session.commit()
예제 #2
0
    def session_get_profile_view(user, session_id):
        """ Retrieves complete data package on a certain session for the current user """
        session = SessionController(user_id=user.id).get(session_id)
        if not session:
            response = jsonify({'message': 'Unable to find session'})
            response.status_code = 404
            return response

        return jsonify(session.get_profile())
예제 #3
0
    def session_get_view(user, session_id):
        """ Retrieves complete data package on a certain session for the current user """
        session = SessionController(user_id=user.id).get(session_id)
        if not session:
            response = jsonify({'message': 'Unable to find session'})
            response.status_code = 404
            return response

        data = session.to_dict()
        data['car_states'] = [state.to_dict() for state in session.car_states]
        return jsonify(data)
예제 #4
0
def get_session_controller(user=None):
    """
    Gets an instance of the SessionController based on <user>.
    If <user> is not informed, will resolve it from current request.

    Raises:
        - AuthHandlerException: If user is not informed and request is not authenticated.

    Args:
        - user (app.models.user.User): User instance.

    Returns:
        - (app.controllers.obd.session.SessionController): Instance of the SessionController.
    """
    if not user:
        user = AuthHandler.handle_auth_request()
    return SessionController(user_id=user.id, db_session=DATABASE.session)
예제 #5
0
 def locations_view(user):
     return jsonify(SessionController(user_id=user.id).get_locations())
예제 #6
0
 def summary_view(user):
     return jsonify(SessionController(user_id=user.id).get_summary())
예제 #7
0
 def session_list_view(user):
     """ Retrieves basic data on all sessions for the current user """
     sessions = SessionController(user_id=user.id).get_all()
     return jsonify({'list': [session.to_dict() for session in sessions]})