Skip to content

Commit

Permalink
Update functionallity and ReadME.
Browse files Browse the repository at this point in the history
  • Loading branch information
stygma committed Feb 17, 2016
1 parent 365d3ee commit 5f991e6
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 72 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
# About
# About the Project

__innovation'__ is HackFMI 5 team and this is the innovation repo!
## Abstract

The project aims to provide a simple way to give appreciation of others who helped you in some way.

## Flow

Users register with a photo. Every user have the ability to say "Thanks" to someone, even if he isn't registered as an user. Saying thanks consists of a) comment what happened b) a photo of the user who helped you c) tags (optional). The photo is used to find the user who is responsible for the good deed and to give him a reward. If no user with such photo is found we create an anonymous user with that photo, once the real person registers the photo from the registration is used to match him to the anonymous user.

## Algorithm

The rewards are given based on the actions (Thanks given). The value of the reward is calculated with Katz's graph algorithm. This approach is used in social networks and page rank algorithms.


## Used Technologies

- NodeJS
- SailsJS
- Mongo
- OpenCV
- vis.js

### Setup

install NodeJS
install mongo
install OpenCV
run npm install
run sails lift
visit http://localhost:1337/
11 changes: 8 additions & 3 deletions server/api/controllers/ActionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ function thanks(req, res) {

var uploadFile = req.file('uploadFile');
var category = req.param('category');
var description = req.param('description');
var description = req.param('desc');

User.findOne({ username: req.session.username }).then(function(user) {
sails.log(description);

User.findOne({ username: req.session.user.username }).then(function(user) {
var action = {
file: uploadFile,
category: category,
description: description
};

sails.log('desc: ', action.description, description);
UtilService.sayHello();

UserActionService.registerAction(action, user).then(function(action) {
req.flash('success', 'Your thank you was recieved!');
return res.redirect('/user/' + action.agent);
return res.redirect('/user/' + action.recipient);
});
});
};
Expand Down
64 changes: 37 additions & 27 deletions server/api/controllers/GraphController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ function view(req, res) {
return res.view('graph');
};

function generateMockData(req, res) {
generateUsers().then(function(users) {
generateActions(users).then(function(actions) {
return res.ok({ users: users, actions: actions });
});
});
};

function graphData(req, res){
User.find().then(function(users){
User.find({ active: true }).then(function(users){
Action.find().then(function(actions){
var graphData = GraphEngingService.buildGraph(actions, users);
var katzCentrality = GraphEngingService.katzCentrality(graphData);
Expand All @@ -19,43 +27,45 @@ function graphData(req, res){
});
}

function generateUser(){
var users = [];
for(var i=0; i < 5; i++){
var userObj = {
username: 'user'+i,
password: 'user'+i,
karma: 200,
};
users.push(userObj);
}

User.create(users).then();
function generateUsers(){
return new Promise(function(resolve) {
var users = [];
for(var i=0; i < 6; i++){
var userObj = {
username: 'user'+i,
password: 'user'+i,
karma: 200,
};
users.push(userObj);
}

User.create(users).then(resolve);
});
}

function generateActions(){
var actions =[
{agent: "553cbe32b5758d4b25fc64c1", recipient:"553b524fb20676a213420ce1", description:"Action test description!"},
{agent: "553cbe32b5758d4b25fc64c2", recipient:"553b524fb20676a213420ce1", description:"Action test description!"},
function generateActions(users){
return new Promise(function(resolve) {
var actions =[
{agent: users[0].id, recipient: users[1].id, description: 'Thanks ' + users[1].id},
{agent: users[4].id, recipient: users[1].id, description: 'Thanks ' + users[1].id},
{agent: users[2].id, recipient: users[1].id, description: 'Thanks ' + users[1].id},

{agent: "553b524fb20676a213420ce1", recipient:"553bb5882374bae63f37165b", description:"Action test description!"},
{agent: "553cbe32b5758d4b25fc64c2", recipient:"553bb5882374bae63f37165b", description:"Action test description!"},
{agent: "553cbe32b5758d4b25fc64c0", recipient:"553bb5882374bae63f37165b", description:"Action test description!"},
{agent: users[3].id, recipient: users[0].id, description: 'Thanks ' + users[0].id},
{agent: users[4].id, recipient: users[0].id, description: 'Thanks ' + users[0].id},

{agent: "553cbe32b5758d4b25fc64c2", recipient:"553cbe32b5758d4b25fc64c1", description:"Action test description!"},
{agent: "553cbe32b5758d4b25fc64c3", recipient:"553cbe32b5758d4b25fc64c1", description:"Action test description!"},
{agent: users[4].id, recipient: users[3].id, description: 'Thanks ' + users[3].id},
{agent: users[5].id, recipient: users[3].id, description: 'Thanks ' + users[3].id},

{agent: "553cbe32b5758d4b25fc64c2", recipient:"553cbe32b5758d4b25fc64c0", description:"Action test description!"},
{agent: users[4].id, recipient: users[2].id, description: 'Thanks ' + users[2].id},
];

{agent: "553cbe32b5758d4b25fc64c1", recipient:"553cbe32b5758d4b25fc64c4", description:"Action test description!"}

];
Action.create({agent: "553cbe32b5758d4b25fc64c1", recipient:"553cbe32b5758d4b25fc64c4", description:"Action test description!"}).then();
Action.create(actions).then(resolve);
});
}

module.exports = {
view: view,
graphData: graphData,
generateMockData: generateMockData,
};

3 changes: 1 addition & 2 deletions server/api/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

function view(req, res) {
User.findOne(req.param('userId')).populateAll().then(function(user) {
console.log(user);
if(req.session.partner){
Partner.findOne(req.session.partner.id).populate('rewards').then(function(partner){
var userIds = [];
Expand All @@ -26,7 +25,7 @@ function view(req, res) {
})
});
});
}else{
} else {
var userIds = [];
_.each(user.sentThanks, function(action) {
userIds.push(action.agent);
Expand Down
10 changes: 7 additions & 3 deletions server/api/services/UserActionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function registerAction(action, recipient) {
preprocessImage(file).then(function(preprocImg) {

identifyUser(preprocImg).then(function(actor) {
Action.create({ photo: preprocImg.fd, agent: actor.id, description: action.description, tags: extractTags(action.description)}).then(function(action) {
sails.log('in register proc: ', action.description);
Action.create({ photo: preprocImg.fd, recipient: actor.id, agent: recipient.id, description: action.description, tags: extractTags(action.description)}).then(function(action) {
return resolve(action);
});
});
Expand All @@ -46,7 +47,6 @@ function registerActor(image) {
}

// TODO

return resolve(null);
});
});
Expand All @@ -58,8 +58,12 @@ function identifyUser(image) {

return new Promise(function(resolve) {
opencv.readImage(image, function(err, img) {
var predict = fr.predictSync(img);

console.log(predict);


User.find().then(function(users) {
User.find({ active: true }).then(function(users) {
var user = users[0];

sails.log('USER: ', user);
Expand Down
5 changes: 5 additions & 0 deletions server/api/services/UtilService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function uploadFile(file) {
});
};

function sayHello() {
console.log('hello');
}

module.exports = {
uploadFile: uploadFile,
sayHello: sayHello
};
Binary file modified server/assets/images/users/0/ogy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified server/assets/images/users/1/ivan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions server/assets/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ $(document).ready(function () {
var data = {
dot: 'dinetwork {node[shape=circle]; ' + networkString + ' }'
};

var options = {
width: '900px',
height: '500px'
Expand Down
7 changes: 7 additions & 0 deletions server/assets/js/dependencies/moment.min.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions server/assets/styles/prifle-actions.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
position: relative;
margin-left: 0;
list-style: none;
border-radius: 5px;
width: 46%;
/*width: 46%;*/
/*float: left;*/
/*display: block;*/
}
.profile-actions-container-right{
position: relative;
list-style: none;
border-radius: 5px;
width: 46%;
/*width: 46%;*/
/*float: right;*/
/*display: inline;*/
}
Expand Down
21 changes: 11 additions & 10 deletions server/config/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var predir = './assets/images/pre/';
var usersdir = './assets/images/users/';

Promise = require('bluebird');
moment = require('moment');
cv = opencv = require('opencv');
fr = opencv.FaceRecognizer.createLBPHFaceRecognizer();
trainSet = [];
Expand Down Expand Up @@ -58,9 +59,15 @@ function train(userPhotos) {
});
});


});

new Promise(function(resolve) {
setTimeout(function(){
console.log('Training with: ' + photo);
},1000);
console.log('Training with: ' + trainSet);
fr.trainSync(trainSet);
resolve();
}, 1000);
});

return resolve();
Expand All @@ -69,17 +76,11 @@ function train(userPhotos) {


module.exports.bootstrap = function(cb) {
//fr.trainSync([[0, img], [1, img1], [2, img2]]);

var lower_threshold = [46, 57, 83];
var upper_threshold = [80, 96, 115];

train({
'0': 'ogy.jpg',
'1': 'ivan.jpg',
'2': 'user.jpg',
}).then(cb);
});

//var whoisit = fr.predictSync(img4);
// console.log("Identified image", whoisit);
cb();
};
2 changes: 1 addition & 1 deletion server/config/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports.connections = {
port: 27017,
// user: 'username',
// password: 'password',
// database: 'your_mongo_db_name_here'
database: '10x_db'
},

/***************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions server/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module.exports.routes = {
'get /graph': 'GraphController.view',
'get /graph/data': 'GraphController.graphData',

'get /generate-mock-data': 'GraphController.generateMockData',

/***************************************************************************
* *
* Custom routes here... *
Expand Down
3 changes: 3 additions & 0 deletions server/contact.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Dimitar dimitrov 0887233881 [email protected]



82 changes: 82 additions & 0 deletions server/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
apply api/controllers/PartnerController.js /^function apply(req, res) {$/;" f
badRequest api/responses/badRequest.js /^module.exports = function badRequest(data, options) {$/;" f
buildGraph api/services/GraphEngingService.js /^function buildGraph(actions, users){$/;" f
buildGraph.graph.edges api/services/GraphEngingService.js /^ edges: edges,$/;" p
buildGraph.graph.index api/services/GraphEngingService.js /^ index: nodeIndexed$/;" p
buildGraph.graph.nodes api/services/GraphEngingService.js /^ nodes: nodes,$/;" p
buildGraphMock api/services/GraphEngingService.js /^function buildGraphMock(){$/;" f
consume api/controllers/RewardController.js /^function consume(req, res) {$/;" f
create api/controllers/RewardController.js /^function create(req, res) {$/;" f
dirname api/services/UtilService.js /^var dirname = '..\/..\/assets\/images\/upload';$/;" v
extractTags api/services/UserActionService.js /^function extractTags(description){$/;" f
forbidden api/responses/forbidden.js /^module.exports = function forbidden (data, options) {$/;" f
generateActions api/controllers/GraphController.js /^function generateActions(users){$/;" f
generateMockData api/controllers/GraphController.js /^function generateMockData(req, res) {$/;" f
generateUsers api/controllers/GraphController.js /^function generateUsers(){$/;" f
graph.edges api/services/GraphEngingService.js /^ edges: edges$/;" p
graph.nodes api/services/GraphEngingService.js /^ nodes: nodes,$/;" p
graphData api/controllers/GraphController.js /^function graphData(req, res){$/;" f
home api/controllers/FlatPageController.js /^function home(req, res) {$/;" f
identifyUser api/services/UserActionService.js /^function identifyUser(image) {$/;" f
katzCentrality api/services/GraphEngingService.js /^function katzCentrality(graph){$/;" f
login api/controllers/AuthController.js /^function login(req, res) {$/;" f
login.userObj.username api/controllers/AuthController.js /^ username: req.param('username'),$/;" p
logout api/controllers/AuthController.js /^function logout(req, res) {$/;" f
module.exports api/policies/sessionAuth.js /^module.exports = function(req, res, next) {$/;" f
module.exports api/policies/userAuth.js /^module.exports = function(req, res, next) {$/;" f
module.exports api/responses/badRequest.js /^module.exports = function badRequest(data, options) {$/;" f
module.exports api/responses/forbidden.js /^module.exports = function forbidden (data, options) {$/;" f
module.exports api/responses/notFound.js /^module.exports = function notFound (data, options) {$/;" f
module.exports api/responses/ok.js /^module.exports = function sendOK (data, options) {$/;" f
module.exports api/responses/serverError.js /^module.exports = function serverError (data, options) {$/;" f
module.exports.apply api/controllers/PartnerController.js /^ apply: apply,$/;" p
module.exports.attributes api/models/Action.js /^ attributes: {$/;" p
module.exports.attributes api/models/Partner.js /^ attributes: {$/;" p
module.exports.attributes api/models/Reward.js /^ attributes: {$/;" p
module.exports.attributes api/models/User.js /^ attributes: {$/;" p
module.exports.buildGraph api/services/GraphEngingService.js /^ buildGraph: buildGraph,$/;" p
module.exports.buildGraphMock api/services/GraphEngingService.js /^ buildGraphMock: buildGraphMock,$/;" p
module.exports.consume api/controllers/RewardController.js /^ consume: consume,$/;" p
module.exports.create api/controllers/RewardController.js /^ create: create,$/;" p
module.exports.generateMockData api/controllers/GraphController.js /^ generateMockData: generateMockData,$/;" p
module.exports.graphData api/controllers/GraphController.js /^ graphData: graphData,$/;" p
module.exports.home api/controllers/FlatPageController.js /^ home: home,$/;" p
module.exports.identifyUser api/services/UserActionService.js /^ identifyUser: identifyUser,$/;" p
module.exports.katzCentrality api/services/GraphEngingService.js /^ katzCentrality: katzCentrality,$/;" p
module.exports.login api/controllers/AuthController.js /^ login: login,$/;" p
module.exports.logout api/controllers/AuthController.js /^ logout: logout,$/;" p
module.exports.partnerLogin api/controllers/AuthController.js /^ partnerLogin: partnerLogin,$/;" p
module.exports.register api/controllers/AuthController.js /^ register: register,$/;" p
module.exports.registerAction api/services/UserActionService.js /^ registerAction: registerAction,$/;" p
module.exports.registerActor api/services/UserActionService.js /^ registerActor: registerActor,$/;" p
module.exports.thanks api/controllers/ActionController.js /^ thanks: thanks,$/;" p
module.exports.uploadFile api/services/UtilService.js /^ uploadFile: uploadFile,$/;" p
module.exports.view api/controllers/GraphController.js /^ view: view,$/;" p
module.exports.view api/controllers/PartnerController.js /^ view: view,$/;" p
module.exports.view api/controllers/RewardController.js /^ view: view,$/;" p
module.exports.view api/controllers/UserController.js /^ view: view,$/;" p
normalised api/services/GraphEngingService.js /^function normalised(principalEigenvector) {$/;" f
notFound api/responses/notFound.js /^module.exports = function notFound (data, options) {$/;" f
opencv api/services/UserActionService.js /^var opencv = require('opencv');$/;" v
opencv api/services/UtilService.js /^var opencv = require('opencv');$/;" v
partnerLogin api/controllers/AuthController.js /^function partnerLogin(req, res) {$/;" f
partnerLogin.partnerObj.email api/controllers/AuthController.js /^ email: req.param('email'),$/;" p
preprocessImage api/services/UserActionService.js /^function preprocessImage(file) {$/;" f
register api/controllers/AuthController.js /^function register(req, res) {$/;" f
registerAction api/services/UserActionService.js /^function registerAction(action, recipient) {$/;" f
registerActor api/services/UserActionService.js /^function registerActor(image) {$/;" f
sendOK api/responses/ok.js /^module.exports = function sendOK (data, options) {$/;" f
serverError api/responses/serverError.js /^module.exports = function serverError (data, options) {$/;" f
sum api/services/GraphEngingService.js /^function sum(principalEigenvector) {$/;" f
thanks api/controllers/ActionController.js /^function thanks(req, res) {$/;" f
uploadFile api/services/UtilService.js /^function uploadFile(file) {$/;" f
view api/controllers/GraphController.js /^function view(req, res) {$/;" f
view api/controllers/PartnerController.js /^function view(req, res) {$/;" f
view api/controllers/RewardController.js /^function view(req, res) {$/;" f
view api/controllers/UserController.js /^function view(req, res) {$/;" f
1 change: 1 addition & 0 deletions server/views/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<script src="/js/dependencies/ie-10-view-port.js"></script>
<script src="/js/dependencies/jquery-1.11.1.js"></script>
<script src="/js/dependencies/jquery.easing.min.js"></script>
<script src="/js/dependencies/moment.min.js"></script>
<script src="/js/dependencies/vis.min.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/custom.js"></script>
Expand Down
Loading

0 comments on commit 5f991e6

Please sign in to comment.