Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox css #36

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion receiptifyv1/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h2>Top Track Generator</h2>
</div>
</div>
<div class="customize">
<!-- Somewhere here add the checkbox-->


<div class="mobile-ad"><div id="home_header"></div></div>
<p class="customize-header">Customize Receipt</p>
Expand Down
115 changes: 105 additions & 10 deletions receiptifyv1/public/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,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) {
Expand Down Expand Up @@ -978,7 +1062,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 = [];
Expand All @@ -998,6 +1083,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) {
Expand All @@ -1011,14 +1099,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) => {
Expand Down Expand Up @@ -1071,6 +1161,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) {
Expand All @@ -1084,11 +1176,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
};
Expand Down Expand Up @@ -1213,6 +1306,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++) {
Expand All @@ -1230,6 +1324,7 @@ function showCheckbox() {
};

const label = document.createElement('label');
label.id = "user-checkbox-label";
label.textContent = users[i];
label.htmlFor = checkbox.id;

Expand Down
21 changes: 21 additions & 0 deletions receiptifyv1/public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions receiptifyv1/users.csv
Original file line number Diff line number Diff line change
@@ -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,
Loading