Commit 94d8f718 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

màj checkword pour phonographe + addStat

parent 63610aea
......@@ -34,9 +34,11 @@ def connexion():
print('Connexion à AlemDic...')
mongodb_client = pymongo.MongoClient("mongodb+srv://alemadmin:"+mdp+"@cluster0.6nopd.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
print(mongodb_client.list_database_names())
return mongodb_client['alemdic']
return mongodb_client
alemdic = connexion()
alemDb = connexion()
alemdic = alemDb['alemdic']
appStats = alemDb['alem-app_db']['appStats']
dicoFr = alemdic['dicoFr']
dicoEn = alemdic['dicoEn']
dicoZh = alemdic['dicoZh']
......@@ -81,7 +83,7 @@ def getLenDic(lang):
##### MISE EN MÉMOIRE DES DICTIONNAIRES (seulement les transcriptions+regions)
def makeWord2trans(alemDic):
query = alemDic.find()#.limit(100000)
query = alemDic.find()#.limit(10000)
word2trans = {}
cpt = 0
for q in query:
......@@ -598,4 +600,14 @@ def writeLog(Type,user,mot,oldMot,newMot,lang):
logDic.insert_one(newlog)
print("New log: lang={} ; user={} ; word={} ; type={}".format(lang,user,mot,Type))
return noIdDict(newlog)
\ No newline at end of file
return noIdDict(newlog)
def addStat(app, module, ip, lang):
newStat = {
'date':datetime.datetime.now(),
'app': app,
'module': module,
'ip': ip,
'lang': lang
}
appStats.insert_one(newStat)
\ No newline at end of file
......@@ -294,6 +294,21 @@ def checkWord(request):
}
return JsonResponse(rep)
def checkWordList(request):
colis = json.loads(request.body)
wordPhonoSpansList = colis['wordPhonoSpansList']
lang = colis['lang']
repList = []
for w in wordPhonoSpansList:
repList.append(txtphono.checkIfWordExists(w['w'],w['t'],lang))
rep = {
'rep': repList
}
return JsonResponse(rep)
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
......@@ -330,4 +345,15 @@ def supprEntry(request):
def getLog(request):
lang = request.GET.get('lang', None)
rep = txtphono.sendMeLogPlease(lang)
return JsonResponse({"logs":rep})
\ No newline at end of file
return JsonResponse({"logs":rep})
def addStat(request):
colis = json.loads(request.body)
app = colis["app"]
module = colis["module"]
ip = get_client_ip(request)
lang = colis["lang"]
txtphono.addStat(app, module, ip, lang)
return JsonResponse({})
\ No newline at end of file
......@@ -33,12 +33,14 @@ CORS_ORIGIN_ALLOW_ALL = False
CORS_ALLOWED_ORIGINS = [
"http://91.175.103.88:8000",
"http://127.0.0.1:8000",
"http://127.0.0.1:7000",
"https://phonographe.alem-app.fr",
"https://51.83.72.79:7000"
]
CSRF_TRUSTED_ORIGINS = [
"http://91.175.103.88:8000",
"http://127.0.0.1:8000",
"http://127.0.0.1:7000",
"https://phonographe.alem-app.fr",
"https://51.83.72.79:7000"
]
......@@ -91,17 +93,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'coloriseur.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
......
......@@ -32,8 +32,10 @@ urlpatterns = [
path('app/dico/zh', colorapp_views.dicoViewZh),
path('dicoSearch/', colorapp_views.dicoReq),
path('checkWord/', colorapp_views.checkWord),
path('checkWordList/', csrf_exempt(colorapp_views.checkWordList)),
path('editEntry/', csrf_exempt(colorapp_views.editEntry)),
path('addEntry/', colorapp_views.newEntry),
path('delEntry/', colorapp_views.supprEntry),
path('getLog/', colorapp_views.getLog)
path('getLog/', colorapp_views.getLog),
path('addStat/', csrf_exempt(colorapp_views.addStat))
]
......@@ -124,6 +124,7 @@ $(document).ready(function(){
lastEntrShowed = nb;
if (nb >= Object.keys(dico).length) document.getElementById('btnShowMore').style.display = 'none';
}
addStat("dicoSearch");
});
});
......
......@@ -164,4 +164,27 @@ function interface(lang) {
title.title = langJson[title.id]["fr"];
}
}
}
async function addStat(modul) {
var lang = document.getElementById('choixLang').value;
// ON EMBALLE TOUT ÇA
var colis = {
app: "wikicolor",
module: modul,
lang: lang
}
// Paramètres d'envoi
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(colis)
};
// ENVOI
await fetch('/addStat/', options);
}
\ No newline at end of file
......@@ -3,216 +3,218 @@ var dicoTok = {};
var dicoId = {};
async function getColorisation() {
document.getElementById('loader').style.display = "block";
var inText = document.getElementById('inText').value;
var lang = document.getElementById('choixLang').value;
// ON EMBALLE TOUT ÇA
var colis = {
inText: inText,
lang: lang
}
// console.log('Envoi colis:',colis);
// Paramètres d'envoi
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(colis)
};
// ENVOI
const response = await fetch('/colorize/', options)
const data = await response.json();
console.log(data);
// ÉCRITURE DU RÉSULTATS DANS DIV RÉSULTATS
if (lang == "fr" || lang == "en"){
document.getElementById('outputzh').innerHTML = "";
var outputDiv = document.getElementById('output');
var outText = data['outText'];
outputDiv.innerHTML = "";
dicoTok = {};
dicoId = {};
var noSpace = false;
for (i=0; i<outText.length; i++) {
// REMPLISSAGE DES ZONES MOTS DANS DIV RÉSULTATS
if (outText[i][0][0] == []) {
// Sécurité: si phonigraphie est une liste vide, on tente quand même d'afficher du texte en gris
console.log("Bug outText[",i,"][0][0] is empty!");
} else if (outText[i][0][0][0] == undefined){
console.log("undefined: index",i,outText[i][0][0])
} else {
if (outText[i][0][0][0].graph.match(/\n+/)){
for (h=0; h<outText[i][0][0][0].graph.length; h++) {
outputDiv.innerHTML = outputDiv.innerHTML + '<br>';
}
} else if (outText[i][0][0][0].graph.match(/^‿|-͜$/)){
if(outText[i][0][3] == "Liaison obligatoire") {
classliaison = "liaisonObligatoire"
} else if (outText[i][0][3] == "Liaison facultative") {
classliaison = "liaisonFacultative"
if (inText.length>0) {
document.getElementById('loader').style.display = "block";
// ON EMBALLE TOUT ÇA
var colis = {
inText: inText,
lang: lang
}
// console.log('Envoi colis:',colis);
// Paramètres d'envoi
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(colis)
};
// ENVOI
const response = await fetch('/colorize/', options)
const data = await response.json();
console.log(data);
// ÉCRITURE DU RÉSULTATS DANS DIV RÉSULTATS
if (lang == "fr" || lang == "en"){
document.getElementById('outputzh').innerHTML = "";
var outputDiv = document.getElementById('output');
var outText = data['outText'];
outputDiv.innerHTML = "";
dicoTok = {};
dicoId = {};
var noSpace = false;
for (i=0; i<outText.length; i++) {
// REMPLISSAGE DES ZONES MOTS DANS DIV RÉSULTATS
if (outText[i][0][0] == []) {
// Sécurité: si phonigraphie est une liste vide, on tente quand même d'afficher du texte en gris
console.log("Bug outText[",i,"][0][0] is empty!");
} else if (outText[i][0][0][0] == undefined){
console.log("undefined: index",i,outText[i][0][0])
} else {
if (outText[i][0][0][0].graph.match(/\n+/)){
for (h=0; h<outText[i][0][0][0].graph.length; h++) {
outputDiv.innerHTML = outputDiv.innerHTML + '<br>';
}
} else if (outText[i][0][0][0].graph.match(/^‿|-͜$/)){
if(outText[i][0][3] == "Liaison obligatoire") {
classliaison = "liaisonObligatoire"
} else if (outText[i][0][3] == "Liaison facultative") {
classliaison = "liaisonFacultative"
}
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="'+ classliaison +' phon '+ outText[i][0][0][0].phon +'" title="'+ outText[i][0][3] +'">'+ outText[i][0][0][0].graph +'</span>';
noSpace = true;
} else if (outText[i][0][0][0].graph.match(/^(,|\.|…|\)|\]|\}|%|>|»|”|-)$/)) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="phon_neutre">'+ outText[i][0][0][0].graph +'</span>';
if (outText[i][0][0][0].graph.match(/^-$/)) noSpace = true; else noSpace = false;
} else if (outText[i][0][0][0].graph.match(/\(|\[|\{|<|«|“/)) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="phon_neutre">'+ outText[i][0][0][0].graph +'</span>';
noSpace = true;
} else if (noSpace) {
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'"></span>';
}
if (outText[i][0][0][0].graph.match(/^.+’$/)) noSpace = true; else noSpace = false;
} else {
if (outText[i][0][0][0].graph.match(/^’.+$/)) { // I'll you're
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'"></span>';
}
} else {
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="tokens" id="tok'+ i +'"></span>';
}
}
if (outText[i][0][0][0].graph.match(/^.+’$/)) noSpace = true; else noSpace = false;
}
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="'+ classliaison +' phon '+ outText[i][0][0][0].phon +'" title="'+ outText[i][0][3] +'">'+ outText[i][0][0][0].graph +'</span>';
noSpace = true;
} else if (outText[i][0][0][0].graph.match(/^(,|\.|…|\)|\]|\}|%|>|»|”|-)$/)) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="phon_neutre">'+ outText[i][0][0][0].graph +'</span>';
if (outText[i][0][0][0].graph.match(/^-$/)) noSpace = true; else noSpace = false;
} else if (outText[i][0][0][0].graph.match(/\(|\[|\{|<|«|“/)) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="phon_neutre">'+ outText[i][0][0][0].graph +'</span>';
noSpace = true;
} else if (noSpace) {
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'"></span>';
}
if (outText[i][0][0][0].graph.match(/^.+’$/)) noSpace = true; else noSpace = false;
} else {
if (outText[i][0][0][0].graph.match(/^’.+$/)) { // I'll you're
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="tokens" id="tok'+ i +'"></span>';
}
} else {
if (outText[i].length>1) {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="tokens" id="tok'+ i +'" onclick="showAlignPop(this.id)"></span>';
} else {
outputDiv.innerHTML = outputDiv.innerHTML + '<span class="space"> </span><span class="tokens" id="tok'+ i +'"></span>';
}
}
if (outText[i][0][0][0].graph.match(/^.+’$/)) noSpace = true; else noSpace = false;
}
// FORMATAGE DES SPANS
if (outText[i][0][0][0].graph != '\n'){
dicoTok['tok'+i] = [];
waitinglist = []; // we will put all non aligned ones here, waiting for pushing them all at the end (so that they can't appear first)
prioritylist = []; // this will be for making UK pronunciations appearing first if thisRegion is set to UK (user choice)
otherTranslist = []; // for other spellings (other regions)
for (j=0; j<outText[i].length; j++) {
var newWord = '';
for (k=0; k<outText[i][j][0].length; k++) {
newWord = newWord + '<span class="phon '+ outText[i][j][0][k].phon +'">'+ outText[i][j][0][k].graph +'</span>';
}
if (outText[i][j][3].length == 0 && outText[i][j][0].length>0) {
var priorityCheck = false;
for (r=0; r<outText[i][j][1].length; r++) {
// for each region, if thisRegion here, put this spelling in the prioritylist
if (loc2stand[outText[i][j][1][r]]==thisRegion){ priorityCheck = true }
// FORMATAGE DES SPANS
if (outText[i][0][0][0].graph != '\n'){
dicoTok['tok'+i] = [];
waitinglist = []; // we will put all non aligned ones here, waiting for pushing them all at the end (so that they can't appear first)
prioritylist = []; // this will be for making UK pronunciations appearing first if thisRegion is set to UK (user choice)
otherTranslist = []; // for other spellings (other regions)
for (j=0; j<outText[i].length; j++) {
var newWord = '';
for (k=0; k<outText[i][j][0].length; k++) {
newWord = newWord + '<span class="phon '+ outText[i][j][0][k].phon +'">'+ outText[i][j][0][k].graph +'</span>';
}
if (priorityCheck) {
prioritylist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
if (outText[i][j][3].length == 0 && outText[i][j][0].length>0) {
var priorityCheck = false;
for (r=0; r<outText[i][j][1].length; r++) {
// for each region, if thisRegion here, put this spelling in the prioritylist
if (loc2stand[outText[i][j][1][r]]==thisRegion){ priorityCheck = true }
}
if (priorityCheck) {
prioritylist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
} else {
otherTranslist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
}
} else {
otherTranslist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
waitinglist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
}
} else {
waitinglist.push([newWord,outText[i][j][1],outText[i][j][2],outText[i][j][3]]);
}
}
for (l=0; l<prioritylist.length; l++){
dicoTok['tok'+i].push(prioritylist[l]);
}
for (l=0; l<otherTranslist.length; l++){
dicoTok['tok'+i].push(otherTranslist[l]);
}
for (l=0; l<waitinglist.length; l++){
dicoTok['tok'+i].push(waitinglist[l]);
}
}
// INITIALISATION DU dicoId
if (outText[i][0][0][0].graph != '\n'){
dicoId['tok'+i] = 0;
}
}
document.getElementById('loader').style.display = "none";
}
}
for (l=0; l<prioritylist.length; l++){
dicoTok['tok'+i].push(prioritylist[l]);
}
for (l=0; l<otherTranslist.length; l++){
dicoTok['tok'+i].push(otherTranslist[l]);
}
for (l=0; l<waitinglist.length; l++){
dicoTok['tok'+i].push(waitinglist[l]);
}
}
var tokens = document.getElementsByClassName("tokens");
for (i = 0; i < tokens.length; i++) {
if (dicoTok[tokens[i].id].length > 1) {
tokens[i].innerHTML = dicoTok[tokens[i].id][0][0];
if (lang=="en") {
$('#'+tokens[i].id).addClass('transMultEn');
$('#'+tokens[i].id).prop('title', langJson['ti_multitrans']['en']);
} else {
$('#'+tokens[i].id).addClass('transMult');
$('#'+tokens[i].id).prop('title', langJson['ti_multitrans']['fr']);
}
} else {
tokens[i].innerHTML = dicoTok[tokens[i].id][0][0];
};
};
unknownMark();
bugMark();
toggleLiaisons()
// INITIALISATION DU dicoId
if (outText[i][0][0][0].graph != '\n'){
dicoId['tok'+i] = 0;
}
}
document.getElementById('loader').style.display = "none";
}
if (document.getElementById('bicolor').checked) {
toBicolor();
}
if (document.getElementById('monochrome').checked) {
toMonochrome();
}
} else if (lang == "zh") {
document.getElementById('output').innerHTML = "";
var outputDiv = document.getElementById('outputzh');
var outText = data['outText'];
outputDiv.innerHTML = "";
var linediv = document.createElement('div');
outputDiv.appendChild(linediv);
var tones = {1:'˥',2:'˧˥',3:'˨˩˦',4:'˥˩',5:''};
for (i=0; i<outText.length; i++) {
// Pour chaque mot outText[i]
var worddiv = document.createElement('div');
worddiv.classList = "zhtoken";
linediv.appendChild(worddiv);
for (j=0; j<outText[i].length; j++) {
// Pour chaque hanzi outText[i][j]
var zi = outText[i][j][0];
var pinyin = outText[i][j][1];
var api = outText[i][j][2];
var phonList = outText[i][j][3];
var ton = outText[i][j][4];
if (zi == '\n'){
linediv = document.createElement('div');
outputDiv.appendChild(linediv);
var newbr = document.createElement('br');
outputDiv.appendChild(newbr);
linediv = document.createElement('div');
outputDiv.appendChild(linediv);
} else {
if (phonList.length>0){
var svg = createZh(zi,phonList.length,phonList,ton);
var svgdiv = document.createElement('div');
svgdiv.title = `${pinyin}${ton}\n${api}`+tones[ton];
svgdiv.appendChild(svg);
worddiv.appendChild(svgdiv);
} else {
// Le contenu n'est pas colorisé : on met en gris sans cadre
var newEl = document.createElement('span');
newEl.classList = "sinosvgNeutre";
newEl.innerHTML = zi;
worddiv.appendChild(newEl);
}
}
}
}
document.getElementById('loader').style.display = "none";
}
var tokens = document.getElementsByClassName("tokens");
for (i = 0; i < tokens.length; i++) {
if (dicoTok[tokens[i].id].length > 1) {
tokens[i].innerHTML = dicoTok[tokens[i].id][0][0];
if (lang=="en") {
$('#'+tokens[i].id).addClass('transMultEn');
$('#'+tokens[i].id).prop('title', langJson['ti_multitrans']['en']);
} else {
$('#'+tokens[i].id).addClass('transMult');
$('#'+tokens[i].id).prop('title', langJson['ti_multitrans']['fr']);
}
} else {
tokens[i].innerHTML = dicoTok[tokens[i].id][0][0];
};
};
unknownMark();
bugMark();
toggleLiaisons()
if (document.getElementById('bicolor').checked) {
toBicolor();
}
if (document.getElementById('monochrome').checked) {
toMonochrome();
}
} else if (lang == "zh") {
document.getElementById('output').innerHTML = "";
var outputDiv = document.getElementById('outputzh');
var outText = data['outText'];
outputDiv.innerHTML = "";
var linediv = document.createElement('div');
outputDiv.appendChild(linediv);
var tones = {1:'˥',2:'˧˥',3:'˨˩˦',4:'˥˩',5:''};
for (i=0; i<outText.length; i++) {
// Pour chaque mot outText[i]
var worddiv = document.createElement('div');
worddiv.classList = "zhtoken";
linediv.appendChild(worddiv);
for (j=0; j<outText[i].length; j++) {
// Pour chaque hanzi outText[i][j]
var zi = outText[i][j][0];
var pinyin = outText[i][j][1];
var api = outText[i][j][2];
var phonList = outText[i][j][3];
var ton = outText[i][j][4];
if (zi == '\n'){
linediv = document.createElement('div');
outputDiv.appendChild(linediv);
var newbr = document.createElement('br');
outputDiv.appendChild(newbr);
linediv = document.createElement('div');
outputDiv.appendChild(linediv);
} else {
if (phonList.length>0){
var svg = createZh(zi,phonList.length,phonList,ton);
var svgdiv = document.createElement('div');
svgdiv.title = `${pinyin}${ton}\n${api}`+tones[ton];
svgdiv.appendChild(svg);
worddiv.appendChild(svgdiv);
} else {
// Le contenu n'est pas colorisé : on met en gris sans cadre
var newEl = document.createElement('span');
newEl.classList = "sinosvgNeutre";
newEl.innerHTML = zi;
worddiv.appendChild(newEl);
}
}
}
}
document.getElementById('loader').style.display = "none";
}
addStat("coloriser");
}
}