Skip to content

Commit

Permalink
Close #52 - Display successful flags as activities
Browse files Browse the repository at this point in the history
  • Loading branch information
bpred754 committed Dec 31, 2016
1 parent 23b79b5 commit 13aeb2b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/model/schema/augeo/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// Schema declaration
var AUGEO_FLAG = Mongoose.Schema({
activity: {type: Mongoose.Schema.Types.ObjectId, ref: 'ACTIVITY'},
flaggee: String,
newClassification: String,
previousClassification: String,
reclassifiedDate: Date
Expand Down
12 changes: 12 additions & 0 deletions src/model/schema/augeo/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@
});
};

AUGEO_USER.statics.getUserWithId = function(id, logData, callback) {
this.findOne({_id: id}, function(error, user) {
if(error) {
log.functionError(COLLECTION, 'getUserWithId', logData.parentProcess, logData.username, 'Failed to find user with id: ' + id);
callback();
} else {
log.functionError(COLLECTION, 'getUserWithId', logData.parentProcess, logData.username, {'id': id});
callback(user);
}
});
};

AUGEO_USER.statics.getUserWithEmail = function(email, logData, callback) {
this.findOne({email:{'$regex': AugeoUtility.buildRegex(email, logData), $options: 'i'}})
.select(exports.PROJECTION_STRING)
Expand Down
2 changes: 1 addition & 1 deletion src/module/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
}
},

functionError: function (file, functionName, identifier, message) {
functionError: function (file, functionName, parentProcess, identifier, message) {
if (process.env.TEST != 'true') {
log.warn(this.buildLogString(file, functionName, null, identifier, null, message));
}
Expand Down
64 changes: 64 additions & 0 deletions src/public/javascript/common/flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

/***************************************************************************/
/* Augeo.io is a web application that uses Natural Language Processing to */
/* classify a user's internet activity into different 'skills'. */
/* Copyright (C) 2016 Brian Redd */
/* */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/***************************************************************************/

/***************************************************************************/
/* Description: Object to store Augeo's flag logic and attributes */
/***************************************************************************/

// Required local modules
var AbstractObject = require('./abstract-object');
var Activity = require('./activity');

// Constructor
var $this = function(json, user) {
$this.base.constructor.call(this, json);

if(json) {

var data;
if (json.data) {
data = json.data;
} else {
data = json;
}

// public variables
this.flaggedActivityId = data.activity;
this.flaggee = data.flaggee;
this.newClassification = data.newClassification;
this.previousClassification = data.previousClassification;
this.reclassifiedDate = data.reclassifiedDate;

// Client only attributes
this.avatarImageSrc = user.profileImg;
this.displayScreenName = user.username;
this.interfaceLink = 'https://www.augeo.io';
this.interfaceLogo = 'image/augeo-logo-small.png';
this.interfaceProfileUrl = 'https://www.augeo.io/dashboard/' + user.username;
this.html = 'Correctly flagged <a href="https://www.augeo.io/dashboard/'+this.flaggee+'" target="_blank">'+this.flaggee+'\'s</a> <a class="clickable" onclick="console.log(\''+this.flaggedActivityId+'\')">activity</a> with an original classification of ' + this.previousClassification + ' as ' + this.newClassification;
this.link = this.interfaceLink;
this.name = user.firstName + ' ' + user.lastName;
this.screenName = user.username;
}
};

AbstractObject.extend(Activity, $this, {});

module.exports = $this;
1 change: 1 addition & 0 deletions src/public/javascript/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@

require('./abstract-object');
require('./activity');
require('./flag');
require('./commit');
require('./tweet');
4 changes: 4 additions & 0 deletions src/public/javascript/service/activity-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/****************************************************************************/

var Commit = require('../common/commit');
var Flag = require('../common/flag');
var DaySteps = require('../common/day-steps');
var Tweet = require('../common/tweet');

Expand All @@ -33,6 +34,9 @@

var activity = rawActivity;
switch(rawActivity.kind) {
case 'AUGEO_FLAG':
activity = new Flag(rawActivity, user);
break;
case 'FITBIT_DAY_STEPS':
activity = new DaySteps(rawActivity, user.fitbit);
break;
Expand Down
49 changes: 27 additions & 22 deletions src/queue-task/augeo/reclassify-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,33 @@
// Determine if the activity's staged flag had the correct vote
if (activityStagedFlag.suggestedClassification === newClassification) {

// Add the staged flag to the AUGEO_FLAG collection
var flag = {
activity: stagedFlag.activity,
newClassification: newClassification,
previousClassification: oldClassification,
reclassifiedDate: stagedFlag.reclassifyDate
};

Flag.addFlag(flag, logData, function (addedFlag) {

// Create a new activity for the successful flag
var activity = flag;
activity.classification = 'Community';
activity.classificationGlyphicon = AugeoUtility.getGlyphicon('Community', logData);
activity.data = addedFlag._id;
activity.experience = AugeoUtility.FLAG_EXPERIENCE;
activity.kind = 'AUGEO_FLAG';
activity.timestamp = stagedFlag.timestamp;
activity.user = updatedActivity.user;

Activity.addActivity(activity, logData, function (addedActivity) {
nextStagedActivityIteration();
// Get the flaggee's username
User.getUserWithId(updatedActivity.user, logData, function(flaggee) {

// Add the staged flag to the AUGEO_FLAG collection
var flag = {
activity: stagedFlag.activityId,
flaggee: flaggee.username,
newClassification: newClassification,
previousClassification: oldClassification,
reclassifiedDate: stagedFlag.reclassifyDate
};

Flag.addFlag(flag, logData, function (addedFlag) {

// Create a new activity for the successful flag
var activity = flag;
activity.classification = 'Community';
activity.classificationGlyphicon = AugeoUtility.getGlyphicon('Community', logData);
activity.data = addedFlag._id;
activity.experience = AugeoUtility.FLAG_EXPERIENCE;
activity.kind = 'AUGEO_FLAG';
activity.timestamp = stagedFlag.timestamp;
activity.user = updatedActivity.user;

Activity.addActivity(activity, logData, function (addedActivity) {
nextStagedActivityIteration();
});
});
});
} else { // Activity did not have the correct vote
Expand Down

0 comments on commit 13aeb2b

Please sign in to comment.