Skip to content

Commit

Permalink
Recommendation g2024 (#10)
Browse files Browse the repository at this point in the history
* Enabled recommendations for g2024

* Refreshed events

* Fixed recommendations data & prioritise direct matches over recommendations

* Use correct album artwork

* Mention AI 😆
  • Loading branch information
JHFarrant authored Jun 4, 2024
1 parent d0390fc commit 56f4db5
Show file tree
Hide file tree
Showing 4 changed files with 89,738 additions and 145 deletions.
80 changes: 55 additions & 25 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Image,
} from "@spotify/web-api-ts-sdk/dist/mjs/types";
import { Favorite, Event } from "@/types";
import spotifyIDsJson from "../public/g2024SpotifyIDs.json";
import spotifyIDs2Acts from "../public/g2024SpotifyIDs.json";
import rawEvents from "../public/g2024.json";
import moment from "moment";
import { Button, Card, Spinner } from "flowbite-react";
Expand All @@ -26,7 +26,8 @@ import testTopArtists from "../testData/jack/topArtists.json";
import testTopTracks from "../testData/jack/topTracks.json";
import testFollows from "../testData/jack/follows.json";

const testMode = false;
const USE_TEST_SPOTIFY_DATA =
process.env.NEXT_PUBLIC_USE_TEST_SPOTIFY_DATA == "true";

const spotifyTokenStorageID =
"spotify-sdk:AuthorizationCodeWithPKCEStrategy:token";
Expand Down Expand Up @@ -246,7 +247,7 @@ export default function Home() {
setTracksLoading(false);
};

if (testMode) {
if (USE_TEST_SPOTIFY_DATA) {
setTopArtists(testTopArtists as Artist[]);
setTopTracks(testTopTracks as TrackWithAlbum[]);
setFollows(testFollows as Artist[]);
Expand All @@ -264,9 +265,9 @@ export default function Home() {
fetchFollows().catch(console.error);
}
};
const spotifyIDs2ActsIncludingRecommendations: any = spotifyIDsJson;
const spotifyIDs2ActsIncludingRecommendations: any = spotifyIDs2Acts;
const spotifyIDs2ActsWithoutRecommendations: any = Object.entries(
spotifyIDsJson
spotifyIDs2Acts
).reduce(
(filteredSpotifyIds: any, [id, value]: [string, any]) => ({
...filteredSpotifyIds,
Expand All @@ -275,59 +276,54 @@ export default function Home() {
{}
);

// const spotifyIDsIncludingRecommendations: any = Object.keys(spotifyIDs2ActsIncludingRecommendations);

const spotifyIDs2Acts = recommendationsEnabled
? spotifyIDs2ActsIncludingRecommendations
: spotifyIDs2ActsWithoutRecommendations;
const spotifyIDs = Object.keys(spotifyIDs2Acts);
const spotifyIDsIncludingRecommendations = Object.keys(
spotifyIDs2ActsIncludingRecommendations
);
const spotifyIDsWithoutRecommendations: any = Object.keys(
spotifyIDs2ActsWithoutRecommendations
);

// console.log(JSON.stringify(spotifyIDs, null, 3));
const matchedArtists = topArtists
.filter((a) => spotifyIDs.includes(a.id))
.filter((a) => spotifyIDsWithoutRecommendations.includes(a.id))
.reduce((artists, a) => {
const matchedArtist = spotifyIDs2Acts[a.id];
const matchedArtist = spotifyIDs2ActsWithoutRecommendations[a.id];
return {
...artists,
[matchedArtist.act_name]: {
artist: matchedArtist.related_artist_name
? matchedArtist.act_artist_data
: a,
artist: matchedArtist.act_artist_data,
setName: matchedArtist.act_name,
relatedArtistName: matchedArtist.related_artist_name,
},
};
}, {});

const matchedFollows = follows
.filter((a) => spotifyIDs.includes(a.id))
.filter((a) => spotifyIDsWithoutRecommendations.includes(a.id))
.reduce((artists, a) => {
const matchedArtist = spotifyIDs2Acts[a.id];
const matchedArtist = spotifyIDs2ActsWithoutRecommendations[a.id];
return {
...artists,
[matchedArtist.act_name]: {
artist: a,
artist: matchedArtist.act_artist_data,
setName: matchedArtist.act_name,
relatedArtistName: matchedArtist.related_artist_name,
},
};
}, {});

const spotifyIDsWithoutRecommendations: any = Object.keys(
spotifyIDs2ActsWithoutRecommendations
);
const matchedArtistsWithTracks = topTracks.reduce(
(artists, t) => ({
...artists,
...t.artists
.filter((a) => spotifyIDsWithoutRecommendations.includes(a.id))
.reduce((trackArtists, a) => {
const matchedArtist = spotifyIDs2Acts[a.id];
const matchedArtist = spotifyIDs2ActsWithoutRecommendations[a.id];
return {
...trackArtists,
[matchedArtist.act_name]: {
track: t,
artist: a,
artist: matchedArtist.act_artist_data,
setName: matchedArtist.act_name,
relatedArtistName: null,
},
Expand All @@ -337,6 +333,38 @@ export default function Home() {
{}
);

const matchedRecommendedArtists = recommendationsEnabled
? topArtists
.filter((a) => spotifyIDsIncludingRecommendations.includes(a.id))
.reduce((artists, a) => {
const matchedArtist = spotifyIDs2ActsIncludingRecommendations[a.id];
return {
...artists,
[matchedArtist.act_name]: {
artist: matchedArtist.act_artist_data,
setName: matchedArtist.act_name,
relatedArtistName: matchedArtist.related_artist_name,
},
};
}, {})
: {};

const matchedRecommendedFollows = recommendationsEnabled
? follows
.filter((a) => spotifyIDsIncludingRecommendations.includes(a.id))
.reduce((artists, a) => {
const matchedArtist = spotifyIDs2ActsIncludingRecommendations[a.id];
return {
...artists,
[matchedArtist.act_name]: {
artist: matchedArtist.act_artist_data,
setName: matchedArtist.act_name,
relatedArtistName: matchedArtist.related_artist_name,
},
};
}, {})
: {};

const extractEventsByTime = (json: any): Event[] => {
const events = json.locations.reduce(
(events: any, location: any) =>
Expand Down Expand Up @@ -369,6 +397,8 @@ export default function Home() {
// );

const favoriteArtists: { [key: string]: Favorite } = {
...matchedRecommendedArtists,
...matchedRecommendedFollows,
...matchedArtistsWithTracks,
...matchedArtists,
...matchedFollows,
Expand Down Expand Up @@ -466,7 +496,7 @@ export default function Home() {
setInitialLoadDone(true);
}
};
if (testMode) {
if (USE_TEST_SPOTIFY_DATA) {
setUser(true);
setInitialLoadDone(true);
fetchAll();
Expand Down
37 changes: 21 additions & 16 deletions components/itinerary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ const Itinearry = ({
return (
<>
<Card className={showShareDrawer ? "mb-20" : ""}>
{/* <div className="flex items-center justify-center">
<h5 className="text-xl font-bold leading-none text-gray-900 dark:text-white">
{"Your Glasto Set Menu 🔥"}
</h5>
</div>*/}
{/* {!!setRecommendationsEnabled && (
<div className="min-w-150">
<ToggleSwitch
color={"success"}
theme={customThemeToggleSwitch}
checked={recommendationsEnabled}
label="Suggest similar artists"
onChange={() => setRecommendationsEnabled(!recommendationsEnabled)}
/>
</div>
)}*/}
<p className={`text-xs text-center opacity-50`}>
{"Select events to add to your set menu"}
</p>
{!!setRecommendationsEnabled && (
<div className="min-w-150">
<ToggleSwitch
color={"success"}
theme={customThemeToggleSwitch}
checked={recommendationsEnabled}
label="Suggest similar artists using AI ✨"
onChange={() =>
setRecommendationsEnabled(!recommendationsEnabled)
}
/>
</div>
)}
<div className="flow-root">
<ul className="divide-y divide-gray-200 dark:divide-gray-700">
{itineraryInDays.map((dailyItinerary: any) => {
Expand Down Expand Up @@ -237,6 +237,11 @@ const Itinearry = ({
</Button>
</div>
} */}
{!!itineraryInDays.length && <p
className={`pt-5 text-xs text-red-500 text-bold text-center opacity-90`}
>
{"Times are not yet confirmed ⚠️"}
</p>}
{loadingSpotifyData && (
<div className="flex justify-center py-10">
<Spinner aria-label="Extra large spinner example" size="xl" />
Expand Down
15 changes: 8 additions & 7 deletions public/g2024.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"copyright": "Licensed under a Creative Commons Attribution-NonCommercial 3.0 License https://creativecommons.org/licenses/by-nc/3.0/. Free for non-commercial use. Contact halvin@clashfinder.com for other uses.",
"modified": "2024-05-28 13:06",
"modified": "2024-06-01 10:59",
"name": "Glastonbury Festival 2024",
"id": "g2024",
"url": "https://clashfinder.com/s/g2024/",
Expand Down Expand Up @@ -322,7 +322,8 @@
"short": "jungle(1)",
"start": "2024-06-28 22:15",
"end": "2024-06-28 23:45",
"id": "4337d44cf815bc5d38b3cc44ae1c55362f6a9f9fb69ad0f42a4455dc118988f6"
"mbId": "6bbb3983-ce8a-4971-96e0-7cae73268fc4",
"id": "193b7285de5ed516c74c44b006bc64567ddfaa2872f6893a2a0ebdc5e833b51d"
},
{
"name": "47SOUL",
Expand Down Expand Up @@ -950,8 +951,8 @@
"short": "ghetts(1)",
"start": "2024-06-30 19:45",
"end": "2024-06-30 20:45",
"mbId": "f3e2a7d9-c6bb-4848-95e5-04c0a1e2f511",
"id": "2263d0047cc5e36072c97854c90aa79381872251f475782b914ab8d821dbff4c"
"mbId": "62ffd9ee-13a1-49ed-8721-d07fd0b2f07d",
"id": "12fd04fe7d5b1973bdae5f3d6614367d9eba6b98600b2e8d8a6ff2e2c82999e6"
},
{
"name": "London Grammar",
Expand Down Expand Up @@ -1847,11 +1848,11 @@
"id": "6a6e1bf1b7584ecfdc361a5e29215ea67534a41c8763b110bb278ab9b22401d4"
},
{
"name": "Leon Vyneshall",
"short": "leonvy(1)",
"name": "Leon Vynehall",
"short": "leonvy1(1)",
"start": "2024-06-28 18:20",
"end": "2024-06-28 19:05",
"id": "5792d7b7cbd92b23336359d0c9f94e41cf9b8323021edd2d06f662ebd44b2bba"
"id": "92a9d3931857c37c969e2f9dfcfdd9f4b2550a86dfb28601ec7e2e33a7a3201a"
},
{
"name": "Friction",
Expand Down
Loading

0 comments on commit 56f4db5

Please sign in to comment.