Init
This commit is contained in:
commit
06fa7f096d
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.venv
|
||||
*.json
|
||||
*.csv
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
10
.idea/adlimport.iml
Normal file
10
.idea/adlimport.iml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12 (adlimport)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (adlimport)" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/adlimport.iml" filepath="$PROJECT_DIR$/.idea/adlimport.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
102
main.py
Normal file
102
main.py
Normal file
@ -0,0 +1,102 @@
|
||||
import json
|
||||
import csv
|
||||
import codecs
|
||||
|
||||
def decode_unicode_escapes(data):
|
||||
if isinstance(data, str):
|
||||
return codecs.decode(data, 'unicode_escape')
|
||||
elif isinstance(data, dict):
|
||||
return {key: decode_unicode_escapes(value) for key, value in data.items()}
|
||||
elif isinstance(data, list):
|
||||
return [decode_unicode_escapes(element) for element in data]
|
||||
else:
|
||||
return data
|
||||
|
||||
# Load data from JSON file with UTF-8 encoding
|
||||
with open('data.json', 'r', encoding='utf-8') as f:
|
||||
raw_data = f.read()
|
||||
|
||||
# Decode Unicode escape sequences
|
||||
decoded_data = decode_unicode_escapes(raw_data)
|
||||
|
||||
# Parse the JSON data
|
||||
data = json.loads(decoded_data)
|
||||
|
||||
teachers = data['teachers']
|
||||
classes = data['classes']
|
||||
subjects = data['subjects']
|
||||
classrooms = data['classrooms']
|
||||
|
||||
teacherid = 1
|
||||
teacherEduMap = {}
|
||||
teacherClassroomMap = {}
|
||||
teacher_dicts = []
|
||||
for eduID, teacher in teachers.items():
|
||||
firstname = teacher["firstname"]
|
||||
lastname = teacher["lastname"]
|
||||
isFemale = 0 if teacher["gender"] == "M" else 1
|
||||
classroom = teacher["classroomid"] or 0
|
||||
if classroom:
|
||||
teacherClassroomMap[classroom] = teacherid
|
||||
short = teacher["short"]
|
||||
startedTeaching = teacher["datefrom"]
|
||||
teacher_dicts.append([teacherid, eduID, firstname, lastname, isFemale, classroom, short, startedTeaching])
|
||||
teacherEduMap[eduID] = teacherid
|
||||
teacherid += 1
|
||||
|
||||
subjectID = 1
|
||||
subjectEduMap = {}
|
||||
subject_dicts = []
|
||||
for eduID, subject in subjects.items():
|
||||
name = subject["name"]
|
||||
short = subject["short"]
|
||||
subject_dicts.append([subjectID, eduID, name, short])
|
||||
subjectEduMap[eduID] = subjectID
|
||||
subjectID += 1
|
||||
|
||||
classroomID = 1
|
||||
classroomEduMap = {}
|
||||
classroom_dicts = []
|
||||
for eduID, classroom in classrooms.items():
|
||||
name = classroom["name"]
|
||||
short = classroom["short"]
|
||||
teacher = teacherClassroomMap.get(eduID, 0)
|
||||
classroom_dicts.append([classroomID, eduID, name, short, teacher])
|
||||
classroomEduMap[eduID] = classroomID
|
||||
classroomID += 1
|
||||
|
||||
classID = 1
|
||||
classEduMap = {}
|
||||
class_dicts = []
|
||||
for eduID, classobj in classes.items():
|
||||
name = classobj["name"]
|
||||
short = classobj["short"]
|
||||
grade = classobj["grade"]
|
||||
classTeacher = teacherEduMap.get(classobj["teacherid"], 0)
|
||||
backupTeacher = teacherEduMap.get(classobj["teacher2id"], 0)
|
||||
classroom = classroomEduMap.get(classobj["classroomid"], 0)
|
||||
class_dicts.append([classID, eduID, grade, name, short, classTeacher, backupTeacher, classroom])
|
||||
classEduMap[eduID] = classID
|
||||
classID += 1
|
||||
|
||||
for teacher in teacher_dicts:
|
||||
if teacher[5] not in classroomEduMap:
|
||||
classroomEduMap[teacher[5]] = 0
|
||||
teacher_dicts[teacher[0] - 1][5] = classroomEduMap[teacher[5]]
|
||||
|
||||
# Write dictionaries to CSV files
|
||||
with open('teachers.csv', 'w', encoding="utf-8", newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
writer.writerows(teacher_dicts)
|
||||
|
||||
with open('subjects.csv', 'w', encoding="utf-8", newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
writer.writerows(subject_dicts)
|
||||
|
||||
with open('classrooms.csv', 'w', encoding="utf-8", newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
writer.writerows(classroom_dicts)
|
||||
|
||||
with open('classes.csv', 'w', encoding="utf-8", newline='') as csvfile:
|
||||
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
|
||||
writer.writerows(class_dicts)
|
Loading…
Reference in New Issue
Block a user