16/10/22 - 15h00

master
ChérifBALDE 2022-10-16 21:22:19 +02:00 committed by cherif
parent 1019da4b1a
commit 1d4c2ffb99
5 changed files with 145 additions and 31 deletions

View File

@ -64,8 +64,8 @@ token_fr_pontuation = []
La taille maximal d'un champs à retourner.
Au dela de 300 caractère, le système rame
'''
MAX_CARACT = 200
MAX_CARACT_DEDUIT = 50
MAX_CARACT = 100
MAX_CARACT_DEDUIT = 150
TOKEN_SIZE = 25
MAX_CARACT_DETAIL = 500

View File

@ -22,7 +22,7 @@ import GlobalVariable as MYSY_GV
import user_message_mgt as umm
import Ela_Spacy as ES
import GlobalVariable as MYSY_GV
import re
class JSONEncoder(json.JSONEncoder):
def default(self, o):
@ -63,7 +63,7 @@ def get_all_articles_avis(diction):
for x in coll_name.find({'valide': '1', 'locked': '0'},
{ "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, }).sort(
[("title_formation",pymongo.ASCENDING), ("date_avis",pymongo.ASCENDING)]):
[ ("date_avis",pymongo.DESCENDING), ("title_formation",pymongo.ASCENDING),]):
# mycommon.myprint("AVANT ==> "+str(x['description']))
val = x['qualite']
if (len(x['qualite']) > MYSY_GV.MAX_CARACT):
@ -73,11 +73,18 @@ def get_all_articles_avis(diction):
x['qualite'] = val[:MYSY_GV.MAX_CARACT]
val = x['avis']
if (len(x['avis']) > MYSY_GV.MAX_CARACT):
x['avis'] = val[:MYSY_GV.MAX_CARACT] + " ..."
CLEANR = re.compile('<.*?>')
clean_avis = re.sub(CLEANR, '', str(val))
clean_avis = str(clean_avis).replace("&nbsp;", " ");
#print(" ### CLEANRCLEANR = "+str(clean_avis))
if (len(clean_avis) > MYSY_GV.MAX_CARACT):
x['avis'] = clean_avis[:MYSY_GV.MAX_CARACT] + " ..."
else:
x['avis'] = val[:MYSY_GV.MAX_CARACT]
x['avis'] = str(clean_avis)
# mycommon.myprint("APRES ==> " + str(x['description']))
@ -546,11 +553,15 @@ def recherche_articles_avis(diction):
x['qualite'] = val[:MYSY_GV.MAX_CARACT]
val = x['avis']
if (len(x['avis']) > MYSY_GV.MAX_CARACT):
x['avis'] = val[:MYSY_GV.MAX_CARACT] + " ..."
CLEANR = re.compile('<.*?>')
clean_avis = re.sub(CLEANR, '', str(val))
#print(" ### CLEANRCLEANR = "+str(CLEANR))
if (len(clean_avis) > MYSY_GV.MAX_CARACT):
x['avis'] = clean_avis[:MYSY_GV.MAX_CARACT] + " ..."
else:
x['avis'] = val[:MYSY_GV.MAX_CARACT]
x['avis'] = str(clean_avis)
print(user)
insertObject.append(JSONEncoder().encode(user))

View File

@ -419,10 +419,14 @@ def add_class(diction):
if ret_val and ret_val['_id']:
#Indexation Title de la nouvelle formation ajoutée
training_to_index_title = {}
training_to_index_title['internal_url'] =mydata['internal_url']
training_to_index_title['internal_url'] = mydata['internal_url']
training_to_index_title['reindex_all'] = '0'
eibdd.ela_index_given_classes_title(training_to_index_title)
# Indexation Title des mots clées
eibdd.ela_index_given_classes_keywords(training_to_index_title)
return True, "La formation a bien été ajoutée"
else:
mycommon.myprint(" Impossible d'ajouter la formation "+str(str(mydata['external_code'])))

View File

@ -269,12 +269,111 @@ def ela_index_all_classes_keywords():
mycommon.myprint(str(nb_class_indexed) + " ont été indexes")
return True, str(nb_class_indexed) + " ont été indexes "
return True
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible d'indexer la BDD des formations ==> KO"
"""
Cette fonction va indexer les mots clés d'une formation donnée ou toutes les formation d'un partenaire.
Pour ce faire elle prend en argument :
- internal_url
- partenaire_recid
/!\ Important : La fonction peut reindexer les formation si l'argument
reindexe = 1
"""
def ela_index_given_classes_keywords(diction) :
# Making a Connection with MongoClient
try:
# Dictionnaire des champs utilisables
field_list = ['internal_url', 'partner_owner_recid', 'reindex_all']
incom_keys = diction.keys()
'''
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list.
'''
for val in incom_keys:
if str(val).lower() not in str(field_list).lower():
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, MAJ annulée")
return False, " Impossible de se connecter, merci de contacter le support technique"
check = False
internal_url = ""
if ("internal_url" in diction.keys()):
if diction['internal_url']:
check = True
internal_url = diction['internal_url']
partner_owner_recid = ""
if ("partner_owner_recid" in diction.keys()):
if diction['partner_owner_recid']:
check = True
partner_owner_recid = diction['partner_owner_recid']
reindex_all = ""
if ("reindex_all" in diction.keys()):
if diction['reindex_all']:
check = True
reindex_all = diction['reindex_all']
if( check is False ):
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucune formation à indexer")
return True, " Aucune formation à indexer"
collection = MYSY_GV.dbname["myclass"]
nb_class_indexed = 0
myquery = {'valide':'1'}
if( internal_url and len(str(internal_url)) > 0 ):
myquery['internal_url'] = internal_url
if (partner_owner_recid and len(str(partner_owner_recid)) > 0):
myquery['partner_owner_recid'] = partner_owner_recid
if (reindex_all and len(str(reindex_all)) > 0):
if(reindex_all != "1" ):
myquery['indexed_keyword'] = "0"
print(" QUERY INDEX keyword ="+str(myquery))
for doc in collection.find(myquery):
if ("title" in doc.keys()):
chaine = doc["title"]
mycommon.myprint(" external_code = " + str(doc["external_code"]) + " ==> " + str(chaine))
retval = ela_index_class(str(doc["external_code"]), "keyword")
print(" apres : ela_index_given_classes_keywords retval = " + str(retval))
if (retval is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + "IMPOSSIBLE d'indexer la formation = " + str(doc["external_code"]))
else:
nb_class_indexed = nb_class_indexed + 1
# retval = ls.ela_index_record_field(chaine, str(doc["external_code"]))
mycommon.myprint(str(nb_class_indexed) + " ont été indexes ==> keyword")
return True, str(nb_class_indexed) + " ont été indexes ==> keyword"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, "Impossible d'indexer la BDD des formations ==> KO"
'''
La fonction "ela_index_all_classes_title" va aller chercher chaque cours dans la BDD
et créer les mots clées des title qui sont ensuite enregister dans la table "elaindex"
@ -384,24 +483,8 @@ def ela_index_given_classes_title(diction) :
collection = MYSY_GV.dbname["myclass"]
'''
ATTENTION ATTENTION
/!\ : avant l'indexation, on vide la table des indexes.
cette logique est tres gourmande.
ce quil faudrait faire :
- si une formation est indexée, mettre un fag pour dire : indexé => OK
- si on met à jour une formation ==> Mettre le flag à KO
- si on ajoute une formation, mettre le flag à KO
ex : indexation du champ 'title' ou du champ 'objectif', je vais introduitre la notion de 'source_fied'
pour l'indexation title, 'source_fied' = 'title'
pour l'indexation objectif, 'source_fied' = 'objectif'
apres pour l'indexation, il ne faudra indexer que les formation dont le flag est KO.
aussi, avant d'indexer une formation, supprimer tous les index de la dite formation pour remplacer tous les anciens et eviter un doublon
'''
nb_class_indexed = 0
myquery = {'valide':'1'}
if( internal_url and len(str(internal_url)) > 0 ):
@ -431,8 +514,8 @@ def ela_index_given_classes_title(diction) :
# retval = ls.ela_index_record_field(chaine, str(doc["external_code"]))
mycommon.myprint(str(nb_class_indexed) + " ont été indexes")
return True, str(nb_class_indexed) + " ont été indexes "
mycommon.myprint(str(nb_class_indexed) + " ont été indexes => title")
return True, str(nb_class_indexed) + " ont été indexes => title "
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()

18
main.py
View File

@ -1603,7 +1603,7 @@ def recordClassImage():
"""
Cette API va indexer une formation donnée ou toutes les formation d'un partenaire.
Indexation du titre : Cette API va indexer une formation donnée ou toutes les formation d'un partenaire.
Pour ce faire elle prend en argument :
- internal_url
- partenaire_recid
@ -1618,6 +1618,22 @@ def ela_index_given_classes_title():
return jsonify(status=status, message=retval)
"""
Indexation des mots clés : Cette API va indexer une formation donnée ou toutes les formation d'un partenaire.
Pour ce faire elle prend en argument :
- internal_url
- partenaire_recid
"""
@app.route('/myclass/api/ela_index_given_classes_keywords/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_given_classes_keywords():
# On recupere le corps (payload) de la requete
payload = request.form.to_dict()
print(" ### payload = ",payload)
status, retval = ela_index_class.ela_index_given_classes_keywords(payload)
return jsonify(status=status, message=retval)
"""
Stripe Payement : Creation d'un abonnement
"""