Commit e335954a authored by Sylvain Coulange's avatar Sylvain Coulange 🌼
Browse files

stats synthese vocale

parent 255b4fe2
......@@ -71,6 +71,8 @@ urlpatterns = [
path('_getStats/', csrf_exempt(user_views.getTracesStats)),
path('_getSynthVocTraces/', csrf_exempt(user_views.getSynthVocTraces)),
path('_getSynthVocTracesJson/', csrf_exempt(user_views.getSynthVocTracesJson)),
path('_getSynthVocRecords/', csrf_exempt(user_views.getSynthVocRecords)),
path('users/', user_views.usersPage, name='users'),
path('users/<str:username>/', user_views.userInfo, name='userInfo'),
......
......@@ -4,6 +4,8 @@ var filter= {app:[],mod:[],pay:[],lan:[],use:[],age:[],dev:[],nav:[]}
var initfilter = {app:[],mod:[],pay:[],lan:[],use:[],age:[],dev:[],nav:[]}
getStats()
getSynthVocTraces()
getSynthVocRecords()
async function getStats() {
// Paramètres d'envoi
......@@ -230,17 +232,24 @@ function makeChart(canvasName, stats, legend=true) {
var data = {
labels: Object.keys(stats),
datasets: [{
label: canvasName,
data: Object.values(stats),
backgroundColor: COLORS,
hoverOffset: 4
label: canvasName,
data: Object.values(stats),
backgroundColor: COLORS,
hoverOffset: 4
}]
};
};
const config = {
type: 'doughnut',
data: data,
options: {
if (["svappChart","svapplenssmlChart","svuserChart","svuserlenssmlChart", "svlangChart"].includes(canvasName)) {
var options = {
plugins: {
legend: {
display: legend,
position: 'bottom'
}
}
}
} else {
var options = {
plugins: {
legend: {
display: legend,
......@@ -256,8 +265,13 @@ function makeChart(canvasName, stats, legend=true) {
console.log("In click", datasetLabel, label, value);
select(label);
}
}
}
const config = {
type: 'doughnut',
data: data,
options: options
};
const myChart = new Chart(
......@@ -269,16 +283,14 @@ function makeChart(canvasName, stats, legend=true) {
}
// DISPLAY TIME CHART
function makeTimeChart(canvasName, day2traces) {
const labels = Object.keys(day2traces);
const data = {
labels: labels,
datasets: [{
label: canvasName,
label: CHARTS[canvasName],
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: Object.values(day2traces),
......@@ -291,6 +303,13 @@ function makeTimeChart(canvasName, day2traces) {
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
type: 'linear',
display: true,
position: 'left',
},
}
}
};
......@@ -302,6 +321,101 @@ function makeTimeChart(canvasName, day2traces) {
return myChart
}
async function getSynthVocTraces() {
// Paramètres d'envoi
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
// ENVOI
const response = await fetch('/_getSynthVocTracesJson/', options);
var data = await response.json();
console.log(data);
document.getElementById('nbTracesSynthVoc').innerText = data.nbTraces;
document.getElementById('lenssmlThisMonth').innerText = data.lenssmlThisMonth;
svappChart = makeChart('svappChart', data.app2nbTraces, true);
svapplenssmlChart = makeChart('svapplenssmlChart', data.app2Lenssml, true);
svuserChart = makeChart('svuserChart', data.user2nbTraces, false);
svuserlenssmlChart = makeChart('svuserlenssmlChart', data.user2Lenssml, false);
var day2nbTraces = {}
var day2lenssml = {}
Object.entries(data.day2nbTracesLenssml).forEach((k) => {
day2nbTraces[k[0]] = k[1][0]
day2lenssml[k[0]] = k[1][1]
})
console.log(day2nbTraces)
console.log(day2lenssml)
svDaychart = makeTimeChart('svDaychart', day2nbTraces);
svDaychart.data.datasets.push({
label: "nb caractères ssml",
backgroundColor: 'green',
borderColor: 'green',
data: Object.values(day2lenssml),
yAxisID: 'y1',
})
svDaychart.options.scales['y1'] = {
type: 'linear',
display: true,
position: 'right',
// grid line settings
grid: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
}
svDaychart.update()
}
async function getSynthVocRecords() {
// Paramètres d'envoi
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
};
// ENVOI
const response = await fetch('/_getSynthVocRecords/', options);
var data = await response.json();
console.log(data);
document.getElementById('nbFreqSynthVoc').innerText = data.nbFreq;
svlangChart = makeChart('svlangChart', data.lang2freq, true);
var itemsfr = Object.keys(data.ipa2freq['fr']).map(function(key) { return [key, data.ipa2freq['fr'][key]]; });
itemsfr.sort(function(first, second) { return second[1] - first[1]; });
var itemsen = Object.keys(data.ipa2freq['en']).map(function(key) { return [key, data.ipa2freq['en'][key]]; });
itemsen.sort(function(first, second) { return second[1] - first[1]; });
document.getElementById('topfr').innerHTML = ""
itemsfr.slice(0,20).forEach((el)=> {
document.getElementById('topfr').innerHTML += el[0]+' : '+el[1]+'<br>'
})
document.getElementById('topen').innerHTML = ""
itemsen.slice(0,20).forEach((el)=> {
document.getElementById('topen').innerHTML += el[0]+' : '+el[1]+'<br>'
})
}
let svappChart;
let svapplenssmlChart;
let svuserChart;
let svuserlenssmlChart;
let svDaychart;
let svlangChart;
//////////////////////////////////
......@@ -316,4 +430,9 @@ const COLORS = [
'#00a950',
'#58595b',
'#8549ba'
];
\ No newline at end of file
];
const CHARTS = {
'chartTime': 'Nombre de traces',
'svDaychart': 'Nombre de requêtes Polly',
}
\ No newline at end of file
......@@ -1259,6 +1259,7 @@ function checkWord() {
} else {
window.alert("Cette fonctionnalité n'est pas encore disponible pour cette langue");
}
addStat("checkword",thisPageLang);
}
async function reqWiki(wordPhonoSpansList,lang) {
......@@ -1322,55 +1323,4 @@ async function reqWiki(wordPhonoSpansList,lang) {
document.getElementById('checkWordLoading').style.display = "none";
document.getElementById('checkWordValid').style.display = "block";
}
///// VIEUX --- 1 REQUETE PAR MOT (trop lent)
// async function reqWiki(word,phono,lang,listSpans,fin) {
// console.log("reqWiki",word,phono,lang,listSpans,fin);
// // Paramètres d'envoi
// const options = {
// method: 'GET',
// headers: {
// 'Content-Type': 'application/json'
// }
// }
// const response = await fetch(`https://wikicolor.alem-app.fr/checkWord?w=${word}&t=${phono}&lang=${lang}`, options);
// const data = await response.json();
// console.log(data);
// for (span of listSpans){
// var el = document.getElementById(span);
// var title = []
// el.classList.remove("FBortho");
// el.classList.remove("FBphonoCarte");
// el.classList.remove("FBphonoGraphCarte");
// el.classList.remove("FBphono");
// el.classList.remove("FBphonoGraph");
// if (!data.rep.t) {
// if (el.classList[0]=="carte" || el.classList[0]=="carteZh") el.classList.add("FBphonoCarte"); // que bouches et mandarin
// else el.classList.add("FBphono");
// title.push("problème de phonologie")
// }
// if (!data.rep.w) {
// if (!el.classList.contains("carte")) el.classList.add("FBortho"); // tous sauf bouches
// title.push("problème d'orthographe")
// } else if (data.rep.t && !data.rep.wt) {
// if (el.classList[0]=="carte" || el.classList[0]=="carteZh") el.classList.add("FBphonoGraphCarte"); // que bouches et mandarin
// else el.classList.add("FBphonoGraph");
// title.push("orthographe et phonologie existantes mais pas pour le même mot")
// }
// el.title = title.join("\n");
// }
// if (fin) {
// document.getElementById('checkWordLoading').style.display = "none";
// document.getElementById('checkWordValid').style.display = "block";
// }
// }
\ No newline at end of file
}
\ No newline at end of file
......@@ -529,4 +529,8 @@ footer {
color:red;
cursor:pointer;
font-size: .8em;
}
.myChart {
max-width: 600px;
}
\ No newline at end of file
......@@ -57,6 +57,58 @@
<canvas id="chartTime"></canvas>
</div>
<hr style="margin:auto; margin-top:30px; width:70%; border-top:3px solid black; border-radius: 5px;">
<h2>Traces relatives à la synthèse vocale</h2>
<p>(depuis le 24 février 2021)</p>
<p><strong><span id="nbFreqSynthVoc"></span> synthèses vocales enregistrées.</strong></p>
<p><strong><span id="nbTracesSynthVoc"></span> requêtes de synthèse envoyées à Amazon Polly.</strong></p>
<p><strong>Nombre de caractères ssml envoyés depuis le début du mois courant <span id="lenssmlThisMonth"></span> (max 1 million de caractères par mois).</strong></p>
<div class="container">
<div class="row">
<div class="col myChart">
<div class="svappChartTitle">Nombre de nouvelles requêtes par application</div>
<canvas id="svappChart"></canvas>
</div>
<div class="col myChart">
<div class="svapplenssmlChartTitle">Longueur SSML par application</div>
<canvas id="svapplenssmlChart"></canvas>
</div>
<div class="col myChart">
<div class="svuserChartTitle">Nombre de nouvelles requêtes par utilisateur</div>
<canvas id="svuserChart"></canvas>
</div>
<div class="col myChart">
<div class="svuserlenssmlChartTitle">Longueur SSML par utilisateur</div>
<canvas id="svuserlenssmlChart"></canvas>
</div>
</div>
<div class="mt-2 row">
<div class="col myChart">
<div class="svlangChartTitle">Langue de la synthèse vocale</div>
<canvas id="svlangChart"></canvas>
</div>
<div class="col">
<div style="margin: auto">
<strong>Top 20 des suites phonologiques les plus synthétisées :</strong>
<div class="d-flex justify-content-evenly">
<div><strong>En français :</strong><br>
<div id="topfr" class="px-2" style="height: 400px; overflow: scroll;"></div>
</div>
<div><strong>En anglais :</strong><br>
<div id="topen" class="px-2" style="height: 400px; overflow: scroll;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="mb-4" style="height: 300px;position:relative">
<div class="svDayChartTitle">Total de nouvelles synthèses Polly par jour</div>
<canvas id="svDaychart"></canvas>
</div>
{% endblock content %}
......
......@@ -591,6 +591,88 @@ def getSynthVocTraces(request):
return response
@allowed_users(allowed_roles=['admin'])
def getSynthVocTracesJson(request):
print("Requête json synthVocTraces...")
synthVocTraces = SynthVocTrace.objects.all()
data = {
"nbTraces":0,
"lenssmlThisMonth": 0,
"user2nbTraces": {},
"user2Lenssml": {},
"app2nbTraces": {},
"app2Lenssml": {},
"day2nbTracesLenssml": {},
}
thisMonth = datetime.datetime.now().strftime("%Y%m")
# initialisation de day2nbTraces
daylist = np.arange('2021-02-15', np.datetime64('today', 'D')+np.timedelta64(1, 'D'), dtype='datetime64[D]')
day2traces = {}
# Initialisation liste vide
for day in daylist:
day2traces[str(day)] = [0, 0] # nbTraces, lenssml
# Remplissage avec les dates des traces
for trace in synthVocTraces:
day2traces[trace.date.strftime("%Y-%m-%d")][0] += 1
day2traces[trace.date.strftime("%Y-%m-%d")][1] += trace.lenssml
data['nbTraces'] += 1
if trace.date.strftime("%Y%m")==thisMonth:
data['lenssmlThisMonth'] += trace.lenssml
if trace.user not in data["user2nbTraces"].keys():
data["user2nbTraces"][trace.user] = 0
data["user2Lenssml"][trace.user] = 0
data["user2nbTraces"][trace.user] += 1
data["user2Lenssml"][trace.user] += trace.lenssml
if trace.appli not in data["app2nbTraces"].keys():
data["app2nbTraces"][trace.appli] = 0
data["app2Lenssml"][trace.appli] = 0
data["app2nbTraces"][trace.appli] += 1
data["app2Lenssml"][trace.appli] += trace.lenssml
data["day2nbTracesLenssml"] = day2traces
return JsonResponse(data)
@allowed_users(allowed_roles=['admin'])
def getSynthVocRecords(request):
print("Requête json synthVocRecords...")
synthVocRecords = SynthVocRecord.objects.all()
data = {
"nbRecords": 0,
"nbFreq": 0,
"ipa2freq": {},
"lang2freq": {}
}
# Remplissage avec les dates des traces
for record in synthVocRecords:
data['nbRecords'] += 1
data['nbFreq'] += record.cptEcoute+1 # compteur démarre à 0 lors de synthèse Polly
if record.lang == "enbr": lang = "en"
else: lang = record.lang
if lang not in data['ipa2freq'].keys():
data['ipa2freq'][lang] = {}
if record.ipa not in data["ipa2freq"][lang].keys():
data["ipa2freq"][lang][record.ipa] = 0
data["ipa2freq"][lang][record.ipa] += record.cptEcoute+1
if lang not in data["lang2freq"].keys():
data["lang2freq"][lang] = 0
data["lang2freq"][lang] += record.cptEcoute+1
return JsonResponse(data)
# Fonction de réharmonisation de la base de séries
def exportAllSeries():
ss = Serie.objects.all()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment