Spaces:
Runtime error
Runtime error
Commit
•
b645841
1
Parent(s):
f7a0806
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
在Streamlit中,你可以使用`st.slider`函数来创建滑条,它允许用户选择一个值。以下是一个修改后的例子:
|
2 |
+
|
3 |
+
```python
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
# 设定参数
|
7 |
+
k = st.slider('设定最低价', min_value=0, max_value=100, value=10)
|
8 |
+
h = st.slider('设定最高价', min_value=0, max_value=100, value=76)
|
9 |
+
max_score = st.slider('设定满分', min_value=0, max_value=10, value=2)
|
10 |
+
high_penalty = st.slider('设定高价扣分值', min_value=0.00, max_value=0.05, value=0.03, step=0.01)
|
11 |
+
low_penalty = st.slider('设定低价扣分值', min_value=0.00, max_value=0.05, value=0.02, step=0.01)
|
12 |
+
step = st.slider('设定迭代步长', min_value=0.01, max_value=1.00, value=0.01, step=0.01)
|
13 |
+
|
14 |
+
def score(price, base_price):
|
15 |
+
deviation_rate = (price - base_price) / base_price
|
16 |
+
if price == base_price:
|
17 |
+
return max_score
|
18 |
+
elif price > base_price:
|
19 |
+
return max(max_score - deviation_rate * 100 * high_penalty, 0)
|
20 |
+
else:
|
21 |
+
return max(max_score - abs(deviation_rate) * 100 * low_penalty, 0)
|
22 |
+
|
23 |
+
def find_range():
|
24 |
+
max_score_diff = max_score / 3 # 最大分数差距
|
25 |
+
A0_range = [k, h]
|
26 |
+
for A6_price in [k, (k+h)/2, h]:
|
27 |
+
# 找到使A0的得分不低于A6的得分的最大值的A0的报价
|
28 |
+
temp_range = [0.0, 0.0]
|
29 |
+
for A0_price in [k + x*step for x in range(int((h-k)/step) + 1)]:
|
30 |
+
base_price = (h * 2 + k * 2 + A6_price + A0_price) / 6
|
31 |
+
A6_score = score(A6_price, base_price)
|
32 |
+
A0_score = score(A0_price, base_price)
|
33 |
+
if A0_score >= A6_score - max_score_diff:
|
34 |
+
temp_range[0] = A0_price
|
35 |
+
break
|
36 |
+
# 找到使A0的得分不低于A6的得分的最小值的A0的报价
|
37 |
+
for A0_price in [h - x*step for x in range(int((h-k)/step) + 1)]:
|
38 |
+
base_price = (h * 2 + k * 2 + A6_price + A0_price) / 6
|
39 |
+
A6_score = score(A6_price, base_price)
|
40 |
+
A0_score = score(A0_price, base_price)
|
41 |
+
if A0_score >= A6_score - max_score_diff:
|
42 |
+
temp_range[1] = A0_price
|
43 |
+
break
|
44 |
+
# 取交集更新A0_range
|
45 |
+
A0_range = [max(A0_range[0], temp_range[0]), min(A0_range[1], temp_range[1])]
|
46 |
+
return A0_range
|
47 |
+
|
48 |
+
st.title('A0报价范围计算')
|
49 |
+
A0_range = find_range()
|
50 |
+
st.write(f'A0的报价范围是 {A0_range[0]} 到 {A0_range[1]}')
|