python 需求排序管理系统
时间: 2023-07-25 12:45:38 浏览: 120
好的,一个简单的需求排序管理系统可以包含以下功能:
1. 添加需求:用户可以添加新的需求,包括需求名称、需求描述、优先级等信息。
2. 查看需求列表:用户可以查看所有的需求,并按照不同的排序方式进行排序,如按照优先级、创建时间等排序。
3. 修改需求:用户可以修改已有的需求信息。
4. 删除需求:用户可以删除已有的需求。
5. 保存和加载:系统可以将所有需求保存到本地文件中,并在下次打开时自动加载之前保存的需求。
以下是一个简单的 Python 实现:
```python
import json
import time
class Requirement:
def __init__(self, name, description, priority):
self.name = name
self.description = description
self.priority = priority
self.created_time = time.time()
def __str__(self):
return f'Name: {self.name}\nDescription: {self.description}\nPriority: {self.priority}\nCreated Time: {time.ctime(self.created_time)}\n'
class RequirementList:
def __init__(self):
self.requirements = []
def add_requirement(self, requirement):
self.requirements.append(requirement)
def remove_requirement(self, index):
del self.requirements[index]
def get_requirements(self, sort_key='priority'):
return sorted(self.requirements, key=lambda x: getattr(x, sort_key))
def save(self, filename):
with open(filename, 'w') as f:
json.dump([ob.__dict__ for ob in self.requirements], f)
def load(self, filename):
with open(filename, 'r') as f:
data = json.load(f)
self.requirements = [Requirement(ob['name'], ob['description'], ob['priority']) for ob in data]
def menu():
print('Requirement Management System')
print('1. Add Requirement')
print('2. View Requirements')
print('3. Modify Requirement')
print('4. Delete Requirement')
print('5. Save to File')
print('6. Load from File')
print('7. Quit')
if __name__ == '__main__':
requirement_list = RequirementList()
while True:
menu()
choice = input('Enter your choice: ')
if choice == '1':
name = input('Enter requirement name: ')
description = input('Enter requirement description: ')
priority = int(input('Enter requirement priority: '))
requirement = Requirement(name, description, priority)
requirement_list.add_requirement(requirement)
print('Requirement added successfully!')
elif choice == '2':
sort_key = input('Enter sorting key (priority/created_time): ')
requirements = requirement_list.get_requirements(sort_key)
for index, requirement in enumerate(requirements):
print(f'Requirement {index+1}:')
print(requirement)
elif choice == '3':
index = int(input('Enter requirement index: '))
name = input('Enter requirement name: ')
description = input('Enter requirement description: ')
priority = int(input('Enter requirement priority: '))
requirement = Requirement(name, description, priority)
requirement_list.requirements[index] = requirement
print('Requirement modified successfully!')
elif choice == '4':
index = int(input('Enter requirement index: '))
requirement_list.remove_requirement(index)
print('Requirement deleted successfully!')
elif choice == '5':
filename = input('Enter filename to save: ')
requirement_list.save(filename)
print('Requirements saved successfully!')
elif choice == '6':
filename = input('Enter filename to load: ')
requirement_list.load(filename)
print('Requirements loaded successfully!')
elif choice == '7':
print('Exiting...')
break
else:
print('Invalid choice, please try again!')
```
这段代码包含了一个 Requirement 类和一个 RequirementList 类。Requirement 类表示某一个具体的需求,包含需求名称、需求描述、优先级和创建时间等信息。RequirementList 类表示整个需求列表,包括添加需求、删除需求、获取需求列表、保存到文件和从文件中加载等功能。用户可以通过菜单界面来执行不同的操作。需要注意的是,这里我们将需求信息保存到一个 JSON 文件中,如果需求信息较多,可以考虑使用数据库来存储。
阅读全文