def build_schedule_weekly(self): try: DAYS_IN_A_WEEK = 7 session = Session() masterdao = MasterDAO() max_date = masterdao.get_master_schedule_max_date() master_ids = masterdao.get_all_master_ids() for mid in master_ids: free_times_by_date = masterdao.get_available_time_by_date(mid) for i in xrange(DAYS_IN_A_WEEK): date = max_date + dt.timedelta(days=i + 1) free_times = free_times_by_date[date.weekday( )] if date.weekday() in free_times_by_date else None if free_times != None: free_from = free_times[0] free_to = free_times[1] schedule_by_date = MasterScheduleByDate( master_id=mid, date=date, free_from=free_from, free_to=free_to) session.add(schedule_by_date) session.commit() print 'build schedule weekly successfully performed its task in', dt.datetime.now( ) except Exception, e: session.rollback() print_err_detail(e)
def initial_build_schedule(self): try: # 모든 홈마스터에 대해, 오늘 이후 20주 데이터 빌드 (140 days) NUM_DAYS = 140 session = Session() masterdao = MasterDAO() master_ids = masterdao.get_all_master_ids() for mid in master_ids: today = dt.datetime.now() free_times_by_date = masterdao.get_available_time_by_date(mid) for i in xrange(NUM_DAYS): date = today + dt.timedelta(days=(i + 1)) free_times = free_times_by_date[date.weekday( )] if date.weekday() in free_times_by_date else None if free_times != None: free_from = free_times[0] free_to = free_times[1] schedule_by_date = MasterScheduleByDate( master_id=mid, date=date.date(), free_from=free_from, free_to=free_to) session.add(schedule_by_date) session.commit() except Exception, e: session.rollback() print_err_detail(e)
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') date = self.get_argument('date', '') sigungu = self.get_argument('sigungu', '') customer_sigungu = self.get_argument('customer_sigungu', '') if date == None or date == '': date = dt.datetime.now() date = dt.datetime.strptime(date, '%Y%m%d') ret = {} try: session = Session() userdao = UserDAO() masterdao = MasterDAO() if sigungu == '': master_ids = masterdao.get_all_master_ids() else: master_ids = masterdao.get_master_ids_where_regions_available( sigungu) master_times = [] day_of_week = date.weekday() for mid in master_ids: master_schedules = [] '''start_times, end_times = masterdao.get_master_working_time(mid) start_times = start_times.split(',') end_times = end_times.split(',') st = start_times[day_of_week] if start_times[day_of_week] != '' else 8 et = end_times[day_of_week] if end_times[day_of_week] != '' else 8 st = int(st) et = int(et)''' st, et = masterdao.get_master_working_time_for_day( mid, date.date()) current_cleaning_counts = masterdao.get_master_completed_cleaning_count_at_date( mid, date) is_unassigned = masterdao.is_unassigned(mid) master_dict = {} master_dict['master_name'] = masterdao.get_master_name(mid) master_dict['master_id'] = mid master_dict['is_unassigned'] = is_unassigned master_dict[ 'is_beginner'] = True if current_cleaning_counts <= 10 else False master_dict[ 'current_cleaning_counts'] = current_cleaning_counts master_dict[ 'master_available_from'] = '0%s:00' % st if st < 10 else '%s:00' % st master_dict[ 'master_available_to'] = '0%s:00' % et if et < 10 else '%s:00' % et # for day off master_dict['is_day_off'] = masterdao.is_day_off( mid, date.date()) for row in session.query(Master, Booking, User, UserAddress, UserDefaultCard, Promotion, EventPromotionBooking) \ .outerjoin(Booking, Master.id == Booking.master_id) \ .join(User, User.id == Booking.user_id) \ .join(UserAddress, and_(Booking.user_id == UserAddress.user_id, Booking.addr_idx == UserAddress.user_addr_index)) \ .outerjoin(UserDefaultCard, User.id == UserDefaultCard.user_id) \ .outerjoin(Promotion, Booking.id == Promotion.booking_id) \ .outerjoin(EventPromotionBooking, Booking.id == EventPromotionBooking.booking_id) \ .filter(func.DATE(Booking.start_time) == date) \ .filter(Master.id == mid) \ .filter(or_(Booking.cleaning_status == BC.BOOKING_UPCOMMING, Booking.cleaning_status == BC.BOOKING_STARTED, Booking.cleaning_status == BC.BOOKING_COMPLETED)) \ .order_by(Master.name, Booking.start_time) \ .all(): key = userdao.get_user_salt_by_id(row.User.id)[:16] crypto = aes.MyCrypto(key) discount_price = 0 if row.Promotion != None: discount_price += row.Promotion.discount_price if row.EventPromotionBooking != None: discount_price += row.EventPromotionBooking.discount_price kind = row.UserAddress.kind if kind == 0: kind = '오피스텔' elif kind == 1: kind = '주택' else: kind = '아파트' address = crypto.decodeAES(row.UserAddress.address) if customer_sigungu in address: master_schedules.append( self.make_schedule_dict( row.Booking.id, row.User.devicetype, row.Booking.appointment_type, row.Booking.appointment_index, dt.datetime.strftime(row.Booking.start_time, '%H:%M'), dt.datetime.strftime( row.Booking.estimated_end_time, '%H:%M'), row.Booking.havereview, row.Booking.user_id, crypto.decodeAES(row.User.name), crypto.decodeAES(row.User.phone), crypto.decodeAES(row.UserAddress.address), row.UserAddress.size, kind, row.Booking.is_dirty, row.Booking.status, row.Booking.cleaning_status, row.Booking.payment_status, row.Booking.price_with_task, discount_price, row.Booking.routing_method, row.User.is_b2b, row.UserDefaultCard)) master_dict['time_list'] = master_schedules master_times.append(master_dict) ret['response'] = master_times self.set_status(Response.RESULT_OK) except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} try: session = Session() masterdao = MasterDAO() masters = [] master_ids = masterdao.get_all_master_ids() for mid in master_ids: master_info = {} basic = masterdao.get_master_basic_info(mid) rating_clean, rating_master = masterdao.get_master_rating(mid) total_salary = masterdao.get_master_total_granted_salary(mid) last_month_salary = masterdao.get_master_last_month_granted_salary( mid) prefered_area = masterdao.get_master_prefered_area(mid) start_times, end_times = masterdao.get_master_working_time(mid) working_startdate = masterdao.get_master_working_start_date( mid) completed_cleaning_count = masterdao.get_master_completed_cleaning_count( mid) bank_name, bank_code, account_no = masterdao.get_master_account( mid) master_info['master_id'] = mid master_info['name'] = basic['name'] master_info['phone'] = basic['phone'] master_info['img'] = basic['img'] master_info['age'] = basic['age'] master_info['gender'] = basic['gender'] master_info['address'] = basic['address'] master_info['pet_alergy'] = basic['pet_alergy'] master_info['manager_name'] = basic['manager_name'] master_info['manager_phone'] = basic['manager_phone'] master_info['cardinal'] = basic['cardinal'] master_info['level'] = basic['level'] master_info['need_route'] = basic['need_route'] master_info['t_size'] = basic['t_size'] master_info['rating_clean'] = float(rating_clean) master_info['rating_master'] = float(rating_master) master_info['total_salary'] = int(total_salary) master_info['last_month_salary'] = int(last_month_salary) master_info['prefered_area'] = prefered_area master_info['prefered_area_list'] = [ area for area in prefered_area.split(',') ] master_info['start_times'] = start_times master_info['end_times'] = end_times master_info['active'] = basic['active'] master_info['working_startdate'] = working_startdate master_info['cleaning_count'] = completed_cleaning_count master_info['account'] = { 'name': bank_name, 'code': bank_code, 'account_no': account_no } masters.append(master_info) ret['response'] = masters self.set_status(Response.RESULT_OK) except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])