Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecom-svc-reviewsense
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bhargava Rellu
ecom-svc-reviewsense
Commits
c068bacc
Commit
c068bacc
authored
Apr 09, 2025
by
Shaik Afreed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rolled back the bayesian formulae to old formulae for average rating changes implemented
parent
1d3fa3de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
18 deletions
+8
-18
FeatureUpdater.py
src/reviewsense_ecom/service/FeatureUpdater.py
+8
-18
No files found.
src/reviewsense_ecom/service/FeatureUpdater.py
View file @
c068bacc
...
@@ -19,6 +19,7 @@ class FeatureUpdater:
...
@@ -19,6 +19,7 @@ class FeatureUpdater:
existing_total_reviews
=
self
.
product_data
.
get
(
"total_reviews"
,
0
)
existing_total_reviews
=
self
.
product_data
.
get
(
"total_reviews"
,
0
)
current_overall_rating
=
self
.
product_data
.
get
(
"overall_rating"
,
0.0
)
current_overall_rating
=
self
.
product_data
.
get
(
"overall_rating"
,
0.0
)
for
feature
,
new_data
in
feature_data
.
items
():
for
feature
,
new_data
in
feature_data
.
items
():
if
feature
not
in
features
:
if
feature
not
in
features
:
features
[
feature
]
=
{
features
[
feature
]
=
{
...
@@ -30,37 +31,25 @@ class FeatureUpdater:
...
@@ -30,37 +31,25 @@ class FeatureUpdater:
current_feature
=
features
[
feature
]
current_feature
=
features
[
feature
]
existing_review_count
=
current_feature
[
"review_count"
]
existing_review_count
=
current_feature
[
"review_count"
]
M
=
4
C
=
max
(
2
,
10
-
(
existing_review_count
//
20
))
# Reduce prior influence faster
# if existing_review_count < 5:
# C = 5
# elif existing_review_count < 50:
# C = 10
# elif existing_review_count < 500:
# C = 15
# else:
# C = 20
new_ratings
=
new_data
.
get
(
"ratings"
,
[])
new_ratings
=
new_data
.
get
(
"ratings"
,
[])
new_rating
=
sum
(
new_ratings
)
/
len
(
new_ratings
)
if
new_ratings
else
0
new_rating
=
sum
(
new_ratings
)
/
len
(
new_ratings
)
if
new_ratings
else
0
new_positive
=
new_data
.
get
(
"positive_count"
,
0
)
or
0
new_positive
=
new_data
.
get
(
"positive_count"
,
0
)
or
0
new_negative
=
new_data
.
get
(
"negative_count"
,
0
)
or
0
new_negative
=
new_data
.
get
(
"negative_count"
,
0
)
or
0
# Apply the Bayesian Average Formula
new_average_rating
=
(
new_average_rating
=
(
(
current_feature
[
"average_rating"
]
*
existing_review_count
)
+
(
(
current_feature
[
"average_rating"
]
*
existing_review_count
)
+
new_rating
C
*
M
)
+
new_rating
)
/
(
existing_review_count
+
1
)
if
existing_review_count
>
0
else
new_rating
)
/
(
existing_review_count
+
C
+
1
)
if
existing_review_count
>
0
else
new_rating
print
(
f
"{new_average_rating}+--------------------------$$$----------------"
)
print
(
f
"{new_average_rating}--------------------------$$$----------------"
)
features
[
feature
][
"average_rating"
]
=
new_average_rating
features
[
feature
][
"average_rating"
]
=
new_average_rating
features
[
feature
][
"review_count"
]
+=
1
features
[
feature
][
"review_count"
]
+=
1
features
[
feature
][
"positive_count"
]
+=
new_positive
features
[
feature
][
"positive_count"
]
+=
new_positive
features
[
feature
][
"negative_count"
]
+=
new_negative
features
[
feature
][
"negative_count"
]
+=
new_negative
ratings_distribution
[
str
(
new_overall_rating
)]
+=
1
ratings_distribution
[
str
(
new_overall_rating
)]
+=
1
updated_total_reviews
=
existing_total_reviews
+
1
updated_total_reviews
=
existing_total_reviews
+
1
...
@@ -68,9 +57,10 @@ class FeatureUpdater:
...
@@ -68,9 +57,10 @@ class FeatureUpdater:
(
current_overall_rating
*
existing_total_reviews
)
+
new_overall_rating
(
current_overall_rating
*
existing_total_reviews
)
+
new_overall_rating
)
/
updated_total_reviews
if
existing_total_reviews
>
0
else
new_overall_rating
)
/
updated_total_reviews
if
existing_total_reviews
>
0
else
new_overall_rating
self
.
product_data
[
"features"
]
=
features
self
.
product_data
[
"features"
]
=
features
self
.
product_data
[
"ratings_distribution"
]
=
ratings_distribution
self
.
product_data
[
"ratings_distribution"
]
=
ratings_distribution
self
.
product_data
[
"overall_rating"
]
=
round
(
new_overall_rating
,
1
)
self
.
product_data
[
"overall_rating"
]
=
round
(
new_overall_rating
,
1
)
self
.
product_data
[
"total_reviews"
]
=
updated_total_reviews
self
.
product_data
[
"total_reviews"
]
=
updated_total_reviews
return
self
.
product_data
return
self
.
product_data
\ 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