def program_layer_get_days_helper(self, visiting_group_id ): visiting_group = common_couch.getVisitingGroup(holly_couch, visiting_group_id) ####date_range = dateRange(visiting_group['from_date'], visiting_group['to_date']) #...create temporary mapping title-> id, in the future, this should be based on time rather on the title (which can be dangerous) time_id_mapping = self.getTimeIdMapping() booking_days = [bd.doc for bd in getBookingDays(holly_couch, visiting_group['from_date'], visiting_group['to_date'])] schema_id_map = dict() for b in booking_days: schema_id_map[b['day_schema_id']] = b #...now, if we have too many day schema ids, we have a problem... # TODO dangerous below, we can have diffreent schemas for different days first_booking_day=booking_days[0] schema_id = first_booking_day['day_schema_id'] schema_doc = holly_couch[schema_id] schema = schema_doc['schema'] #...if we assume the same layout for every slot row, we can get first row in schema and use it as template any_slot_row_in_schema = schema[schema.keys()[0]][1:] # skip first part, now we have four time-slots that can be used #...it would be best if we now could clean out the slot_id from the mapping generalized_slot_row = [] layer_times = [] #...will change its parameters self.fillInGeneralizedSlotRow(time_id_mapping, any_slot_row_in_schema, generalized_slot_row, layer_times) ####datetime_map = [] #...iterate through schema and find FM EM etc # iterate through schema and find the slot_id maping. layer_days = [] for d in booking_days: tmp_item = dict(booking_day_id=d['_id'], date=d['date']) layer_days.append(tmp_item) #... program_layers = visiting_group.get('layers', []) #...I need to build this mapping from booking_day_id:slot_id:layer_id to datetime bucket # so iterate through all schema rows and look at time, slot_id_time_map = {} for tmp_schema_id in schema_id_map.keys(): tmp_schema_doc = holly_couch[tmp_schema_id] tmp_schema = tmp_schema_doc['schema'] for tmp_activity_id, tmp_activity_row in tmp_schema.items(): for tmp_slot in tmp_activity_row[1:]: tmp_time = tmp_slot['title'] slot_id_time_map[tmp_slot['slot_id']] = time_id_mapping[tmp_time] # TODO return activity title map activity_title_map = getActivityTitleMap(holly_couch) return dict(layer_time=layer_times, layer_days=layer_days, slot_id_time_map=slot_id_time_map, visiting_group_id=visiting_group_id, activity_title_map=activity_title_map, program_layers=program_layers)
def sanity_check_property_usage(self): # ...iterate through all bookings, we are only interested in scheduled bookings bookings = getAllScheduledBookings(holly_couch, limit=1000000) booking_days_map = dict() for bd in getAllBookingDays(holly_couch): booking_days_map[bd.doc["_id"]] = bd.doc visiting_group_map = dict() for vg in getAllVisitingGroups(holly_couch): visiting_group_map[vg.key[1]] = vg.doc # activity_map = dict() activity_title_map = getActivityTitleMap(holly_couch) problems = list() for tmp_bx in bookings: tmp_b = tmp_bx.doc tmp_b_day_id = tmp_b["booking_day_id"] tmp_b_day = booking_days_map[tmp_b_day_id] # if not activity_map.has_key(tmp_b_day['day_schema_id']): # activity_map[tmp_b_day['day_schema_id']] = getSchemaSlotActivityMap(holly_couch, tmp_b_day['day_schema_id']) # tmp_activity_map = activity_map[tmp_b_day['day_schema_id']] if None != tmp_b_day: # and tmp_b_day.date >= datetime.date.today(): if tmp_b["visiting_group_id"] != "" and (False == tmp_b.get("hide_warn_on_suspect_booking", False)): tmp_date = tmp_b_day["date"] tmp_content = activity_title_map[tmp_b["activity_id"]] + " " + tmp_b["content"] tmp_b_visiting_group = visiting_group_map[tmp_b["visiting_group_id"]] if not tmp_b_visiting_group.has_key("from_date"): problems.append( dict( booking=tmp_b, msg="visiting group %s has no from_date" % tmp_b_visiting_group["visiting_group_name"], severity=100, ) ) else: if tmp_b_visiting_group["from_date"] > tmp_date: problems.append( dict( booking=tmp_b, msg="arrives at %s but booking %s is at %s" % (str(tmp_b_visiting_group["from_date"]), tmp_content, str(tmp_date)), severity=10, ) ) if tmp_b_visiting_group["from_date"] == tmp_date: problems.append( dict( booking=tmp_b, msg="arrives same day as booking %s, at %s" % (tmp_content, str(tmp_b_visiting_group["from_date"])), severity=self.get_severity(tmp_b_visiting_group, 1), ) ) if tmp_b_visiting_group["to_date"] < tmp_date: problems.append( dict( booking=tmp_b, msg="leves at %s but booking %s is at %s" % (str(tmp_b_visiting_group["to_date"]), tmp_content, str(tmp_date)), severity=10, ) ) if tmp_b_visiting_group["to_date"] == tmp_date: problems.append( dict( booking=tmp_b, msg="leves same day as booking %s, at %s" % (tmp_content, str(tmp_b_visiting_group["to_date"])), severity=self.get_severity(tmp_b_visiting_group, 1), ) ) tmp_content = tmp_b["content"] for tmp_prop in tmp_b_visiting_group["visiting_group_properties"].values(): checks = [x + tmp_prop["property"] for x in ["$$", "$", "$#", "#"]] for check in checks: if check in tmp_content: if tmp_prop["from_date"] > tmp_date: problems.append( dict( booking=tmp_b, msg="property $" + tmp_prop["property"] + " usable from " + str(tmp_prop["from_date"]) + " but booking is at " + str(tmp_date), severity=10, ) ) if tmp_prop["from_date"] == tmp_date: problems.append( dict( booking=tmp_b, msg="property $" + tmp_prop["property"] + " arrives at " + str(tmp_prop["from_date"]) + " and booking is the same day", severity=self.get_severity(tmp_b_visiting_group, 1), ) ) if tmp_prop["to_date"] < tmp_date: problems.append( dict( booking=tmp_b, msg="property $" + tmp_prop["property"] + " usable to " + str(tmp_prop["to_date"]) + " but booking is at " + str(tmp_date), severity=10, ) ) if tmp_prop["to_date"] == tmp_date: problems.append( dict( booking=tmp_b, msg="property $" + tmp_prop["property"] + " leavs at " + str(tmp_prop["to_date"]) + " and booking is the same day ", severity=self.get_severity(tmp_b_visiting_group, 1), ) ) break # there can be more than one match in checks problems.sort(self.fn_sort_problems_by_severity) return dict(problems=problems, visiting_group_map=visiting_group_map)
def sanity_check_property_usage(self): log.info("sanity_check_property_usage()") ##ensurePostRequest(request, __name__) #...iterate through all bookings, we are only interested in scheduled bookings bookings = getAllScheduledBookings(holly_couch, limit=1000000) booking_days_map = dict() for bd in getAllBookingDays(holly_couch): booking_days_map[bd.doc['_id']] = bd.doc visiting_group_map = dict() for vg in getAllVisitingGroups(holly_couch): visiting_group_map[vg.key[1]] = vg.doc #activity_map = dict() activity_title_map = getActivityTitleMap(holly_couch) problems = list() for tmp_bx in bookings: tmp_b = tmp_bx.doc tmp_b_day_id = tmp_b['booking_day_id'] tmp_b_day = booking_days_map[tmp_b_day_id] # if not activity_map.has_key(tmp_b_day['day_schema_id']): # activity_map[tmp_b_day['day_schema_id']] = getSchemaSlotActivityMap(holly_couch, tmp_b_day['day_schema_id']) # tmp_activity_map = activity_map[tmp_b_day['day_schema_id']] if None != tmp_b_day: # and tmp_b_day.date >= datetime.date.today(): if tmp_b['visiting_group_id'] != '' and (False == tmp_b.get('hide_warn_on_suspect_booking', False)): tmp_date = tmp_b_day['date'] tmp_content = activity_title_map[tmp_b['activity_id']] + ' ' + tmp_b['content'] tmp_b_visiting_group = visiting_group_map[tmp_b['visiting_group_id']] if not tmp_b_visiting_group.has_key('from_date'): problems.append(dict(booking=tmp_b, msg='visiting group %s has no from_date' % tmp_b_visiting_group['visiting_group_name'], severity=100)) else: if tmp_b_visiting_group['from_date'] > tmp_date: problems.append(dict(booking=tmp_b, msg='arrives at %s but booking %s is at %s' %(str(tmp_b_visiting_group['from_date']), tmp_content ,str(tmp_date)), severity=10)) if tmp_b_visiting_group['from_date'] == tmp_date: problems.append(dict(booking=tmp_b, msg='arrives same day as booking %s, at %s' % (tmp_content, str(tmp_b_visiting_group['from_date'])), severity=self.get_severity(tmp_b_visiting_group, 1))) if tmp_b_visiting_group['to_date'] < tmp_date: problems.append(dict(booking=tmp_b, msg='leves at %s but booking %s is at %s' % (str(tmp_b_visiting_group['to_date']), tmp_content , str(tmp_date)), severity=10)) if tmp_b_visiting_group['to_date'] == tmp_date: problems.append(dict(booking=tmp_b, msg='leves same day as booking %s, at %s' % (tmp_content, str(tmp_b_visiting_group['to_date'])), severity=self.get_severity(tmp_b_visiting_group, 1))) tmp_content = tmp_b['content'] for tmp_prop in tmp_b_visiting_group['visiting_group_properties'].values(): checks = [x+tmp_prop['property'] for x in ['$$','$', '$#','#']] for check in checks: if check in tmp_content: if tmp_prop['from_date'] > tmp_date: problems.append(dict(booking=tmp_b, msg='property $' + tmp_prop['property'] + ' usable from ' + str(tmp_prop['from_date']) + ' but booking is at ' + str(tmp_date), severity=10)) if tmp_prop['from_date'] == tmp_date: problems.append(dict(booking=tmp_b, msg='property $' + tmp_prop['property'] + ' arrives at ' + str(tmp_prop['from_date']) + ' and booking is the same day', severity=self.get_severity(tmp_b_visiting_group, 1))) if tmp_prop['to_date'] < tmp_date: problems.append(dict(booking=tmp_b, msg='property $' + tmp_prop['property'] + ' usable to ' + str(tmp_prop['to_date']) + ' but booking is at ' + str(tmp_date), severity=10)) if tmp_prop['to_date'] == tmp_date: problems.append(dict(booking=tmp_b, msg='property $' + tmp_prop['property'] + ' leavs at ' + str(tmp_prop['to_date']) + ' and booking is the same day ', severity=self.get_severity(tmp_b_visiting_group, 1))) break # there can be more than one match in checks problems.sort(self.fn_sort_problems_by_severity) return dict (problems=problems, visiting_group_map=visiting_group_map)
def view_unscheduled(self): unscheduled_bookings = [b.doc for b in getAllUnscheduledBookings(holly_couch)] return dict(unscheduled_bookings=unscheduled_bookings, workflow_map=workflow_map, result_title='Unscheduled bookings', activity_map=getActivityTitleMap(holly_couch), booking_date_map=getBookingDayInfoMap(holly_couch), user_name_map=getUserNameMap(holly_couch), slot_map=getSchemaSlotActivityMap(holly_couch, 'day_schema.1'), workflow_submenu=workflow_submenu)
def view_disapproved(self): scheduled_bookings = scheduled_bookings = [b.doc for b in gelAllBookingsWithBookingState(holly_couch, [-10])] return dict(scheduled_bookings=scheduled_bookings, workflow_map=workflow_map, result_title='Disapproved bookings', activity_map=getActivityTitleMap(holly_couch), booking_date_map=getBookingDayInfoMap(holly_couch), user_name_map=getUserNameMap(holly_couch), slot_map=getSchemaSlotActivityMap(holly_couch, 'day_schema.1'), workflow_submenu=workflow_submenu)
def overview(self): """Show an overview of all bookings""" scheduled_bookings = [b.doc for b in getAllScheduledBookings(holly_couch)] unscheduled_bookings = [b.doc for b in getAllUnscheduledBookings(holly_couch)] #...I need a map from booking_day_id to booking day date and from [booking_day_i, slot_id] to time. # actually, I do thin couch could create such a view, it's just going to be very messy # TODO: in the future we cant use a hard coded day schema, we will need one map for each day schema that exists. return dict(scheduled_bookings=scheduled_bookings, unscheduled_bookings=unscheduled_bookings, workflow_map=workflow_map, activity_map=getActivityTitleMap(holly_couch), booking_date_map=getBookingDayInfoMap(holly_couch), user_name_map=getUserNameMap(holly_couch), slot_map=getSchemaSlotActivityMap(holly_couch, 'day_schema.1'), workflow_submenu=workflow_submenu)