diff --git a/CHANGELOG.md b/CHANGELOG.md index c96f4dbdfbac8f3c9ea5254268d868e00da8e806..5f2d8b3750a026aad5df7a4a211863706558e089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Provide properties in API schemas in CamelCase notation (aura#141) +- Use datatype float instead of int for `trackDuration` (#132) ### Removed diff --git a/schemas/openapi-tank.json b/schemas/openapi-tank.json index ca1010dc0491535fbb30a17a8431eeb9ea17df76..44daaabcd7c91e63f78985940468b19620594bc4 100644 --- a/schemas/openapi-tank.json +++ b/schemas/openapi-tank.json @@ -27,7 +27,7 @@ "type": "string" }, "duration": { - "type": "integer" + "type": "number" }, "id": { "type": "integer" @@ -128,7 +128,7 @@ "PlaylistEntry": { "properties": { "duration": { - "type": "integer" + "type": "number" }, "file": { "$ref": "#/components/schemas/File" diff --git a/src/aura_engine/scheduling/models.py b/src/aura_engine/scheduling/models.py index b6a5f8f6265b01fa62d72b680a01fa330adbdf0e..3cd6c1fb041ac5a0b23b21c8142017f597f3e2b8 100644 --- a/src/aura_engine/scheduling/models.py +++ b/src/aura_engine/scheduling/models.py @@ -28,10 +28,10 @@ import time import sqlalchemy as sa from sqlalchemy import ( - BigInteger, Column, ColumnDefault, DateTime, + Float, ForeignKey, Integer, String, @@ -407,10 +407,10 @@ class Playlist(DB.Model, AuraDatabaseModel): """Return the total length of the playlist in seconds. Returns: - (Integer): Length in seconds + (Float): Length in seconds """ - total = 0 + total: float = 0 for entry in self.entries: total += entry.duration @@ -447,7 +447,7 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel): # Data entry_num = Column(Integer) - duration = Column(BigInteger) + duration = Column(Float) volume = Column(Integer, ColumnDefault(100)) source = Column(String(1024)) entry_start = Column(DateTime) diff --git a/src/aura_engine/scheduling/programme.py b/src/aura_engine/scheduling/programme.py index 3b42d0ca4cfaf8f126aed355265af6750c717d4d..dcd197ef69497a864e4a06f1ae1180b6bdb124e4 100644 --- a/src/aura_engine/scheduling/programme.py +++ b/src/aura_engine/scheduling/programme.py @@ -450,7 +450,7 @@ class ProgrammeStore: entry_db.entry_start = datetime.fromtimestamp(time_marker) entry_db.artificial_playlist_id = playlist_db.artificial_id entry_db.entry_num = entry_num - entry_db.duration = SU.nano_to_seconds(entry["duration"]) + entry_db.duration = entry["duration"] if "uri" in entry: entry_db.source = entry["uri"] @@ -497,8 +497,8 @@ class ProgrammeStore: """ total_seconds = (timeslot_db.timeslot_end - timeslot_db.timeslot_start).total_seconds() - total_duration = SU.seconds_to_nano(total_seconds) - actual_duration = 0 + total_duration = float(total_seconds) + actual_duration: float = 0 missing_duration = [] idx = 0 diff --git a/src/aura_engine/scheduling/utils.py b/src/aura_engine/scheduling/utils.py index 1ce21d162765cad676c3e790a444d9933b91336c..71ecda105069697208183854e8d964c01b36274f 100644 --- a/src/aura_engine/scheduling/utils.py +++ b/src/aura_engine/scheduling/utils.py @@ -167,7 +167,7 @@ class M3UPlaylistProcessor: "title": metadata[1].split(" - ")[1], } }, - "duration": SU.seconds_to_nano(int(metadata[0])), + "duration": float(metadata[0]), "uri": "file://" + lines[i + 1], } entries.append(entry) diff --git a/src/aura_tank_api/models/file.py b/src/aura_tank_api/models/file.py index 91a95e0a8f688f33f63e4e75cfb4a10537449235..2e45bc180bd49628866276068852b8cb9d839272 100644 --- a/src/aura_tank_api/models/file.py +++ b/src/aura_tank_api/models/file.py @@ -17,7 +17,7 @@ class File: """ Attributes: created (Union[Unset, str]): - duration (Union[Unset, int]): + duration (Union[Unset, float]): id (Union[Unset, int]): metadata (Union[Unset, FileMetadata]): show_name (Union[Unset, str]): @@ -27,7 +27,7 @@ class File: """ created: Union[Unset, str] = UNSET - duration: Union[Unset, int] = UNSET + duration: Union[Unset, float] = UNSET id: Union[Unset, int] = UNSET metadata: Union[Unset, "FileMetadata"] = UNSET show_name: Union[Unset, str] = UNSET diff --git a/src/aura_tank_api/models/playlist_entry.py b/src/aura_tank_api/models/playlist_entry.py index c575c632048a06c3101227b0592c05f3e72fb34d..49d0e349dde616b8a8e5a53365219278a077e082 100644 --- a/src/aura_tank_api/models/playlist_entry.py +++ b/src/aura_tank_api/models/playlist_entry.py @@ -15,12 +15,12 @@ T = TypeVar("T", bound="PlaylistEntry") class PlaylistEntry: """ Attributes: - duration (Union[Unset, int]): + duration (Union[Unset, float]): file (Union[Unset, File]): uri (Union[Unset, str]): """ - duration: Union[Unset, int] = UNSET + duration: Union[Unset, float] = UNSET file: Union[Unset, "File"] = UNSET uri: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/tests/json/tank-api-v1-playlists-1.json b/tests/json/tank-api-v1-playlists-1.json index 4c4b3348eb07b20930de9d785ffb1921c07452d4..efb6a8add441a01355db248ace26c567a7e127c2 100644 --- a/tests/json/tank-api-v1-playlists-1.json +++ b/tests/json/tank-api-v1-playlists-1.json @@ -8,7 +8,7 @@ "entries":[ { "uri":"file://musikprogramm/2", - "duration":199040000000, + "duration":199040000000.0, "file":{ "id":2, "created":"2023-02-28T14:42:09.540485+01:00", @@ -27,7 +27,7 @@ "album":"Test Album" }, "size":36496517, - "duration":199040000000 + "duration":199040000000.0 } } ] diff --git a/tests/test_scheduling_api_tank.py b/tests/test_scheduling_api_tank.py index 06749ef62bd6cf6a58478ba9ffc184e5e3c90333..dbd7db12185282843bc785d211fea8674720f6bf 100644 --- a/tests/test_scheduling_api_tank.py +++ b/tests/test_scheduling_api_tank.py @@ -61,7 +61,7 @@ class TestApiTank(unittest.TestCase): self.assertIsNotNone(1, playlist.entries) self.assertEqual(1, len(entries)) self.assertEqual("file://musikprogramm/2", entries[0].uri) - self.assertEqual(199040000000, entries[0].duration) + self.assertEqual(199040000000.0, entries[0].duration) file = playlist.entries[0].file self.assertEqual(2, file.id)