From b2fb497ecf09bd38db83fc9a90ba6f449037e599 Mon Sep 17 00:00:00 2001 From: danis Date: Fri, 22 Sep 2023 14:53:36 +0200 Subject: [PATCH 1/8] populate.py updated with midi length --- assets/populate.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/assets/populate.py b/assets/populate.py index 387c914..4f2d233 100755 --- a/assets/populate.py +++ b/assets/populate.py @@ -4,6 +4,7 @@ import sys import os import requests import glob +from mido import MidiFile from configparser import ConfigParser url = os.environ.get("API_URL") @@ -20,16 +21,16 @@ def getOrCreateAlbum(name, artistId): return out["id"] def getOrCreateGenre(names): - ids = [] - for name in names.split(","): - res = requests.post(f"{url}/genre", json={ - "name": name, - }) - out = res.json() - print(out) - ids += [out["id"]] - #TODO handle multiple genres - return ids[0] + ids = [] + for name in names.split(","): + res = requests.post(f"{url}/genre", json={ + "name": name, + }) + out = res.json() + print(out) + ids += [out["id"]] + #TODO handle multiple genres + return ids[0] def getOrCreateArtist(name): res = requests.post(f"{url}/artist", json={ @@ -42,8 +43,10 @@ def getOrCreateArtist(name): def populateFile(path, midi, mxl): config = ConfigParser() config.read(path) + mid = MidiFile(midi) metadata = config["Metadata"]; difficulties = dict(config["Difficulties"]) + difficulties["length"] = round((mid.length), 2) artistId = getOrCreateArtist(metadata["Artist"]) print(f"Populating {metadata['Name']}") res = requests.post(f"{url}/song", json={ @@ -58,6 +61,11 @@ def populateFile(path, midi, mxl): }) print(res.json()) +def addLenghtToIni(path): + mid = MidiFile(file) + lenght = round((mid.length), 2) + print(f"song file: {file} lenght: {lenght}") + def main(): global url From a81c0b83bb3339e9028f73ed8e7a80576ee63392 Mon Sep 17 00:00:00 2001 From: danis Date: Fri, 22 Sep 2023 15:08:28 +0200 Subject: [PATCH 2/8] song length SongRow --- front/components/SongRow.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/front/components/SongRow.tsx b/front/components/SongRow.tsx index a2c0588..c300a46 100644 --- a/front/components/SongRow.tsx +++ b/front/components/SongRow.tsx @@ -55,6 +55,14 @@ const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { > {song.artistId ?? 'artist'} + + {song.details.length ?? '--.--'} + Date: Fri, 22 Sep 2023 15:49:12 +0200 Subject: [PATCH 3/8] added DurationInfo --- front/components/SongRow.tsx | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/front/components/SongRow.tsx b/front/components/SongRow.tsx index c300a46..5e8ad24 100644 --- a/front/components/SongRow.tsx +++ b/front/components/SongRow.tsx @@ -11,6 +11,26 @@ type SongRowProps = { handleLike: (state: boolean, songId: number) => Promise; }; +type DurationInfoProps = { + length: number; +} + +const DurationInfo = ({length}: DurationInfoProps) => { + const minutes = Math.floor(length / 60); + const seconds = Math.round(length - minutes * 60); + + return ( + + {`${minutes}'${seconds}` ?? '--.--'} + + ); +} + const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { return ( @@ -55,14 +75,7 @@ const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { > {song.artistId ?? 'artist'} - - {song.details.length ?? '--.--'} - + Date: Fri, 22 Sep 2023 15:50:26 +0200 Subject: [PATCH 4/8] pretty --- front/components/SongRow.tsx | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/front/components/SongRow.tsx b/front/components/SongRow.tsx index 5e8ad24..d2a2276 100644 --- a/front/components/SongRow.tsx +++ b/front/components/SongRow.tsx @@ -12,24 +12,24 @@ type SongRowProps = { }; type DurationInfoProps = { - length: number; -} + length: number; +}; -const DurationInfo = ({length}: DurationInfoProps) => { - const minutes = Math.floor(length / 60); - const seconds = Math.round(length - minutes * 60); +const DurationInfo = ({ length }: DurationInfoProps) => { + const minutes = Math.floor(length / 60); + const seconds = Math.round(length - minutes * 60); - return ( - - {`${minutes}'${seconds}` ?? '--.--'} - - ); -} + return ( + + {`${minutes}'${seconds}` ?? '--.--'} + + ); +}; const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { return ( @@ -75,7 +75,7 @@ const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { > {song.artistId ?? 'artist'} - + Date: Mon, 25 Sep 2023 14:24:08 +0200 Subject: [PATCH 5/8] Duration component --- front/components/DurationComponent.tsx | 29 ++++++++++++++++++++++++++ front/components/FavSongRow.tsx | 2 ++ front/components/SongRow.tsx | 24 +++------------------ front/views/SongLobbyView.tsx | 2 ++ 4 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 front/components/DurationComponent.tsx diff --git a/front/components/DurationComponent.tsx b/front/components/DurationComponent.tsx new file mode 100644 index 0000000..87ac0e6 --- /dev/null +++ b/front/components/DurationComponent.tsx @@ -0,0 +1,29 @@ +import { Box, Icon, Text } from 'native-base'; +import { MaterialIcons } from '@expo/vector-icons'; + +type DurationComponentProps = { + length: number; +}; + +const DurationComponent = ({ length }: DurationComponentProps) => { + const minutes = Math.floor(length / 60); + const seconds = Math.round(length - minutes * 60); + + return ( + + + + {`${minutes}'${seconds}` ?? '--\'--'} + + + ); +}; + +export default DurationComponent; \ No newline at end of file diff --git a/front/components/FavSongRow.tsx b/front/components/FavSongRow.tsx index c015b2a..db1b060 100644 --- a/front/components/FavSongRow.tsx +++ b/front/components/FavSongRow.tsx @@ -4,6 +4,7 @@ import TextButton from './TextButton'; import { LikedSongWithDetails } from '../models/LikedSong'; import { MaterialIcons } from '@expo/vector-icons'; import API from '../API'; +import DurationComponent from './DurationComponent'; type FavSongRowProps = { FavSong: LikedSongWithDetails; // TODO: remove Song @@ -54,6 +55,7 @@ const FavSongRow = ({ FavSong, onPress }: FavSongRowProps) => { > {FavSong.addedDate.toLocaleDateString()} + Promise; }; -type DurationInfoProps = { - length: number; -}; - -const DurationInfo = ({ length }: DurationInfoProps) => { - const minutes = Math.floor(length / 60); - const seconds = Math.round(length - minutes * 60); - - return ( - - {`${minutes}'${seconds}` ?? '--.--'} - - ); -}; - const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { return ( @@ -75,7 +56,8 @@ const SongRow = ({ song, onPress, handleLike, isLiked }: SongRowProps) => { > {song.artistId ?? 'artist'} - + {/* */} + ) => { } /> + Date: Mon, 25 Sep 2023 14:51:20 +0200 Subject: [PATCH 6/8] css whatever + pretty --- front/components/DurationComponent.tsx | 24 +++++++++++++++--------- front/views/SongLobbyView.tsx | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/front/components/DurationComponent.tsx b/front/components/DurationComponent.tsx index 87ac0e6..5e22b20 100644 --- a/front/components/DurationComponent.tsx +++ b/front/components/DurationComponent.tsx @@ -1,4 +1,4 @@ -import { Box, Icon, Text } from 'native-base'; +import { HStack, Icon, Text } from 'native-base'; import { MaterialIcons } from '@expo/vector-icons'; type DurationComponentProps = { @@ -10,20 +10,26 @@ const DurationComponent = ({ length }: DurationComponentProps) => { const seconds = Math.round(length - minutes * 60); return ( - - + + - {`${minutes}'${seconds}` ?? '--\'--'} + {`${minutes}'${seconds}` ?? "--'--"} - + ); }; -export default DurationComponent; \ No newline at end of file +export default DurationComponent; diff --git a/front/views/SongLobbyView.tsx b/front/views/SongLobbyView.tsx index 7bd6c31..09be78b 100644 --- a/front/views/SongLobbyView.tsx +++ b/front/views/SongLobbyView.tsx @@ -67,7 +67,7 @@ const SongLobbyView = (props: RouteProps) => { } /> - + Date: Mon, 25 Sep 2023 17:17:05 +0200 Subject: [PATCH 7/8] removed useless function --- assets/populate.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/assets/populate.py b/assets/populate.py index 4f2d233..4b06513 100755 --- a/assets/populate.py +++ b/assets/populate.py @@ -61,12 +61,6 @@ def populateFile(path, midi, mxl): }) print(res.json()) -def addLenghtToIni(path): - mid = MidiFile(file) - lenght = round((mid.length), 2) - print(f"song file: {file} lenght: {lenght}") - - def main(): global url if url == None: From cd87451208843285f85f4f33b412a39b88f29a80 Mon Sep 17 00:00:00 2001 From: Arthur Jamet Date: Mon, 25 Sep 2023 17:55:46 +0200 Subject: [PATCH 8/8] Front: Typechecking --- front/components/DurationComponent.tsx | 8 ++++---- front/yarn.lock | 21 ++++++--------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/front/components/DurationComponent.tsx b/front/components/DurationComponent.tsx index 5e22b20..830471f 100644 --- a/front/components/DurationComponent.tsx +++ b/front/components/DurationComponent.tsx @@ -2,12 +2,12 @@ import { HStack, Icon, Text } from 'native-base'; import { MaterialIcons } from '@expo/vector-icons'; type DurationComponentProps = { - length: number; + length: number | undefined; }; const DurationComponent = ({ length }: DurationComponentProps) => { - const minutes = Math.floor(length / 60); - const seconds = Math.round(length - minutes * 60); + const minutes = Math.floor((length ?? 0) / 60); + const seconds = Math.round((length ?? 0) - minutes * 60); return ( @@ -26,7 +26,7 @@ const DurationComponent = ({ length }: DurationComponentProps) => { }} fontSize={'16px'} > - {`${minutes}'${seconds}` ?? "--'--"} + {length ? `${minutes}'${seconds}` : "--'--"} ); diff --git a/front/yarn.lock b/front/yarn.lock index 4e17b2b..68f46b0 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -4755,7 +4755,7 @@ dependencies: "@types/react" "*" -"@types/react-native@~0.70.6": +"@types/react-native@~0.70.5": version "0.70.14" resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.70.14.tgz#8619b8c94296f6456c5362d74a3d1b4fad3f54ab" integrity sha512-Kwc+BYBrnDqvacNxKp1UtcZJnJJnTih2NYmi/ieAKlHdxEPN6sYMwmIwgHdoLHggvml6bf3DYRaH2jt+gzaLjw== @@ -4783,7 +4783,7 @@ dependencies: "@types/react" "*" -"@types/react@*": +"@types/react@*", "@types/react@~18.2.0": version "18.2.22" resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.22.tgz#abe778a1c95a07fa70df40a52d7300a40b949ccb" integrity sha512-60fLTOLqzarLED2O3UQImc/lsNRgG0jE/a1mPW9KjMemY0LMITWEsbS4VvZ4p6rorEHd5YKxxmMKSDK505GHpA== @@ -4792,15 +4792,6 @@ "@types/scheduler" "*" csstype "^3.0.2" -"@types/react@~18.0.24": - version "18.0.38" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.38.tgz#02a23bef8848b360a0d1dceef4432c15c21c600c" - integrity sha512-ExsidLLSzYj4cvaQjGnQCk4HFfVT9+EZ9XZsQ8Hsrcn8QNgXtpZ3m9vSIC2MWtx7jHictK6wYhQgGh6ic58oOw== - dependencies: - "@types/prop-types" "*" - "@types/scheduler" "*" - csstype "^3.0.2" - "@types/scheduler@*": version "0.16.3" resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5" @@ -15713,10 +15704,10 @@ react-use-precision-timer@^3.3.1: dependencies: react-sub-unsub "^2.1.6" -react@18.1.0: - version "18.1.0" - resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890" - integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ== +react@18.2.0: + version "18.2.0" + resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5" + integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ== dependencies: loose-envify "^1.1.0"