涵盖医院全部科研活动的全方位科研项目管理系统
class ResearchProject: def __init__(self, project_id, title, budget): self.project_id = project_id self.title = title self.budget = budget self.expenditures = [] def add_expenditure(self, amount, description): self.expenditures.append({"amount": amount, "description": description}) def calculate_performance(self): total_spent = sum(exp['amount'] for exp in self.expenditures) return (total_spent / self.budget) * 100
这个类包含了项目的ID、名称、预算,以及支出列表,并且提供了一个计算科研绩效的方法。
from flask import Flask, request, jsonify app = Flask(__name__) projects = {} @app.route('/project', methods=['POST']) def create_project(): data = request.get_json() project_id = data['project_id'] title = data['title'] budget = data['budget'] new_project = ResearchProject(project_id, title, budget) projects[project_id] = new_project return jsonify({"message": "Project created successfully"}), 201
这个API允许用户通过POST请求创建新的科研项目。
@app.route('/project//performance', methods=['GET']) def get_performance(project_id): if project_id not in projects: return jsonify({"error": "Project not found"}), 404 performance = projects[project_id].calculate_performance() return jsonify({"performance": f"{performance:.2f}%"})
这个接口会返回该项目的科研绩效百分比。
Copyright © 医院科研管理系统