18/09/22 - 15h30

master
ChérifBALDE 2022-09-18 15:41:14 +02:00 committed by cherif
parent 271279400a
commit b57764c980
4 changed files with 111 additions and 33 deletions

12
main.py
View File

@ -1474,8 +1474,16 @@ def removeLSaccount():
status, message = mycommon.removeLSaccount()
return jsonify(status=status, message=message)
"""
Correction
"""
@app.route('/myclass/api/correction_collection/', methods=['GET','POST'])
@crossdomain(origin='*')
def correction_collection():
# On recupere le corps (payload) de la requete
print(" correction_collection ")
status, message = mycommon.correction_collection()
return jsonify(status=status, message=message)
if __name__ == '__main__':
print(" debut api")

View File

@ -1776,3 +1776,63 @@ def TryUrlImage(url=None):
exc_type, exc_obj, exc_tb = sys.exc_info()
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, False
"""
Suite à un bug dans la collection : user_recherche_result
le champs "partner_owner_recid" n'existe pas . \
Cette fonction va corriger en cela en mettant la bonne valeur\
"""
def correction_collection():
try:
nb_line = 0
my_coll = MYSY_GV.dbname['user_recherche_result']
my_coll_class = MYSY_GV.dbname['myclass']
for val in my_coll.find():
if ("external_code" in val.keys()):
if val['external_code']:
training_external_code = val['external_code']
#print(" TRAITEMENT DE "+training_external_code)
val_tmp = my_coll_class.count_documents({'external_code':str(training_external_code)})
if( val_tmp > 0 ):
class_part_recid = my_coll_class.find({'external_code':str(training_external_code)})
if( class_part_recid and class_part_recid[0]) :
#print(" pour la formation : "+str(training_external_code)+" --- le partner_owner_recid = "+
# str(class_part_recid[0]))
x = class_part_recid[0]
if ("partner_owner_recid" in x.keys()):
if x['partner_owner_recid']:
result = my_coll.update_many(
{'external_code': str(training_external_code)},
{
"$set": {"partner_owner_recid": str(x['partner_owner_recid'])}
})
if (result.matched_count > 0):
nb_line = nb_line + 1
print(" OK "+str(training_external_code))
else:
print(' PBBBBBBBBBB pour external_code = '+str(training_external_code))
else:
result = my_coll.update_many(
{'external_code': str(training_external_code)},
{
"$set": {"partner_owner_recid": "todelete"}
})
if (result.matched_count > 0):
nb_line = nb_line + 1
print(" TO DELETE " + str(training_external_code))
return True, str(nb_line)+" ont été traitées "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, False

View File

@ -203,7 +203,7 @@ def GetStat_class_view(diction):
pipe2 = [
{'$match': {'date_update' : { '$gte' : str(date_start), '$lte' : str(date_end)},
'token':str(mydata['token'])
'partner_owner_recid':str(user_recid)
}},
{
'$group': {
@ -249,10 +249,7 @@ def GetStat_class_view(diction):
tmp_val['nb_view'] = str(result['count'])
insertObject.append(JSONEncoder().encode(tmp_val))
tmp_val2 = {}
tmp_val2['data'] = "21, 35, 75, 51, 41, 47"
insertObject.append(JSONEncoder().encode(tmp_val2))
# print(result)
# print(result)
return True, insertObject
@ -263,7 +260,8 @@ def GetStat_class_view(diction):
"""
Cette fonction retourne le top 5 sur une periode donnée
Cette fonction retourne le top 5 sur une periode donnée pour un partenaire.
Dans ses arguments, elle prendra le token, puis va allercherche le recid du partenaire
"""
def GetStat_class_view_topX(diction):
try:
@ -299,26 +297,30 @@ def GetStat_class_view_topX(diction):
# recuperation des paramettre
mydata = {}
my_token = ""
if ("token" in diction.keys()):
if diction['token']:
mydata['token'] = diction['token']
my_token = diction['token']
date_start = ""
if ("date_start" in diction.keys()):
if diction['date_start']:
date_start = diction['date_start']
mydata['date_start'] = diction['date_start']
date_end = ""
if ("date_end" in diction.keys()):
if diction['date_end']:
date_end = diction['date_end']
mydata['date_end'] = diction['date_end']
topX = 0
if ("topX" in diction.keys()):
if diction['topX']:
topX = mycommon.tryInt(diction['topX'])
mydata['topX'] = diction['topX']
local_status, try_end_date = mycommon.TryToDateYYYMMDD(str(diction['date_end']))
@ -337,7 +339,7 @@ def GetStat_class_view_topX(diction):
tmp = tmp - 1
day_before = new_end_date + timedelta(days=tmp)
categories_val = categories_val+str(day_before)+","
print(" day_before DATE = " + str(day_before)+ " VS "+str(new_from_date))
#print(" day_before DATE = " + str(day_before)+ " VS "+str(new_from_date))
if(categories_val.endswith(',') ):
categories_val = categories_val[:-1]
@ -353,25 +355,31 @@ def GetStat_class_view_topX(diction):
CONCERNANT LES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
'''
retval = mycommon.check_partner_token_validity("", str(mydata['token']))
retval = mycommon.check_partner_token_validity("", str(my_token))
if retval is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
return False, "L'email ou le token ne sont pas valident"
# Recuperation du recid du partenaire
user_recid = mycommon.get_parnter_recid_from_token(str(mydata['token']))
user_recid = mycommon.get_parnter_recid_from_token(str(my_token))
if user_recid is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du partenaire")
return False, " Les informations d'identification sont incorrectes"
mydata['partner_owner_recid'] = str(user_recid)
"""
Recuperation des id (internal_url) des formations
"""
status_tmp, diction_topx = Get_X_Best_Class_On_Given_period(diction)
print(" ICI diction = "+str(mydata))
status_tmp, diction_topx = Get_X_Best_Class_On_Given_period(mydata)
if( status_tmp is False):
return False, "Impossible de recuperer les stats- erreur interne"
print(" pour cette stat, le voix le top " + str(topX) + " des ref concernées ")
print(" pour cette stat, voici le top " + str(topX) + " des ref concernées ")
print(diction_topx)
print(" ========= print(diction_topx)")
@ -406,7 +414,7 @@ def GetStat_class_view_topX(diction):
pipe2 = [
{'$match': {'date_update' : { '$gte' : str(date_start), '$lte' : str(date_end)},
'token':str(mydata['token']),
'partner_owner_recid':str(user_recid),
'internal_url': {'$in': liste_formation},
}},
{
@ -470,7 +478,7 @@ les plus vue sur une periode donnée
def Get_X_Best_Class_On_Given_period(diction):
try:
field_list = ['token', 'date_start', 'date_end', 'topX']
field_list = ['partner_owner_recid', 'date_start', 'date_end', 'topX']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list:
@ -481,10 +489,10 @@ def Get_X_Best_Class_On_Given_period(diction):
# collection
collection = MYSY_GV.dbname["user_recherche_result"]
mytoken = ""
if ("token" in diction.keys()):
if diction['token']:
mytoken = diction['token']
partner_owner_recid = ""
if ("partner_owner_recid" in diction.keys()):
if diction['partner_owner_recid']:
partner_owner_recid = diction['partner_owner_recid']
date_start = ""
if ("date_start" in diction.keys()):
@ -503,7 +511,7 @@ def Get_X_Best_Class_On_Given_period(diction):
pipe2 = [
{'$match': {'date_update': {'$gte': str(date_start), '$lte': str(date_end)},
'token': str(mytoken)
'partner_owner_recid': str(partner_owner_recid)
}},
{
'$group': {
@ -524,24 +532,24 @@ def Get_X_Best_Class_On_Given_period(diction):
}
]
#print(" PIP 222 =" + str(pipe2))
print(" PIP 222 =" + str(pipe2))
insertObject = []
for result in collection.aggregate(pipe2):
tmp_val = {}
# tab_training_id.append(str(result["_id"]))
#tab_training_id.append(str(result["_id"]))
# print(result['_id'])
if ("OWNER" in result['_id'].keys()):
if result['_id']['OWNER']:
#print("Owner = " + str(result['_id']['OWNER']))
print("Owner = " + str(result['_id']['OWNER']))
tmp_val['owner'] = str(result['_id']['OWNER'])
if ("INTERNAL URL" in result['_id'].keys()):
if result['_id']['INTERNAL URL']:
#print("INTERNAL URL = " + str(result['_id']['INTERNAL URL']))
print("INTERNAL URL = " + str(result['_id']['INTERNAL URL']))
tmp_val['internal_url'] = str(result['_id']['INTERNAL URL'])
#print("Nombre = " + str(result['count']))

View File

@ -57,7 +57,7 @@ def get_recherche_gle_class(sentence):
for x in coll_name.find({"external_code": {"$in": tab_training}, 'published':'1'}, {"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0, "valide": 0,
"locked": 0, "partner_owner_recid": 0, }):
"locked": 0, }):
mycommon.myprint(x)
user = x
insertObject.append(JSONEncoder().encode(user))
@ -82,7 +82,7 @@ def get_class_by_list_attr(attribut, list_values):
insertObject = []
for x in coll_name.find({attribut:{ "$in":ela_array}, 'published':'1'},{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }):
"valide": 0, "locked": 0, }):
mycommon.myprint(x)
user = x
insertObject.append(JSONEncoder().encode(user))
@ -105,7 +105,7 @@ def update_class_by_attribut(objId, attribut, value):
insertObject = []
for x in coll_name.find({attribut: value, 'published':'1'}, {"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0,
"indexed_title": 0, "valide": 0, "locked": 0, "partner_owner_recid": 0, }):
"indexed_title": 0, "valide": 0, "locked": 0, }):
mycommon.myprint(x)
user = x
insertObject.append(JSONEncoder().encode(user))
@ -191,7 +191,7 @@ def get_all_class(diction):
for x in coll_name.find({ "$or": [ {'valide':'1', 'locked':'0', 'isalaune':'1', 'published':'1'}, { 'coeur': 1, 'published':'1' } ] },
{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }).\
"valide": 0, "locked": 0, }).\
limit(nb_formation_a_jouter).\
sort(
[("display_rank", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING) ]):
@ -308,7 +308,7 @@ def get_training_in_user_zone(diction):
for x in coll_name.find({ "$or": [ {'valide':'1', 'locked':'0', 'isalaune':'1','published':'1', "zone_diffusion.country":str(mydata['user_country_code']).lower()},
{'valide':'1', 'locked':'0', 'isalaune':'1', 'published':'1', "zone_diffusion.city":str(mydata['user_city']).lower()} ] },
{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }).\
"valide": 0, "locked": 0, }).\
limit(MYSY_GV.MAINPAGE_QUERY_LIMIT_ROW).\
sort(
[ ("display_rank", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING),]):
@ -523,7 +523,7 @@ def recherche_text_simple(diction):
for x in coll_name.find({"external_code": {"$in": final_message2}, 'published':'1'},
{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0,
"indexed_title": 0, "valide": 0, "locked": 0, "partner_owner_recid": 0, }).\
"indexed_title": 0, "valide": 0, "locked": 0, }).\
sort([("display_rank", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING), ]):
nb_result = nb_result +1
@ -598,14 +598,16 @@ def recherche_text_simple(diction):
for x in coll_name.find({"external_code":{"$in":tab_training}, 'published':'1'},
{"_id": 0, "indexed": 0, "indexed_desc": 0,
"indexed_obj": 0, "indexed_title": 0, "valide": 0,
"locked": 0, "partner_owner_recid": 0, }).sort([("display_rank", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING), ]):
"locked": 0 }).sort([("display_rank", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING), ]):
nb_result = nb_result + 1
my_recid = {}
my_recid['user_rec_id'] = str(user_recid)
#print(" XXXXXXXXXX = "+str(x))
mydict_combined = {**diction, **x, **my_recid}
mydict_combined['date_update'] = str(datetime.now())
mydict_combined['type_view'] = "summary"
#print( "mydict_combined YYYYYYYYY = "+str(mydict_combined))
if ("_id" in mydict_combined.keys()):
mydict_combined['class_id'] = mydict_combined.pop('_id')
@ -1136,7 +1138,7 @@ def recherche_tips(diction):
insertObject = []
for x in coll_name.find({"external_code": {"$in": tab_training}, 'published':'1'}, {"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }):
"valide": 0, "locked": 0, }):
#mycommon.myprint(x)
user = x
val = x['description']