Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
615bae90
Commit
615bae90
authored
Feb 22, 2020
by
黄静
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hj
parent
85d1363f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
107 deletions
+82
-107
calc_result/IndexComputerFile.py
+8
-9
calc_result/main.py
+74
-98
No files found.
calc_result/IndexComputerFile.py
View file @
615bae90
...
...
@@ -8,6 +8,7 @@ class IndexComputer:
def
Init
(
self
):
return
""
def
Compute
(
self
,
indexItem
):
#计算单一指标
print
(
"================计算风控公式"
)
# 如果所有因子有一个为空,返回数据不存在
i
=
0
X
=
[]
...
...
@@ -37,7 +38,6 @@ class IndexComputer:
funstr
=
funstr
.
replace
(
s
,
str
(
V
[
s
]))
strinfo
=
re
.
compile
(
r'X\[\d*\]='
)
funstr
=
strinfo
.
sub
(
""
,
funstr
)
# funstr=funstr.replace("/X[d]=/","")
try
:
print
(
funstr
,
"======funstr"
)
val
=
eval
(
funstr
)
...
...
@@ -49,8 +49,6 @@ class IndexComputer:
except
(
ValueError
):
print
(
'other:'
,
ValueError
)
return
"0"
# try:
if
X
[
j
-
1
]
==
True
:
return
"2"
else
:
...
...
@@ -65,10 +63,12 @@ class IndexComputer:
S
=
[]
for
factorkey
in
indexItem
.
FactorsValue
:
tempval
=
indexItem
.
FactorsValue
[
factorkey
]
if
type
(
tempval
)
==
str
:
print
(
factorkey
,
tempval
,
'===============factorkey,tempval'
)
try
:
eval
(
tempval
)
else
:
tempval
=
tempval
except
Exception
as
e
:
print
(
e
,
"======eval抛出财务异常"
)
return
'—'
Y
.
append
(
float
(
indexItem
.
FactorsValue
[
factorkey
]))
V
[
factorkey
]
=
str
(
"Y["
+
str
(
i
)
+
"]"
)
S
.
append
(
factorkey
)
...
...
@@ -82,6 +82,7 @@ class IndexComputer:
strinfo
=
re
.
compile
(
r'X\[\d*\]='
)
funstr
=
strinfo
.
sub
(
""
,
funstr
)
try
:
print
(
"计算正常公式"
)
if
type
(
funstr
)
==
str
:
val
=
eval
(
funstr
)
else
:
...
...
@@ -89,11 +90,9 @@ class IndexComputer:
X
.
append
(
val
)
j
=
j
+
1
except
ZeroDivisionError
as
err
:
print
(
"计算异常公式时"
)
print
(
'finance error:'
,
err
)
return
"∞"
except
(
ValueError
):
print
(
'other:'
,
ValueError
)
return
"—"
Finance_result
=
int
(
X
[
j
-
1
])
if
Finance_result
==
0.0
:
Finance_result
=
int
(
Finance_result
)
...
...
calc_result/main.py
100755 → 100644
View file @
615bae90
...
...
@@ -15,10 +15,6 @@ FK_REDIS_PORT = env_dist.get('FK_REDIS_PORT') #获取redis端口号
FK_REDIS_PWD
=
env_dist
.
get
(
'FK_REDIS_PWD'
)
#获取redis密码
FK_REDIS_DB
=
env_dist
.
get
(
'FK_REDIS_DB'
)
#获取redis库
# print(FK_REDIS_HOST)
# print(FK_REDIS_PORT)
# print(FK_REDIS_PWD)
# print(FK_REDIS_DB)
#使用任务号获取任务信息
def
getInfo_ByBatchNo
(
BatchNo
):
...
...
@@ -27,11 +23,6 @@ def getInfo_ByBatchNo(BatchNo):
name
=
{
"batchCode"
:
BatchNo
}
# 根据任务号进行接口访问参数
taskInfo
=
requests
.
get
(
url
,
name
)
# 访问接口返回的信息
taskInfo_New
=
json
.
loads
(
taskInfo
.
text
)
# print("任务信息获取:",taskInfo_New,BatchNo)
if
taskInfo_New
[
'data'
]
is
None
:
print
(
"taskInfo_New['data'] is None"
)
# client.rpop('notifyRule')
quit
()
Info_Task
=
taskInfo_New
[
'data'
]
AccountInfo
=
{}
AccountInfo
[
"taxCode"
]
=
Info_Task
[
'taxCode'
]
# 获取纳税人识别号
...
...
@@ -88,7 +79,6 @@ def posmap(coordinate,position):
if
position
in
posmap_lists
:
posmap_result
[
'cellDesc'
]
=
posmap_lists
[
position
]
posmap_result
[
'cellPos'
]
=
""
print
(
posmap_result
[
'cellDesc'
],
"===============因子中文编码位置"
)
else
:
posmap_result
[
'cellDesc'
]
=
""
posmap_result
[
'cellPos'
]
=
coordinate
...
...
@@ -118,7 +108,6 @@ def getValue(batchCode,cellDesc,cellPos,currentIssue,fileCode,taxCode,timeType):
else
:
index
=
index_Values
[
0
]
index_Value
=
index
[
"cellContent"
]
# print("单元格数据为:",index_Value)
return
index_Value
def
fun
(
str
):
...
...
@@ -152,7 +141,6 @@ def Previous(tasks):
Curr_year
=
Curr_Get
[
0
:
4
]
Curr_month
=
Curr_Get
[
4
:
7
]
Curr_Date
=
Curr_year
+
'-'
+
Curr_month
print
(
Curr_month
,
"=================Curr_month"
)
#转化当前时间
if
Curr_month
in
(
"01"
,
"03"
,
"05"
,
"07"
,
"08"
,
"10"
,
"12"
):
Curr_Day
=
"31"
...
...
@@ -217,7 +205,6 @@ def report(BatchNo):
name
=
{
"batchid"
:
BatchNo
}
reportInfo
=
requests
.
post
(
url
,
name
)
reportInfo_New
=
json
.
loads
(
reportInfo
.
text
)
print
(
reportInfo_New
,
"reportInfo_New"
)
if
reportInfo_New
[
'status'
]
==
0
:
report_result
=
'触发生成报告接口成功'
else
:
...
...
@@ -226,88 +213,77 @@ def report(BatchNo):
redisPool
=
redis
.
ConnectionPool
(
host
=
FK_REDIS_HOST
,
port
=
int
(
FK_REDIS_PORT
),
password
=
FK_REDIS_PWD
,
db
=
FK_REDIS_DB
)
client
=
redis
.
Redis
(
connection_pool
=
redisPool
)
a
=
client
.
lrange
(
'notifyRule'
,
-
1
,
-
1
)
print
(
a
,
"aaa"
)
if
len
(
a
)
==
0
:
print
(
"notifyRule数据为空"
)
quit
()
value
=
a
[
-
1
]
if
client
is
None
:
client
.
rpop
(
'notifyRule'
)
quit
()
if
value
is
None
:
client
.
rpop
(
'notifyRule'
)
quit
()
result
=
json
.
loads
(
value
)
print
(
result
,
"result"
)
content
=
result
[
"content"
]
print
(
content
,
"content"
)
taxTypeCode
=
content
[
"taxTypeCode"
]
#企业性质
accountTypeCode
=
content
[
"accountTypeCode"
]
#会计准则
BatchNo
=
content
[
"batchCode"
]
if
taxTypeCode
==
"ST"
:
taxTypeCode
=
"S"
else
:
taxTypeCode
=
"G"
type
=
taxTypeCode
+
"-"
+
accountTypeCode
indexsGet
=
IndexGet
()
#获取所有指标信息
#根据任务号获取任务信息
Info_task
=
getInfo_ByBatchNo
(
BatchNo
)
tasks
=
Info_task
[
0
]
Previous_Date
=
Previous
(
tasks
)
indexs
=
indexsGet
.
Subscribe
(
tasks
[
'timeType'
],
type
)
#根据时间类型和企业类型获取特征s
print
(
tasks
[
'timeType'
],
type
,
"==============获取查询公式条件"
)
factors
=
{}
for
indexItem
in
indexs
:
factorsStr
=
indexItem
.
Factors
factorsGrp
=
factorsStr
.
replace
(
":"
,
":"
)
.
split
(
":"
)
for
factorItem
in
factorsGrp
:
if
factorItem
not
in
factors
and
len
(
factorItem
.
lstrip
()
.
rstrip
())
>
0
:
factors
[
factorItem
]
=
0.0
factorsnew
=
{}
for
factor
in
factors
:
#获取所有因子
fun_list
=
fun
(
str
(
factor
))
index
=
fun_list
[
0
]
coordinate
=
index
[
'coordinate'
]
position
=
index
[
'position'
]
talbe
=
index
[
'table'
]
batchCode
=
BatchNo
# posmap_result=posmap(talbe,cellPos)
posmap_result
=
posmap
(
coordinate
,
position
)
cellPos
=
posmap_result
[
'cellPos'
]
cellDesc
=
posmap_result
[
'cellDesc'
]
offset
=
index
[
'nums'
]
times
=
index
[
'times'
]
issueNum
=
index
[
'issueNum'
]
YearyearInfo
=
times
[
0
:
2
]
currentIssue
=
tasks
[
"currentIssue"
]
fileCode
=
index
[
'table'
]
taxCode
=
tasks
[
"taxCode"
]
timeType
=
tasks
[
"timeType"
]
currentYear
=
int
(
currentIssue
[
0
:
4
])
# 获取L期数信息
if
"L"
in
YearyearInfo
:
Info_LBatch
=
Transformer
(
currentYear
,
YearyearInfo
,
issueNum
)
a
=
client
.
rpop
(
'notifyRule'
)
print
(
a
,
"=====aaaaa"
)
print
(
"消耗结束"
)
result
=
json
.
loads
(
a
)
print
(
result
,
"result"
)
try
:
content
=
result
[
"content"
]
taxTypeCode
=
content
[
"taxTypeCode"
]
# 企业性质
accountTypeCode
=
content
[
"accountTypeCode"
]
# 会计准则
BatchNo
=
content
[
"batchCode"
]
if
taxTypeCode
==
"ST"
:
taxTypeCode
=
"S"
else
:
# 获取自定义期数
Info_LBatch
=
customBatch
(
currentIssue
,
offset
,
timeType
)
# 获取单元格值
index_Value
=
getValue
(
batchCode
,
cellDesc
,
cellPos
,
currentIssue
,
fileCode
,
taxCode
,
timeType
)
factorsnew
[
factor
]
=
index_Value
factors
=
factorsnew
rc
=
RiskComputer
()
#构建指标计算对象
rc
.
batch_No
=
BatchNo
rc
.
indexs
=
indexs
rc
.
FactorGet
(
factors
)
#把因子装入对象
rc
.
IndexsGet
(
indexs
)
#把指标装入对象
rc
.
Compute
(
Previous_Date
)
#指标计算
jsonstr
=
rc
.
Ret2Json
()
#指标输出成樊辉要的格式
report_result
=
report
(
BatchNo
)
#触发生成报告接口
print
(
jsonstr
)
client
.
rpop
(
'notifyRule'
)
Updqtestatus
=
UpdateId
()
Updqtestatus
.
Update
(
batchCode
)
print
(
batchCode
,
"batchCode"
)
print
(
"消耗结束"
)
\ No newline at end of file
taxTypeCode
=
"G"
type
=
taxTypeCode
+
"-"
+
accountTypeCode
indexsGet
=
IndexGet
()
# 获取所有指标信息
# 根据任务号获取任务信息
Info_task
=
getInfo_ByBatchNo
(
BatchNo
)
tasks
=
Info_task
[
0
]
Previous_Date
=
Previous
(
tasks
)
indexs
=
indexsGet
.
Subscribe
(
tasks
[
'timeType'
],
type
)
# 根据时间类型和企业类型获取特征s
print
(
tasks
[
'timeType'
],
type
,
"==========时间类型"
)
factors
=
{}
for
indexItem
in
indexs
:
factorsStr
=
indexItem
.
Factors
factorsGrp
=
factorsStr
.
replace
(
":"
,
":"
)
.
split
(
":"
)
for
factorItem
in
factorsGrp
:
if
factorItem
not
in
factors
and
len
(
factorItem
.
lstrip
()
.
rstrip
())
>
0
:
factors
[
factorItem
]
=
0.0
factorsnew
=
{}
for
factor
in
factors
:
# 获取所有因子
fun_list
=
fun
(
str
(
factor
))
index
=
fun_list
[
0
]
coordinate
=
index
[
'coordinate'
]
position
=
index
[
'position'
]
talbe
=
index
[
'table'
]
batchCode
=
BatchNo
# posmap_result=posmap(talbe,cellPos)
posmap_result
=
posmap
(
coordinate
,
position
)
cellPos
=
posmap_result
[
'cellPos'
]
cellDesc
=
posmap_result
[
'cellDesc'
]
offset
=
index
[
'nums'
]
times
=
index
[
'times'
]
issueNum
=
index
[
'issueNum'
]
YearyearInfo
=
times
[
0
:
2
]
currentIssue
=
tasks
[
"currentIssue"
]
fileCode
=
index
[
'table'
]
taxCode
=
tasks
[
"taxCode"
]
timeType
=
tasks
[
"timeType"
]
currentYear
=
int
(
currentIssue
[
0
:
4
])
# 获取L期数信息
if
"L"
in
YearyearInfo
:
Info_LBatch
=
Transformer
(
currentYear
,
YearyearInfo
,
issueNum
)
else
:
# 获取自定义期数
Info_LBatch
=
customBatch
(
currentIssue
,
offset
,
timeType
)
# 获取单元格值
index_Value
=
getValue
(
batchCode
,
cellDesc
,
cellPos
,
currentIssue
,
fileCode
,
taxCode
,
timeType
)
factorsnew
[
factor
]
=
index_Value
factors
=
factorsnew
rc
=
RiskComputer
()
# 构建指标计算对象
rc
.
batch_No
=
BatchNo
rc
.
indexs
=
indexs
rc
.
FactorGet
(
factors
)
# 把因子装入对象
rc
.
IndexsGet
(
indexs
)
# 把指标装入对象
rc
.
Compute
(
Previous_Date
)
# 指标计算
jsonstr
=
rc
.
Ret2Json
()
# 指标输出成樊辉要的格式
report_result
=
report
(
BatchNo
)
# 触发生成报告接口
print
(
jsonstr
)
Updqtestatus
=
UpdateId
()
Updqtestatus
.
Update
(
batchCode
)
except
Exception
as
e
:
print
(
e
,
"======抛出异常,数据重写到re_notifyRule队列"
)
client
.
lpush
(
're_notifyRule'
,
a
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment