可以跑了 准备做系统
This commit is contained in:
105
Html/db/course_list.py
Normal file
105
Html/db/course_list.py
Normal file
@@ -0,0 +1,105 @@
|
||||
import os
|
||||
from tinydb import TinyDB, Query, where
|
||||
|
||||
class CourseList:
|
||||
def __init__(self, db_file='db/data/course/course_list.json'):
|
||||
"""初始化课程列表,自动打开并加载 JSON 数据文件。"""
|
||||
self.db_file = db_file
|
||||
self.db = TinyDB(self.db_file)
|
||||
self.course_query = Query()
|
||||
|
||||
def add_course(self, course_data):
|
||||
"""添加新的课程到课程列表。"""
|
||||
if not self.db.search(self.course_query.course_id == course_data['course_id']):
|
||||
self.db.insert(course_data)
|
||||
else:
|
||||
print(f"Course with ID {course_data['course_id']} already exists.")
|
||||
|
||||
def get_course(self, course_id):
|
||||
"""获取指定 course_id 的课程信息。"""
|
||||
result = self.db.search(self.course_query.course_id == course_id)
|
||||
return result[0] if result else None
|
||||
|
||||
def update_course(self, course_id, updated_data):
|
||||
"""更新指定 course_id 的课程信息。"""
|
||||
self.db.update(updated_data, self.course_query.course_id == course_id)
|
||||
|
||||
def delete_course(self, course_id):
|
||||
"""删除指定 course_id 的课程。"""
|
||||
self.db.remove(self.course_query.course_id == course_id)
|
||||
|
||||
def add_lesson_to_course(self, course_id, lesson_data):
|
||||
"""为指定课程添加课时。"""
|
||||
course = self.get_course(course_id)
|
||||
if course:
|
||||
if 'lessons' not in course:
|
||||
course['lessons'] = []
|
||||
course['lessons'].append(lesson_data)
|
||||
self.update_course(course_id, {'lessons': course['lessons']})
|
||||
else:
|
||||
print(f"Course with ID {course_id} not found.")
|
||||
|
||||
def get_lessons_of_course(self, course_id):
|
||||
"""获取指定课程的所有课时信息。"""
|
||||
course = self.get_course(course_id)
|
||||
return course['lessons'] if course else None
|
||||
|
||||
def get_all_courses(self):
|
||||
"""获取所有课程。"""
|
||||
return self.db.all()
|
||||
|
||||
|
||||
# # 课程数据结构示例
|
||||
# course_data = {
|
||||
# 'course_id': 'CS101',
|
||||
# 'course_name': 'Computer Science 101',
|
||||
# 'course_img_path': 'images/cs101.png',
|
||||
# 'lessons': [
|
||||
# {
|
||||
# 'lesson_id': 'L001',
|
||||
# 'lesson_name': 'Introduction to Computer Science',
|
||||
# 'markdown': 'This is the introduction lesson.',
|
||||
# 'markdown_prompt': 'What is Computer Science?',
|
||||
# 'score_prompt': 'Please provide an overview of CS.'
|
||||
# },
|
||||
# {
|
||||
# 'lesson_id': 'L002',
|
||||
# 'lesson_name': 'Data Structures',
|
||||
# 'markdown': 'In this lesson, we cover Data Structures.',
|
||||
# 'markdown_prompt': 'What is an array?',
|
||||
# 'score_prompt': 'Explain how linked lists work.'
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
|
||||
# lesson_data = {
|
||||
# 'lesson_id': 'L003',
|
||||
# 'lesson_name': 'Algorithms',
|
||||
# 'markdown': 'In this lesson, we will discuss algorithms.',
|
||||
# 'markdown_prompt': 'What is a sorting algorithm?',
|
||||
# 'score_prompt': 'Explain the difference between merge sort and quicksort.'
|
||||
# }
|
||||
|
||||
# # 创建 CourseList 实例
|
||||
# course_list = CourseList()
|
||||
|
||||
# # 添加课程
|
||||
# course_list.add_course(course_data)
|
||||
|
||||
# # 添加课时到现有课程
|
||||
# course_list.add_lesson_to_course('CS101', lesson_data)
|
||||
|
||||
# # 获取并显示所有课程
|
||||
# courses = course_list.get_all_courses()
|
||||
# print(courses)
|
||||
|
||||
# # 获取某个课程的课时
|
||||
# lessons = course_list.get_lessons_of_course('CS101')
|
||||
# print(lessons)
|
||||
|
||||
# # 更新课程信息
|
||||
# updated_data = {'course_name': 'Computer Science 101 - Updated'}
|
||||
# course_list.update_course('CS101', updated_data)
|
||||
|
||||
# # 删除课程
|
||||
# course_list.delete_course('CS101')
|
||||
21
Html/db/data/course/course_list.json
Normal file
21
Html/db/data/course/course_list.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"course_id": "CS101",
|
||||
"course_name": "Computer Science 101",
|
||||
"course_img_path": "images/cs101.png",
|
||||
"lessons": [
|
||||
{
|
||||
"lesson_id": "L001",
|
||||
"lesson_name": "Introduction to Computer Science",
|
||||
"markdown": "This is the introduction lesson.",
|
||||
"markdown_prompt": "What is Computer Science?",
|
||||
"score_prompt": "Please provide an overview of CS."
|
||||
},
|
||||
{
|
||||
"lesson_id": "L002",
|
||||
"lesson_name": "Data Structures",
|
||||
"markdown": "In this lesson, we cover Data Structures.",
|
||||
"markdown_prompt": "What is an array?",
|
||||
"score_prompt": "Explain how linked lists work."
|
||||
}
|
||||
]
|
||||
}
|
||||
57
Html/db/data/user/cake.json
Normal file
57
Html/db/data/user/cake.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"user_id": "user123",
|
||||
"select_course": ["algorithm", "data-structure"],
|
||||
"head_icon": "/static/image/book_cover.jpg",
|
||||
"course_process_dict": {
|
||||
"algorithm": {
|
||||
"course_process": {
|
||||
"lesson_processs": [
|
||||
{
|
||||
"lesson_process": [
|
||||
{
|
||||
"chapter_info": {
|
||||
"dialog": ["This is chapter 1 dialog"],
|
||||
"score": 85,
|
||||
"is_rebuttal": true,
|
||||
"rebuttal_score": 90
|
||||
}
|
||||
},
|
||||
{
|
||||
"chapter_info": {
|
||||
"dialog": ["This is chapter 2 dialog"],
|
||||
"score": 75,
|
||||
"is_rebuttal": false,
|
||||
"rebuttal_score": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"course_put_in_date": "2024-01-01",
|
||||
"course_last_study_date": "2024-12-25",
|
||||
"course_total_study_time": 120
|
||||
}
|
||||
},
|
||||
"data-structure": {
|
||||
"course_process": {
|
||||
"lesson_processs": [
|
||||
{
|
||||
"lesson_process": [
|
||||
{
|
||||
"chapter_info": {
|
||||
"dialog": ["This is course2 chapter 1 dialog"],
|
||||
"score": 88,
|
||||
"is_rebuttal": false,
|
||||
"rebuttal_score": 0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"course_put_in_date": "2024-01-01",
|
||||
"course_last_study_date": "2024-12-25",
|
||||
"course_total_study_time": 90
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Html/db/data/user/user_id_list.json
Normal file
7
Html/db/data/user/user_id_list.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"user123": "password123",
|
||||
"user456": "password456",
|
||||
"user789": "password789",
|
||||
"cake": "12138ckC"
|
||||
}
|
||||
|
||||
116
Html/db/user.py
Normal file
116
Html/db/user.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from datetime import date
|
||||
from tinydb import TinyDB, Query
|
||||
|
||||
class User:
|
||||
def __init__(self, db_file='user_data.json'):
|
||||
"""初始化用户管理,自动打开并加载 JSON 数据文件。"""
|
||||
self.db_file = db_file
|
||||
self.db = TinyDB(self.db_file)
|
||||
self.user_query = Query()
|
||||
|
||||
def add_user(self, user_data):
|
||||
"""添加新的用户"""
|
||||
if not self.db.search(self.user_query.user_id == user_data['user_id']):
|
||||
self.db.insert(user_data)
|
||||
else:
|
||||
print(f"User with ID {user_data['user_id']} already exists.")
|
||||
|
||||
def get_user(self, user_id):
|
||||
"""根据 user_id 获取用户信息"""
|
||||
result = self.db.search(self.user_query.user_id == user_id)
|
||||
return result[0] if result else None
|
||||
|
||||
def update_user(self, user_id, updated_data):
|
||||
"""更新用户信息"""
|
||||
self.db.update(updated_data, self.user_query.user_id == user_id)
|
||||
|
||||
def delete_user(self, user_id):
|
||||
"""删除用户"""
|
||||
self.db.remove(self.user_query.user_id == user_id)
|
||||
|
||||
def get_all_users(self):
|
||||
"""获取所有用户"""
|
||||
return self.db.all()
|
||||
|
||||
|
||||
# 用户数据结构示例
|
||||
# user_data = {
|
||||
# 'user_id': 'user123',
|
||||
# 'select_course': ['course1', 'course2'],
|
||||
# 'course_process_dict': {
|
||||
# 'course1': {
|
||||
# 'course_process': {
|
||||
# 'lesson_processs': [
|
||||
# {
|
||||
# 'lesson_process': [
|
||||
# {
|
||||
# 'chapter_info': {
|
||||
# 'dialog': ['This is chapter 1 dialog'],
|
||||
# 'score': 85,
|
||||
# 'is_rebuttal': True,
|
||||
# 'rebuttal_score': 90
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# 'chapter_info': {
|
||||
# 'dialog': ['This is chapter 2 dialog'],
|
||||
# 'score': 75,
|
||||
# 'is_rebuttal': False,
|
||||
# 'rebuttal_score': 0
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# ],
|
||||
# 'course_put_in_date': date(2024, 1, 1),
|
||||
# 'course_last_study_date': date(2024, 12, 25),
|
||||
# 'course_total_study_time': 120 # 总学习时间:分钟
|
||||
# }
|
||||
# },
|
||||
# 'course2': {
|
||||
# 'course_process': {
|
||||
# 'lesson_processs': [
|
||||
# {
|
||||
# 'lesson_process': [
|
||||
# {
|
||||
# 'chapter_info': {
|
||||
# 'dialog': ['This is course2 chapter 1 dialog'],
|
||||
# 'score': 88,
|
||||
# 'is_rebuttal': False,
|
||||
# 'rebuttal_score': 0
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# ],
|
||||
# 'course_put_in_date': date(2024, 2, 1),
|
||||
# 'course_last_study_date': date(2024, 12, 24),
|
||||
# 'course_total_study_time': 90
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# updated_user_data = {
|
||||
# 'select_course': ['course1', 'course3']
|
||||
# }
|
||||
|
||||
# # 创建 User 实例
|
||||
# user_list = User()
|
||||
|
||||
# # 添加用户
|
||||
# user_list.add_user(user_data)
|
||||
|
||||
# # 获取用户信息
|
||||
# user = user_list.get_user('user123')
|
||||
# print(user)
|
||||
|
||||
# # 更新用户选择的课程
|
||||
# user_list.update_user('user123', updated_user_data)
|
||||
|
||||
# # 获取所有用户
|
||||
# all_users = user_list.get_all_users()
|
||||
# print(all_users)
|
||||
|
||||
# # 删除用户
|
||||
# user_list.delete_user('user123')
|
||||
54
Html/db/user_list.py
Normal file
54
Html/db/user_list.py
Normal file
@@ -0,0 +1,54 @@
|
||||
from tinydb import TinyDB, Query
|
||||
|
||||
class UserList:
|
||||
def __init__(self, db_file='db/data/user/user_id_list.json'):
|
||||
"""初始化用户管理,自动打开并加载 JSON 数据文件。"""
|
||||
self.db_file = db_file
|
||||
self.db = TinyDB(self.db_file)
|
||||
self.user_query = Query()
|
||||
|
||||
def add_user(self, user_id, password):
|
||||
"""添加新的用户登录信息"""
|
||||
# 检查是否已经有该用户
|
||||
if not self.db.search(self.user_query.user_id == user_id):
|
||||
self.db.insert({'user_id': user_id, 'password': password})
|
||||
else:
|
||||
print(f"User with ID {user_id} already exists.")
|
||||
|
||||
def get_user(self, user_id):
|
||||
"""获取指定 user_id 的用户信息"""
|
||||
result = self.db.search(self.user_query.user_id == user_id)
|
||||
return result[0] if result else None
|
||||
|
||||
def update_password(self, user_id, new_password):
|
||||
"""更新用户的密码"""
|
||||
self.db.update({'password': new_password}, self.user_query.user_id == user_id)
|
||||
|
||||
def delete_user(self, user_id):
|
||||
"""删除用户"""
|
||||
self.db.remove(self.user_query.user_id == user_id)
|
||||
|
||||
def get_all_users(self):
|
||||
"""获取所有用户的信息"""
|
||||
return self.db.all()
|
||||
|
||||
# 创建 UserList 实例
|
||||
# user_list = UserList()
|
||||
|
||||
# # 添加用户
|
||||
# user_list.add_user("user123", "password123")
|
||||
# user_list.add_user("user456", "password456")
|
||||
|
||||
# # 获取用户
|
||||
# user = user_list.get_user("user123")
|
||||
# print(user)
|
||||
|
||||
# # 更新密码
|
||||
# user_list.update_password("user123", "newpassword")
|
||||
|
||||
# # 获取所有用户
|
||||
# all_users = user_list.get_all_users()
|
||||
# print(all_users)
|
||||
|
||||
# # 删除用户
|
||||
# user_list.delete_user("user123")
|
||||
Reference in New Issue
Block a user