Пример #1
0
	def parseAbsentTeachers(self):
		# find the absent teachers.
		for les in self._fileContent['result']['teacherAbsences']:
			if les['startDate'] != les['endDate']:
				self._errorDialog.addDebug(
					'Don\'t support different starting and ending date - skipping!',
					pprint.pformat(les)
				)
			elif les['startTime'] != '0000' or les['endTime'] != '0000':
				self._errorDialog.addDebug(
					'Don\'t support start/end time for absent classes - skipping!',
					pprint.pformat(les)
				)
			else:
				entryDate = '%s.%s.%s' % (
					les['startDate'][6:],
					les['startDate'][4:6],
					les['startDate'][:4]
				)

				newEntry = ChangeEntry([entryDate], 5, None)
				newEntry._hours = [0]
				newEntry._startTime = '00:00:00'
				newEntry._endTime = '23:59:59'
				teacher = self._teacherList.findById(les['teacherRef'])
				if teacher is None:
					self.dlg.addData(pprint.pformat(les))
					self.dlg.addError('Teacher unknown for absent teachers - skipping!')
					continue

				newEntry._teacher = teacher
				self._absentTeacher.append(newEntry)
Пример #2
0
	def parseAbsentClasses(self):
		# first find the absent classes
		for les in self._fileContent['result']['classAbsences']:
			if les['startDate'] != les['endDate']:
				self._errorDialog.addDebug(
					'Don\'t support different starting and ending date - skipping!',
					pprint.pformat(les)
				)
			elif les['startTime'] != '0000' or les['endTime'] != '0000':
				self._errorDialog.addDebug(
					'Don\'t support start/end time for absent classes - skipping!',
					pprint.pformat(les)
				)
			else:
				entryDate = '%s.%s.%s' % (
					les['startDate'][6:],
					les['startDate'][4:6],
					les['startDate'][:4]
				)

				newEntry = ChangeEntry([entryDate], 2, None)
				newEntry._hours = [0]
				newEntry._startTime = '00:00:00'
				newEntry._endTime = '23:59:59'
				course = self._classList.findClassById(les['classRef'])
				if course is None:
					self.dlg.addData(pprint.pformat(les))
					self.dlg.addError('Course unknown for absent course - skipping!')
					continue

				newEntry._course = [course]
				self._absentClasses.append(newEntry)
Пример #3
0
	def parseYardDuty(self):
		# find the absent teachers.
		for les in self._fileContent['result']['displaySchedule']['supervisionTimes']:
				# skip which don't have changes
				if 'changes' not in les.keys():
					continue

				entryDates = []
				for dt in les['dates']:
					entryDates.append('%s.%s.%s' % (dt[6:], dt[4:6], dt[:4]))

				newEntry = ChangeEntry(entryDates, 4, None)
				newEntry._startTime = '%s:%s:00' % (les['startTime'][:2], les['startTime'][2:4])
				newEntry._endTime = '%s:%s:00' % (les['endTime'][:2], les['endTime'][2:4])
				newEntry._hours = self._timeFramesDuty.getMatchingEntries(les['startTime'], les['endTime'])

				if 'supervisionTitle' in les.keys():
					newEntry._info = les['supervisionTitle']

				if 'areaCode' in les.keys():
					newEntry._room = les['areaCode']

				oldTeacher = None
				# the teacher (strange that it is a list)
				try:
					for t in les['absentTeacherCodes']:
						oldTeacher = t
						break
				except KeyError as e:
					# is it allowed, if the reasonType == classAbsence!
					self._errorDialog.addData(pprint.pformat(les))
					self._errorDialog.addWarning('Cannot parse yard chnage due missing old teacher - skipping!')
					continue

				newTeacher = None
				# the teacher (strange that it is a list)
				try:
					for t in les['teacherCodes']:
						newTeacher = t
						break
				except KeyError as e:
					# is it allowed, if the reasonType == classAbsence!
					self._errorDialog.addData(pprint.pformat(les))
					self._errorDialog.addWarning('Cannot parse yard chnage due missing new teacher - skipping!')
					continue

				newEntry._teacher = oldTeacher
				newEntry._changeTeacher = newTeacher
				self._supervision.append(newEntry)
Пример #4
0
	def parseStandin(self):
		# some patterns (better don't ask which possibilities we have).
		pattMovedFrom = re.compile(self._config.get('changekind', 'movedFrom'))
		pattMovedTo = re.compile(self._config.get('changekind', 'movedTo'))

		# find the absent teachers.
		for les in self._fileContent['result']['displaySchedule']['lessonTimes']:
				# skip which don't have changes
				if 'changes' not in les.keys():
					continue

				entryDates = []
				for dt in les['dates']:
					entryDates.append('%s.%s.%s' % (dt[6:], dt[4:6], dt[:4]))

				newEntry = ChangeEntry(entryDates, 1, None)
				newEntry._startTime = '%s:%s:00' % (les['startTime'][:2], les['startTime'][2:4])
				newEntry._endTime = '%s:%s:00' % (les['endTime'][:2], les['endTime'][2:4])
				newEntry._hours = self._timeFramesPupil.getMatchingEntries(les['startTime'], les['endTime'])
				if len(newEntry._hours) <= 0:
					self._errorDialog.addData(pprint.pformat(les))
					self._errorDialog.addError(
						'Could not find a proper lesson for time: %s to %s - skipping!' % (
							newEntry._startTime,
							newEntry._endTime
						)
					)
					continue

				# now check if the type is classAbsence. In that case, we need to switch to classFree, if the 
				# we have hours given! - otherwise we misinterpret the data.
				if 'reasonType' in les['changes'].keys() and les['changes']['reasonType'] == 'classAbsence' \
					and les['startTime'] != '0000':
					les['changes']['reasonType'] = 'classFree'

				# subject of course
				try:
					subject = les['subjectCode']
				except KeyError as e:
					# maybe its an additional lesson...?
					if 'lessonTitle' in les['changes'].keys():
						subject = les['changes']['lessonTitle']
					else:
						# is it allowed, if the reasonType == classAbsence!
						if 'reasonType' not in les['changes'].keys() or les['changes']['reasonType'] != 'classAbsence':
							self._errorDialog.addData(pprint.pformat(les))
							self._errorDialog.addWarning(
								'Could not found "subjectCode" (subject) in record - skipping!'
							)
							continue
				newEntry._subject = subject

				# new subject?
				if 'newSubjectCode' in les['changes'].keys():
					newEntry._changeSubject = les['changes']['newSubjectCode']

				# the teacher (strange that it is a list)
				try:
					for t in les['teacherCodes']:
						teacher = t
						break
				except KeyError as e:
					# is it allowed, if the reasonType == classAbsence!
					if 'reasonType' not in les['changes'].keys() or les['changes']['reasonType'] != 'classAbsence':
						self._errorDialog.addData(pprint.pformat(les))
						self._errorDialog.addWarning('Could not found "teacherCodes" (teacher) in record - skipping!')
						continue
				newEntry._teacher = teacher
				
				# new teacher?
				if 'newTeacherCodes' in les['changes'].keys():
					for t in les['changes']['newTeacherCodes']:
						newEntry._changeTeacher = t
						break

				# Maybe there is no room, but absentRoomCodes; then we have to use this.
				# Changed on 11.11.: absentRoomCodes has the higher priority than the normal room codes.
				if 'absentRoomCodes' in les['changes'].keys() and len(les['changes']['absentRoomCodes']) > 0:
					les['roomCodes'] = les['changes']['absentRoomCodes']

				# Room (we also consider here only the first)
				try:
					for r in les['roomCodes']:
						room = r
						break
				except KeyError as e:
					# is it allowed, if the reasonType == classAbsence!
					if 'reasonType' not in les['changes'].keys() or les['changes']['reasonType'] != 'classAbsence':
						self._errorDialog.addData(pprint.pformat(les))
						self._errorDialog.addWarning('Could not found "roomCodes" (room) in record - skipping!')
						continue
				newEntry._room = room

				# new room?
				if 'newRoomCodes' in les['changes'].keys():
					for t in les['changes']['newRoomCodes']:
						newEntry._changeRoom = t
						break

				# courses
				try:
					for cl in les['classCodes']:
						newEntry._course.append(cl)
				except KeyError:
					self._errorDialog.addData(pprint.pformat(les))
					self._errorDialog.addWarning('Could not found "classCodes" (course) in record - skipping!')
					continue

				# some information?
				if 'caption' in les['changes'].keys():
					newEntry._info = les['changes']['caption']
					if 'information' in les['changes'].keys():
						newEntry._note = les['changes']['information']
				elif 'information' in les['changes'].keys():
					newEntry._info = les['changes']['information']

				# hour cancelled?
				if 'cancelled' in les['changes'].keys():
					# it was moved!
					if les['changes']['cancelled'] == 'movedAway':
						# it was moved far away. Lets get the details!
						if 'caption' in les['changes'].keys():
							tstMove = pattMovedTo.match(les['changes']['caption'])
							if tstMove is not None:
								day, month, non = tstMove.group(1).split('.')
								weekday = tstMove.group(2)
								mvstr = tstMove.group(3)
								mvend = tstMove.group(5)
								if mvend is not None:
									hourtxt = '%s.-%s.' % (mvstr, mvend)
								else:
									hourtxt = '%s.' % (mvstr,)
								newEntry._info = ''
								newEntry._note = self._config.get('vplan', 'txtMoved').format(weekday, hourtxt, int(day), int(month))

						chgType = 16
					# or the hour is just cancelled.
					elif les['changes']['cancelled'] == 'classFree':
						chgType = 64
						# if the info + notes field is empty, lets populate the field by our own:
						if len(newEntry._info) == 0 and len(newEntry._note) == 0:
							newEntry._info = self._config.get('vplan', 'txtReplaceFree')

				# date moved from? Then lets get the detail!
				if 'caption' in les['changes'].keys():
					tstMove = pattMovedFrom.match(les['changes']['caption'])
					if tstMove is not None:
						day, month, non = tstMove.group(1).split('.')
						weekday = tstMove.group(2)
						mvstr = tstMove.group(3)
						mvend = tstMove.group(5)
						if mvend is not None:
							hourtxt = '%s.-%s.' % (mvstr, mvend)
						else:
							hourtxt = '%s.' % (mvstr,)
						newEntry._info = ''
						newEntry._note = self._config.get('vplan', 'txtMovedNote').format(
							weekday, hourtxt, int(day), int(month)
						)
						chgType = 32

				# remove some kind of infos.
				if len(newEntry._info) > 0:
					if newEntry._info in self._config.get('vplan', 'rmvInfos').split(';'):
						newEntry._info = ''

				lessonRef = None
				try:
					lessonRef = les['lessonRef']
				except KeyError:
					pass

				# a new lesson which replaces an old one but has no reference...
				if lessonRef is None and newEntry._teacher == newEntry._changeTeacher \
					and newEntry._room == newEntry._changeRoom:
					# is the guess algorithm disabled => skip?
					if not self._config.getboolean('options', 'guessOriginalLesson'):
						self._errorDialog.addData(pprint.pformat(les))
						self._errorDialog.addInfo(
							'No lesson reference given and the "guess" algorithm is disabled - skipping!'
						)
						continue

					self._errorDialog.addData(pprint.pformat(les))
					self._errorDialog.addInfo('Found something to guess!')

					# does it already exist there?
					for e in data['plan']:
						if entry['date'] == entryDates[0] \
						 and entry['hour'] == hour \
						 and entry['course'] == courses[0]:
							# found an entry.
							newEntry._teacher = entry['teacher']
							newEntry._room = entry['room']
							if newEntry._subject == '':
								newEntry._subject = entry['subject']
							newEntry._chgType = 0
							break

				self._standin.append(newEntry)