def dateSchedule(request): if request.method == "GET": if request.GET.get("what") == "range": academy = Academy.objects.all() return render_to_response('passenger/rangeSchedule.html',{"academy" : academy,'user':request.user}) elif request.GET.get("what") == "single": academy = Academy.objects.all() return render_to_response('passenger/dateSchedule.html', {"academy" : academy,'user':request.user}) elif request.GET.get("what") == "car": group = Group.objects.all() return render_to_response('passenger/carRangeSchedule.html', {"group" : group,'user':request.user}) elif request.method == "POST": what = request.POST.get('what') aid = request.POST.get('aid') gid = request.POST.get('gid') date = request.POST.get('date') toDate = request.POST.get('to') fromDate = request.POST.get('from') if what == "single": a_name = Academy.objects.get(id = aid).name contacts = ScheduleDate.objects.filter(date=date).filter(a_name__contains = a_name).order_by('today','time') return render_to_response('passenger/viewDateSchedule.html', {"contacts": contacts, "count" : count,'user':request.user}) elif what == "range": t = timeToDate() toD = t.timeToDtype(toDate) fromD = t.timeToDtype(fromDate) a_name = Academy.objects.get(id = aid).name contacts2 = [] a_name.strip() contacts = ScheduleDate.objects.filter(today__range=[fromD,toD]).filter(a_name__contains = a_name).order_by('today','time') for contact in contacts: anames = contact.a_name.strip().split('&') if (a_name in anames): contacts2.append(contact) count = len(contacts2) return render_to_response('passenger/viewDateSchedule.html', {"contacts": contacts2, "count" : count,'user':request.user}) elif what == 'car': t = timeToDate() toD = t.timeToDtype(toDate) fromD = t.timeToDtype(fromDate) contacts = ScheduleDate.objects.filter(today__range=[fromD,toD]).filter(gid=gid).order_by('today','time') count = len(contacts) return render_to_response('passenger/viewDateSchedule.html', {"contacts": contacts, "count" : count,'user':request.user})
def find_update(): t = timeToDate() d = t.timeToD() studentset = set() scheduletables = list() lastweek = '' lastweekt = timeToDate() lastweekt.setLastWeekDay() lastweek = lastweekt.timeToYmd() inventory_ids = list() inventories = Inventory.objects.filter(day=d).select_related() for inventory in inventories: inventory_ids.append(inventory.id) scheduletables = ScheduleTable.objects.filter(iid_id = inventory.id).order_by('time') for scheduletable in scheduletables: if (scheduletable.slist != None or len(scheduletable.slist) != 0): for sid in scheduletable.slist: studentset.add(str(sid)) #print "lastweek = " + lastweek print "len = " + str(len(studentset)) #print "inv_len = " + str(len(inventory_ids)) for sid in studentset: #for inventory in inventories: try : studentinfo = StudentInfo.objects.get(id=sid) except StudentInfo.DoesNotExist: continue scheduletables = ScheduleTable.objects.filter(iid_id__in = inventory_ids).filter(slist__contains = [sid]).order_by('time') old_scheduletables = HistoryScheduleTable.objects.filter(date = lastweek).filter(iid_id__in = inventory_ids).filter(members__in = [studentinfo]).order_by('time') msg = "" for scheduletable in scheduletables: found = False same_inventory = False for old_scheduletable in old_scheduletables: if (scheduletable.iid_id == old_scheduletable.iid_id) : same_inventory = True if (scheduletable.time == old_scheduletable.time and scheduletable.addr == old_scheduletable.addr): found = True print "found True : " + str(sid) if found == False : inventory = Inventory.objects.get(id = scheduletable.iid_id) if same_inventory == False : msg += "\t\t신규 {" + inventory.day + "} [" + scheduletable.time + "] : " + scheduletable.addr + "\n" #msg += u"\t\t신규 {" + inventory.day + "} [" + scheduletable.time + "] : " + scheduletable.addr + ":" + str(scheduletable.iid_id) + "\n" else : msg += u"\t\t변경 {" + inventory.day + "} [" + scheduletable.time + "] : " + scheduletable.addr + "\n" if (msg != ""): notice_to_student(sid, msg) notice_to_student(0, "end")
def store_historyschedule(): t = timeToDate() dmy = t.timeToDmy() ymd = t.timeToYmd() d = t.timeToD() if (ymd == '2017-10-02'): d = '10/2' inventories = Inventory.objects.filter(day=d).select_related() #print "# of inventory = " + str(len(inventories)) for inventory in inventories: scheduletables = ScheduleTable.objects.filter(iid_id = inventory.id) #print "# of scheduletables = " + str(len(scheduletables)) for scheduletable in scheduletables: hst = HistoryScheduleTable(date=ymd, iid_id=scheduletable.iid_id, carnum=inventory.carnum, time=scheduletable.time, addr=scheduletable.addr, alist=scheduletable.alist, tflag=scheduletable.tflag, lflag=scheduletable.lflag, req=scheduletable.req) hst.save() try : for sid in scheduletable.slist: student = StudentInfo.objects.get(id=sid) hst.members.add(student) for aid in scheduletable.alist: academy = Academy.objects.get(id=aid) hst.academies.add(academy) offmembers = get_offmember_list(scheduletable.tflag, scheduletable.slist) for offmember in offmembers: student = StudentInfo.objects.get(id=offmember) hst.offmembers.add(student) except Exception as e: print(e)
def store_historyschedule_old(): t = timeToDate() dmy = t.timeToDmy() d = t.timeToD() sschedule = ShuttleSchedule.objects.filter(day=d) for s in sschedule: ds = ScheduleDate(a_name = s.a_name, day = s.day, time = s.time,schedule = s.schedule, gid = s.gid, aid = s.aid,slist = s.slist,p_schedule = s.p_schedule, alist = s.alist, memo = s.memo, date = dmy) ds.save()
def inventories(request): t = timeToDate() today = t.timeToD() green_numofstudent = 2 orange_numofstudent = 5 if request.GET.get('green_numofstudent'): green_numofstudent = int(request.GET.get('green_numofstudent')) if request.GET.get('orange_numofstudent'): orange_numofstudent = int(request.GET.get('orange_numofstudent')) if request.GET.get('aid') : aid = int(request.GET.get('aid')) else : aid = 0 if (request.GET.get('bid')) : bid = int(request.GET.get('bid')) else : bid = 1 if (request.GET.get('day')) : day = request.GET.get('day') else : day = today crowdedbuses = [] shuttles = {} inventories = Inventory.objects.filter(day = day, bid = bid) for inventory in inventories: crowdedbus = CrowdedBus() crowdedbus.carnum = inventory.carnum (crowdedbus.stime_hr, crowdedbus.stime_min) = makeTimeStr(inventory.stime) (crowdedbus.etime_hr, crowdedbus.etime_min) = makeTimeStr(inventory.etime) crowdedbus.numofstudent = len(inventory.slist) crowdedbus.alist = inventory.alist crowdedbuses.append(crowdedbus) shuttles[inventory.carnum] = 1 academies = Academy.objects.filter(bid = bid).order_by('name') try: aname = academies.get(id = aid).name except Academy.DoesNotExist: aname = "" aid = 0 return render(request, 'crowdedbus.html', {'crowdedbuses': crowdedbuses, 'shuttles': shuttles.keys(), 'green_numofstudent': green_numofstudent, 'orange_numofstudent': orange_numofstudent, 'range': range(10), 'dayrange': ['월', '화', '수', '목', '금', '토'], 'academies': academies, 'aid': aid, 'aname': aname, 'bid': bid, 'day': day})
def realtimeLocationHistory(request): realtimeLocationHistories = list() #cars = Car.objects.all().order_by('carname') area_id = request.GET.get('area_id') if (area_id == None): area_id = "1" areas = Area.objects.all().order_by('name') cars = Car.objects.filter(branchid__areaid_id = int(area_id)).order_by('carname') cursor = connection.cursor() cur_date = request.GET.get('cur_date') if (cur_date == None): t = timeToDate() t.setDiffTime(-24*60*60) cur_date = t.timeToYmd() for car in cars: cursor.execute("select addr, lflag, time, departure_time from schedule_historyscheduletable history LEFT OUTER JOIN (SELECT carnum, schedule_time, MIN(departure_time) AS departure_time FROM schedule_realtimelocation WHERE date = '%s' and carnum = %s group by carnum, schedule_time) realtimelocation ON( realtimelocation.schedule_time = history.time) WHERE history.date = '%s' and history.carnum = %s" % (cur_date, car.carname, cur_date, car.carname)); realtimeLocationHistory = RealtimeLocationHistory() realtimeLocationHistory.carnum = car.carname realtimeLocationHistory.historyscheduletables = list() for row in cursor.fetchall(): h = HistoryScheduleTableWithRealtimeLocation() h.schedule_time = row[2] if (row[1] == 2): h.addr = '출발' elif (row[1] == 3): h.addr = '도착' else: h.addr = row[0] if (row[3] == None): h.color = 'red' elif (get_difference(row[3], row[2]) >= 3): h.color = 'orange' else: h.color = 'green' realtimeLocationHistory.historyscheduletables.append(h) realtimeLocationHistories.append(realtimeLocationHistory) #return render(request, 'realtimeLocationHistory.html', {'histories': realtimeLocationHistories, 'cur_date': cur_date.replace("-", "/")}) return render(request, 'realtimeLocationHistory.html', {'histories': realtimeLocationHistories, 'cur_date': cur_date, 'areas': areas, 'area_id': int(area_id)})
def notice(request): if request.method == "GET": com = Community.objects.all() return render(request, 'pushchecker.html', {'com': com} ); elif request.method == "POST": choice = request.POST.get('choice') cid = request.POST.get('cid') response_data = {} if choice: try: com = Community.objects.get(id=cid) com.clike = com.clike+1 response_data['num'] = com.clike com.save() return HttpResponse(json.dumps(response_data), content_type="application/json") except Exception as e: return HttpResponse(e.message) else: response_data = {} aname = request.POST.get('aname') complain = request.POST.get('complain') plan = request.POST.get('plan') t = timeToDate() toDate = t.timeToYmd() c = Community(aname=aname, complain=complain, plan=plan,showdate = toDate,clike=0,dlike=0,disuser=[],disuserid=[],likeuserid=[],likeuser=[]) c.save() com = Community.objects.all() return render(request, 'pushchecker.html', {'com': com} );
def experienceGetRouteMap(request): t = timeToDate() current_time = t.timeToHM() msg = {} msg['routemap'] = list() data = {} data['addr'] = '출발' data['sequence'] = 1 data['time'] = minusHM(current_time, 15) msg['routemap'].append(data) data = {} data['addr'] = '강동자이 프라자아파트 정문' data['sequence'] = 2 data['time'] = minusHM(current_time, 10) msg['routemap'].append(data) data = {} data['addr'] = '현대아파트 (현대중앙상가 앞)' data['sequence'] = 3 data['time'] = minusHM(current_time, 7) msg['routemap'].append(data) data = {} data['addr'] = '위례초 정문' data['sequence'] = 4 data['time'] = current_time msg['routemap'].append(data) data = {} data['addr'] = '도착' data['sequence'] = 5 data['time'] = plusHM(current_time, 15) msg['routemap'].append(data) return JsonResponse(msg)
def shuttles(request): # filter inventories t = timeToDate() today = t.timeToYmd() hm = t.timeToHM() rawhm = t.timeToRawHM() d = t.timeToD() msg = "" inventories = Inventory.objects.filter(day = d, stime__lte = int(rawhm) + 30, etime__gte = int(rawhm) - 30) invens = list() for inventory in inventories: diff1 = -1 diff2 = -1 inven = {} inven['schedules'] = list() inven['shuttle'] = {} inven['id'] = inventory.id scheduletables = ScheduleTable.objects.filter(iid = inventory.id).order_by('time') inven['shuttle']['carnum'] = inventory.carnum lastlocation = RealtimeLocation.objects.filter(date=today, carnum=inventory.carnum, schedule_time__lte=str(inventory.etime)[:2]+':'+str(inventory.etime)[2:], schedule_time__gte=str(inventory.stime)[:2]+':'+str(inventory.stime)[2:]).order_by('schedule_time').last() if (lastlocation): diff1 = get_difference(lastlocation.departure_time, lastlocation.schedule_time) hoursMinutes = setTimeDelta(hm, diff1).split(':') inven['shuttle']['hour'] = hoursMinutes[0] inven['shuttle']['minute'] = hoursMinutes[1] for scheduletable in scheduletables: hoursMinutes = scheduletable.time.split(':') if (scheduletable.lflag == 2): addr = '출발' if (lastlocation and lastlocation.schedule_time >= scheduletable.time): pass # 아직 출발하지 않았으면 else: inven['shuttle']['hour'] = hoursMinutes[0] inven['shuttle']['minute'] = hoursMinutes[1] elif (scheduletable.lflag == 3): addr = '도착' # 도착했으면 if (lastlocation and lastlocation.schedule_time == scheduletable.time): inven['shuttle']['hour'] = hoursMinutes[0] inven['shuttle']['minute'] = hoursMinutes[1] else: addr = scheduletable.addr if (lastlocation and lastlocation.schedule_time < scheduletable.time and hm > scheduletable.time and diff2 < 0): diff2 = 1 hoursMinutes = setTimeDelta(scheduletable.time, -1).split(':') inven['shuttle']['hour'] = hoursMinutes[0] inven['shuttle']['minute'] = hoursMinutes[1] inven['schedules'].append({'hour': hoursMinutes[0], 'minute': hoursMinutes[1], 'addr': addr}) invens.append(inven) msg += "id : " + str(inventory.id) msg += "car : " + str(inventory.carnum) msg += "\n" inven_id = inventory.id return render(request, 'shuttles.html', {'msg': msg, 'invens': invens})
def today_schedule_notification(): time = timeToDate() date = time.timeToD() si = [] scheduleTables = [] schedules = [] slist_list = [] tflag_list = [] dict_s = {} inventorys = Inventory.objects.filter( day=date).prefetch_related('scheduletables').reverse() for inventory in inventorys: scheduletables = ScheduleTable.objects.filter(iid=inventory.id) for scheduletable in scheduletables: if len(scheduletable.slist) == len(scheduletable.tflag): schedules.extend(scheduletable.slist) slist_list.extend(scheduletable.slist) tflag_list.extend(scheduletable.tflag) for s in slist_list: try: t = slist_list.index(s) except: t = None else: if dict_s.has_key(s): dict_s[s] += int(tflag_list[t]) slist_list[t] = [] else: dict_s[s] = int(tflag_list[t]) slist_list[t] = [] for inventory in inventorys: scheduleTables.extend(inventory.scheduletables.all()) count_slist = [] for schTable in scheduleTables: if len(schTable.slist) >= 1: count_slist.extend(schTable.slist) dict_slist = dict(Counter(count_slist)) push_content = [] for key, value in dict_slist.iteritems(): for schTable in scheduleTables: if len(schTable.slist) >= 1: while (key in schTable.slist): try: sInfo = StudentInfo.objects.get(id=key) except StudentInfo.DoesNotExist: sInfo = None break else: try: pin = PersonalInfo.objects.get( id=sInfo.personinfo_id) module_push_content = {} module_push_content[ 'personinfoid'] = sInfo.personinfo_id module_push_content['sname'] = sInfo.sname module_push_content['time'] = schTable.time module_push_content['addr'] = schTable.addr module_push_content['lflag'] = schTable.lflag module_push_content['aname'] = sInfo.aid.name module_push_content['pin'] = pin.pin_number module_push_content['sid'] = key module_push_content['count'] = value module_push_content['sid'] = sInfo.id push_content.append(module_push_content) break except PersonalInfo.DoesNotExist: break print module_push_content['personinfoid'] if module_push_content['personinfoid'] != 'None': count = module_push_content['count'] - 1 lflag = module_push_content['lflag'] sname = module_push_content['sname'] sid = module_push_content['sid'] if dict_s.has_key(sid): tflag_count = dict_s[sid] else: tflag_count = 0 if lflag == 0: flag = "하원을 위한" elif lflag == 1: flag = "등원을 위한" else: flag = "에 대한" if count == 0: msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "] 승차 스케줄이 있습니다" if tflag_count > 0: cancel_msg = "[승차취소]오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "] 승차 스케줄을 취소하셨습니다." print cancel_msg module_push_content['personinfoid'] = 'None' else: print msg module_push_content['personinfoid'] = 'None' else: msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "]승차 외" + str(count) + "건의 스케줄이 있습니다." if tflag_count > 0: cancel_msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "]승차 외" + str( tflag_count) + "건의 취소된 스케줄이 있습니다." print cancel_msg module_push_content['personinfoid'] = 'None' else: print msg module_push_content['personinfoid'] = 'None'
def experienceGetSchedulesForStudent(request): t = timeToDate() d = t.timeToD() startdayOfWeek = t.timeToStartDayOfWeek() #current_time = str(timezone.now())[11:16] current_time = t.timeToHM() msg = {} msg['sid'] = '0000' msg['schedules'] = {} daydictionary = { u'월': 'mon', u'화': 'tue', u'수': 'wed', u'목': 'thu', u'금': 'fri', u'토': 'sat', u'일': 'sun' } daylist = [u'월', u'화', u'수', u'목', u'금', u'토', u'일'] for day in daylist: msg['schedules'][daydictionary[day]] = {} msg['schedules'][daydictionary[day]]['list'] = list() msg['schedules'][daydictionary[day]]['date'] = ( startdayOfWeek + timedelta(days=daylist.index(day))).strftime("%Y.%m.%d") if d == day: msg['schedules'][daydictionary[day]]['today'] = True else: msg['schedules'][daydictionary[day]]['today'] = False # monday data = {} data['time'] = '15:38' data['addr'] = '풍덕천동 대우푸르지오 정거장' data['carnum'] = 32 data['inventory_id'] = 0 data['start_time'] = '15:25' data['end_time'] = '15:55' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules']['mon']['list'].append(data) data = {} data['time'] = '17:45' data['addr'] = '풍덕천동 대우푸르지오 정거장' data['carnum'] = 32 data['inventory_id'] = 0 data['start_time'] = '17:35' data['end_time'] = '18:00' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules']['mon']['list'].append(data) # tuesday data = {} data['time'] = '16:17' data['addr'] = '소만 1단지 버스정류장' data['carnum'] = 29 data['inventory_id'] = 0 data['start_time'] = '16:00' data['end_time'] = '16:26' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules']['tue']['list'].append(data) data = {} data['time'] = '19:18' data['addr'] = '소만 1단지 버스정류장' data['carnum'] = 29 data['inventory_id'] = 0 data['start_time'] = '19:00' data['end_time'] = '19:26' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules']['tue']['list'].append(data) # wednesday data = {} data['time'] = '14:00' data['addr'] = '서당초등학교 후문 앞' data['carnum'] = 20 data['inventory_id'] = 0 data['start_time'] = '15:40' data['end_time'] = '14:07' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules']['wed']['list'].append(data) data = {} data['time'] = '16:10' data['addr'] = '현대아파트 113동 앞' data['carnum'] = 20 data['inventory_id'] = 0 data['start_time'] = '16:05' data['end_time'] = '16:25' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules']['wed']['list'].append(data) # thursday data = {} data['time'] = '14:40' data['addr'] = '위례별초 맞은편' data['carnum'] = 13 data['inventory_id'] = 0 data['start_time'] = '14:35' data['end_time'] = '15:05' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules']['thu']['list'].append(data) data = {} data['time'] = '16:20' data['addr'] = '센트럴푸르지오 정문 새싹정류장' data['carnum'] = 32 data['inventory_id'] = 0 data['start_time'] = '16:05' data['end_time'] = '16:25' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules']['thu']['list'].append(data) # friday data = {} data['time'] = '15:40' data['addr'] = '한빛초 병설유치원' data['carnum'] = 4 data['inventory_id'] = 0 data['start_time'] = '15:25' data['end_time'] = '15:55' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules']['fri']['list'].append(data) data = {} data['time'] = '16:59' data['addr'] = '엠코센트로엘 정문' data['carnum'] = 4 data['inventory_id'] = 0 data['start_time'] = '16:55' data['end_time'] = '17:11' data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules']['fri']['list'].append(data) # today msg['schedules'][daydictionary[unicode(d)]]['list'] = list() data = {} data['time'] = current_time data['addr'] = '위례초 정문' data['carnum'] = 4 data['inventory_id'] = 0 data['start_time'] = minusHM(current_time, 15) data['end_time'] = plusHM(current_time, 15) data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '등원' msg['schedules'][daydictionary[unicode(d)]]['list'].append(data) data = {} data['time'] = plusHM(current_time, 120) data['addr'] = '롯데캐슬 정문' data['carnum'] = 4 data['inventory_id'] = 0 data['start_time'] = plusHM(current_time, 105) data['end_time'] = plusHM(current_time, 135) data['institute_name'] = 'ABCD학원' data['scheduletable_id'] = 0 data['driver_telephone'] = '000-0000-0000' data['lflag'] = '하원' msg['schedules'][daydictionary[unicode(d)]]['list'].append(data) return JsonResponse(msg)
def today_schedule_notification(): msg_count= 0 time = timeToDate() date = time.timeToD() si = [] scheduleTables = [] schedules = [] slist_list = [] tflag_list = [] dict_s ={} inventorys = Inventory.objects.filter(day = date).prefetch_related('scheduletables').reverse() for inventory in inventorys: scheduletables = ScheduleTable.objects.filter(iid = inventory.id) for scheduletable in scheduletables: if len(scheduletable.slist) == len(scheduletable.tflag): schedules.extend(scheduletable.slist) slist_list.extend(scheduletable.slist) tflag_list.extend(scheduletable.tflag) for s in slist_list: try: t = slist_list.index(s) except: t = None else: if dict_s.has_key(s): dict_s[s] += int(tflag_list[t]) slist_list[t] = [] else: dict_s[s] = int(tflag_list[t]) slist_list[t] = [] for inventory in inventorys: scheduleTables.extend(inventory.scheduletables.all()) count_slist = [] for schTable in scheduleTables: if len(schTable.slist) >= 1: count_slist.extend(schTable.slist) dict_slist = dict(Counter(count_slist)) push_content = [] for key, value in dict_slist.iteritems(): for schTable in scheduleTables: if len(schTable.slist) >= 1: while(key in schTable.slist): try: sInfo = StudentInfo.objects.get(id=key) except StudentInfo.DoesNotExist: sInfo = None break else: try: pin = PersonalInfo.objects.get(id = sInfo.personinfo_id) module_push_content = {} module_push_content['sname'] = sInfo.sname module_push_content['time'] = schTable.time module_push_content['addr'] = schTable.addr module_push_content['lflag'] = schTable.lflag module_push_content['aname'] = sInfo.aid.name module_push_content['pin'] = pin.pin_number module_push_content['sid'] = key module_push_content['count'] = value module_push_content['sid'] = sInfo.id push_content.append(module_push_content) break except PersonalInfo.DoesNotExist: break pin_prop = PropOfDevice.objects.filter(pin_number = module_push_content['pin']) for p in pin_prop: msg_count+= 1 if p.receivePush == False: print p.pin_number
def getRealtimeLocation(request): if request.method == "GET": max_diff = 10 t = timeToDate() d = t.timeToD() today = t.timeToYmd() rawhm = int(t.timeToRawHM()) hm = t.timeToHM() sid = request.GET.get('sid') inventory_id = request.GET.get('inventory_id') carnum = -1 iid = "" siid = "" sname = "" msg = "" debug = request.GET.get('debug') if (debug): debug = 1 else: debug = 0 if (sid and len(sid) > 0): try: student = StudentInfo.objects.get(id=sid) sname = student.sname except StudentInfo.DoesNotExist: msg = "해당 사용자가 존재하지 않습니다." return getResponse(debug, 401, msg) else: msg = "파라미터가 유효하지 않습니다." return getResponse(debug, 400, msg) if (debug == 1): rawhm = int(request.GET.get('rawhm')) hm = request.GET.get('hm') today = request.GET.get('today') d = request.GET.get('d') #today_inventories = Inventory.objects.filter(day=d) #today_inventory_ids = today_inventories.values('id') if (inventory_id == None): msg = "파라미터가 유효하지 않습니다." return getResponse(debug, 400, msg) try: inventory = Inventory.objects.get(id=int(inventory_id)) except Inventory.DoesNotExist: msg = "파라미터가 유효하지 않습니다." return getResponse(debug, 400, msg) if (inventory.day != d): msg = str(inventory.carnum) + "호차가 아직 출발 전입니다." return getResponse(debug, 202, msg) scheduletables = ScheduleTable.objects.filter( iid_id=int(inventory_id)).filter( slist__contains=[sid]).order_by('-time') if (len(scheduletables) <= 0): msg = sname + "님은 오늘 스케쥴이 없습니다." return getResponse(debug, 204, msg) ## 마지막 스케쥴도 지났으면 (desc order 인 것 주의) inventory = Inventory.objects.get(id=scheduletables.first().iid_id) if (inventory.etime < rawhm): carnum = inventory.carnum msg = str(carnum) + "호차 셔틀버스의 운행 스케쥴이 종료되었습니다. " return getResponse(debug, 203, msg) for scheduletable in scheduletables: inventory = Inventory.objects.get(id=scheduletable.iid_id) format_etime = format_hm(str(inventory.etime)) if (inventory.etime > rawhm): ## inventory 중간에 있으면.. if (inventory.stime <= rawhm): carnum = inventory.carnum expected_time = scheduletable.time realtimelocations = RealtimeLocation.objects.filter( date=today, carnum=carnum, departure_time__lte=format_etime) if (realtimelocations): realtimelocation = realtimelocations.order_by( 'schedule_time').last() diff = get_difference(realtimelocation.schedule_time, realtimelocation.departure_time) if (diff >= max_diff): diff = max_diff waittime = get_difference(hm, expected_time) + diff - 1 else: waittime = get_difference(hm, expected_time) if (waittime < 0): msg = str(carnum) + "호차가 출발했습니다." return getResponse(debug, 201, msg) msg = str(carnum) + "호차가 " + str(waittime) + "분 후 도착합니다." return getResponse(debug, 200, msg, waittime) ## 다음 inventory 로.. else: continue ## inventory 사이에.. else: carnum = inventory.carnum if (rawhm - inventory.etime < 10): msg = str(carnum) + "호차 셔틀버스의 운행 스케쥴이 종료되었습니다." return getResponse(debug, 203, msg) else: msg = str(carnum) + "호차가 아직 출발 전입니다." return getResponse(debug, 202, msg) carnum = inventory.carnum msg = str(carnum) + "호차가 아직 출발 전입니다." return getResponse(debug, 202, msg)
def getSchedulesForStudent(request): if request.method == "GET": max_diff = 10 t = timeToDate() d = t.timeToD() today = t.timeToYmd() rawhm = t.timeToRawHM() hm = t.timeToHM() startdayOfWeek = t.timeToStartDayOfWeek() sid = request.GET.get('sid') carnum = -1 iid = "" siid = "" sname = "" msg = "" debug = request.GET.get('debug') if (debug): debug = 1 else: debug = 0 if (sid and len(sid) > 0): try: student = StudentInfo.objects.get(id=sid) sname = student.sname except StudentInfo.DoesNotExist: msg = "해당 사용자가 존재하지 않습니다." return getResponse(debug, 401, msg) else: msg = "파라미터가 유효하지 않습니다." return getResponse(debug, 400, msg) scheduletables = ScheduleTable.objects.filter( slist__contains=[sid]).select_related() msg = {} msg['sid'] = sid msg['schedules'] = {} daydictionary = { u'월': 'mon', u'화': 'tue', u'수': 'wed', u'목': 'thu', u'금': 'fri', u'토': 'sat', u'일': 'sun' } daylist = [u'월', u'화', u'수', u'목', u'금', u'토', u'일'] for day in daylist: msg['schedules'][daydictionary[day]] = {} msg['schedules'][daydictionary[day]]['list'] = list() msg['schedules'][daydictionary[day]]['date'] = ( startdayOfWeek + timedelta(days=daylist.index(day))).strftime("%Y.%m.%d") if d == day: msg['schedules'][daydictionary[day]]['today'] = True else: msg['schedules'][daydictionary[day]]['today'] = False for scheduletable in scheduletables: data = {} data['time'] = scheduletable.time data['addr'] = scheduletable.addr data['carnum'] = scheduletable.iid.carnum data['inventory_id'] = scheduletable.iid_id data['start_time'] = makeTimeStr(scheduletable.iid.stime) data['end_time'] = makeTimeStr(scheduletable.iid.etime) data['institute_name'] = Academy.objects.get( id=student.aid_id).name data['scheduletable_id'] = scheduletable.id try: car = Car.objects.get(carname=scheduletable.iid.carnum) if car.passenger and len(str(car.passenger)) > 9: data['driver_telephone'] = '0' + str(car.passenger) else: data['driver_telephone'] = "0" + str(car.driver) except Car.DoesNotExist: data['driver_telephone'] = '' if scheduletable.lflag == 1: data['lflag'] = '등원' elif scheduletable.lflag == 0: data['lflag'] = '하원' #if scheduletable.iid.day in msg['schedules'].keys(): #pass #else: #msg['schedules'][daydictionary[scheduletable.iid.day]] = {} #msg['schedules'][daydictionary[scheduletable.iid.day]]['list'] = list() #msg['schedules'][daydictionary[scheduletable.iid.day]]['date'] = (startdayOfWeek + timedelta(days=daylist.index(scheduletable.iid.day))).strftime("%Y.%m.%d") #if d == scheduletable.iid.day : #msg['schedules'][daydictionary[scheduletable.iid.day]]['today'] = True #else: #msg['schedules'][daydictionary[scheduletable.iid.day]]['today'] = False if (scheduletable.iid.day in daydictionary.keys()): msg['schedules'][daydictionary[ scheduletable.iid.day]]['list'].append(data) return JsonResponse(msg)
def today_schedule_notification(): fcmdevice = FCMDevice.objects.all() device_count = 0 day = datetime.datetime.now() # today = day.strftime('%Y-%m-%d') today = '2017-10-27' msg_count = 0 push_num = 0 push_false_num = 0 total_msg = 0 refuse_user = 0 time = timeToDate() date = time.timeToD() si = [] scheduleTables = [] schedules = [] slist_list = [] tflag_list = [] dict_s = {} inventorys = Inventory.objects.filter( day=date).prefetch_related('scheduletables').reverse() for inventory in inventorys: scheduletables = ScheduleTable.objects.filter(iid=inventory.id) for scheduletable in scheduletables: if len(scheduletable.slist) == len(scheduletable.tflag): schedules.extend(scheduletable.slist) slist_list.extend(scheduletable.slist) tflag_list.extend(scheduletable.tflag) for s in slist_list: try: t = slist_list.index(s) except: t = None else: if dict_s.has_key(s): dict_s[s] += int(tflag_list[t]) slist_list[t] = [] else: dict_s[s] = int(tflag_list[t]) slist_list[t] = [] for inventory in inventorys: scheduleTables.extend(inventory.scheduletables.all()) count_slist = [] for schTable in scheduleTables: if len(schTable.slist) >= 1: count_slist.extend(schTable.slist) dict_slist = dict(Counter(count_slist)) push_content = [] for key, value in dict_slist.iteritems(): for schTable in scheduleTables: if len(schTable.slist) >= 1: while (key in schTable.slist): try: sInfo = StudentInfo.objects.get(id=key) except StudentInfo.DoesNotExist: sInfo = None break else: try: pin = PersonalInfo.objects.get( id=sInfo.personinfo_id) module_push_content = {} module_push_content['sname'] = sInfo.sname module_push_content['time'] = schTable.time module_push_content['addr'] = schTable.addr module_push_content['lflag'] = schTable.lflag module_push_content['aname'] = sInfo.aid.name module_push_content['pin'] = pin.pin_number module_push_content['sid'] = key module_push_content['count'] = value module_push_content['sid'] = sInfo.id push_content.append(module_push_content) break except PersonalInfo.DoesNotExist: break total_msg += 1 pin_prop = PropOfDevice.objects.filter( pin_number=module_push_content['pin']) for p in pin_prop: msg_count += 1 if p.receivePush == False: refuse_user += 1 count = module_push_content['count'] - 1 lflag = module_push_content['lflag'] sname = module_push_content['sname'] sid = module_push_content['sid'] if dict_s.has_key(sid): tflag_count = dict_s[sid] else: tflag_count = 0 if lflag == 0: flag = "하원을 위한" elif lflag == 1: flag = "등원을 위한" else: flag = "에 대한" if count == 0: msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "] 승차 스케줄이 있습니다" if tflag_count > 0: cancel_msg = "[승차취소]오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "] 승차 스케줄을 취소하셨습니다." send_msg(module_push_content['sid'], module_push_content['pin'], cancel_msg) else: send_msg(module_push_content['sid'], module_push_content['pin'], msg) else: msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "]승차 외" + str(count) + "건의 스케줄이 있습니다." if tflag_count > 0: cancel_msg = "오늘 " + sname + " 학생의 " + module_push_content[ 'aname'] + " " + flag + " " + module_push_content[ 'time'] + " [" + module_push_content[ 'addr'] + "]승차 외" + str( tflag_count) + "건의 취소된 스케줄이 있습니다." send_msg(module_push_content['sid'], module_push_content['pin'], cancel_msg) else: send_msg(module_push_content['sid'], module_push_content['pin'], msg) for fcmdevices in fcmdevice: device_count += 1 pushconf = PushConfirming.objects.filter(date__icontains=today) for pushconfs in pushconf: push_num += 1 if pushconfs.status == False: push_false_num += 1 pm = PushMonitoring.objects.create(date=today, total_S=device_count, expec_push=total_msg, expec_push_s=msg_count, push_num=push_num, false_num=push_false_num, refuse_user=refuse_user) pm.save() print today print device_count print total_msg print msg_count print push_num print push_false_num print refuse_user
def run(): time = timeToDate() date = time.timeToD() scheduleTables = [] schedules = [] inventorys = Inventory.objects.filter(day = date).prefetch_related('scheduletables').reverse() for inventory in inventorys: scheduletables = ScheduleTable.objects.filter(iid = inventory.id) for scheduletable in scheduletables: schedules.extend(scheduletable.slist) for inventory in inventorys: scheduleTables.extend(inventory.scheduletables.all()) count_slist = [] for schTable in scheduleTables: if len(schTable.slist) >= 1: count_slist.extend(schTable.slist) dict_slist = dict(Counter(count_slist)) push_content = [] msg_count = 0 error_count = 0 for key, value in dict_slist.iteritems(): for schTable in scheduleTables: if len(schTable.slist) >= 1: while(key in schTable.slist): try: sInfo = StudentInfo.objects.get(id=key) except StudentInfo.DoesNotExist: sInfo = None break else: pin = PersonalInfo.objects.get(id = sInfo.personinfo_id) module_push_content = {} module_push_content['sname'] = sInfo.sname module_push_content['time'] = schTable.time module_push_content['addr'] = schTable.addr module_push_content['lflag'] = schTable.lflag module_push_content['aname'] = sInfo.aid.name module_push_content['pin'] = pin.pin_number module_push_content['sid'] = key module_push_content['count'] = value push_content.append(module_push_content) break count = module_push_content['count']-1 lflag = module_push_content['lflag'] sname = module_push_content['sname'] if lflag == 0: flag = "하원을 위한" elif lflag == 1: flag = "등원을 위한" else: flag = "에 대한" if count == 0: msg = "오늘 " + sname + " 학생의 " + module_push_content['aname'] + " " + flag + " " + module_push_content['time'] + " [" + module_push_content['addr'] + "] 승차 스케줄이 있습니다" send_msg(module_push_content['sid'], module_push_content['pin'], msg) else: msg = "오늘 " + sname + " 학생의 " + module_push_content['aname'] + " 등원을 위한 " + module_push_content['time'] + " [" + module_push_content['addr'] + "]승차 외" + str(count) + "건의 스케줄이 있습니다." send_msg(module_push_content['sid'], module_push_content['pin'], msg)
def community(request): if request.method == "GET": contacts = Community.objects.order_by('-id') return render_to_response('passenger/community.html',{"contacts":contacts,'user':request.user}) elif request.method == "POST": choice = request.POST.get('choice') uid = request.POST.get('uid') cid = request.POST.get('cid') response_data = {} if choice: try: contact = Community.objects.get(id=cid) for user in contact.disuserid: if str(user) == uid: response_data['error'] = 'true' return HttpResponse(json.dumps(response_data), content_type="application/json") for user in contact.likeuserid: if str(user) == uid: response_data['error'] = 'true' return HttpResponse(json.dumps(response_data), content_type="application/json") if(choice == '0'): contact.dlike = contact.dlike+1 contact.disuser.append(request.user) contact.disuserid.append(uid) response_data['like'] = '0' response_data['num'] = contact.dlike elif(choice == '1'): contact.clike = contact.clike+1 contact.likeuser.append(request.user) contact.likeuserid.append(uid) response_data['like'] = '1' response_data['num'] = contact.clike response_data['error'] = 'false' contact.save() return HttpResponse(json.dumps(response_data), content_type="application/json") except Exception as e: return HttpResponse(e.message) else: aname = request.POST.get('aname') complain = request.POST.get('complain') plan = request.POST.get('plan') t = timeToDate() toDate = t.timeToYmd() c = Community(aname=aname, complain=complain, plan=plan,showdate = toDate,clike=0,dlike=0,disuser=[],disuserid=[],likeuserid=[],likeuser=[]) c.save() contacts = Community.objects.order_by('-id') return render_to_response('passenger/community.html',{"contacts":contacts,'user':request.user})
from passenger.models import ShuttleSchedule,ScheduleDate from passenger.dateSchedule import timeToDate t = timeToDate() dmy = t.timeToDmy() d = t.timeToD() sschedule = ShuttleSchedule.objects.filter(day=d) for s in sschedule: ds = ScheduleDate(a_name = s.a_name, day = s.day, time = s.time,schedule = s.schedule, gid = s.gid, aid = s.aid,slist = s.slist,p_schedule = s.p_schedule, alist = s.alist, memo = s.memo, date = dmy) ds.save()
def store_historyschedule(): t = timeToDate() store_historyschedule_func(t)