siat 3.10.131__py3-none-any.whl → 3.10.132__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- build/lib/build/lib/siat/__init__.py +75 -0
- build/lib/build/lib/siat/allin.py +137 -0
- build/lib/build/lib/siat/assets_liquidity.py +915 -0
- build/lib/build/lib/siat/beta_adjustment.py +1058 -0
- build/lib/build/lib/siat/beta_adjustment_china.py +548 -0
- build/lib/build/lib/siat/blockchain.py +143 -0
- build/lib/build/lib/siat/bond.py +2900 -0
- build/lib/build/lib/siat/bond_base.py +992 -0
- build/lib/build/lib/siat/bond_china.py +100 -0
- build/lib/build/lib/siat/bond_zh_sina.py +143 -0
- build/lib/build/lib/siat/capm_beta.py +783 -0
- build/lib/build/lib/siat/capm_beta2.py +887 -0
- build/lib/build/lib/siat/common.py +5360 -0
- build/lib/build/lib/siat/compare_cross.py +642 -0
- build/lib/build/lib/siat/copyrights.py +18 -0
- build/lib/build/lib/siat/cryptocurrency.py +667 -0
- build/lib/build/lib/siat/economy.py +1471 -0
- build/lib/build/lib/siat/economy2.py +1853 -0
- build/lib/build/lib/siat/esg.py +536 -0
- build/lib/build/lib/siat/event_study.py +815 -0
- build/lib/build/lib/siat/fama_french.py +1521 -0
- build/lib/build/lib/siat/fin_stmt2_yahoo.py +982 -0
- build/lib/build/lib/siat/financial_base.py +1160 -0
- build/lib/build/lib/siat/financial_statements.py +598 -0
- build/lib/build/lib/siat/financials.py +2339 -0
- build/lib/build/lib/siat/financials2.py +1278 -0
- build/lib/build/lib/siat/financials_china.py +4433 -0
- build/lib/build/lib/siat/financials_china2.py +2212 -0
- build/lib/build/lib/siat/fund.py +629 -0
- build/lib/build/lib/siat/fund_china.py +3307 -0
- build/lib/build/lib/siat/future_china.py +551 -0
- build/lib/build/lib/siat/google_authenticator.py +47 -0
- build/lib/build/lib/siat/grafix.py +3636 -0
- build/lib/build/lib/siat/holding_risk.py +867 -0
- build/lib/build/lib/siat/luchy_draw.py +638 -0
- build/lib/build/lib/siat/market_china.py +1168 -0
- build/lib/build/lib/siat/markowitz.py +2363 -0
- build/lib/build/lib/siat/markowitz2.py +3150 -0
- build/lib/build/lib/siat/markowitz2_20250704.py +2969 -0
- build/lib/build/lib/siat/markowitz2_20250705.py +3158 -0
- build/lib/build/lib/siat/markowitz_simple.py +373 -0
- build/lib/build/lib/siat/ml_cases.py +2291 -0
- build/lib/build/lib/siat/ml_cases_example.py +60 -0
- build/lib/build/lib/siat/option_china.py +3069 -0
- build/lib/build/lib/siat/option_pricing.py +1925 -0
- build/lib/build/lib/siat/other_indexes.py +409 -0
- build/lib/build/lib/siat/risk_adjusted_return.py +1576 -0
- build/lib/build/lib/siat/risk_adjusted_return2.py +1900 -0
- build/lib/build/lib/siat/risk_evaluation.py +2218 -0
- build/lib/build/lib/siat/risk_free_rate.py +351 -0
- build/lib/build/lib/siat/sector_china.py +4140 -0
- build/lib/build/lib/siat/security_price2.py +727 -0
- build/lib/build/lib/siat/security_prices.py +3408 -0
- build/lib/build/lib/siat/security_trend.py +402 -0
- build/lib/build/lib/siat/security_trend2.py +646 -0
- build/lib/build/lib/siat/stock.py +4284 -0
- build/lib/build/lib/siat/stock_advice_linear.py +934 -0
- build/lib/build/lib/siat/stock_base.py +26 -0
- build/lib/build/lib/siat/stock_china.py +2095 -0
- build/lib/build/lib/siat/stock_prices_kneighbors.py +910 -0
- build/lib/build/lib/siat/stock_prices_linear.py +386 -0
- build/lib/build/lib/siat/stock_profile.py +707 -0
- build/lib/build/lib/siat/stock_technical.py +3305 -0
- build/lib/build/lib/siat/stooq.py +74 -0
- build/lib/build/lib/siat/transaction.py +347 -0
- build/lib/build/lib/siat/translate.py +5183 -0
- build/lib/build/lib/siat/valuation.py +1378 -0
- build/lib/build/lib/siat/valuation_china.py +2076 -0
- build/lib/build/lib/siat/var_model_validation.py +444 -0
- build/lib/build/lib/siat/yf_name.py +811 -0
- build/lib/siat/__init__.py +75 -0
- build/lib/siat/allin.py +137 -0
- build/lib/siat/assets_liquidity.py +915 -0
- build/lib/siat/beta_adjustment.py +1058 -0
- build/lib/siat/beta_adjustment_china.py +548 -0
- build/lib/siat/blockchain.py +143 -0
- build/lib/siat/bond.py +2900 -0
- build/lib/siat/bond_base.py +992 -0
- build/lib/siat/bond_china.py +100 -0
- build/lib/siat/bond_zh_sina.py +143 -0
- build/lib/siat/capm_beta.py +783 -0
- build/lib/siat/capm_beta2.py +887 -0
- build/lib/siat/common.py +5360 -0
- build/lib/siat/compare_cross.py +642 -0
- build/lib/siat/copyrights.py +18 -0
- build/lib/siat/cryptocurrency.py +667 -0
- build/lib/siat/economy.py +1471 -0
- build/lib/siat/economy2.py +1853 -0
- build/lib/siat/esg.py +536 -0
- build/lib/siat/event_study.py +815 -0
- build/lib/siat/fama_french.py +1521 -0
- build/lib/siat/fin_stmt2_yahoo.py +982 -0
- build/lib/siat/financial_base.py +1160 -0
- build/lib/siat/financial_statements.py +598 -0
- build/lib/siat/financials.py +2339 -0
- build/lib/siat/financials2.py +1278 -0
- build/lib/siat/financials_china.py +4433 -0
- build/lib/siat/financials_china2.py +2212 -0
- build/lib/siat/fund.py +629 -0
- build/lib/siat/fund_china.py +3307 -0
- build/lib/siat/future_china.py +551 -0
- build/lib/siat/google_authenticator.py +47 -0
- build/lib/siat/grafix.py +3636 -0
- build/lib/siat/holding_risk.py +867 -0
- build/lib/siat/luchy_draw.py +638 -0
- build/lib/siat/market_china.py +1168 -0
- build/lib/siat/markowitz.py +2363 -0
- build/lib/siat/markowitz2.py +3150 -0
- build/lib/siat/markowitz2_20250704.py +2969 -0
- build/lib/siat/markowitz2_20250705.py +3158 -0
- build/lib/siat/markowitz_simple.py +373 -0
- build/lib/siat/ml_cases.py +2291 -0
- build/lib/siat/ml_cases_example.py +60 -0
- build/lib/siat/option_china.py +3069 -0
- build/lib/siat/option_pricing.py +1925 -0
- build/lib/siat/other_indexes.py +409 -0
- build/lib/siat/risk_adjusted_return.py +1576 -0
- build/lib/siat/risk_adjusted_return2.py +1900 -0
- build/lib/siat/risk_evaluation.py +2218 -0
- build/lib/siat/risk_free_rate.py +351 -0
- build/lib/siat/sector_china.py +4140 -0
- build/lib/siat/security_price2.py +727 -0
- build/lib/siat/security_prices.py +3408 -0
- build/lib/siat/security_trend.py +402 -0
- build/lib/siat/security_trend2.py +646 -0
- build/lib/siat/stock.py +4284 -0
- build/lib/siat/stock_advice_linear.py +934 -0
- build/lib/siat/stock_base.py +26 -0
- build/lib/siat/stock_china.py +2095 -0
- build/lib/siat/stock_prices_kneighbors.py +910 -0
- build/lib/siat/stock_prices_linear.py +386 -0
- build/lib/siat/stock_profile.py +707 -0
- build/lib/siat/stock_technical.py +3305 -0
- build/lib/siat/stooq.py +74 -0
- build/lib/siat/transaction.py +347 -0
- build/lib/siat/translate.py +5183 -0
- build/lib/siat/valuation.py +1378 -0
- build/lib/siat/valuation_china.py +2076 -0
- build/lib/siat/var_model_validation.py +444 -0
- build/lib/siat/yf_name.py +811 -0
- siat/__init__.py +0 -0
- siat/allin.py +0 -0
- siat/assets_liquidity.py +0 -0
- siat/beta_adjustment.py +0 -0
- siat/beta_adjustment_china.py +0 -0
- siat/blockchain.py +0 -0
- siat/bond.py +0 -0
- siat/bond_base.py +0 -0
- siat/bond_china.py +0 -0
- siat/bond_zh_sina.py +0 -0
- siat/capm_beta.py +0 -0
- siat/capm_beta2.py +0 -0
- siat/common.py +136 -3
- siat/compare_cross.py +0 -0
- siat/copyrights.py +0 -0
- siat/cryptocurrency.py +0 -0
- siat/economy.py +0 -0
- siat/economy2.py +0 -0
- siat/esg.py +0 -0
- siat/event_study.py +0 -0
- siat/exchange_bond_china.pickle +0 -0
- siat/fama_french.py +0 -0
- siat/fin_stmt2_yahoo.py +0 -0
- siat/financial_base.py +0 -0
- siat/financial_statements.py +0 -0
- siat/financials.py +0 -0
- siat/financials2.py +0 -0
- siat/financials_china.py +0 -0
- siat/financials_china2.py +0 -0
- siat/fund.py +0 -0
- siat/fund_china.pickle +0 -0
- siat/fund_china.py +0 -0
- siat/future_china.py +0 -0
- siat/google_authenticator.py +0 -0
- siat/grafix.py +1 -1
- siat/holding_risk.py +0 -0
- siat/luchy_draw.py +0 -0
- siat/market_china.py +1 -1
- siat/markowitz.py +0 -0
- siat/markowitz2.py +240 -39
- siat/markowitz2_20250704.py +2969 -0
- siat/markowitz2_20250705.py +3158 -0
- siat/markowitz_simple.py +0 -0
- siat/ml_cases.py +0 -0
- siat/ml_cases_example.py +0 -0
- siat/option_china.py +0 -0
- siat/option_pricing.py +0 -0
- siat/other_indexes.py +0 -0
- siat/risk_adjusted_return.py +0 -0
- siat/risk_adjusted_return2.py +0 -0
- siat/risk_evaluation.py +0 -0
- siat/risk_free_rate.py +0 -0
- siat/sector_china.py +0 -0
- siat/security_price2.py +0 -0
- siat/security_prices.py +3 -1
- siat/security_trend.py +0 -0
- siat/security_trend2.py +1 -1
- siat/stock.py +4 -2
- siat/stock_advice_linear.py +0 -0
- siat/stock_base.py +0 -0
- siat/stock_china.py +0 -0
- siat/stock_info.pickle +0 -0
- siat/stock_prices_kneighbors.py +0 -0
- siat/stock_prices_linear.py +0 -0
- siat/stock_profile.py +0 -0
- siat/stock_technical.py +0 -0
- siat/stooq.py +0 -0
- siat/transaction.py +0 -0
- siat/translate.py +11 -11
- siat/valuation.py +0 -0
- siat/valuation_china.py +0 -0
- siat/var_model_validation.py +0 -0
- siat/yf_name.py +0 -0
- {siat-3.10.131.dist-info → siat-3.10.132.dist-info}/METADATA +235 -227
- siat-3.10.132.dist-info/RECORD +218 -0
- {siat-3.10.131.dist-info → siat-3.10.132.dist-info}/WHEEL +1 -1
- {siat-3.10.131.dist-info → siat-3.10.132.dist-info/licenses}/LICENSE +0 -0
- siat-3.10.132.dist-info/top_level.txt +4 -0
- siat-3.10.131.dist-info/RECORD +0 -76
- siat-3.10.131.dist-info/top_level.txt +0 -1
@@ -0,0 +1,638 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
"""
|
4
|
+
本模块功能:幸运抽奖,仅限课堂案例演示用
|
5
|
+
创建日期:2024年6月29日
|
6
|
+
最新修订日期:
|
7
|
+
作者:王德宏 (WANG Dehong, Peter)
|
8
|
+
作者单位:北京外国语大学国际商学院
|
9
|
+
用途限制:仅限研究与教学使用,不可商用!商用需要额外授权。
|
10
|
+
特别声明:作者不对使用本工具进行证券投资导致的任何损益负责!
|
11
|
+
"""
|
12
|
+
|
13
|
+
#==============================================================================
|
14
|
+
#关闭所有警告
|
15
|
+
import warnings; warnings.filterwarnings('ignore')
|
16
|
+
import warnings; warnings.filterwarnings('ignore')
|
17
|
+
|
18
|
+
import pandas as pd
|
19
|
+
import pickle
|
20
|
+
import random
|
21
|
+
import datetime
|
22
|
+
import time
|
23
|
+
import os
|
24
|
+
from IPython.display import display_html, HTML
|
25
|
+
|
26
|
+
#==============================================================================
|
27
|
+
|
28
|
+
def current_dir(printout=True):
|
29
|
+
"""
|
30
|
+
功能:找出当前路径
|
31
|
+
"""
|
32
|
+
|
33
|
+
current_path = os.getcwd()
|
34
|
+
|
35
|
+
if printout:
|
36
|
+
print(f"[Current path] {current_path}")
|
37
|
+
|
38
|
+
return current_path
|
39
|
+
|
40
|
+
#==============================================================================
|
41
|
+
if __name__=='__main__':
|
42
|
+
file_path="S:\北外工作-24春\小学期-人大\学生名单\student_list.xlsx"
|
43
|
+
pickle_path="student_list.pkl"
|
44
|
+
|
45
|
+
existing(file_path)
|
46
|
+
existing(pickle_path)
|
47
|
+
|
48
|
+
|
49
|
+
def existing(file_path):
|
50
|
+
"""
|
51
|
+
功能:检查文件file_path是否存在,不带路径时检查当前目录
|
52
|
+
"""
|
53
|
+
# 检查文件是否存在
|
54
|
+
if os.path.exists(file_path):
|
55
|
+
if os.path.isfile(file_path):
|
56
|
+
return True
|
57
|
+
else:
|
58
|
+
return False
|
59
|
+
else:
|
60
|
+
return False
|
61
|
+
|
62
|
+
#==============================================================================
|
63
|
+
if __name__=='__main__':
|
64
|
+
text="A B C"
|
65
|
+
text_color='red'
|
66
|
+
text_size=12
|
67
|
+
delay=1
|
68
|
+
|
69
|
+
typewriter(text,text_color='red',text_size=12,delay=1)
|
70
|
+
|
71
|
+
def typewriter(text,text_color='blue',text_size=12,delay=3):
|
72
|
+
"""
|
73
|
+
功能:居中显示带颜色的大字体
|
74
|
+
"""
|
75
|
+
from IPython.display import display_html
|
76
|
+
|
77
|
+
time.sleep(delay)
|
78
|
+
|
79
|
+
text_html="<center><font size="+str(text_size)+" color="+text_color+">"+text
|
80
|
+
display_html(text_html, raw=True)
|
81
|
+
|
82
|
+
return
|
83
|
+
|
84
|
+
#==============================================================================
|
85
|
+
|
86
|
+
def pickle_write(df,pickle_path,overlap_confirm=True):
|
87
|
+
|
88
|
+
ok2go=True
|
89
|
+
|
90
|
+
if overlap_confirm:
|
91
|
+
cur_dir=current_dir(printout=False)
|
92
|
+
|
93
|
+
prompt=pickle_path+" already exists in "+cur_dir+", overwrite it?"
|
94
|
+
file_exist=existing(pickle_path)
|
95
|
+
if file_exist:
|
96
|
+
#是否覆盖已经存在的文件
|
97
|
+
yes=read_yes_no(prompt, default=None)
|
98
|
+
if not yes:
|
99
|
+
ok2go=False
|
100
|
+
|
101
|
+
if ok2go:
|
102
|
+
with open(pickle_path, 'wb') as pickle_file:
|
103
|
+
# 使用pickle模块的dump函数写入对象
|
104
|
+
pickle.dump(df,pickle_file)
|
105
|
+
|
106
|
+
return
|
107
|
+
|
108
|
+
if __name__=='__main__':
|
109
|
+
course="SICS RUC24"
|
110
|
+
file_path="S:\北外工作-24春\小学期-人大\学生名单\student_list.xlsx"
|
111
|
+
pickle_path="student_list.pkl"
|
112
|
+
skiprows=1
|
113
|
+
column='Name'
|
114
|
+
|
115
|
+
draw_limit=2
|
116
|
+
absent_limit=2
|
117
|
+
pass_limit=2
|
118
|
+
|
119
|
+
lucky_draw_header_create(course,file_path, \
|
120
|
+
skiprows=1,column='Name',draw_limit=2, \
|
121
|
+
absent_limit=2,pass_limit=2)
|
122
|
+
pickle_read(pickle_path=course+' header.pkl')
|
123
|
+
|
124
|
+
|
125
|
+
def lucky_draw_header_create(course,file_path, \
|
126
|
+
skiprows=1,column='Name',draw_limit=2, \
|
127
|
+
absent_limit=2,pass_limit=2):
|
128
|
+
"""
|
129
|
+
功能:创建随机点名头文件,存储随机点名的参数信息
|
130
|
+
"""
|
131
|
+
|
132
|
+
pickle_path=course+" detail.pkl"
|
133
|
+
header_path=course+" header.pkl"
|
134
|
+
cur_dir=current_dir(printout=False)
|
135
|
+
|
136
|
+
header_dict={'course':course,'file_path':file_path,'pickle_path':pickle_path, \
|
137
|
+
'skiprows':skiprows,'column':column,'draw_limit':draw_limit, \
|
138
|
+
'absent_limit':absent_limit,'pass_limit':pass_limit}
|
139
|
+
|
140
|
+
pickle_write(header_dict,header_path)
|
141
|
+
print(header_path,"is created in",cur_dir)
|
142
|
+
|
143
|
+
return
|
144
|
+
|
145
|
+
if __name__=='__main__':
|
146
|
+
course="SICS RUC24"
|
147
|
+
|
148
|
+
lucky_draw_header_modify(course,draw_limit=3)
|
149
|
+
pickle_read(pickle_path=course+' header.pkl')
|
150
|
+
|
151
|
+
def lucky_draw_header_modify(course,file_path="current",pickle_path="current", \
|
152
|
+
skiprows="current",column="current",draw_limit="current", \
|
153
|
+
absent_limit="current",pass_limit="current"):
|
154
|
+
|
155
|
+
header_path=course+" header.pkl"
|
156
|
+
header_dict=pickle_read(header_path)
|
157
|
+
cur_dir=current_dir(printout=False)
|
158
|
+
|
159
|
+
if file_path !='current':
|
160
|
+
header_dict['file_path']=file_path
|
161
|
+
else:
|
162
|
+
file_path=header_dict['file_path']
|
163
|
+
|
164
|
+
if pickle_path !='current':
|
165
|
+
header_dict['pickle_path']=pickle_path
|
166
|
+
else:
|
167
|
+
pickle_path=header_dict['pickle_path']
|
168
|
+
|
169
|
+
if skiprows !='current':
|
170
|
+
header_dict['skiprows']=skiprows
|
171
|
+
else:
|
172
|
+
skiprows=header_dict['skiprows']
|
173
|
+
|
174
|
+
if column !='current':
|
175
|
+
header_dict['column']=column
|
176
|
+
else:
|
177
|
+
column=header_dict['column']
|
178
|
+
|
179
|
+
if draw_limit !='current':
|
180
|
+
header_dict['draw_limit']=draw_limit
|
181
|
+
else:
|
182
|
+
draw_limit=header_dict['draw_limit']
|
183
|
+
|
184
|
+
if absent_limit !='current':
|
185
|
+
header_dict['absent_limit']=absent_limit
|
186
|
+
else:
|
187
|
+
absent_limit=header_dict['absent_limit']
|
188
|
+
|
189
|
+
if pass_limit !='current':
|
190
|
+
header_dict['pass_limit']=pass_limit
|
191
|
+
else:
|
192
|
+
pass_limit=header_dict['pass_limit']
|
193
|
+
|
194
|
+
header_dict={'course':course,'file_path':file_path,'pickle_path':pickle_path, \
|
195
|
+
'skiprows':skiprows,'column':column,'draw_limit':draw_limit, \
|
196
|
+
'absent_limit':absent_limit,'pass_limit':pass_limit}
|
197
|
+
|
198
|
+
pickle_write(header_dict,header_path,overlap_confirm=False)
|
199
|
+
print(header_path,"is modified in",cur_dir)
|
200
|
+
|
201
|
+
return
|
202
|
+
|
203
|
+
#==============================================================================
|
204
|
+
if __name__=='__main__':
|
205
|
+
course="SICS RUC24"
|
206
|
+
lucky_draw_detail_create(course)
|
207
|
+
pickle_read(course+" detail.pkl")
|
208
|
+
|
209
|
+
|
210
|
+
def lucky_draw_detail_create(course):
|
211
|
+
"""
|
212
|
+
功能:创建随机点名明细文件,记录随机点名的过程
|
213
|
+
"""
|
214
|
+
#读取参数信息
|
215
|
+
header_path=course+" header.pkl"
|
216
|
+
header_dict=pickle_read(header_path)
|
217
|
+
detail_path=header_dict['pickle_path']
|
218
|
+
cur_dir=current_dir(printout=False)
|
219
|
+
|
220
|
+
#读取学生名单
|
221
|
+
df = pd.read_excel(header_dict['file_path'],skiprows=header_dict['skiprows'])
|
222
|
+
df1=df[[header_dict['column']]].copy()
|
223
|
+
|
224
|
+
todaydt = str(datetime.date.today())
|
225
|
+
df1['Date']=todaydt
|
226
|
+
df1['Lucky']=0
|
227
|
+
df1['Absent']=0
|
228
|
+
df1['Pass']=0
|
229
|
+
|
230
|
+
#排序
|
231
|
+
df1.sort_values(by=[header_dict['column'],'Date','Lucky','Absent','Pass'],inplace=True)
|
232
|
+
df1.reset_index(drop=True,inplace=True)
|
233
|
+
df1.index=df1.index + 1
|
234
|
+
|
235
|
+
pickle_write(df1,detail_path)
|
236
|
+
print(detail_path,"is created in",cur_dir)
|
237
|
+
|
238
|
+
return
|
239
|
+
|
240
|
+
if __name__=='__main__':
|
241
|
+
course="SICS RUC24"
|
242
|
+
|
243
|
+
lucky_draw_detail_add(course,name="Liu Chixin")
|
244
|
+
lucky_draw_detail_add(course,name=["Liu Chixin","Zhang San Feng","Li Si Ye"])
|
245
|
+
|
246
|
+
pickle_read(course+" detail.pkl")
|
247
|
+
|
248
|
+
|
249
|
+
def lucky_draw_detail_add(course,name):
|
250
|
+
"""
|
251
|
+
功能:在随机点名明细文件中增加一个名字,支持批量增加
|
252
|
+
"""
|
253
|
+
#读取参数信息
|
254
|
+
header_path=course+" header.pkl"
|
255
|
+
header_dict=pickle_read(header_path)
|
256
|
+
|
257
|
+
#读取明细文件
|
258
|
+
detail_path=header_dict['pickle_path']
|
259
|
+
df=pickle_read(detail_path)
|
260
|
+
|
261
|
+
todaydt = str(datetime.date.today())
|
262
|
+
|
263
|
+
if isinstance(name,str):
|
264
|
+
name=[name]
|
265
|
+
|
266
|
+
added=False
|
267
|
+
for n in name:
|
268
|
+
#重名检查
|
269
|
+
if n in list(df[header_dict['column']]):
|
270
|
+
print(n,"is already in file, no need to add")
|
271
|
+
continue
|
272
|
+
|
273
|
+
#增加名单
|
274
|
+
added=True
|
275
|
+
row=pd.Series({header_dict['column']:n,'Date':todaydt,'Lucky':0,'Absent':0,'Pass':0})
|
276
|
+
try:
|
277
|
+
df=df.append(row,ignore_index=True)
|
278
|
+
except:
|
279
|
+
df=df._append(row,ignore_index=True)
|
280
|
+
|
281
|
+
print(n,"is added into file")
|
282
|
+
|
283
|
+
#写回明细文件
|
284
|
+
if added:
|
285
|
+
pickle_write(df,detail_path,overlap_confirm=False)
|
286
|
+
|
287
|
+
return
|
288
|
+
|
289
|
+
#==============================================================================
|
290
|
+
if __name__=='__main__':
|
291
|
+
course="SICS RUC24"
|
292
|
+
|
293
|
+
lucky_draw_detail_remove(course,name="Liu Chixin")
|
294
|
+
lucky_draw_detail_remove(course,name=["Liu Chixin","Zhang San Feng","Li Si Ye"])
|
295
|
+
pickle_read(course+" detail.pkl")
|
296
|
+
|
297
|
+
|
298
|
+
def lucky_draw_detail_remove(course,name):
|
299
|
+
"""
|
300
|
+
功能:在随机点名明细文件中删除一个名字的所有记录,支持批量删除
|
301
|
+
"""
|
302
|
+
#读取参数信息
|
303
|
+
header_path=course+" header.pkl"
|
304
|
+
header_dict=pickle_read(header_path)
|
305
|
+
|
306
|
+
#读取明细文件
|
307
|
+
detail_path=header_dict['pickle_path']
|
308
|
+
df=pickle_read(detail_path)
|
309
|
+
|
310
|
+
if isinstance(name,str):
|
311
|
+
name=[name]
|
312
|
+
|
313
|
+
found=False
|
314
|
+
for n in name:
|
315
|
+
#检查是否存在
|
316
|
+
if n not in list(df[header_dict['column']]):
|
317
|
+
print(n,"is not in file, no need to remove")
|
318
|
+
continue
|
319
|
+
|
320
|
+
found=True
|
321
|
+
#删除该名字的所有记录
|
322
|
+
to_drop = df[df[header_dict['column']] == n].index
|
323
|
+
df.drop(to_drop, inplace=True)
|
324
|
+
|
325
|
+
print(n,"is removed from file")
|
326
|
+
|
327
|
+
#写回明细文件
|
328
|
+
if found:
|
329
|
+
pickle_write(df,detail_path,overlap_confirm=False)
|
330
|
+
|
331
|
+
return
|
332
|
+
|
333
|
+
#==============================================================================
|
334
|
+
if __name__=='__main__':
|
335
|
+
course="SICS RUC24"
|
336
|
+
lucky_color="blue"
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
def random_draw(course,lucky_color="blue"):
|
341
|
+
"""
|
342
|
+
随机点名,并记录
|
343
|
+
draw_limit:整个课程每人最多几次抽签机会
|
344
|
+
absent_limit:整个课程每人最多缺席几次,超过就丧失抽签资格
|
345
|
+
pass_limit:整个课程每人最多可以pass几次,超过就丧失抽签资格
|
346
|
+
"""
|
347
|
+
#读取参数信息
|
348
|
+
header_path=course+" header.pkl"
|
349
|
+
header_dict=pickle_read(header_path)
|
350
|
+
|
351
|
+
#读取明细文件
|
352
|
+
detail_path=header_dict['pickle_path']
|
353
|
+
df=pickle_read(detail_path)
|
354
|
+
|
355
|
+
#点名名单
|
356
|
+
column=header_dict['column']
|
357
|
+
alist=list(set(list(df[column])))
|
358
|
+
|
359
|
+
found=False
|
360
|
+
todaydt = str(datetime.date.today())
|
361
|
+
draw_limit=header_dict['draw_limit']
|
362
|
+
absent_limit=header_dict['absent_limit']
|
363
|
+
pass_limit=header_dict['pass_limit']
|
364
|
+
column=header_dict['column']
|
365
|
+
|
366
|
+
prompt="*** Is the lucky person here on site?"
|
367
|
+
prompt2="*** Does the lucky person expect to pass?"
|
368
|
+
prompt3="*** Continue lucky draw?"
|
369
|
+
|
370
|
+
while True:
|
371
|
+
while True:
|
372
|
+
aname=random_select(alist)
|
373
|
+
|
374
|
+
adf=df[df[column]==aname]
|
375
|
+
atimes=adf['Lucky'].sum()
|
376
|
+
aonsite=adf['Absent'].sum()
|
377
|
+
apass=adf['Pass'].sum()
|
378
|
+
|
379
|
+
if atimes < draw_limit and aonsite <= absent_limit and apass < pass_limit:
|
380
|
+
#检查今日是否被抽中过
|
381
|
+
drew_today=False
|
382
|
+
try:
|
383
|
+
adf_today=adf[adf['Date']==todaydt]
|
384
|
+
if len(adf_today) > 0:
|
385
|
+
if adf_today['Lucky'].sum() > 0:
|
386
|
+
#有当日记录,且被抽中过(排除当日刚刚加入课程的情形)
|
387
|
+
drew_today=True
|
388
|
+
except: pass
|
389
|
+
|
390
|
+
if not drew_today:
|
391
|
+
found=True
|
392
|
+
break
|
393
|
+
else: continue
|
394
|
+
else:
|
395
|
+
continue
|
396
|
+
|
397
|
+
if not found:
|
398
|
+
#循环完毕,无合适人选
|
399
|
+
print("Congratulations! all person has been lucky for",draw_limit,"times")
|
400
|
+
else:
|
401
|
+
typewriter(text=aname,text_color=lucky_color,text_size=12,delay=1)
|
402
|
+
|
403
|
+
#是否到场
|
404
|
+
onsite=read_yes_no(prompt)
|
405
|
+
if onsite: absent=0
|
406
|
+
else: absent=1
|
407
|
+
|
408
|
+
#是否pass
|
409
|
+
onpass=False
|
410
|
+
bpass=0
|
411
|
+
if onsite:
|
412
|
+
onpass=read_yes_no(prompt2)
|
413
|
+
#是否pass
|
414
|
+
if onpass: bpass=1
|
415
|
+
|
416
|
+
#只要抽中,不论是否到场都记录
|
417
|
+
row=pd.Series({column:aname,'Date':todaydt,'Lucky':1,'Absent':absent,'Pass':bpass})
|
418
|
+
try:
|
419
|
+
df=df.append(row,ignore_index=True)
|
420
|
+
except:
|
421
|
+
df=df._append(row,ignore_index=True)
|
422
|
+
|
423
|
+
if onsite and not onpass:
|
424
|
+
proceed=read_yes_no(prompt3)
|
425
|
+
if not proceed:
|
426
|
+
#到场且不pass,结束本轮抽签
|
427
|
+
print("=== Lucky draw ends!")
|
428
|
+
break
|
429
|
+
else:
|
430
|
+
#未到场或pass,继续抽签
|
431
|
+
continue
|
432
|
+
|
433
|
+
df.sort_values(by=[column,'Date'],inplace=True)
|
434
|
+
pickle_write(df,detail_path,overlap_confirm=False)
|
435
|
+
|
436
|
+
return
|
437
|
+
|
438
|
+
#==============================================================================
|
439
|
+
#==============================================================================
|
440
|
+
if __name__=='__main__':
|
441
|
+
file_path="S:\北外工作-24春\小学期-人大\学生名单\student_list.xlsx"
|
442
|
+
|
443
|
+
draw_limit=2
|
444
|
+
absent_limit=2
|
445
|
+
pass_limit=2
|
446
|
+
|
447
|
+
|
448
|
+
lucky_draw_initialize(file_path,skiprows=1,column='Name',pickle_path="student_list.pkl")
|
449
|
+
|
450
|
+
def lucky_draw_initialize(file_path,skiprows=1,column='Name',pickle_path="student_list.pkl"):
|
451
|
+
"""
|
452
|
+
功能:读入带有指定路径的Excel文件file_path,跳过前skiprows行
|
453
|
+
Excel文件结构:抽奖名单字段为'Name',字段位于第2行
|
454
|
+
输出:存入pickle文件student_list.pkl
|
455
|
+
废弃!!!
|
456
|
+
"""
|
457
|
+
|
458
|
+
df = pd.read_excel(file_path,skiprows=skiprows)
|
459
|
+
|
460
|
+
df1=df[[column]].copy()
|
461
|
+
|
462
|
+
todaydt = str(datetime.date.today())
|
463
|
+
df1['Date']=todaydt
|
464
|
+
df1['Lucky']=0
|
465
|
+
df1['Absent']=0
|
466
|
+
df1['Answer']=0
|
467
|
+
|
468
|
+
#排序
|
469
|
+
df1.sort_values(by=[column,'Date','Lucky','Absent','Answer'],inplace=True)
|
470
|
+
df1.reset_index(drop=True,inplace=True)
|
471
|
+
|
472
|
+
pickle_write(df1,pickle_path)
|
473
|
+
|
474
|
+
return
|
475
|
+
|
476
|
+
#==============================================================================
|
477
|
+
if __name__=='__main__':
|
478
|
+
pickle_path="SICS RUC24 detail.pkl"
|
479
|
+
|
480
|
+
df=pickle_read(pickle_path)
|
481
|
+
|
482
|
+
def pickle_read(pickle_path):
|
483
|
+
with open(pickle_path,'rb') as pickle_file:
|
484
|
+
df = pickle.load(pickle_file)
|
485
|
+
return df
|
486
|
+
|
487
|
+
|
488
|
+
#==============================================================================
|
489
|
+
if __name__=='__main__':
|
490
|
+
alist=["A","B","C","D"]
|
491
|
+
|
492
|
+
for i in range(4):
|
493
|
+
print(random_select(alist))
|
494
|
+
|
495
|
+
|
496
|
+
def random_select(alist):
|
497
|
+
return random.choice(alist)
|
498
|
+
|
499
|
+
#==============================================================================
|
500
|
+
|
501
|
+
if __name__=='__main__':
|
502
|
+
prompt="Is the lucky person here in class?"
|
503
|
+
|
504
|
+
read_yes_no(prompt)
|
505
|
+
|
506
|
+
|
507
|
+
def read_yes_no(prompt, default=None):
|
508
|
+
if default is None:
|
509
|
+
prompt += " [yes/no] "
|
510
|
+
else:
|
511
|
+
prompt += " [yes/no] (default: %s) " % ('yes' if default else 'no')
|
512
|
+
while True:
|
513
|
+
user_input = input(prompt).lower()
|
514
|
+
if user_input in ['', 'yes', 'y', 'true']:
|
515
|
+
return True
|
516
|
+
elif user_input in ['no', 'n', 'false']:
|
517
|
+
return False
|
518
|
+
elif user_input == '' and default is not None:
|
519
|
+
return default
|
520
|
+
else:
|
521
|
+
print("Please enter 'yes' or 'no' (or 'y'/'n').")
|
522
|
+
|
523
|
+
return
|
524
|
+
|
525
|
+
#==============================================================================
|
526
|
+
if __name__=='__main__':
|
527
|
+
draw_limit=2
|
528
|
+
absent_limit=2
|
529
|
+
column='Name'
|
530
|
+
pickle_path="student_list.pkl"
|
531
|
+
|
532
|
+
lucky_draw()
|
533
|
+
df=pickle_read(pickle_path)
|
534
|
+
|
535
|
+
|
536
|
+
def lucky_draw(draw_limit=2,absent_limit=2,column='Name',pickle_path="student_list.pkl"):
|
537
|
+
"""
|
538
|
+
draw_limit=2:整个课程每人最多2次抽签机会
|
539
|
+
absent_limit=2:整个课程每人最多缺席2次,超过就丧失抽签资格
|
540
|
+
废弃!
|
541
|
+
"""
|
542
|
+
df=pickle_read(pickle_path)
|
543
|
+
|
544
|
+
alist=list(set(list(df[column])))
|
545
|
+
|
546
|
+
found=False
|
547
|
+
todaydt = str(datetime.date.today())
|
548
|
+
prompt="*** Is the lucky person here on site?"
|
549
|
+
prompt2="*** Does the lucky person expect to pass?"
|
550
|
+
prompt3="*** Continue luck draw?"
|
551
|
+
|
552
|
+
while True:
|
553
|
+
while True:
|
554
|
+
aname=random_select(alist)
|
555
|
+
|
556
|
+
adf=df[df[column]==aname]
|
557
|
+
atimes=adf['Lucky'].sum()
|
558
|
+
aonsite=adf['Absent'].sum()
|
559
|
+
|
560
|
+
if atimes < draw_limit and aonsite <= absent_limit:
|
561
|
+
#检查今日是否被抽中过
|
562
|
+
drew_today=False
|
563
|
+
try:
|
564
|
+
adf_today=adf[adf['Date']==todaydt]
|
565
|
+
if len(adf_today) > 0:
|
566
|
+
if adf_today['Lucky'].sum() > 0 or adf_today['Absent'].sum() > 0:
|
567
|
+
drew_today=True
|
568
|
+
except: pass
|
569
|
+
|
570
|
+
if not drew_today:
|
571
|
+
found=True
|
572
|
+
break
|
573
|
+
else: continue
|
574
|
+
else:
|
575
|
+
continue
|
576
|
+
|
577
|
+
if not found:
|
578
|
+
print("Congratulations! all person has been lucky for",limit,"times")
|
579
|
+
else:
|
580
|
+
"""
|
581
|
+
print("\nThe lucky person is ",end='')
|
582
|
+
typewriter(aname,delay=1)
|
583
|
+
"""
|
584
|
+
typewriter(text=aname,text_color='blue',text_size=12,delay=1)
|
585
|
+
|
586
|
+
#print('')
|
587
|
+
onsite=read_yes_no(prompt)
|
588
|
+
#是否到场
|
589
|
+
if onsite: absent=0
|
590
|
+
else: absent=1
|
591
|
+
|
592
|
+
onpass=False; answer=0
|
593
|
+
if onsite:
|
594
|
+
onpass=read_yes_no(prompt2)
|
595
|
+
#是否pass
|
596
|
+
if onpass: answer=0
|
597
|
+
else: answer=1
|
598
|
+
|
599
|
+
#只要抽中,不论是否到场都记录
|
600
|
+
row=pd.Series({column:aname,'Date':todaydt,'Lucky':1,'Absent':absent,'Answer':answer})
|
601
|
+
try:
|
602
|
+
df=df.append(row,ignore_index=True)
|
603
|
+
except:
|
604
|
+
df=df._append(row,ignore_index=True)
|
605
|
+
|
606
|
+
if onsite and not onpass:
|
607
|
+
#到场且不pass,结束本轮抽签
|
608
|
+
proceed=read_yes_no(prompt3)
|
609
|
+
if not proceed:
|
610
|
+
break
|
611
|
+
else:
|
612
|
+
#未到场或pass,继续抽签
|
613
|
+
continue
|
614
|
+
|
615
|
+
df.sort_values(by=[column,'Date'],inplace=True)
|
616
|
+
pickle_write(df,pickle_path)
|
617
|
+
|
618
|
+
return
|
619
|
+
|
620
|
+
#==============================================================================
|
621
|
+
#==============================================================================
|
622
|
+
#==============================================================================
|
623
|
+
#==============================================================================
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
|
634
|
+
#==============================================================================#==============================================================================
|
635
|
+
#==============================================================================#==============================================================================
|
636
|
+
#==============================================================================#==============================================================================
|
637
|
+
|
638
|
+
#==============================================================================
|