Skip to content

Commit 6cbaa3d

Browse files
committed
add
add
1 parent 5450f95 commit 6cbaa3d

File tree

12 files changed

+267
-7
lines changed

12 files changed

+267
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ uv sync # 安装依赖
105105
source .venv/bin/activate # MacOS or Linux
106106
venv\Scripts\activate.bat # Windows
107107
# MacOS or Linux 运行这条命令
108-
ENV=DEV uvicorn app.main:app --host 0.0.0.0 --port 8000 --ws-ping-interval 60 --ws-ping-timeout 120
108+
ENV=DEV uvicorn app.main:app --host 0.0.0.0 --port 8000 --ws-ping-interval 60 --ws-ping-timeout 120 --reload
109109
# Windows 运行这条命令
110110
set ENV=DEV ; uvicorn app.main:app --host 0.0.0.0 --port 8000 --ws-ping-interval 60 --ws-ping-timeout 120
111111
```

backend/app/routers/modeling.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from app.utils.log_util import logger
66
from app.utils.redis_manager import redis_manager
77
from app.schemas.request import Problem
8-
from app.schemas.response import AgentMessage, AgentType, Message, SystemMessage
8+
from app.schemas.response import SystemMessage
99
from app.utils.common_utils import create_task_id, create_work_dir, get_config_template
1010
import os
1111
import asyncio
1212
from fastapi import HTTPException
13-
from app.utils.common_utils import md_2_docx
13+
from app.utils.common_utils import md_2_docx, get_work_dir
14+
import subprocess
15+
from icecream import ic
1416

1517
router = APIRouter()
1618

@@ -91,6 +93,23 @@ async def get_writer_seque():
9193
return list(config_template.keys())
9294

9395

96+
@router.get("/open_folder")
97+
async def open_folder(task_id: str):
98+
ic(task_id)
99+
# 打开工作目录
100+
work_dir = get_work_dir(task_id)
101+
102+
# 打开工作目录
103+
if os.name == "nt":
104+
subprocess.run(["explorer", work_dir])
105+
elif os.name == "posix":
106+
subprocess.run(["open", work_dir])
107+
else:
108+
raise HTTPException(status_code=500, detail=f"不支持的操作系统: {os.name}")
109+
110+
return {"message": "打开工作目录成功", "work_dir": work_dir}
111+
112+
94113
async def run_modeling_task_async(
95114
task_id: str,
96115
ques_all: str,

frontend/src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup lang="ts">
2+
import Toaster from '@/components/ui/toast/Toaster.vue'
23
</script>
34

45
<template>
6+
<Toaster />
57
<router-view />
68
</template>

frontend/src/apis/commonApi.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ export function getHelloWorld() {
88
export function getWriterSeque() {
99
return request.get<{ writer_seque: string[] }>("/writer_seque");
1010
}
11+
12+
13+
export function openFolderAPI(task_id: string) {
14+
return request.get<{ message: string }>("/open_folder", {
15+
params: {
16+
task_id,
17+
},
18+
});
19+
}
1.7 MB
Loading
711 KB
Loading
228 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import { ref } from 'vue'
3+
import { Button } from '@/components/ui/button'
4+
import { useRouter } from 'vue-router'
5+
6+
// 定义样例类型
7+
interface ModelingExample {
8+
id: number
9+
title: string
10+
source: string
11+
description: string
12+
tags: string[]
13+
problemText: string
14+
}
15+
16+
const router = useRouter()
17+
const examples = ref<ModelingExample[]>([
18+
{
19+
id: 1,
20+
title: "基于改进随机森林算法的农作物产量预测",
21+
source: "2023年高教社杯全国大学生数学建模竞赛",
22+
description: "通过历史气象和产量数据,建立农作物产量预测模型。",
23+
tags: ["随机森林", "数据分析", "气象预测"],
24+
problemText: "给定历年中国主要粮食作物产量数据及气象数据,建立一个预测模型,预测未来五年的粮食产量,并分析气候变化对粮食产量的影响。"
25+
},
26+
{
27+
id: 2,
28+
title: "共享单车潮汐调度优化研究",
29+
source: "2022年美国大学生数学建模竞赛",
30+
description: "针对城市高峰期共享单车分布不均问题,构建调度优化模型。",
31+
tags: ["图论", "线性规划", "智能调度"],
32+
problemText: "针对共享单车系统在早晚高峰期出现的车辆分布不均问题,构建一个优化调度模型,最小化调度成本同时满足用户需求。"
33+
},
34+
{
35+
id: 3,
36+
title: "新冠疫情传播模型与干预策略评估",
37+
source: "2021年高教社杯全国大学生数学建模竞赛",
38+
description: "基于SEIR模型改进的传染病传播预测与防控策略分析。",
39+
tags: ["微分方程", "蒙特卡洛", "策略评估"],
40+
problemText: "基于已有的疫情数据,构建传染病传播模型,模拟不同干预措施对疫情发展的影响,为防控决策提供科学依据。"
41+
}
42+
])
43+
44+
// 选择样例并跳转到任务创建步骤
45+
const selectExample = (example: ModelingExample) => {
46+
// 这里可以存储选中的样例数据到 localStorage 或 pinia store
47+
localStorage.setItem('selectedExample', JSON.stringify(example))
48+
// 跳转到任务创建流程
49+
router.push('/task/create')
50+
}
51+
52+
53+
</script>
54+
55+
<template>
56+
<div class="mt-8 mb-12">
57+
<h2 class="text-xl font-medium mb-4">样例解析</h2>
58+
<p class="text-sm text-muted-foreground mb-6">浏览历年数模竞赛优秀案例,快速开始你的建模任务</p>
59+
60+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
61+
<div v-for="example in examples" :key="example.id"
62+
class="border rounded-lg overflow-hidden hover:shadow-md transition-shadow">
63+
<div class="p-4 border-b bg-muted/30">
64+
<h3 class="font-medium line-clamp-2">{{ example.title }}</h3>
65+
<p class="text-xs text-muted-foreground mt-1">{{ example.source }}</p>
66+
</div>
67+
<div class="p-4">
68+
<p class="text-sm text-muted-foreground mb-3">{{ example.description }}</p>
69+
<div class="flex flex-wrap gap-2 mt-2 mb-3">
70+
<span v-for="tag in example.tags" :key="tag"
71+
class="px-2 py-0.5 bg-primary/10 text-primary rounded-full text-xs">
72+
{{ tag }}
73+
</span>
74+
</div>
75+
<div class="flex gap-2 mt-4">
76+
77+
<Button variant="default" size="sm" class="flex-1" @click="selectExample(example)">
78+
基于此开始
79+
</Button>
80+
</div>
81+
</div>
82+
</div>
83+
</div>
84+
</div>
85+
</template>

frontend/src/pages/chat/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
import AppSidebar from '@/components/AppSidebar.vue'
55
import UserStepper from '@/components/UserStepper.vue'
6+
import ModelingExamples from '@/components/ModelingExamples.vue'
67
import { ref, onMounted } from 'vue'
78
import {
89
SidebarInset,
@@ -37,6 +38,8 @@ onMounted(() => {
3738

3839
<UserStepper>
3940
</UserStepper>
41+
42+
<ModelingExamples />
4043
</div>
4144
</div>
4245
</SidebarInset>
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<script setup lang="ts">
2+
import { ref, onMounted } from 'vue'
3+
import { useRoute, useRouter } from 'vue-router'
4+
import { Button } from '@/components/ui/button'
5+
6+
interface ModelingExample {
7+
id: number
8+
title: string
9+
source: string
10+
description: string
11+
tags: string[]
12+
problemText: string
13+
}
14+
15+
const route = useRoute()
16+
const router = useRouter()
17+
const exampleId = route.params.id as string
18+
const example = ref<ModelingExample | null>(null)
19+
const loading = ref(true)
20+
21+
onMounted(() => {
22+
// 从localStorage获取样例数据
23+
const storedExample = localStorage.getItem('viewingExample')
24+
if (storedExample) {
25+
example.value = JSON.parse(storedExample)
26+
loading.value = false
27+
} else {
28+
// 如果没有找到缓存的数据,可以模拟一个API请求
29+
// 实际项目中应该从API获取
30+
setTimeout(() => {
31+
example.value = {
32+
id: parseInt(exampleId),
33+
title: "数学建模样例案例",
34+
source: "全国大学生数学建模竞赛",
35+
description: "这是一个示例数模案例。",
36+
tags: ["数据分析", "算法优化"],
37+
problemText: "这里是完整的竞赛题目描述文本。"
38+
}
39+
loading.value = false
40+
}, 800)
41+
}
42+
})
43+
44+
// 基于当前样例开始新任务
45+
const startModelingTask = () => {
46+
if (example.value) {
47+
localStorage.setItem('selectedExample', JSON.stringify(example.value))
48+
router.push('/task/create')
49+
}
50+
}
51+
52+
// 返回样例列表
53+
const goBack = () => {
54+
router.push('/chat')
55+
}
56+
</script>
57+
58+
<template>
59+
<div class="container mx-auto py-8 px-4 max-w-4xl">
60+
<Button variant="ghost" class="mb-6" @click="goBack">
61+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
62+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="mr-2">
63+
<path d="m15 18-6-6 6-6" />
64+
</svg>
65+
返回首页
66+
</Button>
67+
68+
<div v-if="loading" class="flex justify-center py-12">
69+
<div class="animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"></div>
70+
</div>
71+
72+
<div v-else-if="example" class="space-y-8">
73+
<div class="space-y-4">
74+
<h1 class="text-2xl font-semibold">{{ example.title }}</h1>
75+
<p class="text-muted-foreground">{{ example.source }}</p>
76+
<div class="flex flex-wrap gap-2 mt-4">
77+
<span v-for="tag in example.tags" :key="tag"
78+
class="px-3 py-1 bg-primary/10 text-primary rounded-full text-sm">
79+
{{ tag }}
80+
</span>
81+
</div>
82+
</div>
83+
84+
<div class="space-y-4">
85+
<h2 class="text-xl font-medium">题目描述</h2>
86+
<div class="p-6 border rounded-lg bg-muted/20">
87+
<p class="whitespace-pre-line">{{ example.problemText }}</p>
88+
</div>
89+
</div>
90+
91+
<div class="space-y-4">
92+
<h2 class="text-xl font-medium">解题思路</h2>
93+
<div class="p-6 border rounded-lg">
94+
<ol class="list-decimal list-inside space-y-3">
95+
<li>分析问题背景和关键变量</li>
96+
<li>收集和预处理相关数据</li>
97+
<li>构建数学模型并确定算法</li>
98+
<li>实现代码并训练模型</li>
99+
<li>验证模型并分析结果</li>
100+
<li>撰写论文并呈现结论</li>
101+
</ol>
102+
</div>
103+
</div>
104+
105+
<div class="flex justify-center pt-6">
106+
<Button size="lg" @click="startModelingTask">
107+
基于此案例开始建模
108+
</Button>
109+
</div>
110+
</div>
111+
112+
<div v-else class="text-center py-12">
113+
<p>未找到相关样例</p>
114+
<Button variant="outline" class="mt-4" @click="goBack">返回首页</Button>
115+
</div>
116+
</div>
117+
</template>

0 commit comments

Comments
 (0)