Skip to content

Commit

Permalink
chart data interface
Browse files Browse the repository at this point in the history
  • Loading branch information
joy2king committed Feb 26, 2016
1 parent 3c48dfb commit 0970e1b
Show file tree
Hide file tree
Showing 11 changed files with 970 additions and 66 deletions.
128 changes: 114 additions & 14 deletions db/MongodbTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var MongoDB = require('./mongodb.js');
var mongoose = require('mongoose');
var moment = require('moment');
mongoose.connect('mongodb://localhost/test');

var user = {
Expand Down Expand Up @@ -30,10 +31,11 @@ var user = {

// @@@@ History test
// var msg = {
// from: "xxxxx1",
// from: "xxxxx2",
// to: "xxxxx2",
// msgtype: 'MSG_SINGLE',
// content: 'xxfsfdsfds'
// msgtype: 'MSG_GROUP',
// content: 'xxfsfdsfds',
// date: new Date('2016-02-23')
// };

// MongoDB.logchat(msg).then((saveObj) => {
Expand All @@ -43,15 +45,15 @@ var user = {
// });


var chatRoom = {
description: "it's a room test",
roomName: 'test',
owner: {
username: '123',
pid: 'ljfdljslfj'
},
tags: ['df1', 'df2', 'df3']
};
// var chatRoom = {
// description: "it's a room test",
// roomName: 'test',
// owner: {
// username: '123',
// pid: 'ljfdljslfj'
// },
// tags: ['df1', 'df2', 'df3']
// };

// MongoDB.createChatRoom(chatRoom).then(function(createdObject) {
// console.log(createdObject);
Expand All @@ -74,6 +76,104 @@ var chatRoom = {
// console.log(findRoom);
// })

MongoDB.findAllLivesRoom().then((findRoom) => {
console.log(findRoom);
// MongoDB.findAllLivesRoom().then((findRoom) => {
// console.log(findRoom);
// });

// MongoDB.aggregateDateByUserId('xxxxx2').then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

// MongoDB.aggregateMonthDateById('xxxxx2', 2016).then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

// MongoDB.aggregateCurrentWeekTotal('xxxxx2').then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

// MongoDB.aggregateMonthTotal('xxxxx2', 2016).then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

// MongoDB.groupMonthByUser('00001', 2016).then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

// MongoDB.groupMonthTotalByUser('00001', 2016).then(function(result) {
// console.log(result);
// }).catch(function(err) {
// console.log(err);
// });

MongoDB.groupWeekByUser('00001').then(function(results) {
var week = ['Monday', 'Tuesday', 'WensDady', 'Turesday', 'Friday', 'Saturday', 'Sunday'];
var monday = moment(new Date()).day(1).date();
var sunday = moment(new Date()).day(7).date();
var rooms = {};

results.forEach(function(result) {
if (!rooms[result.rid]) {
rooms[result.rid] = [];
}
rooms[result.rid].push(result);
});

// rooms.forEach(function(room) {

// });

var _create_weekmap = function() {
var map = {};
var d = moment(new Date());
for (var i = 1; i <= 7; i++) {
map[d.day(i).format('YYYY-M-D')] = true;
};
return map;
}

for (var roomId in rooms) {
var week = _create_weekmap();
rooms[roomId].forEach(function(roomstatics) {
if (roomstatics.key in week) {
delete week[roomstatics.key];
};
});

for(var i in week) {
var da = moment(i, 'YYYY-M-D');
var emptyWeek = {
key : i,
rid : roomId,
year : da.year(),
date : da.date(),
count : 0
}
rooms[roomId].push(emptyWeek);
}
var sortedRoom = rooms[roomId].sort(function(r1, r2) {
return r1.key > r2.key ? 1 : (r1.key === r2.key ? 0 : -1);
});

rooms[roomId] = sortedRoom;
};

}).catch(function(err) {
console.log(err);
});

MongoDB.groupWeekTotalByUser('00001').then(function(result) {
console.log(result);
}).catch(function(err) {
console.log(err);
});
Loading

0 comments on commit 0970e1b

Please sign in to comment.