artemis-model 0.1.95__tar.gz → 0.1.97__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {artemis_model-0.1.95 → artemis_model-0.1.97}/PKG-INFO +1 -1
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/redis/__init__.py +2 -0
- artemis_model-0.1.97/artemis_model/redis/bucket.py +54 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/redis/keys.py +1 -0
- artemis_model-0.1.97/artemis_model/redis/play_history +43 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/pyproject.toml +1 -1
- {artemis_model-0.1.95 → artemis_model-0.1.97}/README.md +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/__init__.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/album.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/artist.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/auth.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/base.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/category.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/dj_set.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/genre.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/location.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/message.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/organization.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/otp.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/permission.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/playlist.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/redis/device.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/redis/zone_state.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/schedule.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/setting.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/sqs/__init__.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/sqs/messages.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/track.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/user.py +0 -0
- {artemis_model-0.1.95 → artemis_model-0.1.97}/artemis_model/zone.py +0 -0
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
from .zone_state import ZoneState, NowPlaying, SessionId, BucketId
|
4
4
|
from .device import ActiveDevice
|
5
|
+
from .bucket import RedisTrackBucketItem
|
5
6
|
from .keys import (
|
6
7
|
KEY_ZONE_PLAY_HISTORY_TEMPLATE,
|
7
8
|
KEY_ZONE_PUSH_PLAYLIST_BUCKET_TEMPLATE,
|
@@ -21,4 +22,5 @@ __all__ = [
|
|
21
22
|
"KEY_ZONE_SCHEDULE_BUCKET_TEMPLATE",
|
22
23
|
"KEY_ZONE_STATE_TEMPLATE",
|
23
24
|
"KEY_ZONE_ACTIVE_DEVICE_TEMPLATE",
|
25
|
+
"RedisTrackBucketItem",
|
24
26
|
]
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"""Redis track buckets"""
|
2
|
+
from pydantic import BaseModel, Field, ConfigDict
|
3
|
+
from typing import Annotated
|
4
|
+
from datetime import datetime, timezone
|
5
|
+
import uuid
|
6
|
+
|
7
|
+
|
8
|
+
TrackId = Annotated[
|
9
|
+
uuid.UUID,
|
10
|
+
Field(description="Track ID (UUID)")
|
11
|
+
]
|
12
|
+
|
13
|
+
PlaylistId = Annotated[
|
14
|
+
int,
|
15
|
+
Field(description="Playlist ID (integer)")
|
16
|
+
]
|
17
|
+
|
18
|
+
Timestamp = Annotated[
|
19
|
+
int,
|
20
|
+
Field(description="Unix timestamp")
|
21
|
+
]
|
22
|
+
|
23
|
+
|
24
|
+
class RedisTrackBucketItem(BaseModel):
|
25
|
+
"""
|
26
|
+
Represents a composite Redis key along with a timestamp.
|
27
|
+
The Redis entry will be:
|
28
|
+
{ '{"track_id": "...", "playlist_id": ...}': ts }
|
29
|
+
ts is the timestamp of utc now.
|
30
|
+
"""
|
31
|
+
|
32
|
+
track_id: TrackId
|
33
|
+
playlist_id: PlaylistId
|
34
|
+
ts: Timestamp = Field(default_factory=lambda: int(datetime.now(timezone.utc).timestamp()))
|
35
|
+
|
36
|
+
model_config = ConfigDict(
|
37
|
+
json_encoders={uuid.UUID: str},
|
38
|
+
populate_by_name=True
|
39
|
+
)
|
40
|
+
|
41
|
+
def as_redis_entry(self) -> dict[str, int]:
|
42
|
+
"""
|
43
|
+
Generate a Redis-ready dictionary:
|
44
|
+
{ '{"track_id": "...", "playlist_id": ...}': ts }
|
45
|
+
"""
|
46
|
+
key = self.model_dump_json(include={"track_id", "playlist_id"})
|
47
|
+
return {key: self.ts}
|
48
|
+
|
49
|
+
@classmethod
|
50
|
+
def from_redis_entry(cls, entry: dict[str, int]) -> "RedisTrackBucketItem":
|
51
|
+
"""
|
52
|
+
Parse a Redis entry into a RedisTrackBucketItem.
|
53
|
+
"""
|
54
|
+
return cls.model_validate_json(list(entry.keys())[0])
|
@@ -6,6 +6,7 @@ KEY_ZONE_SCHEDULE_BUCKET_TEMPLATE = "zone_{zone_id}_sc_bucket_{timeslot_ts}"
|
|
6
6
|
KEY_ZONE_STATE_TEMPLATE = "zone_{zone_id}_state"
|
7
7
|
KEY_ZONE_ACTIVE_DEVICE_TEMPLATE = "zone_{zone_id}_active_devices"
|
8
8
|
|
9
|
+
|
9
10
|
__all__ = [
|
10
11
|
"KEY_ZONE_PLAY_HISTORY_TEMPLATE",
|
11
12
|
"KEY_ZONE_PUSH_PLAYLIST_BUCKET_TEMPLATE",
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"""Redis play history"""
|
2
|
+
|
3
|
+
from pydantic import BaseModel, Field
|
4
|
+
from typing import Annotated
|
5
|
+
from datetime import datetime, timezone
|
6
|
+
|
7
|
+
|
8
|
+
TrackId = Annotated[
|
9
|
+
str,
|
10
|
+
Field(description="Track ID (UUID or string)")
|
11
|
+
]
|
12
|
+
|
13
|
+
Timestamp = Annotated[
|
14
|
+
int,
|
15
|
+
Field(description="Unix timestamp")
|
16
|
+
]
|
17
|
+
|
18
|
+
|
19
|
+
class TrackPlayHistoryValue(BaseModel):
|
20
|
+
"""
|
21
|
+
Represents the value stored in Redis sorted set:
|
22
|
+
A string like "track_id#timestamp"
|
23
|
+
"""
|
24
|
+
track_id: TrackId
|
25
|
+
ts: Timestamp = Field(default_factory=lambda: int(datetime.now(timezone.utc).timestamp()))
|
26
|
+
|
27
|
+
def as_redis_entry(self) -> str:
|
28
|
+
"""
|
29
|
+
Generate a Redis-ready string:
|
30
|
+
"track_id#timestamp"
|
31
|
+
"""
|
32
|
+
return f"{self.track_id}#{self.ts}"
|
33
|
+
|
34
|
+
@classmethod
|
35
|
+
def from_redis_entry(cls, value: str) -> "TrackPlayHistoryValue":
|
36
|
+
"""
|
37
|
+
Parse a Redis entry into a TrackPlayHistoryValue.
|
38
|
+
"""
|
39
|
+
try:
|
40
|
+
track_id, ts = value.rsplit("#", 1)
|
41
|
+
return cls(track_id=track_id, ts=int(ts))
|
42
|
+
except Exception as e:
|
43
|
+
raise ValueError(f"Invalid format for TrackPlayHistoryValue: {value}") from e
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|