class LogicMetByDevice(object): def __init__(self): self.meet = Meet() self.user = User() self.map = DBOHHOMapInformation() def push_information(self, to_user_id, user_id, apply_id, type, base_url): information = self.user.get_met_user_information( user_id, apply_id, base_url) information["function"] = "met by device" return self.user.push_user_information(to_user_id, type, information) def met(self, user_id, friend_user_id, apply_id, base_url): user_id = int(user_id) friend_user_id = int(friend_user_id) apply_id = int(apply_id) type = PUSH_STATE_TYPE_MET result = self.push_information(friend_user_id, user_id, apply_id, type, base_url) OHHOLog.print_log(result) # information = self.user.get_push_user_information(user_id, apply_id, base_url) # information["function"] = "met by device" # self.user.push_user_information(friend_user_id, PUSH_STATE_TYPE_MET, information) user_map = self.map.get_by_user(user_id) if user_map: user_address = user_map.address else: user_address = "" friend_user_map = self.map.get_by_user(friend_user_id) if friend_user_map: friend_user_address = friend_user_map.address else: friend_user_address = "" data = dict() data["user_id"] = user_id data["another_user_id"] = friend_user_id data["apply_id"] = apply_id data["user_address"] = user_address data["friend_user_map"] = friend_user_address data["type"] = 0 self.meet.add_met(data) return Result.result_success()
class LogicGetUserInformation(object): def __init__(self): self.user = User() def get(self, friend_user_id, user_id, base_url): if friend_user_id: result = Result.result_success() else: result = Result.result_failed() data = self.user.get_user_information(friend_user_id, base_url) relation, apply_id, applied_id = self.user.get_friend_relation( user_id, friend_user_id) data["relation"] = relation data = self.user.set_map_by_exclude(data, user_id, friend_user_id) data = self.user.set_map_by_is_online(data, user_id, friend_user_id) result["data"] = data return result
def __init__(self): self.device = Device() self.user = User() self.meet = Meet() self.friend = Friend() self.map = DBOHHOMapInformation() self.match_condition = LogicGetMatchCondition() self.condition = MatchCondition() self.condition_relation = UserAndMatchCondition() self.device_relation = DBOHHOUserAndDeviceRelation() self.user_extension = DBOHHOUserAccuracyExtension() self.exclude = DBOHHORecordExclude() self.configuration = DBOHHOUserConfiguration() self.match_apply = DBOHHORecordMatchApply() self.favourite_book = DBOHHOUserFavouriteBook() self.favourite_movie = DBOHHOUserFavouriteMovie() self.favourite_music = DBOHHOUserFavouriteMusic() self.favourite_sport = DBOHHOUserFavouriteSport() self.match_online = DBOHHOMatchOnline()
class LogicRefuseMeet(object): def __init__(self): self.meet = Meet() self.user = User() def push_information(self, to_user_id, user_id, apply_id, type, base_url): information = self.user.get_refuse_meet_user_information( user_id, apply_id, base_url) information["function"] = "refuse meet" return self.user.push_user_information(to_user_id, type, information) def refuse_meet(self, user_id, friend_user_id, apply_id, base_url): """ 拒绝见面 只要对方有申请见面,就可以拒绝见面 :param user_id: 用户ID :param friend_user_id: 另一用户ID :param meet_state: 见面状态 0未见,1见面,2 请求相见,3同意相见,4不同意相见,5 取消见面,默认为0 :return: """ # 向对方发送拒绝的推送 try: if user_id and friend_user_id and apply_id: type = PUSH_STATE_TYPE_REFUSE_MEET if not self.meet.is_meet_end(apply_id, friend_user_id): result = self.push_information(friend_user_id, user_id, apply_id, type, base_url) OHHOLog.print_log(result) # information = self.user.get_push_user_information(user_id, apply_id, base_url) # information["function"] = "refuse meet" # self.user.push_user_information(friend_user_id, PUSH_STATE_TYPE_REFUSE_MEET, information) self.meet.add_exclude(user_id, friend_user_id) self.meet.add_refuse(apply_id, user_id) return Result.result_success() else: OHHOLog.print_log( "user_id:%s, friend_user_id:%s, apply_id:%s" % (str(user_id), str(friend_user_id), str(apply_id))) return Result.result_failed("there is some id is 0") except Exception as ex: OHHOLog.print_log(ex) return Result.result_failed(ex)
class LogicPollingGetMatchState(object): def __init__(self): self.agree = MatchAgree() self.apply = MatchApply() self.refuse = MatchRefuse() self.meet = Meet() self.user = User() def get(self, user_id, friend_user_id, is_apply, base_url): result = Result.result_success() user = self.user.get_by_id(user_id) if user: if int(is_apply): apply = self.apply.get_nearest(user_id, friend_user_id) else: apply = self.apply.get_nearest(friend_user_id, user_id) if apply: agree = self.agree.get(apply.id) refuse = self.refuse.get(apply.id) if self.meet.is_meet_by_apply(apply.id): result["state"] = 6 # 见面 else: if agree: if not refuse: result["state"] = 1 # "agree" else: result["state"] = 3 # "cancel" else: if refuse: result["state"] = 2 # "refuse" else: result["state"] = 4 # "default" else: result["state"] = 5 # "no such apply" if result["state"] in [1, 6]: result["data"] = self.user.get_user_basic_information( friend_user_id, base_url) return result
def get(self): the_get = Get() user_id = the_get.get_user_id(self) friend_user_id = the_get.get_friend_id(self) is_delete = the_get.get_delete(self) user = User() meet = Meet() the_user = user.get_by_id(user_id) the_friend = user.get_by_id(friend_user_id) if is_delete: met_instance = meet.get_met_by_users(user_id, friend_user_id) success = meet.met.delete(met_instance) if success: result = Result.result_success("delete successfully!") else: result = Result.result_failed("delete failed!") else: if the_user and the_friend: success = meet.add_apply(user_id, friend_user_id) if success: apply = meet.get_apply_by_user_and_friend( user_id, friend_user_id) if apply: data = dict() data["apply_id"] = apply.id data["user_id"] = user_id data["another_user_id"] = friend_user_id success = meet.add_met(data) if success: result = Result.result_success("add successfully!") else: result = Result.result_failed("add met failed!") else: result = Result.result_failed("get apply failed!") else: result = Result.result_failed("add apply failed!") else: result = Result.result_failed("user does not exist!") self.write(OHHOOperation.dict2json(result))
class LogicGetMapPositions(object): def __init__(self): self.user = User() def get(self, user_id, base_url): result = Result.result_success() users = self.user.get_all() data = list() if self.user.user.is_empty(users): pass else: for user in users: if user_id == user.id: continue temp = self.user.get_user_basic_information(user.id, base_url) if temp: data.append(temp) if data: result["data"] = data return result
def get(self): # name = self.get_body_argument("user_name", None) the_get = Get() result = dict() base_url = the_get.get_base_url(self) user_id = the_get.get_user_id(self) friend_user_id = the_get.get_friend_id(self) user = User() friend_user_id2 = user_id if user_id else 4 user_id = 4 friend_user_id = friend_user_id if friend_user_id else 13 log_string = "1234567890" OHHOLog.print_log(log_string) # message = user.get_user_basic_information(user_id, base_url) for i in range(100): OHHOLog.print_log(user.push(str(i), friend_user_id, user_id)) OHHOLog.print_log(user.push(str(i), friend_user_id2, user_id)) # return Result.result_success() self.write(OHHOOperation.dict2json(Result.result_success()))
class LogicRematch(object): def __init__(self): self.meet = Meet() self.user = User() self.map = DBOHHOMapInformation() self.configuration = DBOHHOUserConfiguration() def rematch(self, user_id, friend_user_id, apply_id, is_published): # 加到exclude表中, 取消见面 # type 0:未被惩罚 # type 1: 惩罚,删除这个人以前的惩罚,加到惩罚表中;关闭本人的配对开关 self.meet.add_exclude(user_id, friend_user_id) user_map = self.map.get_by_user(user_id) friend_map = self.map.get_by_user(friend_user_id) user_address = user_map.address if user_map else "" friend_user_address = friend_map.address if friend_map else "" self.meet.add_meet_end(apply_id, user_id, user_address) self.meet.add_meet_end(apply_id, friend_user_id, friend_user_address) self.meet.delete_meeting(apply_id, user_id) self.meet.delete_meeting(apply_id, friend_user_id) if not self.meet.is_meet_end(apply_id, friend_user_id): data = dict() data["user_id"] = user_id data["apply_id"] = apply_id self.user.push_user_information(friend_user_id, PUSH_STATE_TYPE_END_MEET, data) if is_published: self.meet.delete_published_by_user(user_id) data = dict() data["user_id"] = user_id data["apply_id"] = apply_id self.meet.add_published(data) configuration = self.configuration.get_by_user(user_id) if configuration: self.configuration.close_match(configuration) return Result.result_success()
def post(self): user = User() the_post = Post() country_code = the_post.get_country_code(self) cellphone = the_post.get_username(self) password = the_post.get_password(self) code = the_post.get_code(self) instance = LogicBackstageRegister() register_instance = LogicRegister() msg = "" country_code_object = user.get_country_code(country_code) if country_code_object and not user.get_by_country_code_and_cellphone( country_code_object.id, cellphone): register_result = register_instance.add_new_user( password, cellphone, country_code) OHHOLog.print_log(register_result) if Result.is_success(register_result): user_id = register_result.get("user_id", 0) user_object = user.get_by_id(user_id) if user_object: self.set_secure_cookie("username", user_object.username) return self.redirect("/backstage/home/") # if Code.check_code(username, code): # 目前验证码没有用,先注释掉 # pass # else: # return self.render(BACKSTAGE_REGISTER_HTML, # postUrl=BACKSTAGE_REGISTER_URL, # msg="验证码不正确" # ) # if username and password: # result1 = instance.register(username, password) # if result1: # self.set_secure_cookie("username", username) # return self.redirect("/backstage/home/") return self.render(BACKSTAGE_REGISTER_HTML, postUrl=BACKSTAGE_REGISTER_URL, msg="注册不成功")
def post(self): the_post = Post() user_instance = User() relation_instance = UserAndMatchCondition() username = the_post.get_username(self) name = the_post.get_name(self) match_condition_id = the_post.get_match_condition_id(self) user_and_match_condition_id = the_post.get_id(self) relation = relation_instance.get_by_id(user_and_match_condition_id) match_condition = relation_instance.get_match_condition( match_condition_id) submit = the_post.get_submit(self) delete = the_post.get_delete(self) detail_url = USER_AND_MATCH_CONDITION_DETAIL_URL + "?id=" + user_and_match_condition_id user = user_instance.get_by_cellphone(username) OHHOLog.print_log(submit) OHHOLog.print_log(relation) OHHOLog.print_log(user) OHHOLog.print_log(match_condition) if submit and relation and user and match_condition: OHHOLog.print_log("start logic") data = dict() data["user_id"] = user.id data["name"] = name data["match_condition_id"] = match_condition_id success = relation_instance.update(relation, data) if success: return self.redirect(USER_AND_MATCH_CONDITION_LIST_URL) if delete and relation: success = relation_instance.delete(relation) if success: return self.redirect(USER_AND_MATCH_CONDITION_LIST_URL) return self.redirect(detail_url)
class EncounterStrategy(object): def __init__(self, user_id): self.user_id = user_id self.user = User() self.map = DBOHHOMapInformation() self.impression = DBOHHOUserImpression() self.extension = DBOHHOUserAccuracyExtension() def get_impression(self): return self.impression.get_user_impression_list_by_user_id( self.user_id) def get_sex(self): extension = self.extension.get_by_user(self.user_id) if extension and extension.sex: return '男孩纸' if extension.sex == 1 else '女孩纸' return "X孩纸" def get_age(self): extension = self.extension.get_by_user(self.user_id) if extension and extension.birthday: return self.user.get_age_display(extension.birthday) return "XX后" def get_occupation(self): extension = self.extension.get_by_user(self.user_id) if extension and extension.occupation: return extension.occupation.name return "XX" def get_position(self): extension = self.extension.get_by_user(self.user_id) if extension and extension.position: return extension.position.name return "XX" def get_character(self): pass def get_favourite(self): pass def get_near_pois(self, longitude, latitude): pass def get_default(self): pass def get_end_words(self): pass
def post(self): user = User() the_post = Post() self.set_format(the_post.get_format(self)) user_id = the_post.get_user_id(self) friend_user_id = the_post.get_friend_id(self) apply_id = the_post.get_apply_id(self) category = the_post.get_category(self) reason = the_post.get_reason(self) content = the_post.get_content(self) base_url = the_post.get_base_url(self) cancel_meet = LogicCancelMeet() cancel_meet.cancel_meet(user_id, friend_user_id, apply_id, base_url) feedback = LogicAddCancelMeetFeedback() result = feedback.add_feedback(user_id, friend_user_id, apply_id, reason, content, category) information = user.get_cancel_meet_user_information(user_id, apply_id, base_url) information["message"] = content user.push_user_information(friend_user_id, PUSH_STATE_TYPE_CANCEL_MEET, information) return self.response(result)
class LogicCellphoneUnbindDevice(object): def __init__(self): self.user = User() self.device = Device() self.imei = IMEI() def unbind_device(self, cellphone, code, identity, mac_address, country_code): # OHHOLog.print_log(cellphone) # OHHOLog.print_log(identity) # OHHOLog.print_log(mac_address) if country_code and cellphone: the_cellphone = country_code + cellphone else: return Result.result_parameters_are_invalid( "country_code or cellphone is empty!") success = Code.check_code(the_cellphone, code) if success: country_code_object = self.user.get_country_code(country_code) country_code_id = country_code_object.id if country_code_object else 0 user = self.user.get_by_country_code_and_cellphone( country_code_id, cellphone) if user: self.device.set_mac_address(mac_address) self.device.set_identity(identity) device = self.device.get_by_identity() if device: # OHHOLog.print_log("before delete imei") self.imei.delete_by_user_and_device(user.id, device.id) # OHHOLog.print_log("after delete imei") # query = self.imei.get_by_user_and_device(user.id, device.id) # self.imei.delete_some(query) return self.device.unbind_device(user.id) else: return Result.result_not_exist(USER_NOT_EXIST) else: return Result.result_failed(PASSWORD_IS_INCORRECT)
class LogicApplyMeet(object): def __init__(self): self.apply = MatchApply() self.condition = MatchCondition() self.meet = Meet() self.user = User() def apply_meet(self, user_id, friend_user_id, match_condition_id, base_url): """ 申请见面 见过面的不能申请 :param user_id: 用户ID :param friend_user_id: 另一用户ID :param match_condition_id: 配对条件ID :return: """ result = dict() if self.meet.has_valid_apply(user_id, friend_user_id): return Result.result_has_valid_meet_apply() if self.meet.is_meet(user_id, friend_user_id): return Result.result_is_meet() condition = self.condition.get_by_id(match_condition_id) if condition: success = self.meet.add_apply(user_id, friend_user_id, match_condition_id) if success: log_string = "%d apply %d to meet" % (user_id, friend_user_id) OHHOLog.print_log(log_string) message = self.user.get_user_basic_information(user_id, base_url) self.user.push(log_string, friend_user_id, DEFAULT_IM_USER_ID) return Result.result_success() else: return Result.result_failed() else: return Result.result_failed("no such condition!")
class LogicRebindCellphone(object): def __init__(self): self.user = User() self.cellphone = Cellphone() def rebind_cellphone(self, cellphone_key, cellphone_number, code, base_url, cellphone_dict, country_code): the_cellphone = country_code + cellphone_number check = Code.check_code(the_cellphone, code) if check: country_code_object = self.user.country_code.get_by_country_code(country_code) country_code_id = country_code_object.id if country_code_object else 0 # self.user.get_by_country_code_and_cellphone(country_code, cellphone_number) # user = self.user.get(cellphone_number) user = self.user.get_by_country_code_and_cellphone(country_code_id, cellphone_number) self.cellphone.set_key(cellphone_key) cellphone = self.cellphone.get() if not cellphone: success = self.cellphone.add_cellphone(cellphone_dict) if success: cellphone = self.cellphone.get() else: cellphone = None if cellphone: if not user: OHHOLog.print_log(country_code) OHHOLog.print_log(cellphone_number) result = Result.result_failed("user doest not exist") else: result = self.cellphone.bind_cellphone(cellphone.id, user.id) data = self.user.get_user_information(user.id, base_url) result["data"] = data else: result = Result.result_failed("cellphone does not exist!") else: result = Result.result_failed("code is incorrect!") return result
class LogicUpdateCellphoneNumber(object): def __init__(self): self.user = User() self.country_code = DBOHHOCountryCode() def change(self, user_id, cellphone_number, code, country_code): country_code_obj = self.country_code.get_by_country_code(country_code) if country_code_obj: code_cellphone_number = country_code + cellphone_number else: return Result.result_failed("the country_code not exist") is_correct = Code.check_code(code_cellphone_number, code) if is_correct: the_user = self.user.get_by_id(user_id) if the_user: if self.user.user.exist_valid_cellphone_country_code_id( country_code_obj.id, cellphone_number): return Result.result_failed( "the cellphone number has been registered!") else: last_cellphone = the_user.cellphone cellphone = cellphone_number data = dict() data["last_cellphone"] = last_cellphone data["cellphone"] = cellphone data["country_code_id"] = country_code_obj.id success = self.user.update_user(the_user, data) if success: return Result.result_success() else: return Result.result_failed() else: return Result.result_failed("the user %d does not exist" % (int(user_id))) else: return Result.result_failed("cellphone code is incorrect!")
def get(self): the_get = Get() cellphone = the_get.get_cellphone_number(self) if cellphone is None: cellphone = "" state = the_get.get_state(self) if state is None: state = "" page = the_get.get_page(self) data_count_per_page = the_get.get_data_count_per_page(self) page_count_per_page = the_get.get_page_count_per_page(self) offset = (page - 1) * data_count_per_page limit = data_count_per_page instance = User() if cellphone: query = instance.find_by_cellphone(cellphone) # instance.get_by_cellphone(cellphone) # query = instance.find_by_username() else: query = instance.get_all() try: if state == "": pass elif int(state): query = instance.get_valid(query) else: query = instance.get_invalid(query) except Exception as ex: pass users, count = instance.get_some_users(query, offset, limit) total_page = int(ceil(count / data_count_per_page)) pagination = Pagination(total_page, page, data_count_per_page, page_count_per_page) page_list, previous, next = pagination.get_page_list_of_this_page() # return self.render("backstage/management/user_list.html", return self.render( MANAGEMENT_USER_LIST_HTML, users=users, pages=page_list, previous=previous, next=next, page=page, cellphone_number=cellphone, state=state, detail_url=MANAGEMENT_USER_DETAIL_URL, delete_url=MANAGEMENT_USER_DELETE_URL, )
def add_new_user(password, cellphone, country_code="+86"): username = OHHOUUID.get_uuid1_string() user = User() user.set_username(username) OHHOLog.print_log(user.add_user(password, cellphone, country_code)) the_user = user.get_by_username(username) if the_user: result = Result.result_success() result["user_id"] = the_user.id else: result = Result.result_failed() result["user_id"] = 0 return result
class LogicListBlacks(object): def __init__(self): self.user = User() self.friend = Friend() def list_blacks(self, user_id, base_url): # OHHOLog.print_log("here is black") # OHHOLog.print_log(user_id) friend_relations = self.friend.get_blacks(user_id) # OHHOLog.print_log(self.friend.friend.get_count(friend_relations)) data = list() for relation in friend_relations: # OHHOLog.print_log(relation.id) # user = self.user.get_by_id(relation.friend_account_id) # if user: temp = self.user.get_user_information4friend( relation.friend_account_id, base_url) if temp: data.append(temp) result = Result.result_success() if data: result["data"] = data return result
def __init__(self): self.user = User() self.cellphone = Cellphone()
def __init__(self): self.user = User() self.country_code = DBOHHOCountryCode() self.cellphone = Cellphone()
class LogicResetPassword(object): def __init__(self): self.user = User() self.country_code = DBOHHOCountryCode() self.cellphone = Cellphone() def reset_password(self, cellphone_number, password, code, country_code, cellphone_dict=dict(), base_url=None): country_code_obj = self.user.get_country_code(country_code) if country_code_obj: user = self.user.user.get_by_country_code_and_cellphone(country_code_obj.id, cellphone_number) if user: cellphone_number_check = country_code + cellphone_number if self.user.check_threemonth_isvalid(user): if Code.check_code(cellphone_number_check, code): result = self.user.reset_password(cellphone_number, password, country_code) if Result.is_success(result): if not self.bind_cellphone(cellphone_dict, user.id): return Result.result_failed("bind cellphone failed") self.user.set_username(user.username) if not Result.is_success(self.user.add_token()): result = Result.result_failed("login failed!") else: information = self.user.get_user_information(user.id, base_url) result["data"] = information else: result = Result.result_failed("change password failed!") else: result = Result.result_failed("verification code is incorrect!") else: result = Result.result_update_beyond_three_month() else: result = Result.result_failed("user not exist!") else: result = Result.result_failed("country_code not exist") return result def bind_cellphone(self, cellphone_dict, user_id): OHHOLog.print_log(cellphone_dict) OHHOLog.print_log(user_id) if cellphone_dict and cellphone_dict.get("key", ""): key = cellphone_dict.get("key") OHHOLog.print_log(key) self.cellphone.set_key(key) cellphone_object = self.cellphone.get() if not cellphone_object: OHHOLog.print_log("no cellphone object") self.cellphone.add_cellphone(cellphone_dict) cellphone_object = self.cellphone.get() if cellphone_object: OHHOLog.print_log("no cellphone object at all") if not self.cellphone.is_bound_by_user(cellphone_object.id, user_id): OHHOLog.print_log("begin to bind user") success = self.cellphone.bind_cellphone(cellphone_object.id, user_id) OHHOLog.print_log(success) return Result.is_success(success) else: return True else: return False else: return True
class LogicLogin(object): def __init__(self): self.user = User() self.cellphone = Cellphone() self.imei = IMEI() def authenticate(self, country_code, username, password, cellphone_dict, base_url, code): country_code_object = self.user.get_country_code(country_code) country_code_id = country_code_object.id if country_code_object else 0 OHHOLog.print_log("check user") is_code_login = False if username and code: is_code_login = True user_check_result = self.user.check_user_only_by_user(username, code, country_code_id) else: user_check_result = self.user.check_user(username, password, country_code_id) OHHOLog.print_log(user_check_result) user = self.user.get_by_cellphone(username) cellphone_key = cellphone_dict.get("key", None) self.cellphone.set_key(cellphone_key) cellphone = self.cellphone.get() OHHOLog.print_log("check user and cellphone relation") cellphone_relation_result = Result.result_failed() code_cellphone_relation_result = Result.result_failed() if user and cellphone: is_bind = self.cellphone.is_bound_by_user(cellphone.id, user.id) if is_code_login: success = self.cellphone.bind_cellphone(cellphone.id, user.id) if not Result.is_success(success): code_cellphone_relation_result = Result.result_failed("rebind cellphone failed!") else: code_cellphone_relation_result = Result.result_success() else: if is_bind: cellphone_relation_result = Result.result_success() else: OHHOLog.print_log("user id:") OHHOLog.print_log(user.id) OHHOLog.print_log("cellphone id:") OHHOLog.print_log(cellphone.id) OHHOLog.print_log("unsafe cellphone!") cellphone_relation_result = Result.result_failed() else: OHHOLog.print_log("user or cellphone not exist!") cellphone_relation_result = Result.result_failed() if not cellphone: OHHOLog.print_log("add cellphone!") add_cellphone_result = self.cellphone.add_cellphone(cellphone_dict) OHHOLog.print_log(add_cellphone_result) OHHOLog.print_log(cellphone_relation_result) if not is_code_login: if Result.is_success(user_check_result) and Result.is_success(cellphone_relation_result): result = Result.result_success() elif Result.is_password_incorrect(user_check_result) or Result.is_update_beyond_three_month( user_check_result): result = user_check_result elif Result.is_success(user_check_result): result = Result.result_unsafe() elif Result.is_not_exist(user_check_result): result = Result.result_not_exist() else: result = Result.result_failed() else: if Result.is_success(user_check_result) and Result.is_success(code_cellphone_relation_result): result = Result.result_success() elif Result.is_update_beyond_three_month(user_check_result): result = user_check_result elif Result.is_not_exist(user_check_result): result = Result.result_not_exist() else: result = Result.result_failed() if user and Result.is_success(result): result["data"] = self.user.get_user_information(user.id, base_url) return result
def __init__(self): self.agree = MatchAgree() self.apply = MatchApply() self.refuse = MatchRefuse() self.meet = Meet() self.user = User()
class LogicBluetoothPosition(object): def __init__(self): self.blue_tooth = Bluetooth() self.meet = Meet() self.user = User() self.device = DBOHHODevice() self.relation = DBOHHOUserAndDeviceRelation() self.display_configuration = DBOHHOUserDisplayConfiguration() def get_display_instance(self, distance): instance = self.display_configuration.get_nearest_distance(distance) return instance def get_information(self, user_extension, instance): information = dict() if instance.has_sex: information["sex"] = user_extension.sex return information def get_push_data_by_distance(self, user_id, apply_id, distance, base_url): user_extension = self.user.user_extension.get_by_user(user_id) instance = self.get_display_instance(distance) information = dict() if user_extension and instance: information = self.get_information(user_extension, instance) return information def bluetooth_position(self, user_id, identity_id, rssi, distance, apply_id, base_url): the_meeting = self.meet.is_apply_in_meeting(apply_id, user_id) if the_meeting: friend_user_id = self.meet.get_another_user_id(apply_id, user_id) is_friend_end = self.meet.is_meet_end(apply_id, friend_user_id) is_friend_met = self.meet.is_met(apply_id) if is_friend_met: the_type = PUSH_STATE_TYPE_MET information = self.get_push_data_by_distance( user_id, apply_id, distance, base_url) information["is_blue_tooth"] = 1 self.user.push_user_information(friend_user_id, the_type, information) information = self.get_push_data_by_distance( friend_user_id, apply_id, distance, base_url) information["is_blue_tooth"] = 1 self.user.push_user_information(user_id, the_type, information) return Result.result_success("met!") if not is_friend_end and not is_friend_met: if self.meet.is_met(apply_id): the_type = PUSH_STATE_TYPE_MET elif self.meet.is_meet_end(apply_id, user_id): the_type = PUSH_STATE_TYPE_END_MEET else: the_type = PUSH_STATE_TYPE_MEETING information = self.get_push_data_by_distance( user_id, apply_id, distance, base_url) information["is_blue_tooth"] = 1 self.user.push_user_information(friend_user_id, the_type, information) self.device.set_identity(identity_id) device = self.device.get_by_identity() if device: self.blue_tooth.add_sensor(user_id, device.id, rssi, distance) return Result.result_success()
def __init__(self): self.meet = Meet() self.user = User() self.apply = DBOHHORecordMatchApply()
def get(self): the_get = Get() cellphone_instance = Cellphone() relation_instance = UserAndCellphoneRelation() user_instance = User() users_query = user_instance.get_all() users_query = user_instance.get_valid(users_query) cellphones_query = cellphone_instance.get_all_cellphone() cellphone_key = the_get.get_cellphone_key(self) if cellphone_key is None: cellphone_key = "" username = the_get.get_username(self) if username is None: username = "" page = the_get.get_page(self) data_count_per_page = the_get.get_data_count_per_page(self) page_count_per_page = the_get.get_page_count_per_page(self) offset = (page - 1) * data_count_per_page limit = data_count_per_page query = relation_instance.get_all() if cellphone_key: cellphone_query = cellphone_instance.get_all_cellphone() cellphone_query = cellphone_instance.find_by_key( cellphone_query, cellphone_key) cellphone_id_list = list() if not cellphone_instance.cellphone.is_empty(cellphone_query): cellphone_id_list = [ cellphone.id for cellphone in cellphone_query ] query = relation_instance.find_by_cellphone( query, cellphone_id_list) if username: user_query = user_instance.find_by_username(username) user_id_list = list() if not user_instance.user.is_empty(user_query): user_id_list = [user.id for user in user_query] query = relation_instance.find_by_user(query, user_id_list) query, count = relation_instance.get_some(query, offset, limit) total_page = int(ceil(count / data_count_per_page)) pagination = Pagination(total_page, page, data_count_per_page, page_count_per_page) page_list, previous, next = pagination.get_page_list_of_this_page() relations = list() for q in query: temp = dict() temp["id"] = q.id temp["state"] = q.state user = user_instance.get_by_id(q.user_id) temp["username"] = user.username if user else "" temp["user_id"] = user.id if user else "" cellphone = cellphone_instance.get_by_id(q.cellphone_id) temp["key"] = cellphone.key if cellphone else "" temp["cellphone_id"] = cellphone.id if cellphone else "" relations.append(temp) return self.render(USER_AND_CELLPHONE_LIST_HTML, relations=relations, pages=page_list, previous=previous, next=next, page=page, list_url=USER_AND_CELLPHONE_LIST_URL, detail_url=USER_AND_CELLPHONE_DETAIL_URL, add_url=USER_AND_CELLPHONE_ADD_URL, delete_url=USER_AND_CELLPHONE_DELETE_URL, username=username, cellphone_key=cellphone_key, users_query=users_query, cellphones_query=cellphones_query)
def __init__(self): self.map = DBOHHOMapInformation() self.user = User() self.meet = Meet() self.apply = DBOHHORecordMatchApply() self.user_configuration = DBOHHOUserConfiguration()
class LogicUploadMapPosition(object): def __init__(self): self.map = DBOHHOMapInformation() self.user = User() self.meet = Meet() self.apply = DBOHHORecordMatchApply() self.user_configuration = DBOHHOUserConfiguration() def push_information(self, map_information, to_user_id, user_id, the_type, apply_id, base_url): information = self.user.get_meeting_user_information(user_id, apply_id, base_url) information = OHHOOperation.dict_add_dict(information, map_information) information["is_blue_tooth"] = 0 information = self.user.set_map_by_exclude(information, to_user_id, user_id) information = self.user.set_map_by_is_online(information, to_user_id, user_id) created_at = information.get("created_at", None) if created_at: del information["created_at"] changed_at = information.get("changed_at", None) if changed_at: del information["changed_at"] return self.user.push_user_information(to_user_id, the_type, information) def return_map_information(self, friend_user_id): result = dict() result["is_timeout"] = 0 user = self.user.get_by_id(friend_user_id) if user: map_information = self.user.get_user_map_information_from_redis(user.username) map_information_dict = RedisDB.data2dict(map_information) if map_information_dict: map_information_dict["longitude"] = float(map_information_dict.get("longitude", 0)) map_information_dict["latitude"] = float(map_information_dict["latitude"]) map_information_dict["altitude"] = float(map_information_dict["altitude"]) map_information_dict["accuracy"] = float(map_information_dict["accuracy"]) map_information_dict["angle"] = float(map_information_dict["angle"]) map_information_dict["satellite_number"] = int(map_information_dict["satellite_number"]) now = OHHODatetime.get_current_timestamp() if map_information_dict["timestamp"] > 0 and now - map_information_dict["timestamp"] > 30000: result["is_timeout"] = 1 result["timestamp"] = now result["last_timestamp"] = map_information_dict["timestamp"] else: information = dict() information["user_id"] = friend_user_id information["latitude"] = float(map_information_dict["latitude"]) information["longitude"] = float(map_information_dict["longitude"]) information["accuracy"] = float(map_information_dict["accuracy"]) information["supplier"] = map_information_dict["supplier"] if map_information_dict.get("floor", None): information["floor"] = map_information_dict["floor"] information["address"] = map_information_dict["address"] information["timestamp"] = now result["information"] = map_information_dict return result # def upload_map_position(self, user_id, map_information, apply_id, base_url, timestamp=0): # # 上传地图坐标,只保存最新的坐标 # information = dict() # if map_information: # longitude = float(map_information.get("longitude", 0)) # latitude = float(map_information.get("latitude", 0)) # geohash_code = OHHOGeohash.get(latitude, longitude, 6) # map_information["geohash_code"] = geohash_code # # instance = self.map.get_by_user(user_id) # if instance: # self.map.update(instance, map_information) # else: # map_information["user_id"] = user_id # self.map.add(map_information) # # # self_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, user_id) # friend_user_id = self.meet.get_another_user_id(apply_id, user_id) # friend_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, friend_user_id) # # if friend_state == PUSH_STATE_TYPE_MEETING: # result = self.push_information(map_information, friend_user_id, user_id, self_state, apply_id, # base_url) # OHHOLog.print_log(result) # information = self.return_map_information(friend_user_id, timestamp) # if information.get("information", ""): # information["information"]["apply_id"] = int(apply_id) # # result = Result.result_success() # result["data"] = information # return result def upload_map_position(self, user_id, map_information, apply_id, base_url, timestamp=0): # 上传地图坐标,只保存最新的坐标 information = dict() user = self.user.get_by_id(user_id) longitude = float(map_information.get("longitude", 0)) latitude = float(map_information.get("latitude", 0)) if user: if map_information: geohash_code = OHHOGeohash.get(latitude, longitude, 6) map_information["geohash_code"] = geohash_code map_information["timestamp"] = OHHODatetime.get_current_timestamp() map_information["user_id"] = user_id self.user.set_user_map_information(user.username, map_information) self.user.add_user_geo_position(longitude, latitude, user.username) self.map.add(map_information) self_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, user_id) friend_user_id = self.meet.get_another_user_id(apply_id, user_id) friend_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, friend_user_id) self_state, apply_id = self.meet.get_user_state_by_apply_and_user(apply_id, user_id) if friend_state == PUSH_STATE_TYPE_END_MEET or self_state == PUSH_STATE_TYPE_END_MEET: information["information"] = {"apply_id": int(apply_id)} else: information = self.return_map_information(friend_user_id) if information.get("information", ""): information["information"]["apply_id"] = int(apply_id) map_instance = Map() information["information"]["orientation"] = map_instance.main(user_id, friend_user_id) information["information"]["nearest_poi_name"] = AMAP.get_nearest_poi_name_interface(longitude, latitude) else: information["information"] = {"apply_id": int(apply_id)} result = Result.result_success() apply_id = int(apply_id) temp = self.meet.get_countdown(apply_id) result = OHHOOperation.dict_add_dict(result, temp) result["data"] = information return result