Module redvox.tests.session_model_test
Expand source code
from redvox.cloud.client import CloudClient, cloud_client
from redvox.cloud.session_model_api import Session, DynamicSession, SessionModelsResp
from redvox.cloud.errors import CloudApiError
import redvox.common.date_time_utils as dtu
def main() -> None:
# Create a cloud client, make sure your .redvox.toml is where you want it
client: CloudClient
try:
with cloud_client() as client:
# Session models can be queried by owner, id, id:uuid, start_ts (us) end_ts (us)
# At least one filter must be included, lets look at session models for redvoxcore
resp: SessionModelsResp = client.request_session_models(
owner="redvoxcore@gmail.com",
start_ts=int(dtu.datetime_to_epoch_microseconds_utc(dtu.now() - dtu.timedelta(days=2, minutes=30))),
end_ts=int(dtu.datetime_to_epoch_microseconds_utc(dtu.now() - dtu.timedelta(days=2)))
# 1686771282618112.0
)
# This will give you the top level sessions which encapsulate an entire recording session
# Let's just pick the first one as an example.
session: Session = resp.sessions[0]
print(session)
# Top level sessions also contain links to dynamic sessions which encapsulate a given time range.
# Additional requests are made to retrieve dynamic sessions.
# We currently support daily dynamic sessions and hourly dynamic sessions.
# - Top level sessions contain links to daily dynamic sessions.
# - Daily dynamic sessions contain links to hourly dynamic sessions.
# - Hourly dynamic sessions contain links to individual packets.
daily_dynamic_session: DynamicSession = session.query_dynamic_session(
client, session.sub[0]
).dynamic_session
print(daily_dynamic_session)
hourly_dynamic_session: DynamicSession = session.query_dynamic_session(
client, daily_dynamic_session.sub[0]
).dynamic_session
print(hourly_dynamic_session)
print("timing:", session.timing.mean_lat, session.timing.mean_off)
# Let's get at least one packet name
station_id: str = session.id
packet_name: str = f"{station_id}_{hourly_dynamic_session.sub[0]}.rdvxm"
print(packet_name)
except CloudApiError as e:
print(e)
exit(2)
except Exception as e:
print(e)
exit(3)
if __name__ == "__main__":
main()
Functions
def main() ‑> None
-
Expand source code
def main() -> None: # Create a cloud client, make sure your .redvox.toml is where you want it client: CloudClient try: with cloud_client() as client: # Session models can be queried by owner, id, id:uuid, start_ts (us) end_ts (us) # At least one filter must be included, lets look at session models for redvoxcore resp: SessionModelsResp = client.request_session_models( owner="redvoxcore@gmail.com", start_ts=int(dtu.datetime_to_epoch_microseconds_utc(dtu.now() - dtu.timedelta(days=2, minutes=30))), end_ts=int(dtu.datetime_to_epoch_microseconds_utc(dtu.now() - dtu.timedelta(days=2))) # 1686771282618112.0 ) # This will give you the top level sessions which encapsulate an entire recording session # Let's just pick the first one as an example. session: Session = resp.sessions[0] print(session) # Top level sessions also contain links to dynamic sessions which encapsulate a given time range. # Additional requests are made to retrieve dynamic sessions. # We currently support daily dynamic sessions and hourly dynamic sessions. # - Top level sessions contain links to daily dynamic sessions. # - Daily dynamic sessions contain links to hourly dynamic sessions. # - Hourly dynamic sessions contain links to individual packets. daily_dynamic_session: DynamicSession = session.query_dynamic_session( client, session.sub[0] ).dynamic_session print(daily_dynamic_session) hourly_dynamic_session: DynamicSession = session.query_dynamic_session( client, daily_dynamic_session.sub[0] ).dynamic_session print(hourly_dynamic_session) print("timing:", session.timing.mean_lat, session.timing.mean_off) # Let's get at least one packet name station_id: str = session.id packet_name: str = f"{station_id}_{hourly_dynamic_session.sub[0]}.rdvxm" print(packet_name) except CloudApiError as e: print(e) exit(2) except Exception as e: print(e) exit(3)