diff --git a/receiptifyv1/public/index.html b/receiptifyv1/public/index.html index fdb9a97..a78b974 100644 --- a/receiptifyv1/public/index.html +++ b/receiptifyv1/public/index.html @@ -232,7 +232,7 @@

Top Track Generator

- +

Customize Receipt

diff --git a/receiptifyv1/public/server.js b/receiptifyv1/public/server.js index 4437402..f9b3a83 100644 --- a/receiptifyv1/public/server.js +++ b/receiptifyv1/public/server.js @@ -936,8 +936,92 @@ async function nRecentlyPlayed(n, music) { return recentlyPlayedSongs.flat(); } -function shuffleArray(array){ - return [...array].sort(() => Math.random() - 0.5); +function shuffleArray(array, numPerPerson){ + console.log(`array.length: ${array.length}`); + let numPeople = numPerPerson.length; + console.log(`Num People: ${numPeople}`); + + for (let i = 0; i < array.length; i++) { + console.log(array[i]); + } + + var artists = new Map(); + let curListeners; + let artistInfo; + let currentPerson = 0; + let personOffset = numPerPerson[currentPerson]; + let posInPerson = 0; + + for (let i = 0; i < array.length; i++) { + + console.log(`i: ${i}, current person: ${currentPerson}, person offset: ${personOffset}, pos in person: ${posInPerson}`); + // update the current person based on the number of songs that each person has in the array + if (i >= (personOffset)) + { + console.log("NEW PERSON"); + currentPerson++; + personOffset = numPerPerson[currentPerson]; + numPerPerson[currentPerson] = numPerPerson[currentPerson-1]; + posInPerson = 0; + } + + posInPerson++; + + if (!artists.has(array[i].id)) + { + //console.log("THE ITEM ISN'T IN THE ARRAY"); + curListeners = new Array(numPeople).fill(0); + artistInfo = + { + item: array[i], + listeners: curListeners, + numListeners: 1, + score: 0 + }; + artists.set(array[i].id, artistInfo); + } + else + { + artists.get(array[i].id).numListeners++; + } + + let currentScore = (numPerPerson[currentPerson] - posInPerson) / (parseFloat(numPerPerson[currentPerson])); + + for (let j = 0; j < numPeople; j++) + { + if (j === currentPerson) + { + artists.get(array[i].id).listeners[currentPerson] = currentScore; + } + } + artists.get(array[i].id).score += currentScore; + } + + console.log("THE NEXT THING WE ARE LOGGING IS THE ARTIST THING"); + console.log(artists); + var artistsCombined = new Map(); + var artistsAlone = new Map(); + + for (const info of artists.values()) { + console.log(`info.numlisteners : ${info.numListeners}`); + if (info.numListeners > 1) + { + artistsCombined.set(info.item, info.score); + } + else + { + artistsAlone.set(info.item, info.score); + } + } + + console.log("printing"); + + const sortedCombined = new Map([...artistsCombined.entries()].sort((a, b) => b[1] - a[1])); + const sortedAlone = new Map([...artistsAlone.entries()].sort((a, b) => b[1] - a[1])); + + let newArr = [...sortedCombined.keys(), ...sortedAlone.keys()]; + console.log(newArr); + return newArr; } function retrieveItems(stats, state) { @@ -984,7 +1068,8 @@ function retrieveItems(stats, state) { const selectedType = type === 'genres' ? 'artists' : type; const timeRangeSlug = getPeriod(); const limit = num; - + let numPerPerson = []; + if ( type === 'artists') { const promises = []; let combined = []; @@ -1004,6 +1089,9 @@ function retrieveItems(stats, state) { const artists = response?.items; console.log("Top Artists: ", artists); combined = combined.concat(artists); + numPerPerson.push(combined.length); + + console.log('Concat: ', combined); }, error: function(error) { @@ -1017,14 +1105,16 @@ function retrieveItems(stats, state) { Promise.all(promises).then((artistData) => { const combined = [].concat(...artistData); // Combine all artists data console.log('concat final: ', combined); - const shuffledCombined = shuffleArray(combined); - console.log('shuffled: ', shuffledCombined); + console.log(`NUM per person = ${numPerPerson}`); + + const shuffledCombined = shuffleArray(combined, numPerPerson); + //console.log('shuffled: ', shuffledCombined); // Shuffle the combined data shuffledCombined.splice(num); - console.log('spliced: ', shuffledCombined); + //console.log('spliced: ', shuffledCombined); response_edited = { items: shuffledCombined - }; + }; displayReceipt(response_edited, stats, state, users_checkbox); }) .catch((errors) => { @@ -1077,6 +1167,8 @@ function retrieveItems(stats, state) { const tracks = response?.items; console.log("Top Tracks: ", tracks); combined = combined.concat(tracks); + numPerPerson.push(combined.length); + console.log('Concat: ', combined); }, error: function(error) { @@ -1090,11 +1182,12 @@ function retrieveItems(stats, state) { Promise.all(promises).then((trackData) => { const combined = [].concat(...trackData); // Combine all artists data console.log('concat final: ', combined); - const shuffledCombined = shuffleArray(combined); - console.log('shuffled: ', shuffledCombined); + console.log(`num per person: '${numPerPerson}'`); + const shuffledCombined = shuffleArray(combined, numPerPerson); + //console.log('shuffled: ', shuffledCombined); // Shuffle the combined data shuffledCombined.splice(num); - console.log('spliced: ', shuffledCombined); + //console.log('spliced: ', shuffledCombined); response_edited = { items: shuffledCombined }; @@ -1267,6 +1360,7 @@ function showCheckbox() { const userCheckboxTitle = document.createElement('p'); userCheckboxTitle.textContent = "Select Users"; + userCheckboxTitle.id = "user-checkbox-title"; userCheckbox.appendChild(userCheckboxTitle); for (let i = 0; i < users.length; i++) { @@ -1284,6 +1378,7 @@ function showCheckbox() { }; const label = document.createElement('label'); + label.id = "user-checkbox-label"; label.textContent = users[i]; label.htmlFor = checkbox.id; diff --git a/receiptifyv1/public/styles.css b/receiptifyv1/public/styles.css index 8439984..3fb8b36 100644 --- a/receiptifyv1/public/styles.css +++ b/receiptifyv1/public/styles.css @@ -54,6 +54,27 @@ h2 { p { font-family: Helvetica, Geneva, Tahoma, sans-serif; } + +#user-checkbox { + margin-bottom: 2rem; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + margin-left: 2rem; +} + +#user-checkbox-title { + font-family: Inter, 'Helvetica Neue', sans-serif; + line-height: 1.2; + margin-left: -2rem; +} + +#user-checkbox-label { + padding-left: 1rem; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + color: black !important; + font-size: 18px !important; +} + + .logo { font-family: 'Helvetica Neue', Helvetica, sans-serif; font-weight: 600; diff --git a/receiptifyv1/users.csv b/receiptifyv1/users.csv index c762448..f89444a 100644 --- a/receiptifyv1/users.csv +++ b/receiptifyv1/users.csv @@ -1,3 +1,3 @@ -Martin Duong,BQBq4YqB7OXfUT2ptOYDxZJgVhvLz6PLMnZOQgN1S09N_gJYD0iFZ3_Un9n2r3MTYLg5S-i8KSXgln3iN2ub3j3N9a4TPLk_MWnFBr7JiVKV9tPO1QoLZnnsPaZl0axOBfZA1zBU47FIkn7sKbDSayFpZy5rRdB6xJAgl5mHrFP7R1O1gAJL_CAaud2s5DtpmaqmjD8fr1XiCMWX1PTvVOoCMqOMeWig3P3dJBo,433323,1713640868202, -✧ jizzica ✧,BQDy4kSkGFHSHhvhVSZJnwGhfyaxZlm0uayu0VavAkd6EZ0wSOpax1QRJbcGFtNQxMMp_VhfrcHZQoKUH8yDqUc9jwPUwvLHCzkdTG_P4XpkhqD1oqDArfOgaE-wSt0cXF3Gp1hX5xdSP9YCC9bIB-24kfBdbADU28xmT5LRvPf97-b2lZcBfVzEaDkyoNy2RzlR-pck-8PV2e5iMW7zNtbNQH_Qy7efZB-m_TE,433323,1713640875824, +✧ jizzica ✧,BQBgPzh3R_Kro573KV7alDS0O74nCpx4WW8Xgj18Hp1AQE_ijZFkXsAneOIMF08SuHgfc2Ml_KrfykOjZ9Vxw_n8wc1wTwaqEGd358S21EXMo07-4WdlX3EPDyGqWoFQBcerzJ1hIyKBYb5HqH92WyaAi_laxxZSxkWaOTcgxVulWxVly-4XMvaI9VV3KuHt_JIZjbS8ontGZ3G35PDOLiFB6q5TawNbuTsBR48,261818,1713808836632, +✧ jizzica ✧,BQCrWoS_r3XRI3QaFaZ8lu-zR8W5RRxhLTlnNNJSVuYTyyc_LfZ1GfXqznB7iLb2sEhMr2TH28fcFW7R_pwas8147CwjxJcN5DYOdM41Pf2pazAlLUd1sls0trEuThcC9u8mJIb01RvAOFtVJFhHpB-DfCORDUVZykLrwwSs-V_yQ-9uDbo8vdjBlfLZnQo98BVvRvfc1yQOTMPbhqsbzSRW89tciuY-4LF6dW0,261818,1713808847899,