def __init__(self): self._projects = MongoFactory().get_connection().get_collection(collection_name='projects') self._users = MongoFactory().get_connection().get_collection(collection_name='users') self.weChat = [0.15,0.25,0.1,0.4,0.1] self.App = [0.25,0.35,0.1,0.2,0.1] self.Sitp = [0.4,0.15,0.2,0.15,0.1] self.ShanghaiInnovate = [0.3,0.1,0.1,0.2,0.3] self.mathModeling = [0.2,0.1,0.4,0.25,0.05]
def valid_login(username, password): conn = MongoFactory().get_connection().get_collection(collection_name='users') user = list(conn.find({'username': username})) if user_not_exist(user): return False if equal_password(user, password): user[0]['_id'] = str(user[0]['_id']) g.user = user[0] return True
def UnSolvedMessageCount(username): conn = MongoFactory().get_connection() return len( list( conn.get_collection(collection_name='messages').find({ 'project_owner': username, 'isSolved': 0 })))
def __init__(self): self._projects = MongoFactory().get_connection().get_collection( collection_name='projects') self._users = MongoFactory().get_connection().get_collection( collection_name='users') self.weChat = [0.15, 0.25, 0.1, 0.4, 0.1] self.App = [0.25, 0.35, 0.1, 0.2, 0.1] self.Sitp = [0.4, 0.15, 0.2, 0.15, 0.1] self.ShanghaiInnovate = [0.3, 0.1, 0.1, 0.2, 0.3] self.mathModeling = [0.2, 0.1, 0.4, 0.25, 0.05]
def get_log_by_project_id(project_id): conn = MongoFactory().get_connection() log_conn = conn.get_collection("logs") u_conn = conn.get_collection("users") log = log_conn.find_one({'project_id': project_id}) for timeline in log['timelines']: if timeline['type'] == 0: timeline['creator'] = u_conn.find_one({'username': timeline['creator']}) if timeline['type'] == 1 or timeline['type'] == 2: timeline['applier'] = u_conn.find_one({'username': timeline['applier']}) return log
def signup(user): conn = MongoFactory().get_connection().get_collection(collection_name='users') _user = list(conn.find({'username': user['username']})) if not user_not_exist(_user): return False user['wid'] = 0 result = conn.insert_one(user).inserted_id if result: return True else: return False
def kick_out(username, projectid, project_owner): conn = MongoFactory().get_connection() m_type = 3 message = { 'username': username, 'project_id': projectid, 'message_type': m_type, 'message_state': 0, 'project_owner': project_owner } result = conn.insert_message(message) return result
def kick_out(username, projectid, project_owner): conn = MongoFactory().get_connection() m_type = 3 message = { 'username': username, 'project_id': projectid, 'message_type': m_type, 'message_state': 0, 'project_owner': project_owner } result = conn.insert_message(message) return result
def get_log_by_project_id(project_id): conn = MongoFactory().get_connection() log_conn = conn.get_collection("logs") u_conn = conn.get_collection("users") log = log_conn.find_one({'project_id': project_id}) for timeline in log['timelines']: if timeline['type'] == 0: timeline['creator'] = u_conn.find_one( {'username': timeline['creator']}) if timeline['type'] == 1 or timeline['type'] == 2: timeline['applier'] = u_conn.find_one( {'username': timeline['applier']}) return log
def user_info_edit(user): conn = MongoFactory().get_connection().get_collection(collection_name='users') interest = user['interest'] print interest user_id = find_user_by_username(user['username'])['_id'] return conn.update_one({ '_id': ObjectId(user_id) },{ '$set': { 'school': user['school'], 'grade': user['grade'], 'phone': user['phone'], 'email': user['email'], 'gender': user['gender'], 'interest': interest } })
class CommentManager: def __init__(self): self._comments = MongoFactory().get_connection().get_collection(collection_name='comments') def create_comment(self, username, content, project_id): self._comments.insert_one({ 'username': username, 'content': content, 'project_id': project_id, 'created_time': datetime.now() }).inserted_id def del_comment(self, comment_id): self._comments.delete_one({'_id': ObjectId(comment_id)}) def update_comment(self, comment_id, content): self._comments.update_one({ '_id': ObjectId(comment_id) },{ '$set': { 'content': content } }) def get_all_comment_by_projectid(self, project_id): return list(self._comments.find({ 'project_id': project_id }))
def accept(username, projectid, projectname, project_owner, message_id): conn = MongoFactory().get_connection() m_type = 1 conn.get_collection(collection_name='messages').update_one( {'_id': ObjectId(message_id)}, {'$set': { 'isSolved': 1 }}) message = { 'username': username, 'project_id': projectid, 'projectname': projectname, 'message_type': m_type, 'message_state': 0, 'isSolved': 1, 'project_owner': project_owner } result = conn.insert_message(message) return result
def accept(username, projectid, projectname, project_owner, message_id): conn = MongoFactory().get_connection() m_type = 1 conn.get_collection(collection_name='messages').update_one({ '_id': ObjectId(message_id) }, { '$set': { 'isSolved': 1 } }) message = { 'username': username, 'project_id': projectid, 'projectname': projectname, 'message_type': m_type, 'message_state': 0, 'isSolved': 1, 'project_owner': project_owner } result = conn.insert_message(message) return result
class CommentManager: def __init__(self): self._comments = MongoFactory().get_connection().get_collection( collection_name='comments') def create_comment(self, username, content, project_id): self._comments.insert_one({ 'username': username, 'content': content, 'project_id': project_id, 'created_time': datetime.now() }).inserted_id def del_comment(self, comment_id): self._comments.delete_one({'_id': ObjectId(comment_id)}) def update_comment(self, comment_id, content): self._comments.update_one({'_id': ObjectId(comment_id)}, {'$set': { 'content': content }}) def get_all_comment_by_projectid(self, project_id): return list(self._comments.find({'project_id': project_id}))
def UnSolvedMessageCount(username): conn = MongoFactory().get_connection() return len(list(conn.get_collection(collection_name='messages').find({'project_owner': username,'isSolved': 0})))
def show_all_message(): conn = MongoFactory().get_connection() return conn.findmessage()
class recommendDesigner(): def __init__(self): self._projects = MongoFactory().get_connection().get_collection(collection_name='projects') self._users = MongoFactory().get_connection().get_collection(collection_name='users') self.weChat = [0.15,0.25,0.1,0.4,0.1] self.App = [0.25,0.35,0.1,0.2,0.1] self.Sitp = [0.4,0.15,0.2,0.15,0.1] self.ShanghaiInnovate = [0.3,0.1,0.1,0.2,0.3] self.mathModeling = [0.2,0.1,0.4,0.25,0.05] def createPoi(self, project_id): project = self._projects.find_one({ '_id': ObjectId(project_id) }) type= project['type'] pp = [self.weChat,self.App,self.Sitp,self.mathModeling,self.ShanghaiInnovate] p = pp[int(type)] self._projects.update({ '_id': ObjectId(project_id) },{ '$set':{ 'Poi': p } }) def recomendSta(self,username): user = self._users.find_one({ 'username':username }) u_poi = np.array(user['Poi']) projects = list(self._projects.find()) projects_poi = np.array(map(lambda x: x['Poi'], projects)) result = np.dot(projects_poi, u_poi.reshape(-1, 1)) for i, project in enumerate(projects): project['rate'] = result[i,0] projects.sort(key=lambda x: x['rate'], reverse=True) return projects[:3] def createUPoi(self, user_id): user = self._users.find_one({ '_id':ObjectId(user_id) }) pp = [self.weChat,self.App,self.Sitp,self.mathModeling,self.ShanghaiInnovate] pois = user['interest'] upoi = np.array([0,0,0,0,0]) for poi in pois: poi = np.array(pp[int(poi)]) upoi = upoi + poi if len(pois) != 0: upoi = upoi/len(pois) print 'result' else: upoi = [0.2,0.2,0.2,0.2,0.2] print 'result' return self._users.update_one({ '_id':ObjectId(user_id) },{ '$set':{ 'Poi': list(upoi) } }) def updatePoi(self,p_id,username): user = self._users.find_one({ 'username': username }) project = self._projects.find_one({ '_id': ObjectId(p_id) }) u_poi = np.array(user['Poi']) p_poi = np.array(project['Poi']) u_npoi = (u_poi + 0.5 * p_poi) / 1.5 print list(u_npoi) p_npoi = (0.1 * u_poi + p_poi)/1.1 print list(p_npoi) self._users.update_one({ 'username':username },{ '$set':{ 'Poi': list(u_npoi) } } ) self._projects.update_one({ '_id':ObjectId(p_id) },{ '$set':{ 'Poi': list(p_npoi) } })
def read_message(message_id): conn = MongoFactory().get_connection() return conn.read_message(message_id)
def get_all_message(username): conn = MongoFactory().get_connection() result = conn.get_all_message(username) return result
def get_all_message(username): conn = MongoFactory().get_connection() result = conn.get_all_message(username) return result
def find_user_by_userId(userId): conn = MongoFactory().get_connection().get_collection(collection_name='users') return conn.find_one({'_id': ObjectId(userId)})
def find_user_by_username(username): conn = MongoFactory().get_connection().get_collection(collection_name='users') return conn.find_one({'username': username})
def search_message(input, username): conn = MongoFactory().get_connection() result = conn.search_message(input, username) return result
def get_db(): return MongoFactory().get_connection()._conn_instance
def count_message_by_user(username): conn = MongoFactory().get_connection() return conn.count_message_by_user(username=username)
class recommendDesigner(): def __init__(self): self._projects = MongoFactory().get_connection().get_collection( collection_name='projects') self._users = MongoFactory().get_connection().get_collection( collection_name='users') self.weChat = [0.15, 0.25, 0.1, 0.4, 0.1] self.App = [0.25, 0.35, 0.1, 0.2, 0.1] self.Sitp = [0.4, 0.15, 0.2, 0.15, 0.1] self.ShanghaiInnovate = [0.3, 0.1, 0.1, 0.2, 0.3] self.mathModeling = [0.2, 0.1, 0.4, 0.25, 0.05] def createPoi(self, project_id): project = self._projects.find_one({'_id': ObjectId(project_id)}) type = project['type'] pp = [ self.weChat, self.App, self.Sitp, self.mathModeling, self.ShanghaiInnovate ] p = pp[int(type)] self._projects.update({'_id': ObjectId(project_id)}, {'$set': { 'Poi': p }}) def recomendSta(self, username): user = self._users.find_one({'username': username}) u_poi = np.array(user['Poi']) projects = list(self._projects.find()) projects_poi = np.array(map(lambda x: x['Poi'], projects)) result = np.dot(projects_poi, u_poi.reshape(-1, 1)) for i, project in enumerate(projects): project['rate'] = result[i, 0] projects.sort(key=lambda x: x['rate'], reverse=True) return projects[:3] def createUPoi(self, user_id): user = self._users.find_one({'_id': ObjectId(user_id)}) pp = [ self.weChat, self.App, self.Sitp, self.mathModeling, self.ShanghaiInnovate ] pois = user['interest'] upoi = np.array([0, 0, 0, 0, 0]) for poi in pois: poi = np.array(pp[int(poi)]) upoi = upoi + poi if len(pois) != 0: upoi = upoi / len(pois) print 'result' else: upoi = [0.2, 0.2, 0.2, 0.2, 0.2] print 'result' return self._users.update_one({'_id': ObjectId(user_id)}, {'$set': { 'Poi': list(upoi) }}) def updatePoi(self, p_id, username): user = self._users.find_one({'username': username}) project = self._projects.find_one({'_id': ObjectId(p_id)}) u_poi = np.array(user['Poi']) p_poi = np.array(project['Poi']) u_npoi = (u_poi + 0.5 * p_poi) / 1.5 print list(u_npoi) p_npoi = (0.1 * u_poi + p_poi) / 1.1 print list(p_npoi) self._users.update_one({'username': username}, {'$set': { 'Poi': list(u_npoi) }}) self._projects.update_one({'_id': ObjectId(p_id)}, {'$set': { 'Poi': list(p_npoi) }})
def search_message(input, username): conn = MongoFactory().get_connection() result = conn.search_message(input, username) return result
def find_mes_by_id(message_id): conn = MongoFactory().get_connection() return conn.findmessagebyid(message_id)
def show_all_message(): conn = MongoFactory().get_connection() return conn.findmessage()
def find_mes_by_id(message_id): conn = MongoFactory().get_connection() return conn.findmessagebyid(message_id)
def __init__(self): self._comments = MongoFactory().get_connection().get_collection(collection_name='comments')
def find_message_by_user(username, page_no, page_size): conn = MongoFactory().get_connection() return conn.find_message_by_user(username=username, page_no=page_no, page_size=page_size)
def find_message_by_user(username, page_no, page_size): conn = MongoFactory().get_connection() return conn.find_message_by_user(username=username, page_no=page_no, page_size=page_size)
def count_message_by_user(username): conn = MongoFactory().get_connection() return conn.count_message_by_user(username=username)
def __init__(self): self._comments = MongoFactory().get_connection().get_collection( collection_name='comments')
def read_message(message_id): conn = MongoFactory().get_connection() return conn.read_message(message_id)