Пример #1
0
def _build_cbsd(cbsd: DBCbsd) -> Cbsd:
    # Application may not need those to be sorted.
    # Applying ordering mostly for easier assertions in testing
    config = cbsd.active_mode_config[0]
    cbsd_db_grants = sorted(cbsd.grants, key=lambda x: x.id)
    cbsd_db_channels = sorted(cbsd.channels, key=lambda x: x.id)

    grants = [_build_grant(x) for x in cbsd_db_grants]
    channels = [_build_channel(x) for x in cbsd_db_channels]

    last_seen = _to_timestamp(cbsd.last_seen)
    eirp_capabilities = _build_eirp_capabilities(cbsd)
    db_data = _build_db_data(cbsd)
    return Cbsd(
        id=cbsd.cbsd_id,
        user_id=cbsd.user_id,
        fcc_id=cbsd.fcc_id,
        serial_number=cbsd.cbsd_serial_number,
        state=cbsd_state_mapping[cbsd.state.name],
        desired_state=cbsd_state_mapping[config.desired_state.name],
        grants=grants,
        channels=channels,
        last_seen_timestamp=last_seen,
        eirp_capabilities=eirp_capabilities,
        grant_attempts=cbsd.grant_attempts,
        db_data=db_data,
    )
Пример #2
0
def _build_cbsd(cbsd: DBCbsd) -> Cbsd:
    # Application may not need those to be sorted.
    # Applying ordering mostly for easier assertions in testing
    cbsd_db_grants = sorted(cbsd.grants, key=lambda x: x.id)
    cbsd_db_channels = sorted(cbsd.channels, key=lambda x: x.id)

    grants = [_build_grant(x) for x in cbsd_db_grants]
    channels = [_build_channel(x) for x in cbsd_db_channels]

    last_seen = _to_timestamp(cbsd.last_seen)
    eirp_capabilities = _build_eirp_capabilities(cbsd)
    preferences = _build_preferences(cbsd)
    sas_settings = _build_sas_settings(cbsd)
    installation_params = _build_installation_params(cbsd)
    db_data = _build_db_data(cbsd)
    grant_settings = _build_grant_settings(cbsd)
    return Cbsd(
        cbsd_id=cbsd.cbsd_id,
        state=cbsd_state_mapping[cbsd.state.name],
        desired_state=cbsd_state_mapping[cbsd.desired_state.name],
        grants=grants,
        channels=channels,
        last_seen_timestamp=last_seen,
        eirp_capabilities=eirp_capabilities,
        grant_attempts=cbsd.grant_attempts,
        db_data=db_data,
        preferences=preferences,
        sas_settings=sas_settings,
        installation_params=installation_params,
        grant_settings=grant_settings,
    )
Пример #3
0
    def _build_cbsd(self, config: DBActiveModeConfig) -> Cbsd:
        cbsd = config.cbsd
        # Application may not need those to be sorted.
        # Applying ordering mostly for easier assertions in testing
        cbsd_db_grants = sorted(cbsd.grants, key=lambda x: x.id)
        cbsd_db_channels = sorted(cbsd.channels, key=lambda x: x.id)

        grants = [self._build_grant(x) for x in cbsd_db_grants]
        channels = [self._build_channel(x) for x in cbsd_db_channels]
        pending_requests = [self._build_request(x) for x in cbsd.requests]

        last_seen = _to_timestamp(cbsd.last_seen)
        eirp_capabilities = self._build_eirp_capabilities(cbsd)
        db_data = self._build_db_data(cbsd)
        return Cbsd(
            id=cbsd.cbsd_id,
            user_id=cbsd.user_id,
            fcc_id=cbsd.fcc_id,
            serial_number=cbsd.cbsd_serial_number,
            state=cbsd_state_mapping[cbsd.state.name],
            desired_state=cbsd_state_mapping[config.desired_state.name],
            grants=grants,
            channels=channels,
            pending_requests=pending_requests,
            last_seen_timestamp=last_seen,
            eirp_capabilities=eirp_capabilities,
            db_data=db_data,
        )
Пример #4
0
 def _build_cbsd(self, session: Session, cbsd: DBCbsd) -> Cbsd:
     db_grants = session.query(DBGrant).join(DBGrantState).filter(
         DBGrant.cbsd_id == cbsd.id,
         DBGrantState.name != GrantStates.IDLE.value,
     )
     pending_requests_payloads = session.query(DBRequest.payload, ).join(
         DBRequestState, ).filter(
             DBRequestState.name == RequestStates.PENDING.value,
             DBRequest.cbsd_id == cbsd.id,
         )
     grants = [self._build_grant(x) for x in db_grants]
     channels = [self._build_channel(x) for x in cbsd.channels]
     pending_requests = [
         json.dumps(r.payload, separators=(',', ':'))
         for r in pending_requests_payloads
     ]
     last_seen = self._to_timestamp(cbsd.last_seen)
     eirp_capabilities = self._build_eirp_capabilities(cbsd)
     return Cbsd(
         id=cbsd.cbsd_id,
         user_id=cbsd.user_id,
         fcc_id=cbsd.fcc_id,
         serial_number=cbsd.cbsd_serial_number,
         state=cbsd_state_mapping[cbsd.state.name],
         grants=grants,
         channels=channels,
         pending_requests=pending_requests,
         last_seen_timestamp=last_seen,
         eirp_capabilities=eirp_capabilities,
     )
Пример #5
0
 def build(self) -> Cbsd:
     return Cbsd(
         cbsd_id=self.cbsd_id,
         sas_settings=self.sas_settings,
         state=self.state,
         desired_state=self.desired_state,
         grants=self.grants,
         channels=self.channels,
         last_seen_timestamp=self.last_seen_timestamp,
         eirp_capabilities=self.eirp_capabilities,
         db_data=self.db_data,
         preferences=self.preferences,
         installation_params=self.installation,
         grant_settings=self.grant_settings,
     )
Пример #6
0
 def build(self) -> ActiveModeConfig:
     cbsd = Cbsd(
         id=self.cbsd_id,
         user_id=self.user_id,
         fcc_id=self.fcc_id,
         serial_number=self.serial_number,
         state=self.state,
         grants=self.grants,
         channels=self.channels,
         pending_requests=self.pending_requests,
         last_seen_timestamp=self.last_seen_timestamp,
         eirp_capabilities=self.eirp_capabilities,
     )
     return ActiveModeConfig(
         desired_state=self.desired_state,
         cbsd=cbsd,
     )
Пример #7
0
 def build(self) -> Cbsd:
     db_data = DatabaseCbsd(
         id=self.db_id,
         is_updated=self.is_updated,
         is_deleted=self.is_deleted,
     )
     return Cbsd(
         id=self.cbsd_id,
         user_id=self.user_id,
         fcc_id=self.fcc_id,
         serial_number=self.serial_number,
         state=self.state,
         desired_state=self.desired_state,
         grants=self.grants,
         channels=self.channels,
         last_seen_timestamp=self.last_seen_timestamp,
         grant_attempts=self.grant_attempts,
         eirp_capabilities=self.eirp_capabilities,
         db_data=db_data,
     )