Example #1
0
	def rooms_occupied_by(self, people):
		s = Storage(self.name, self.token, True)
		room_numbers, rooms, person_names, persons, current_timestamp = s.get_stats()
		log = s.get_log()

		people_wanted = { (t[1]+name):True for t, name in people }
		rooms = {}
		result = {}

		for event in log:
			if not event.who in people_wanted or event.room == -1:
				continue

			if event.action == 'A':
				if event.room in rooms:
					people_preset = rooms[event.room]
				else:
					people_present = {}
					rooms[event.room] = people_present

				people_present[event.who] = True
				if people_present == people_wanted:
					result[event.room] = True

			elif event.action == 'L':
				if event.who in rooms[event.room]:
					rooms[event.room].pop(event.who)

		if len(result) == 0:
			return

		result = [e for e in result.keys()]
		result.sort()
		result2 = [str(e) for e in result]
		print(','.join(result2))
Example #2
0
	def rooms_entered_by(self, who, is_employee):
		who = 'E' + who if is_employee else 'G' + who

		s = Storage(self.name, self.token, True)
		room_numbers, rooms, person_names, persons, _ = s.get_stats()
		log = s.get_log()
		print(','.join([str(e.room) for e in log if e.who == who and e.action == 'A' and e.room != -1 ]))
Example #3
0
	def total_time_spent_by(self, who, is_employee):
		who = 'E' + who if is_employee else 'G' + who

		s = Storage(self.name, self.token, True, True)
		if s.error:
			print(0)
			return

		s.verify_log()

		room_numbers, rooms, person_names, persons, current_timestamp = s.get_stats()

		if not who in person_names:
			print(0)
			return

		person = person_names[who]
		if person.is_employee != is_employee:
			libgeneric.print_error_and_exit("invalid")

		total_time = person.time_in_gallery

		if person.gallery_timestamp >= 0:
			total_time += (current_timestamp - person.gallery_timestamp)
		print(total_time)
Example #4
0
	def state(self):
		s = Storage(self.name, self.token, True)
		s.verify_log()
		room_numbers, rooms, person_names, persons, _ = s.get_stats()
		if persons:
			res = [p.name[1:] for p in persons if p.gallery_timestamp >= 0 and p.is_employee]
			res.sort()
			print(','.join(res))
			res = [p.name[1:] for p in persons if p.gallery_timestamp >= 0 and p.is_employee == False]
			res.sort()
			print(','.join(res))
		else:
			print()

		room_dir = {}

		for room in rooms:
			room_dir[room.number] = []

		for person in persons:
			if person.room >= 0:
				room_dir[rooms[person.room].number].append(person.name[1:])

		rooms_and_attendees = []
		for number, people in room_dir.items():
			people.sort()
			rooms_and_attendees.append( (number, ','.join(people)) )

		rooms_and_attendees.sort(key=lambda e : e[0])

		for rooms in rooms_and_attendees:
			if rooms[1] != '':
				print(str(rooms[0]) + ": " + rooms[1])