Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Untis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Untis
Commits
a82eef89
Commit
a82eef89
authored
6 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Working plan with bugs
parent
a34ac86e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
biscuit/apps/untis/parse.py
+14
-150
14 additions, 150 deletions
biscuit/apps/untis/parse.py
biscuit/apps/untis/plan.py
+220
-0
220 additions, 0 deletions
biscuit/apps/untis/plan.py
biscuit/apps/untis/sub.py
+21
-6
21 additions, 6 deletions
biscuit/apps/untis/sub.py
with
255 additions
and
156 deletions
biscuit/apps/untis/parse.py
+
14
−
150
View file @
a82eef89
from
django.conf
import
settings
from
django.utils
import
timezone
from
schoolapps.settings
import
LESSONS
class
Lesson
(
object
):
class
Lesson
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
filled
=
False
self
.
filled
=
False
...
@@ -26,6 +20,7 @@ class Lesson(object):
...
@@ -26,6 +20,7 @@ class Lesson(object):
# Split data (,)
# Split data (,)
lesson_id
=
raw_lesson
.
lesson_id
lesson_id
=
raw_lesson
.
lesson_id
self
.
id
=
lesson_id
raw_lesson_data
=
raw_lesson
.
lessonelement1
.
split
(
"
,
"
)
raw_lesson_data
=
raw_lesson
.
lessonelement1
.
split
(
"
,
"
)
raw_time_data
=
raw_lesson
.
lesson_tt
.
split
(
"
,
"
)
raw_time_data
=
raw_lesson
.
lesson_tt
.
split
(
"
,
"
)
...
@@ -80,9 +75,9 @@ class Lesson(object):
...
@@ -80,9 +75,9 @@ class Lesson(object):
# r = drive["rooms"][room_id]
# r = drive["rooms"][room_id]
# rooms.append(r)
# rooms.append(r)
rooms
=
[]
rooms
=
[]
for
room
in
rooms
:
#
for room in rooms:
print
(
room
)
#
print(room)
print
(
"
--
"
)
#
print("--")
classes
=
[]
classes
=
[]
for
class_id
in
class_ids
:
for
class_id
in
class_ids
:
...
@@ -146,7 +141,7 @@ def build_drive():
...
@@ -146,7 +141,7 @@ def build_drive():
id
=
el
.
id
id
=
el
.
id
drive
[
key
][
id
]
=
el
drive
[
key
][
id
]
=
el
print
(
drive
)
#
print(drive)
return
drive
return
drive
...
@@ -174,40 +169,6 @@ def parse():
...
@@ -174,40 +169,6 @@ def parse():
return
lessons
return
lessons
TYPE_TEACHER
=
0
TYPE_ROOM
=
1
TYPE_CLASS
=
2
class
LessonContainer
(
object
):
"""
Needed for Django template because template language does not support dictionaries
Saves the time object and the lesson elements
"""
def
__init__
(
self
,
):
self
.
time
=
None
self
.
elements
=
[]
def
set_time
(
self
,
time
):
self
.
time
=
time
def
append
(
self
,
element
):
self
.
elements
.
append
(
element
)
class
LessonElementContainer
(
object
):
"""
Needed for Django template because template language does not support dictionaries
Saves the lesson element object and the room (from time object)
"""
def
__init__
(
self
,
element
,
room
,
substitution
=
None
):
self
.
element
=
element
self
.
room
=
room
self
.
substitution
=
substitution
def
get_lesson_by_id
(
id
):
def
get_lesson_by_id
(
id
):
global
drive
global
drive
lesson
=
Lesson
()
lesson
=
Lesson
()
...
@@ -217,29 +178,29 @@ def get_lesson_by_id(id):
...
@@ -217,29 +178,29 @@ def get_lesson_by_id(id):
def
get_lesson_element_by_id_and_teacher
(
lesson_id
,
teacher
,
hour
=
None
,
weekday
=
None
):
def
get_lesson_element_by_id_and_teacher
(
lesson_id
,
teacher
,
hour
=
None
,
weekday
=
None
):
print
(
lesson_id
)
#
print(lesson_id)
print
(
hour
,
"
LEWE
"
,
weekday
)
#
print(hour, "LEWE", weekday)
try
:
try
:
lesson
=
get_lesson_by_id
(
lesson_id
)
lesson
=
get_lesson_by_id
(
lesson_id
)
except
Exception
:
except
Exception
:
return
None
,
None
return
None
,
None
el
=
None
el
=
None
i
=
0
i
=
0
print
(
lesson
.
elements
)
#
print(lesson.elements)
for
i
,
element
in
enumerate
(
lesson
.
elements
):
for
i
,
element
in
enumerate
(
lesson
.
elements
):
print
(
element
.
teacher
.
shortcode
)
#
print(element.teacher.shortcode)
if
element
.
teacher
.
id
==
teacher
.
id
:
if
element
.
teacher
.
id
==
teacher
.
id
:
el
=
element
el
=
element
break
break
t
=
None
t
=
None
print
(
lesson
.
times
)
#
print(lesson.times)
print
(
weekday
)
#
print(weekday)
print
(
hour
)
#
print(hour)
for
time
in
lesson
.
times
:
for
time
in
lesson
.
times
:
print
(
"
DAY
"
,
time
.
day
,
time
.
hour
)
#
print("DAY", time.day, time.hour)
if
time
.
day
==
weekday
and
time
.
hour
==
hour
:
if
time
.
day
==
weekday
and
time
.
hour
==
hour
:
t
=
time
t
=
time
print
(
t
)
#
print(t)
room
=
None
room
=
None
if
t
is
not
None
:
if
t
is
not
None
:
room
=
t
.
rooms
[
i
]
room
=
t
.
rooms
[
i
]
...
@@ -247,100 +208,3 @@ def get_lesson_element_by_id_and_teacher(lesson_id, teacher, hour=None, weekday=
...
@@ -247,100 +208,3 @@ def get_lesson_element_by_id_and_teacher(lesson_id, teacher, hour=None, weekday=
if
el
is
not
None
:
if
el
is
not
None
:
return
el
,
room
return
el
,
room
return
None
,
None
return
None
,
None
def
parse_lesson_times
():
times
=
[]
for
i
,
t
in
enumerate
(
LESSONS
):
start_split
=
t
[
0
].
split
(
"
:
"
)
start_time
=
timezone
.
datetime
(
year
=
2000
,
day
=
1
,
month
=
1
,
hour
=
int
(
start_split
[
0
]),
minute
=
int
(
start_split
[
1
]))
end_time
=
start_time
+
timezone
.
timedelta
(
minutes
=
45
)
print
(
start_time
)
print
(
end_time
)
times
.
append
({
"
number
"
:
i
+
1
,
"
number_format
"
:
t
[
1
],
"
start
"
:
start_time
,
"
end
"
:
end_time
,
})
return
times
def
get_plan
(
type
,
id
):
"""
Generates a plan for type (TYPE_TEACHE, TYPE_CLASS, TYPE_ROOM) and a id of the teacher (class, room)
"""
# Get parsed lessons
lessons
=
parse
()
times_parsed
=
parse_lesson_times
()
# Init plan array
plan
=
[]
# Fill plan array with LessonContainers (show upside), WIDTH and HEIGHT are defined by Django settings
for
hour_idx
in
range
(
settings
.
TIMETABLE_HEIGHT
):
plan
.
append
(([],
times_parsed
[
hour_idx
]
if
len
(
times_parsed
)
>
hour_idx
else
None
))
for
day_idx
in
range
(
settings
.
TIMETABLE_WIDTH
):
plan
[
hour_idx
][
0
].
append
(
LessonContainer
())
# Fill plan with lessons
for
lesson
in
lessons
:
for
i
,
element
in
enumerate
(
lesson
.
elements
):
# Check if the lesson element is important for that plan (look by type and id)
found
=
False
if
type
==
TYPE_CLASS
:
for
lclass
in
element
.
classes
:
if
lclass
.
id
==
id
:
found
=
True
elif
type
==
TYPE_TEACHER
:
if
element
.
teacher
:
if
element
.
teacher
.
id
==
id
:
found
=
True
elif
type
==
TYPE_ROOM
:
for
time
in
lesson
.
times
:
for
j
,
lroom
in
enumerate
(
time
.
rooms
):
if
lroom
.
id
==
id
:
print
(
lroom
.
name
)
found
=
True
# If the lesson element is important then add it to plan array
if
found
:
for
time
in
lesson
.
times
:
# Go for every time the lesson is thought
# print(time.hour, " ", time.day)
# print(element.subject.shortcode)
room_index
=
None
for
j
,
lroom
in
enumerate
(
time
.
rooms
):
if
lroom
.
id
==
id
:
room_index
=
j
# Add the time object to the matching LessonContainer on the right position in the plan array
plan
[
time
.
hour
-
1
][
0
][
time
.
day
-
1
].
set_time
(
time
)
# Check if there is an room for this time and lesson
try
:
room
=
time
.
rooms
[
i
]
except
IndexError
:
room
=
None
# print(element)
# print(room.name)
# Create a LessonElementContainer with room and lesson element
element_container
=
LessonElementContainer
(
element
,
room
)
if
type
!=
TYPE_ROOM
or
i
==
room_index
:
# Add this container object to the LessonContainer object in the plan array
plan
[
time
.
hour
-
1
][
0
][
time
.
day
-
1
].
append
(
element_container
)
# print(plan)
#
# for hour in plan:
# for day in hour:
# print(day.elements)
# for c in day.elements:
# # print(c.element)
# pass
return
plan
This diff is collapsed.
Click to expand it.
biscuit/apps/untis/plan.py
0 → 100644
+
220
−
0
View file @
a82eef89
import
datetime
from
django.utils
import
timezone
from
schoolapps
import
settings
from
schoolapps.settings
import
LESSONS
from
untisconnect.parse
import
parse
from
untisconnect.sub
import
get_substitutions_by_date_as_dict
,
TYPE_CANCELLATION
TYPE_TEACHER
=
0
TYPE_ROOM
=
1
TYPE_CLASS
=
2
class
LessonContainer
(
object
):
"""
Needed for Django template because template language does not support dictionaries
Saves the time object and the lesson elements
"""
def
__init__
(
self
,
):
self
.
time
=
None
self
.
elements
=
[]
def
set_time
(
self
,
time
):
self
.
time
=
time
def
append
(
self
,
element
):
self
.
elements
.
append
(
element
)
class
LessonElementContainer
(
object
):
"""
Needed for Django template because template language does not support dictionaries
Saves the lesson element object and the room (from time object)
"""
def
__init__
(
self
,
element
,
room
,
substitution
=
None
):
self
.
element
=
element
self
.
room
=
room
self
.
substitution
=
substitution
self
.
is_old
=
False
def
parse_lesson_times
():
times
=
[]
for
i
,
t
in
enumerate
(
LESSONS
):
start_split
=
t
[
0
].
split
(
"
:
"
)
start_time
=
timezone
.
datetime
(
year
=
2000
,
day
=
1
,
month
=
1
,
hour
=
int
(
start_split
[
0
]),
minute
=
int
(
start_split
[
1
]))
end_time
=
start_time
+
timezone
.
timedelta
(
minutes
=
45
)
# print(start_time)
# print(end_time)
times
.
append
({
"
number
"
:
i
+
1
,
"
number_format
"
:
t
[
1
],
"
start
"
:
start_time
,
"
end
"
:
end_time
,
})
return
times
def
get_plan
(
type
,
id
,
smart
=
False
,
monday_of_week
=
None
):
"""
Generates a plan for type (TYPE_TEACHE, TYPE_CLASS, TYPE_ROOM) and a id of the teacher (class, room)
"""
# Get parsed lessons
lessons
=
parse
()
times_parsed
=
parse_lesson_times
()
if
smart
:
print
(
"
Get substitutions for smart plan
"
)
week_days
=
[
monday_of_week
+
datetime
.
timedelta
(
days
=
i
)
for
i
in
range
(
5
)]
print
(
week_days
)
subs_for_weekday
=
[]
for
week_day
in
week_days
:
print
(
week_day
)
subs
=
get_substitutions_by_date_as_dict
(
week_day
)
subs_for_weekday
.
append
(
subs
)
print
(
subs
)
print
(
len
(
subs
))
# Init plan array
plan
=
[]
already_added_subs_as_ids
=
[]
# Fill plan array with LessonContainers (show upside), WIDTH and HEIGHT are defined by Django settings
for
hour_idx
in
range
(
settings
.
TIMETABLE_HEIGHT
):
plan
.
append
(([],
times_parsed
[
hour_idx
]
if
len
(
times_parsed
)
>
hour_idx
else
None
))
for
day_idx
in
range
(
settings
.
TIMETABLE_WIDTH
):
plan
[
hour_idx
][
0
].
append
(
LessonContainer
())
# Fill plan with lessons
for
lesson
in
lessons
:
for
i
,
element
in
enumerate
(
lesson
.
elements
):
# Check if the lesson element is important for that plan (look by type and id)
found
=
False
if
type
==
TYPE_CLASS
:
for
lclass
in
element
.
classes
:
if
lclass
.
id
==
id
:
found
=
True
elif
type
==
TYPE_TEACHER
:
if
element
.
teacher
:
if
element
.
teacher
.
id
==
id
:
found
=
True
elif
type
==
TYPE_ROOM
:
for
time
in
lesson
.
times
:
for
j
,
lroom
in
enumerate
(
time
.
rooms
):
if
lroom
.
id
==
id
:
print
(
lroom
.
name
)
found
=
True
# If the lesson element is important then add it to plan array
if
found
:
for
time
in
lesson
.
times
:
# Go for every time the lesson is thought
# print(time.hour, " ", time.day)
# print(element.subject.shortcode)
room_index
=
None
for
j
,
lroom
in
enumerate
(
time
.
rooms
):
if
lroom
.
id
==
id
:
room_index
=
j
# Add the time object to the matching LessonContainer on the right position in the plan array
plan
[
time
.
hour
-
1
][
0
][
time
.
day
-
1
].
set_time
(
time
)
# Check if there is an room for this time and lesson
try
:
room
=
time
.
rooms
[
i
]
except
IndexError
:
room
=
None
# print(element)
# print(room.name)
matching_sub
=
None
if
smart
:
current_weekday
=
week_days
[
time
.
day
-
1
]
current_lesson
=
time
.
hour
print
(
current_weekday
,
current_lesson
)
print
(
lesson
.
id
)
if
subs_for_weekday
[
time
.
day
-
1
].
get
(
lesson
.
id
,
None
)
is
not
None
:
for
sub
in
subs_for_weekday
[
time
.
day
-
1
][
lesson
.
id
]:
# sub = subs_for_weekday[time.day - 1][lesson.id]
if
sub
[
"
sub
"
].
teacher_old
.
id
==
element
.
teacher
.
id
:
matching_sub
=
sub
# print(sub.keys())
# print(sub["sub"].type)
print
(
"
SUB
"
)
if
matching_sub
:
already_added_subs_as_ids
.
append
(
matching_sub
[
"
sub
"
].
id
)
# Create a LessonElementContainer with room and lesson element
element_container
=
LessonElementContainer
(
element
,
room
,
substitution
=
matching_sub
)
if
smart
and
matching_sub
is
not
None
:
print
(
matching_sub
[
"
sub
"
].
teacher_old
.
name
)
print
(
matching_sub
[
"
sub
"
].
room_old
)
print
(
matching_sub
[
"
sub
"
].
room_new
)
if
matching_sub
[
"
sub
"
].
room_new
is
not
None
:
if
matching_sub
[
"
sub
"
].
room_old
is
not
None
:
if
matching_sub
[
"
sub
"
].
room_old
!=
matching_sub
[
"
sub
"
].
room_new
:
element_container
.
is_old
=
True
else
:
element_container
.
is_old
=
True
if
matching_sub
[
"
sub
"
].
type
==
TYPE_CANCELLATION
:
element_container
.
is_old
=
True
print
(
element_container
.
is_old
)
if
type
!=
TYPE_ROOM
or
i
==
room_index
:
# Add this container object to the LessonContainer object in the plan array
plan
[
time
.
hour
-
1
][
0
][
time
.
day
-
1
].
append
(
element_container
)
if
smart
:
for
i
,
week_day
in
enumerate
(
week_days
):
print
(
i
,
week_day
)
subs_for_this_weekday
=
subs_for_weekday
[
i
]
for
lesson_id
,
subs
in
subs_for_this_weekday
.
items
():
for
sub
in
subs
:
print
(
sub
[
"
sub
"
].
id
)
# print(sub)
# print(sub["sub"].room_new)
found
=
False
room
=
sub
[
"
sub
"
].
room_old
if
type
==
TYPE_CLASS
:
if
sub
[
"
sub
"
].
classes
:
for
_class
in
sub
[
"
sub
"
].
classes
:
# print(_class)
if
_class
.
id
==
id
:
# print("Hi")
found
=
True
elif
type
==
TYPE_TEACHER
:
if
sub
[
"
sub
"
].
teacher_new
:
if
sub
[
"
sub
"
].
teacher_new
.
id
==
id
:
found
=
True
elif
type
==
TYPE_ROOM
:
if
sub
[
"
sub
"
].
room_new
:
if
sub
[
"
sub
"
].
room_new
.
id
==
id
:
found
=
True
if
found
:
element_container
=
LessonElementContainer
(
sub
[
"
sub
"
].
lesson_element
,
room
,
substitution
=
sub
)
if
sub
[
"
sub
"
].
id
not
in
already_added_subs_as_ids
:
# if len(plan[sub["sub"].lesson - 1][0][i]) > 0:
# for elc in plan[sub["sub"].lesson - 1][0][i]:
# if elc.substitution is not None:
# if elc.substitution.id == elc.substitutio
plan
[
sub
[
"
sub
"
].
lesson
-
1
][
0
][
i
].
append
(
element_container
)
# print(plan[sub["sub"].lesson - 1][0][i].elements)
# print(len(plan[sub["sub"].lesson - 1][0][i].elements))
# print(plan)
#
# for hour in plan:
# for day in hour:
# print(day.elements)
# for c in day.elements:
# # print(c.element)
# pass
return
plan
This diff is collapsed.
Click to expand it.
biscuit/apps/untis/sub.py
+
21
−
6
View file @
a82eef89
from
django.utils
import
timezone
from
django.utils
import
timezone
from
untisconnect
import
models
from
untisconnect
import
models
from
untisconnect.api
import
run_default_filter
,
row_by_row_helper
,
get_teacher_by_id
,
get_subject_by_id
,
\
from
untisconnect.api
import
run_default_filter
,
row_by_row_helper
get_room_by_id
,
get_class_by_id
,
get_corridor_by_id
from
untisconnect.api_helper
import
run_using
,
untis_split_first
from
untisconnect.api_helper
import
run_using
,
untis_split_first
from
untisconnect.parse
import
get_lesson_by_id
,
get_lesson_element_by_id_and_teacher
,
build_drive
from
untisconnect.parse
import
get_lesson_element_by_id_and_teacher
,
build_drive
DATE_FORMAT
=
"
%Y%m%d
"
DATE_FORMAT
=
"
%Y%m%d
"
...
@@ -85,7 +84,7 @@ class Substitution(object):
...
@@ -85,7 +84,7 @@ class Substitution(object):
self
.
lesson_element
,
self
.
room_old
=
get_lesson_element_by_id_and_teacher
(
self
.
lesson_id
,
self
.
teacher_old
,
self
.
lesson_element
,
self
.
room_old
=
get_lesson_element_by_id_and_teacher
(
self
.
lesson_id
,
self
.
teacher_old
,
self
.
lesson
,
self
.
date
.
weekday
()
+
1
)
self
.
lesson
,
self
.
date
.
weekday
()
+
1
)
# print(self.lesson)
# print(self.lesson)
print
(
self
.
room_old
)
#
print(self.room_old)
# Subject
# Subject
self
.
subject_old
=
self
.
lesson_element
.
subject
if
self
.
lesson_element
is
not
None
else
None
self
.
subject_old
=
self
.
lesson_element
.
subject
if
self
.
lesson_element
is
not
None
else
None
if
db_obj
.
subject_idsubst
!=
0
:
if
db_obj
.
subject_idsubst
!=
0
:
...
@@ -117,10 +116,10 @@ class Substitution(object):
...
@@ -117,10 +116,10 @@ class Substitution(object):
self
.
classes
=
[]
self
.
classes
=
[]
class_ids
=
untis_split_first
(
db_obj
.
classids
,
conv
=
int
)
class_ids
=
untis_split_first
(
db_obj
.
classids
,
conv
=
int
)
print
(
class_ids
)
#
print(class_ids)
for
id
in
class_ids
:
for
id
in
class_ids
:
self
.
classes
.
append
(
drive
[
"
classes
"
][
id
])
self
.
classes
.
append
(
drive
[
"
classes
"
][
id
])
print
(
self
.
classes
)
#
print(self.classes)
def
substitutions_sorter
(
sub
):
def
substitutions_sorter
(
sub
):
...
@@ -264,3 +263,19 @@ def get_substitutions_by_date(date):
...
@@ -264,3 +263,19 @@ def get_substitutions_by_date(date):
# print(class_.name)
# print(class_.name)
subs
.
sort
(
key
=
substitutions_sorter
)
subs
.
sort
(
key
=
substitutions_sorter
)
return
subs
return
subs
def
get_substitutions_by_date_as_dict
(
date
):
subs_raw
=
get_substitutions_by_date
(
date
)
sub_table
=
generate_sub_table
(
subs_raw
)
print
(
"
SUB RAW LEN
"
,
len
(
sub_table
))
subs
=
{}
for
i
,
sub_raw
in
enumerate
(
subs_raw
):
print
(
i
)
if
sub_raw
.
lesson_id
not
in
subs
.
keys
():
subs
[
sub_raw
.
lesson_id
]
=
[]
subs
[
sub_raw
.
lesson_id
].
append
({
"
sub
"
:
sub_raw
,
"
table
"
:
sub_table
[
i
]})
# print(sub_raw.teacher_old)
# print(sub_table[i].teacher)
print
(
len
(
subs
))
return
subs
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment