trex-model 1.2.6__tar.gz → 1.2.7__tar.gz
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.
Potentially problematic release.
This version of trex-model might be problematic. Click here for more details.
- {trex-model-1.2.6/trex_model.egg-info → trex-model-1.2.7}/PKG-INFO +1 -1
- {trex-model-1.2.6 → trex-model-1.2.7}/setup.py +1 -1
- {trex-model-1.2.6 → trex-model-1.2.7/trex_model.egg-info}/PKG-INFO +1 -1
- {trex-model-1.2.6 → trex-model-1.2.7}/trex_model.egg-info/SOURCES.txt +1 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/merchant_models.py +1 -1
- trex-model-1.2.7/trexmodel/models/datastore/rating_models.py +384 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/LICENSE +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/MANIFEST.in +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/README.md +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/setup.cfg +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trex_model.egg-info/dependency_links.txt +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trex_model.egg-info/requires.txt +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trex_model.egg-info/top_level.txt +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/conf.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/admin_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/analytic_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/app_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/coporate_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/customer_model_helpers.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/customer_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/fb_subsriber_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/import_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/inventory_model.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/loyalty_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/lucky_draw_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/membership_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/message_model_helper.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/message_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/model_decorators.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/ndb_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/pos_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/prepaid_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/product_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/program_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/redeem_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/redemption_catalogue_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/reward_model_helpers.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/reward_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/spending_base_program_model.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/system_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/task_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/test_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/transaction_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/user_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/voucher_models.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/merchant_helpers.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/model_decorator.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/prepaid_helpers.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/pos_conf.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/program_conf.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/utils/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/utils/gcloud/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/utils/gcloud/datastore_util.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/utils/model/__init__.py +0 -0
- {trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/utils/model/model_util.py +0 -0
|
@@ -38,6 +38,7 @@ trexmodel/models/datastore/pos_models.py
|
|
|
38
38
|
trexmodel/models/datastore/prepaid_models.py
|
|
39
39
|
trexmodel/models/datastore/product_models.py
|
|
40
40
|
trexmodel/models/datastore/program_models.py
|
|
41
|
+
trexmodel/models/datastore/rating_models.py
|
|
41
42
|
trexmodel/models/datastore/redeem_models.py
|
|
42
43
|
trexmodel/models/datastore/redemption_catalogue_models.py
|
|
43
44
|
trexmodel/models/datastore/reward_model_helpers.py
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Created on 29 Nov 2023
|
|
3
|
+
|
|
4
|
+
@author: jacklok
|
|
5
|
+
'''
|
|
6
|
+
from trexmodel.models.datastore.ndb_models import BaseNModel, DictModel
|
|
7
|
+
from google.cloud import ndb
|
|
8
|
+
from trexmodel.models.datastore.merchant_models import MerchantAcct, Outlet
|
|
9
|
+
from trexmodel.models.datastore.user_models import User
|
|
10
|
+
from trexmodel import conf
|
|
11
|
+
from datetime import datetime, timedelta
|
|
12
|
+
import logging
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger('model')
|
|
15
|
+
|
|
16
|
+
class RatingBase(BaseNModel, DictModel):
|
|
17
|
+
user_acct = ndb.KeyProperty(name="user_acct", kind=User)
|
|
18
|
+
modified_datetime = ndb.DateTimeProperty(required=True, auto_now=True)
|
|
19
|
+
updated = ndb.BooleanProperty(required=True, default=False)
|
|
20
|
+
|
|
21
|
+
class OutletRating(RatingBase):
|
|
22
|
+
outlet = ndb.KeyProperty(name="outlet", kind=Outlet)
|
|
23
|
+
merchant_acct = ndb.KeyProperty(name="merchant_acct", kind=MerchantAcct)
|
|
24
|
+
|
|
25
|
+
service_rating = ndb.FloatProperty(required=True, default=.0)
|
|
26
|
+
ambience_rating = ndb.FloatProperty(required=True, default=.0)
|
|
27
|
+
food_rating = ndb.FloatProperty(required=True, default=.0)
|
|
28
|
+
value_rating = ndb.FloatProperty(required=True, default=.0)
|
|
29
|
+
|
|
30
|
+
previous_service_rating = ndb.FloatProperty(required=True, default=.0)
|
|
31
|
+
previous_ambience_rating = ndb.FloatProperty(required=True, default=.0)
|
|
32
|
+
previous_food_rating = ndb.FloatProperty(required=True, default=.0)
|
|
33
|
+
previous_value_rating = ndb.FloatProperty(required=True, default=.0)
|
|
34
|
+
|
|
35
|
+
dict_properties = ['service_rating', 'ambience_rating', 'food_rating','value_rating',
|
|
36
|
+
'previous_service_rating', 'previous_ambience_rating', 'previous_food_rating','previous_value_rating',
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def get_user_rating_by_outlet(user_acct, outlet):
|
|
41
|
+
return OutletRating.query(ndb.AND(OutletRating.user_acct==user_acct.create_ndb_key(), OutletRating.outlet==outlet.create_ndb_key())).get()
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def list_by_outlet(outlet):
|
|
45
|
+
return OutletRating.query(ndb.AND(OutletRating.outlet==outlet.create_ndb_key())).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def list_new_rating_by_outlet(outlet, checking_datetime_from):
|
|
49
|
+
return OutletRating.query(ndb.AND(OutletRating.outlet==outlet.create_ndb_key(), OutletRating.updated==False, OutletRating.modified_datetime>checking_datetime_from)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def list_updated_rating_by_outlet(outlet, checking_datetime_from):
|
|
53
|
+
return OutletRating.query(ndb.AND(OutletRating.outlet==outlet.create_ndb_key(), OutletRating.updated==True, OutletRating.modified_datetime>checking_datetime_from)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def list_by_merchant(merchant_acct):
|
|
57
|
+
return OutletRating.query(ndb.AND(OutletRating.merchant_acct==merchant_acct.create_ndb_key())).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def list_new_rating_by_merchant(merchant_acct, checking_datetime_from):
|
|
61
|
+
return OutletRating.query(ndb.AND(OutletRating.merchant_acct==merchant_acct.create_ndb_key(), OutletRating.updated==False, OutletRating.modified_datetime>checking_datetime_from)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def list_updated_rating_by_merchant(merchant_acct, checking_datetime_from):
|
|
65
|
+
return OutletRating.query(ndb.AND(OutletRating.merchant_acct==merchant_acct.create_ndb_key(), OutletRating.updated==True, OutletRating.modified_datetime>checking_datetime_from)).fetch(limit=conf.MAX_FETCH_RECORD)
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def create(user_acct, outlet, service_rating=.5, ambience_rating=.5, food_rating=.5, value_rating=.5):
|
|
69
|
+
outlet_rating = OutletRating.get_user_rating_by_outlet(user_acct, outlet)
|
|
70
|
+
if outlet_rating is None:
|
|
71
|
+
merchant_acct = outlet.merchant_acct_entity
|
|
72
|
+
outlet_rating = OutletRating(
|
|
73
|
+
user_acct = user_acct.create_ndb_key(),
|
|
74
|
+
merchant_acct = merchant_acct.create_ndb_key(),
|
|
75
|
+
outlet = outlet.create_ndb_key(),
|
|
76
|
+
service_rating = service_rating,
|
|
77
|
+
ambience_rating = ambience_rating,
|
|
78
|
+
food_rating = food_rating,
|
|
79
|
+
value_rating = value_rating,
|
|
80
|
+
|
|
81
|
+
)
|
|
82
|
+
else:
|
|
83
|
+
outlet_rating.previous_service_rating = outlet_rating.service_rating
|
|
84
|
+
outlet_rating.previous_ambience_rating = outlet_rating.ambience_rating
|
|
85
|
+
outlet_rating.previous_food_rating = outlet_rating.food_rating
|
|
86
|
+
outlet_rating.previous_value_rating = outlet_rating.value_rating
|
|
87
|
+
|
|
88
|
+
outlet_rating.service_rating = service_rating
|
|
89
|
+
outlet_rating.ambience_rating = ambience_rating
|
|
90
|
+
outlet_rating.food_rating = food_rating
|
|
91
|
+
outlet_rating.value_rating = value_rating
|
|
92
|
+
#outlet_rating.updated = True
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
outlet_rating.put()
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def __calculate_rating(rating_list):
|
|
99
|
+
|
|
100
|
+
service_rating = .0
|
|
101
|
+
ambience_rating = .0
|
|
102
|
+
food_rating = .0
|
|
103
|
+
value_rating = .0
|
|
104
|
+
total_rating_count = len(rating_list)
|
|
105
|
+
|
|
106
|
+
for r in rating_list:
|
|
107
|
+
service_rating +=r.service_rating
|
|
108
|
+
ambience_rating +=r.ambience_rating
|
|
109
|
+
food_rating +=r.food_rating
|
|
110
|
+
value_rating +=r.value_rating
|
|
111
|
+
|
|
112
|
+
service_average_rating = service_rating/total_rating_count
|
|
113
|
+
ambience_average_rating = ambience_rating/total_rating_count
|
|
114
|
+
food_average_rating = food_rating/total_rating_count
|
|
115
|
+
value_average_rating = value_rating/total_rating_count
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
'service_rating' : service_average_rating,
|
|
119
|
+
'ambience_rating' : ambience_average_rating,
|
|
120
|
+
'food_rating' : food_average_rating,
|
|
121
|
+
'value_rating' : value_average_rating,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@staticmethod
|
|
125
|
+
def get_outlet_rating(outlet):
|
|
126
|
+
outlet_rating_list = OutletRating.list_by_outlet(outlet)
|
|
127
|
+
|
|
128
|
+
return OutletRating.__calculate_rating(outlet_rating_list)
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
def get_merchant_rating(merchant_acct):
|
|
132
|
+
merchant_rating_list = OutletRating.list_by_outlet(merchant_acct)
|
|
133
|
+
|
|
134
|
+
return OutletRating.__calculate_rating(merchant_rating_list)
|
|
135
|
+
|
|
136
|
+
class RatingResult(BaseNModel, DictModel):
|
|
137
|
+
total_rating_count = ndb.IntegerProperty(required=True, default=0)
|
|
138
|
+
rating_result = ndb.JsonProperty()
|
|
139
|
+
modified_datetime = ndb.DateTimeProperty(required=True, auto_now=True)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class OutletRatingResult(RatingResult):
|
|
143
|
+
outlet = ndb.KeyProperty(name="outlet", kind=Outlet)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
dict_properties = ['total_rating_count', 'rating_result', 'modified_datetime',]
|
|
147
|
+
|
|
148
|
+
@staticmethod
|
|
149
|
+
def get_by_outlet(outlet):
|
|
150
|
+
return OutletRatingResult.query(ndb.AND(OutletRatingResult.outlet==outlet.create_ndb_key())).get()
|
|
151
|
+
|
|
152
|
+
@staticmethod
|
|
153
|
+
def update(outlet, updated_datetime_from=None):
|
|
154
|
+
outlet_rating_result = OutletRatingResult.query(ndb.AND(OutletRatingResult.outlet==outlet.create_ndb_key())).get()
|
|
155
|
+
existing_total_rating_count = 0
|
|
156
|
+
if updated_datetime_from is None:
|
|
157
|
+
updated_datetime_from = datetime.utcnow() - timedelta(days=1)
|
|
158
|
+
|
|
159
|
+
if outlet_rating_result is None:
|
|
160
|
+
outlet_rating_result = OutletRatingResult(
|
|
161
|
+
outlet = outlet.create_ndb_key(),
|
|
162
|
+
)
|
|
163
|
+
rating_result = {
|
|
164
|
+
'service_rating' : .0,
|
|
165
|
+
'ambience_rating' : .0,
|
|
166
|
+
'food_rating' : .0,
|
|
167
|
+
'value_rating' : .0,
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
else:
|
|
171
|
+
rating_result = outlet_rating_result.rating_result
|
|
172
|
+
existing_total_rating_count = outlet_rating_result.total_rating_count
|
|
173
|
+
|
|
174
|
+
new_rating_list = OutletRating.list_new_rating_by_outlet(outlet, updated_datetime_from)
|
|
175
|
+
total_new_rating_count = len(new_rating_list)
|
|
176
|
+
|
|
177
|
+
new_service_rating = .0
|
|
178
|
+
new_ambience_rating = .0
|
|
179
|
+
new_food_rating = .0
|
|
180
|
+
new_value_rating = .0
|
|
181
|
+
|
|
182
|
+
for r in new_rating_list:
|
|
183
|
+
new_service_rating +=r.service_rating
|
|
184
|
+
new_ambience_rating +=r.ambience_rating
|
|
185
|
+
new_food_rating +=r.food_rating
|
|
186
|
+
new_value_rating +=r.value_rating
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
updated_rating_list = OutletRating.list_updated_rating_by_outlet(outlet, updated_datetime_from)
|
|
190
|
+
#total_updated_rating_count = len(updated_rating_list)
|
|
191
|
+
|
|
192
|
+
updated_service_rating = rating_result.get('service_rating') * existing_total_rating_count
|
|
193
|
+
updated_ambience_rating = rating_result.get('ambience_rating') * existing_total_rating_count
|
|
194
|
+
updated_food_rating = rating_result.get('food_rating') * existing_total_rating_count
|
|
195
|
+
updated_value_rating = rating_result.get('value_rating') * existing_total_rating_count
|
|
196
|
+
|
|
197
|
+
for r in updated_rating_list:
|
|
198
|
+
updated_service_rating +=(r.service_rating-r.previous_service_rating)
|
|
199
|
+
updated_ambience_rating +=(r.ambience_rating-r.previous_ambience_rating)
|
|
200
|
+
updated_food_rating +=(r.food_rating-r.previous_food_rating)
|
|
201
|
+
updated_value_rating +=(r.value_rating-r.previous_value_rating)
|
|
202
|
+
|
|
203
|
+
latest_service_rating = (new_service_rating + updated_service_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
204
|
+
latest_ambience_rating = (new_ambience_rating + updated_ambience_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
205
|
+
latest_food_rating = (new_food_rating + updated_food_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
206
|
+
latest_value_rating = (new_value_rating + updated_value_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
score = (latest_service_rating + latest_ambience_rating + latest_food_rating + latest_value_rating)/4
|
|
210
|
+
outlet_rating_result.total_rating_count = existing_total_rating_count + total_new_rating_count
|
|
211
|
+
outlet_rating_result.rating_result = {
|
|
212
|
+
'reviews_details':{
|
|
213
|
+
'service_rating' : latest_service_rating,
|
|
214
|
+
'ambience_rating' : latest_ambience_rating,
|
|
215
|
+
'food_rating' : latest_food_rating,
|
|
216
|
+
'value_rating' : latest_value_rating,
|
|
217
|
+
},
|
|
218
|
+
'total_reviews' : outlet_rating_result.total_rating_count,
|
|
219
|
+
'score' : score,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
outlet_rating_result.put()
|
|
223
|
+
|
|
224
|
+
class MerchantRatingResult(RatingResult):
|
|
225
|
+
merchant_acct = ndb.KeyProperty(name="merchant_acct", kind=MerchantAcct)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
dict_properties = ['total_rating_count', 'rating_result', 'modified_datetime',]
|
|
229
|
+
|
|
230
|
+
@staticmethod
|
|
231
|
+
def get_by_merchant_acct(merchant_acct):
|
|
232
|
+
return MerchantRatingResult.query(ndb.AND(MerchantRatingResult.merchant_acct==merchant_acct.create_ndb_key())).get()
|
|
233
|
+
|
|
234
|
+
@staticmethod
|
|
235
|
+
def update(merchant_acct, updated_datetime_from=None):
|
|
236
|
+
|
|
237
|
+
logger.info('updated_datetime_from=%s', updated_datetime_from)
|
|
238
|
+
|
|
239
|
+
merchant_rating_result = MerchantRatingResult.query(ndb.AND(MerchantRatingResult.merchant_acct==merchant_acct.create_ndb_key())).get()
|
|
240
|
+
existing_total_rating_count = 0
|
|
241
|
+
#if updated_datetime_from is None:
|
|
242
|
+
# updated_datetime_from = datetime.utcnow() - timedelta(days=1)
|
|
243
|
+
is_new_rating_result = False
|
|
244
|
+
if merchant_rating_result is None:
|
|
245
|
+
merchant_rating_result = MerchantRatingResult(
|
|
246
|
+
merchant_acct = merchant_acct.create_ndb_key(),
|
|
247
|
+
)
|
|
248
|
+
rating_result = {
|
|
249
|
+
'reviews_details':{
|
|
250
|
+
'service_rating' : .0,
|
|
251
|
+
'ambience_rating' : .0,
|
|
252
|
+
'food_rating' : .0,
|
|
253
|
+
'value_rating' : .0,
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
is_new_rating_result = True
|
|
258
|
+
|
|
259
|
+
if updated_datetime_from is None:
|
|
260
|
+
updated_datetime_from = merchant_acct.registered_datetime
|
|
261
|
+
|
|
262
|
+
else:
|
|
263
|
+
rating_result = merchant_rating_result.rating_result
|
|
264
|
+
existing_total_rating_count = merchant_rating_result.total_rating_count
|
|
265
|
+
|
|
266
|
+
if updated_datetime_from is None:
|
|
267
|
+
updated_datetime_from = merchant_rating_result.modified_datetime
|
|
268
|
+
|
|
269
|
+
logger.info('rating_result=%s', rating_result)
|
|
270
|
+
|
|
271
|
+
logger.info('updated_datetime_from=%s', updated_datetime_from)
|
|
272
|
+
|
|
273
|
+
new_rating_list = OutletRating.list_new_rating_by_merchant(merchant_acct, updated_datetime_from)
|
|
274
|
+
updated_rating_list = OutletRating.list_updated_rating_by_merchant(merchant_acct, updated_datetime_from)
|
|
275
|
+
|
|
276
|
+
total_new_rating_count = len(new_rating_list)
|
|
277
|
+
total_updated_rating_count = len(updated_rating_list)
|
|
278
|
+
|
|
279
|
+
logger.info('total_new_rating_count=%s', total_new_rating_count)
|
|
280
|
+
logger.info('total_updated_rating_count=%s', total_updated_rating_count)
|
|
281
|
+
logger.info('existing_total_rating_count=%s', existing_total_rating_count)
|
|
282
|
+
|
|
283
|
+
new_service_rating = .0
|
|
284
|
+
new_ambience_rating = .0
|
|
285
|
+
new_food_rating = .0
|
|
286
|
+
new_value_rating = .0
|
|
287
|
+
|
|
288
|
+
for r in new_rating_list:
|
|
289
|
+
new_service_rating +=r.service_rating
|
|
290
|
+
new_ambience_rating +=r.ambience_rating
|
|
291
|
+
new_food_rating +=r.food_rating
|
|
292
|
+
new_value_rating +=r.value_rating
|
|
293
|
+
|
|
294
|
+
r.updated = True
|
|
295
|
+
|
|
296
|
+
ndb.put_multi(new_rating_list)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
logger.info('new_service_rating=%s', new_service_rating)
|
|
300
|
+
logger.info('new_ambience_rating=%s', new_ambience_rating)
|
|
301
|
+
logger.info('new_food_rating=%s', new_food_rating)
|
|
302
|
+
logger.info('new_value_rating=%s', new_value_rating)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
updated_service_rating = rating_result.get('reviews_details').get('service_rating', 0) * existing_total_rating_count
|
|
307
|
+
updated_ambience_rating = rating_result.get('reviews_details').get('ambience_rating', 0) * existing_total_rating_count
|
|
308
|
+
updated_food_rating = rating_result.get('reviews_details').get('food_rating', 0) * existing_total_rating_count
|
|
309
|
+
updated_value_rating = rating_result.get('reviews_details').get('value_rating', 0) * existing_total_rating_count
|
|
310
|
+
|
|
311
|
+
logger.info('updated_service_rating b4=%s', updated_service_rating)
|
|
312
|
+
logger.info('updated_ambience_rating b4=%s', updated_ambience_rating)
|
|
313
|
+
logger.info('updated_food_rating b4=%s', updated_food_rating)
|
|
314
|
+
logger.info('updated_value_rating b4=%s', updated_value_rating)
|
|
315
|
+
|
|
316
|
+
for r in updated_rating_list:
|
|
317
|
+
logger.debug('updated rating = %s', r)
|
|
318
|
+
if is_new_rating_result:
|
|
319
|
+
updated_service_rating +=r.service_rating
|
|
320
|
+
updated_ambience_rating +=r.ambience_rating
|
|
321
|
+
updated_food_rating +=r.food_rating
|
|
322
|
+
updated_value_rating +=r.value_rating
|
|
323
|
+
else:
|
|
324
|
+
updated_service_rating +=(r.service_rating-r.previous_service_rating)
|
|
325
|
+
updated_ambience_rating +=(r.ambience_rating-r.previous_ambience_rating)
|
|
326
|
+
updated_food_rating +=(r.food_rating-r.previous_food_rating)
|
|
327
|
+
updated_value_rating +=(r.value_rating-r.previous_value_rating)
|
|
328
|
+
|
|
329
|
+
logger.info('updated_service_rating after=%s', updated_service_rating)
|
|
330
|
+
logger.info('updated_ambience_rating after=%s', updated_ambience_rating)
|
|
331
|
+
logger.info('updated_food_rating after=%s', updated_food_rating)
|
|
332
|
+
logger.info('updated_value_rating after=%s', updated_value_rating)
|
|
333
|
+
|
|
334
|
+
if is_new_rating_result:
|
|
335
|
+
latest_service_rating = (new_service_rating + updated_service_rating) / (total_updated_rating_count + total_new_rating_count)
|
|
336
|
+
latest_ambience_rating = (new_ambience_rating + updated_ambience_rating) / (total_updated_rating_count + total_new_rating_count)
|
|
337
|
+
latest_food_rating = (new_food_rating + updated_food_rating) / (total_updated_rating_count + total_new_rating_count)
|
|
338
|
+
latest_value_rating = (new_value_rating + updated_value_rating) / (total_updated_rating_count + total_new_rating_count)
|
|
339
|
+
|
|
340
|
+
merchant_rating_result.total_rating_count = total_updated_rating_count + total_new_rating_count
|
|
341
|
+
|
|
342
|
+
else:
|
|
343
|
+
latest_service_rating = (new_service_rating + updated_service_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
344
|
+
latest_ambience_rating = (new_ambience_rating + updated_ambience_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
345
|
+
latest_food_rating = (new_food_rating + updated_food_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
346
|
+
latest_value_rating = (new_value_rating + updated_value_rating) / (existing_total_rating_count + total_new_rating_count)
|
|
347
|
+
|
|
348
|
+
merchant_rating_result.total_rating_count = existing_total_rating_count + total_new_rating_count
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
score = (latest_service_rating + latest_ambience_rating + latest_food_rating + latest_value_rating)/4
|
|
352
|
+
|
|
353
|
+
logger.info('latest_service_rating=%s', latest_service_rating)
|
|
354
|
+
logger.info('latest_ambience_rating=%s', latest_ambience_rating)
|
|
355
|
+
logger.info('latest_food_rating=%s', latest_food_rating)
|
|
356
|
+
logger.info('latest_value_rating=%s', latest_value_rating)
|
|
357
|
+
|
|
358
|
+
logger.info('score=%s', score)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
merchant_rating_result.rating_result = {
|
|
362
|
+
'reviews_details':{
|
|
363
|
+
'service_rating' : latest_service_rating,
|
|
364
|
+
'ambience_rating' : latest_ambience_rating,
|
|
365
|
+
'food_rating' : latest_food_rating,
|
|
366
|
+
'value_rating' : latest_value_rating,
|
|
367
|
+
},
|
|
368
|
+
'total_reviews' : merchant_rating_result.total_rating_count,
|
|
369
|
+
'score' : score,
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
merchant_rating_result.put()
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/redemption_catalogue_models.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{trex-model-1.2.6 → trex-model-1.2.7}/trexmodel/models/datastore/spending_base_program_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|