Skip to content

Commit

Permalink
Merge pull request #40 from chrisshayan/sprint5-BugsFix
Browse files Browse the repository at this point in the history
Sprint5 bugs fix
  • Loading branch information
tankhuu authored Sep 15, 2016
2 parents 5da0128 + e3a059c commit 742e3de
Show file tree
Hide file tree
Showing 23 changed files with 499 additions and 216 deletions.
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ aldeed:moment-timezone
nimble:restivus
shell-server
lepozepo:accounting
okgrow:analytics
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ nimble:[email protected]
[email protected]
[email protected]
[email protected]
okgrow:[email protected]
[email protected]
percolate:[email protected]
[email protected]
Expand Down
3 changes: 3 additions & 0 deletions imports/api/cache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Mongo} from 'meteor/mongo';

export const MiniMongo = new Mongo.Collection(null);
31 changes: 15 additions & 16 deletions imports/api/jobs/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import * as EmailActions from '/imports/api/email/methods';
import {getSendingPlans} from '/imports/api/sending_plans/methods';
import {getLocalDate} from '/imports/api/time/functions';
import {setStatus as setSendingPlanStatus} from '/imports/api/sending_plans/methods';

// functions
import {measureMonthlyMetricScore} from '/imports/api/measures/functions';
import {measureMonthlyMetricScore} from '/imports/api/measures/methods';

// constants
const LOG_LEVEL = {
Expand Down Expand Up @@ -148,21 +146,22 @@ const sendSurveys = function (job, cb) {
}

const measureMetrics = (job, cb) => {
try {
const measure = measureMonthlyMetricScore();
if(measure) {
jobMessage = `measured metrics for leaders done`;
job.log(jobMessage, {level: LOG_LEVEL.INFO});
job.done();
measureMonthlyMetricScore.call({params: {}}, (error, measure) => {
if (!error) {
if (!_.isEmpty(measure)) {
jobMessage = `measured metrics for ${measure.noOfLeader} leaders and ${measure.noOfOrg} organizations done`;
job.log(jobMessage, {level: LOG_LEVEL.INFO});
job.done();
} else {
jobMessage = `No data to measure for job: ${job}`;
job.log(jobMessage, {level: LOG_LEVEL.WARNING});
job.done();
}
} else {
jobMessage = `No data to measure for job: ${job}`;
job.log(jobMessage, {level: LOG_LEVEL.WARNING});
job.done();
job.log(error.reason, {level: LOG_LEVEL.CRITICAL});
job.fail();
}
} catch (error) {
job.log(error.message, {level: LOG_LEVEL.CRITICAL});
job.fail();
}
});
}

// Start Job
Expand Down
153 changes: 151 additions & 2 deletions imports/api/measures/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import _ from 'lodash';

// collections
import {Measures} from './index';
import {Metrics} from '/imports/api/metrics/index';
import {MiniMongo} from '/imports/api/cache/index';

// functions
import {arraySum} from '/imports/utils/index';
import {measure} from './functions';


/**
Expand Down Expand Up @@ -81,8 +84,8 @@ export const getChartData = new ValidatedMethod({
conflict: 0
}, // current score of metrics
selector = {}, // conditions for query database
fields = {} // fields will receive from database
MeasuresData = []
fields = {}, // fields will receive from database
MeasuresData = []
;

// get labels
Expand Down Expand Up @@ -147,4 +150,150 @@ export const getChartData = new ValidatedMethod({
}
return result;
}
});

/**
* @summary Method measure monthly metric score
* @param {Object} params
* @param {String} params.leaderId
* @param {String} params.organizationId
* @param {Date} params.date - the date which is the last month of data
* @return {Number} the number of docs had been upsert
*/
export const measureMonthlyMetricScore = new ValidatedMethod({
name: "measures.measureMonthlyMetricScore",
validate: null,
run({params}) {
const
MiniMongo = new Mongo.Collection(null),
runDate = (!!params.date ? params.date : new Date()),
year = runDate.getFullYear(),
month = runDate.getMonth(),
nextMonth = month + 1,
haveLeaderId = !!params.leaderId,
haveOrgId = !!params.organizationId
;
let
jobMessage = "",
selector = {},
modifier = {},
leaderList = [],
leaderDocs = [],
orgList = [],
metricList = [],
orgDocs = [],
metricDocs = [],
scoreList = [],
averageScore = 0,
noOfScores = 0,
noOfGoodScores = 0, // count the number of score from 4 to 5
noOfBadScores = 0, // count the number of score from 1 to 3
measureDoc = {}, // data of measure for leader
result = false
;

// Get list of leaders
if(haveLeaderId) {
selector.leaderId = params.leaderId;
}
if(haveOrgId) {
selector.organizationId = params.organizationId;
}
selector.date = {
$gte: new Date(year, month, 1),
$lt: new Date(year, nextMonth, 1)
}
; // only get data in current month
modifier = {
fields: {
_id: 0,
leaderId: 1,
organizationId: 1,
metric: 1,
score: 1
}
}; // only return necessary fields

// get leaders data in current month
const docs = Metrics.find(selector, modifier).fetch();
if (!_.isEmpty(docs)) {
MiniMongo.remove({});
docs.map(doc => {
MiniMongo.insert(doc);
if(!haveLeaderId) {
leaderList.push(doc.leaderId);
}
});

if(haveLeaderId) {
leaderList.push(params.leaderId);
} else {
leaderList = _.uniq(leaderList); // get unique leader only
}

// get average score for every leader
leaderList.map(leaderId => {
//get list of organization for specific leader
if(haveOrgId) {
orgList.push(params.organizationId);
} else {
leaderDocs = MiniMongo.find({leaderId}).fetch();
leaderDocs.map(leaderDoc => {
orgList.push(leaderDoc.organizationId);
});
orgList = _.uniq(orgList);
}

// get list of metric for specific organization
orgList.map(organizationId => {
orgDocs = MiniMongo.find({leaderId, organizationId}).fetch();
orgDocs.map(orgDoc => {
metricList.push(orgDoc.metric);
});
metricList = _.uniq(metricList);
// get list of score for specific metric
metricList.map(metric => {
metricDocs = MiniMongo.find({leaderId, organizationId, metric}).fetch();
metricDocs.map(metricDoc => {
const {score} = metricDoc;
if(score > 3) {
noOfGoodScores++;
} else {
noOfBadScores++;
}
scoreList.push(score);
});

noOfScores = scoreList.length;
if(noOfScores > 0) {
averageScore = Number(arraySum(scoreList) / scoreList.length).toFixed(1);
}

measureDoc = {
leaderId,
organizationId,
type: "metric",
interval: "monthly",
year,
month,
key: metric,
value: {
averageScore,
noOfScores,
noOfGoodScores,
noOfBadScores
}
};
measure({data: measureDoc});
});
});
});
return {
noOfLeader: leaderList.length,
noOfOrg: orgList.length
};
} else {
return {};
}
}
});
2 changes: 1 addition & 1 deletion imports/api/profiles/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const getPublicData = new ValidatedMethod({
leaderId = User._id,
noOfPreferences = Preferences.find({userId, name: 'publicInfo'}).count(),
ProfileData = Profiles.findOne({userId}),
OrganizationsData = _.orderBy(Organizations.find({leaderId}).fetch(), ['startTime'], ['desc']),
OrganizationsData = _.orderBy(Organizations.find({leaderId}).fetch(), ['isPresent','startTime'], ['desc','desc']),
FeedbacksData = Feedbacks.find({leaderId}).fetch(),
date = new Date(),
months = [
Expand Down
11 changes: 10 additions & 1 deletion imports/api/scheduler/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { SendingPlans } from '/imports/api/sending_plans';
import * as schedulerUtils from '/imports/utils/scheduler';

export default class SchedulerCollection extends Mongo.Collection {

insert(doc, callback) {
const
_id = super.insert(doc, callback),
data = this.findOne({_id})
;
if(_id) {
this.updateSendingPlan(data)
}
return _id;
}

update(selector, modifier) {
const before = this.findOne(selector);
Expand Down
24 changes: 18 additions & 6 deletions imports/api/sending_plans/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,24 @@ export const getSendingPlans = new ValidatedMethod({
name: "sendingPlans.getSendingPlans",
validate: null,
run({date}) {
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
const nextDay = date.getDate() + 1;
const selector = {sendDate: {$gte: new Date(year, month, day), $lt: new Date(year, month, nextDay)}, status: "READY"};
const modifier = {};
const year = date.getFullYear(),
month = date.getMonth(),
day = date.getDate(),
nextDay = date.getDate() + 1,
selector = {sendDate: {$gte: new Date(year, month, day), $lt: new Date(year, month, nextDay)}, status: "READY"},
modifier = {};
return SendingPlans.find(selector).fetch();
}
});

export const getLeaderPlans = new ValidatedMethod({
name: "sendingPlans.getLeaderPlans",
validate: null,
run() {
const
leaderId = Meteor.userId()
;

return SendingPlans.find({leaderId}).fetch();
}
});
2 changes: 1 addition & 1 deletion imports/api/users/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const confirm = new ValidatedMethod({
"emails.$.verified": true
}
});
ProfileActions.setStatus.call({userId, status: STATUS_ACTIVE});
ProfileActions.setStatus.call({userId: _id, status: STATUS_ACTIVE});
}
} else {
throw new Meteor.Error('invalid-token', 'User token is invalid or has been used.');
Expand Down
2 changes: 0 additions & 2 deletions imports/ui/common/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Navigation extends Component {
{route: 'app.dashboard', path: FlowRouter.url('app.dashboard'), label: 'Dashboard', icon: 'fa fa-dashboard'},
{route: 'app.preferences', path: FlowRouter.url('app.preferences'), label: 'Preferences', icon: 'fa fa-gears'},
{route: 'app.organizations', path: FlowRouter.url('app.organizations'), label: 'Organizations', icon: 'fa fa-sitemap'},
{route: '', path: '', label: 'Feedback', icon: 'fa fa-gift'},
{route: '', path: '', label: 'Measure', icon: 'fa fa-info'},
]
};
}
Expand Down
1 change: 0 additions & 1 deletion imports/ui/common/TopNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class TopNav extends Component {
<li><a href={FlowRouter.url('app.dashboard')}>Dashboard</a></li>
<li><a href={FlowRouter.url('app.preferences')}>Preferences</a></li>
<li><a href={FlowRouter.url('app.organizations')}>Organizations</a></li>
<li><a href={FlowRouter.url('app.feedbacks')}>Feedbacks</a></li>
<li role="separator" className="divider"></li>
<li><a href={FlowRouter.url('app.logout')}>Sign out</a></li>
</ul>
Expand Down
8 changes: 6 additions & 2 deletions imports/ui/components/ProfileMetricsBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ export default class ProfileMetricsBox extends Component {
constructor() {
super();

this.state = {}
this.state = {};
}

render() {
const {label, preferences, data} = this.props;
const
{isPresent, label, preferences, data} = this.props,
status = isPresent ? "current organization" : "latest organization"
;

if (!_.isEmpty(data)) {
const {chart, metrics} = data;
Expand Down Expand Up @@ -120,6 +123,7 @@ export default class ProfileMetricsBox extends Component {
return (
<div className="ibox float-e-margins" style={{marginBottom: 18}}>
<div className="ibox-title">
<span className="label label-info pull-right">{status}</span>
<h5>{label}</h5>
</div>
<IboxContentChartWithChosen
Expand Down
11 changes: 3 additions & 8 deletions imports/ui/containers/LandingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,19 @@ export default class LandingPage extends Component {
</div>
<div className="row">
<div className="col-lg-12 text-center">
<a href="mailto:[email protected]" className="btn btn-primary">Send us mail</a>
<p className="m-t-sm">
Or follow us on social platform
Follow us on social platform
</p>
<ul className="list-inline social-icon">
<li><a href="#"><i className="fa fa-twitter"></i></a>
</li>
<li><a href="#"><i className="fa fa-facebook"></i></a>
</li>
<li><a href="#"><i className="fa fa-linkedin"></i></a>
<li><a href="https://www.linkedin.com/company/6600918"><i className="fa fa-linkedin"></i></a>
</li>
</ul>
</div>
</div>
<div className="row">
<div className="col-lg-8 col-lg-offset-2 text-center m-t-lg m-b-lg">
<p><strong>&copy; 2016 theLeader.io</strong><br/>
We Help Leaders to become a better Leader by improving the Decision Making Process.</p>
STRIVE for Great Leadership</p>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 742e3de

Please sign in to comment.