Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bigdata
api
Commits
7ad7afbb
Commit
7ad7afbb
authored
Jun 04, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加类目判断
parent
11c25c4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
47 deletions
+55
-47
src/main/Python/estools.py
src/main/Python/estools.py
+55
-47
No files found.
src/main/Python/estools.py
View file @
7ad7afbb
...
...
@@ -11,6 +11,7 @@ class ESTools:
_host
=
[{
"host"
:
'172.18.45.18'
,
"port"
:
9200
},
{
"host"
:
'172.18.45.17'
,
"port"
:
9200
},
{
"host"
:
'172.18.45.16'
,
"port"
:
9200
},
{
"host"
:
'172.18.69.190'
,
"port"
:
9200
},
{
"host"
:
'172.18.69.192'
,
"port"
:
9200
}]
# _host = 'localhost:9200'
_TB_RATE
=
0.7
_JD_RATE
=
0.55
...
...
@@ -18,9 +19,10 @@ class ESTools:
def
__init__
(
self
):
self
.
es
=
Elasticsearch
(
self
.
_host
)
def
search_tools
(
self
,
price
=
0
,
title
=
""
,
size
=
20
):
def
search_tools
(
self
,
price
=
0
,
title
=
""
,
category
=
""
,
size
=
20
):
"""
搜索es方法
:param category: 商品类目
:param price: 券后价
:param title: 商品名称
:param size: 商品数量
...
...
@@ -58,64 +60,70 @@ class ESTools:
else
:
return
None
def
data_format
(
self
,
price
=
0
,
title
=
""
,
size
=
20
):
def
data_format
(
self
,
price
=
0
,
title
=
""
,
category
=
""
,
size
=
20
):
"""
格式化数据方法
:param category: 商品类目
:param price: 券后价
:param title: 商品标题
:param size: 商品数量
:return: 格式化后的数据
"""
res
,
sco
=
self
.
search_tools
(
price
=
price
,
title
=
title
,
size
=
size
)
res
,
sco
=
self
.
search_tools
(
price
=
price
,
title
=
title
,
category
=
category
,
size
=
size
)
if
res
:
temp
=
[]
# 匹配分数平均数
score_avg
=
sum
(
sco
)
/
len
(
sco
)
# 匹配分数中位数
score_median
=
sco
[
int
(
len
(
sco
)
/
2
)]
for
i
in
res
:
# 对每条数据进行处理
# 分数大于中位数
if
i
[
"_score"
]
>
score_median
:
# 分数大于平均数
if
i
[
"_score"
]
>
score_avg
:
# 源数据
source
=
i
[
'_source'
]
# 平台
platform
=
source
[
"platform"
]
# 券后佣金
coupon_commission
=
source
[
"coupon_commission"
]
# 给用户的佣金比例
rate
=
self
.
_JD_RATE
if
platform
==
2
else
self
.
_TB_RATE
# 券金额
coupon_amount
=
source
[
"coupon_amount"
]
# 优惠文案
discount_text
=
f'¥
{
coupon_amount
}
券'
if
coupon_amount
>
0
else
''
# 用户佣金
user_commission
=
"{:.2f}"
.
format
(
coupon_commission
*
rate
)
# 券后价
end_price
=
source
[
"coupon_price"
]
# 最终优惠金额
final_price
=
round
(
price
-
end_price
,
2
)
result
=
{
"item_id"
:
source
[
"item_id"
],
"item_pic"
:
source
[
"item_pic_url"
].
split
(
','
)[
0
],
"item_title"
:
source
[
"item_name"
],
"discount_type"
:
"1"
,
"discount_amount"
:
str
(
source
[
"coupon_amount"
]),
"platform"
:
str
(
platform
),
"shop_title"
:
source
[
"shop_name"
],
"user_commission"
:
user_commission
,
"price"
:
str
(
source
[
"price"
]),
"end_price"
:
str
(
end_price
),
"volume_text"
:
f'已抢
{
source
[
"item_volume"
]
}
件'
,
"discount_text"
:
discount_text
,
"discount_tips"
:
f'比查券商品便宜
{
final_price
}
元'
,
"user_commission_text"
:
f'返现
{
user_commission
}
'
}
temp
.
append
(
result
)
# 按价格排序
results
=
sorted
(
temp
,
key
=
lambda
x
:
x
[
"end_price"
])
return
results
score_max
=
max
(
sco
)
if
score_max
<
50
:
return
None
else
:
for
i
in
res
:
# 对每条数据进行处理
# 分数大于中位数
if
i
[
"_score"
]
>
score_median
:
# 分数大于平均数
if
i
[
"_score"
]
>
score_avg
:
# 源数据
source
=
i
[
'_source'
]
# 平台
platform
=
source
[
"platform"
]
# 券后佣金
coupon_commission
=
source
[
"coupon_commission"
]
# 给用户的佣金比例
rate
=
self
.
_JD_RATE
if
platform
==
2
else
self
.
_TB_RATE
# 券金额
coupon_amount
=
source
[
"coupon_amount"
]
# 优惠文案
discount_text
=
f'¥
{
coupon_amount
}
券'
if
coupon_amount
>
0
else
''
# 用户佣金
user_commission
=
"{:.2f}"
.
format
(
coupon_commission
*
rate
)
# 券后价
end_price
=
source
[
"coupon_price"
]
# 最终优惠金额
final_price
=
round
(
price
-
end_price
,
2
)
result
=
{
"item_id"
:
source
[
"item_id"
],
"item_pic"
:
source
[
"item_pic_url"
].
split
(
','
)[
0
],
"item_title"
:
source
[
"item_name"
],
"discount_type"
:
"1"
,
"discount_amount"
:
str
(
source
[
"coupon_amount"
]),
"platform"
:
str
(
platform
),
"shop_title"
:
source
[
"shop_name"
],
"user_commission"
:
user_commission
,
"price"
:
str
(
source
[
"price"
]),
"end_price"
:
str
(
end_price
),
"volume_text"
:
f'已抢
{
source
[
"item_volume"
]
}
件'
,
"discount_text"
:
discount_text
,
"discount_tips"
:
f'比查券商品便宜
{
final_price
}
元'
,
"user_commission_text"
:
f'返现
{
user_commission
}
'
}
temp
.
append
(
result
)
# 按价格排序
results
=
sorted
(
temp
,
key
=
lambda
x
:
x
[
"end_price"
])
return
results
else
:
return
None
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