Download data/test/dynogen_easy_030/server.py from bPtBvkTP/DynoGen-Benchmark: direct link, hf CLI and curl.
- Browser
- Download file 4.41 kB
-
https://huggingface.co/datasets/bPtBvkTP/DynoGen-Benchmark/resolve/main/data/test/dynogen_easy_030/server.py
- Command line
-
hf download hf://datasets/bPtBvkTP/DynoGen-Benchmark/data/test/dynogen_easy_030/server.py
-
curl -L -o server.py https://huggingface.co/datasets/bPtBvkTP/DynoGen-Benchmark/resolve/main/data/test/dynogen_easy_030/server.py
4.41 kB
| from flask import Flask, request, jsonify | |
| from flask_cors import CORS | |
| import random | |
| import datetime | |
| app = Flask(__name__) | |
| CORS(app) | |
| # 模拟数据 | |
| cache_configs = [ | |
| { | |
| "id": "1", | |
| "moduleName": "用户管理", | |
| "cacheKeyPrefix": "user:", | |
| "expirationTime": 3600, | |
| "updateStrategy": "实时", | |
| "owner": "张三", | |
| "updateTime": "2024-01-15 10:30:00" | |
| }, | |
| { | |
| "id": "2", | |
| "moduleName": "商品管理", | |
| "cacheKeyPrefix": "product:", | |
| "expirationTime": 7200, | |
| "updateStrategy": "定时", | |
| "owner": "李四", | |
| "updateTime": "2024-01-14 15:20:00" | |
| }, | |
| { | |
| "id": "3", | |
| "moduleName": "订单管理", | |
| "cacheKeyPrefix": "order:", | |
| "expirationTime": 1800, | |
| "updateStrategy": "实时", | |
| "owner": "王五", | |
| "updateTime": "2024-01-13 09:15:00" | |
| }, | |
| { | |
| "id": "4", | |
| "moduleName": "库存管理", | |
| "cacheKeyPrefix": "inventory:", | |
| "expirationTime": 600, | |
| "updateStrategy": "实时", | |
| "owner": "赵六", | |
| "updateTime": "2024-01-12 14:45:00" | |
| }, | |
| { | |
| "id": "5", | |
| "moduleName": "支付管理", | |
| "cacheKeyPrefix": "payment:", | |
| "expirationTime": 300, | |
| "updateStrategy": "定时", | |
| "owner": "钱七", | |
| "updateTime": "2024-01-11 11:30:00" | |
| } | |
| ] | |
| def get_cache_config_list(): | |
| module_id = request.args.get('moduleId', '') | |
| page_size = int(request.args.get('pageSize', 20)) | |
| page_num = int(request.args.get('pageNum', 1)) | |
| # 过滤数据 | |
| filtered_data = cache_configs | |
| if module_id: | |
| filtered_data = [config for config in cache_configs if module_id.lower() in config['moduleName'].lower()] | |
| # 分页 | |
| total = len(filtered_data) | |
| start_index = (page_num - 1) * page_size | |
| end_index = start_index + page_size | |
| page_data = filtered_data[start_index:end_index] | |
| return jsonify({ | |
| "code": 200, | |
| "message": "success", | |
| "data": { | |
| "list": page_data, | |
| "total": total, | |
| "pageSize": page_size, | |
| "pageNum": page_num | |
| } | |
| }) | |
| def get_cache_config_detail(): | |
| config_id = request.args.get('id') | |
| config = next((c for c in cache_configs if c['id'] == config_id), None) | |
| if config: | |
| return jsonify({ | |
| "code": 200, | |
| "message": "success", | |
| "data": config | |
| }) | |
| else: | |
| return jsonify({ | |
| "code": 404, | |
| "message": "配置不存在" | |
| }) | |
| def save_cache_config(): | |
| data = request.get_json() | |
| if data.get('id'): | |
| # 更新 | |
| for i, config in enumerate(cache_configs): | |
| if config['id'] == data['id']: | |
| cache_configs[i].update({ | |
| "moduleName": data['moduleName'], | |
| "cacheKeyPrefix": data['cacheKeyPrefix'], | |
| "expirationTime": data['expirationTime'], | |
| "updateStrategy": data['updateStrategy'], | |
| "owner": data['owner'], | |
| "updateTime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| }) | |
| break | |
| else: | |
| # 新增 | |
| new_config = { | |
| "id": str(len(cache_configs) + 1), | |
| "moduleName": data['moduleName'], | |
| "cacheKeyPrefix": data['cacheKeyPrefix'], | |
| "expirationTime": data['expirationTime'], | |
| "updateStrategy": data['updateStrategy'], | |
| "owner": data['owner'], | |
| "updateTime": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| } | |
| cache_configs.append(new_config) | |
| return jsonify({ | |
| "code": 200, | |
| "message": "保存成功" | |
| }) | |
| def delete_cache_config(): | |
| data = request.get_json() | |
| config_id = data.get('id') | |
| global cache_configs | |
| cache_configs = [config for config in cache_configs if config['id'] != config_id] | |
| return jsonify({ | |
| "code": 200, | |
| "message": "删除成功" | |
| }) | |
| if __name__ == '__main__': | |
| app.run(debug=True, host='0.0.0.0', port=5000) |