Skip to content

Commit

Permalink
Fix subByCastCategory method by using Mongo to find completedSubmissions
Browse files Browse the repository at this point in the history
  • Loading branch information
youralien committed Nov 23, 2021
1 parent b225d8c commit 0cb0cd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
6 changes: 4 additions & 2 deletions imports/ui/pages/api_custom_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -853,13 +853,14 @@ <h4 class="bold">Thriving or Surviving? Northwestern Seniors during Finals Seaso
</div>
{{/each}}
</div>
{{#if Template.subscriptionsReady}}
<div>
{{#each block in timeBlocks}}
<!-- in before, during, after -->
<div class="time-block">
<p class="time-text center">{{getTimeBlock block}}</p>
<div class="item">

{{#each cat in castCategories}}
<!-- in similar / different -->
<div class="img-text">
Expand All @@ -868,7 +869,7 @@ <h4 class="bold">Thriving or Surviving? Northwestern Seniors during Finals Seaso
<!-- if cat is 'similar', get current user's emotion and get similar posts, if differnet get different-->
{{sub}}
<div class="item-contribution" id="{{sub._id}}">
<p class="contribution-detail bold">{{getUsername sub}} -
<p class="contribution-detail bold">{{getUsername sub}} -
<p class="contribution-detail">{{getEmotion sub}}</p>
</p>
<p class="contribution-detail">{{getTimeStamp sub}}</p>
Expand All @@ -888,6 +889,7 @@ <h4 class="bold">Thriving or Surviving? Northwestern Seniors during Finals Seaso
{{/each}}

</div>
{{/if}}
<!-- <br>
<b style="background-color:#273147;padding:6px;color:white;margin-bottom:10px;">Items remaining</b>
<ul class="items-remaining">
Expand Down
47 changes: 25 additions & 22 deletions imports/ui/pages/api_custom_results.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ Template.api_custom_results.helpers({
let navbar = document.querySelector(".nav-footer");
navbar.style.display = "block";
// console.log(navbar);
this.submissions.sort(function compare(a, b) {
if (a.timestamp === undefined) {
return 1;
} else if (b.timestamp === undefined) {
return -1;
}
if (this.submissions) {
this.submissions.sort(function compare(a, b) {
if (a.timestamp === undefined) {
return 1;
} else if (b.timestamp === undefined) {
return -1;
}

const dateA = new Date(a.timestamp);
const dateB = new Date(b.timestamp);
return dateA - dateB;
});
const dateA = new Date(a.timestamp);
const dateB = new Date(b.timestamp);
return dateA - dateB;
});
}

console.log(this);
console.log(this.images);
// console.log(this);
// console.log(this.images);
return this;
},
});
Expand Down Expand Up @@ -683,7 +685,7 @@ Template.survivingThriving.helpers({
castCategories(){
//To-do: access castCategories
// let castCategories = ['thriving', 'surviving'];

// let castCategories = ['😃','🙏','😌','😬', '😫', '😢'];
let castCategories = ['Similar', 'Different']
// console.log("Time " + Date.now());
Expand All @@ -703,15 +705,15 @@ Template.survivingThriving.helpers({

// find submission in database with user id then find the emotion correlated with the userid to check if the current cat is that
// find all posts by the current user and find all the emotions but pick the most recent...?
let user_emotions = Submissions.find({
let user_emotions = Submissions.find({
uid: Meteor.userId()
}).fetch().map(function (x) {
return x.castCategory;
});

let current_emotion = user_emotions[0]


// if (cat === "happy") {
// cat = "😃";
// }
Expand All @@ -738,15 +740,16 @@ Template.survivingThriving.helpers({
// cat = false
// }

let subsByCat = this.submissions.filter(function(sub){
const completedSubmissions = Submissions.find({"uid": {$ne: null}}).fetch();

This comment has been minimized.

Copy link
@youralien

youralien Nov 23, 2021

Author Member

@jennychang0 I fixed the error by first using Mongo to filter the completed submissions, where uid != null. In contrast, the code before looked at this.submissions, which included lots of emtpy submissions too.

let subsByCat = completedSubmissions.filter(function(sub){
// console.log("BLOCKKKKK", block);

// let day = block.substr(0, 3);
// console.log("cat ", cat);
// console.log("sub ", sub.castCategory);
// && (sub.timestamp === day)

// if sub.castCategory is 'similar' and if cat is the same as the user's emotion
// if sub.castCategory is 'similar' and if cat is the same as the user's emotion
// elif sub.castCategory is 'different'' and if cat is not the same as the user's emotion

// before
Expand Down Expand Up @@ -786,7 +789,7 @@ Template.survivingThriving.helpers({
}

// }



// if ((sub.castCategory === cat) && (block === 0) && ((sub.timestamp.getDay() === 0) || ((sub.timestamp.getDay() === 1) || (sub.timestamp.getDay() === 2)))) {
Expand All @@ -808,7 +811,7 @@ Template.survivingThriving.helpers({
// return sub;
// }
});

console.log("DOES IT NOT GET HERE HWY")
console.log("sub ", subsByCat);
return subsByCat;
Expand Down Expand Up @@ -878,7 +881,7 @@ Template.survivingThriving.helpers({
else{
console.log('in else')
return "\"" + sub.content.sentence + "\"";
}
}
}
});

Expand Down

0 comments on commit 0cb0cd7

Please sign in to comment.