Commit e6747271 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

mise à jour appStats

parent 2df1cc4a
var appdata = [];
var stats = {};
var filter= {app:[],mod:[],pay:[],lan:[],use:[],age:[]}
var initfilter = {app:[],mod:[],pay:[],lan:[],use:[],age:[]}
var filter= {app:[],mod:[],pay:[],lan:[],use:[],age:[],dev:[],nav:[]}
var initfilter = {app:[],mod:[],pay:[],lan:[],use:[],age:[],dev:[],nav:[]}
getStats()
......@@ -17,6 +17,9 @@ async function getStats() {
// ENVOI
const response = await fetch('/_getAppStats/', options);
appdata = await response.json();
for (let i=0; i<appdata.appdata.length; i++) {
appdata.appdata[i].country = code2country[appdata.appdata[i].country];
}
console.log(appdata);
document.getElementById('nbTracesTotal').innerText = appdata.appdata.length;
......@@ -42,15 +45,36 @@ async function getStats() {
filter.use.push(i);
initfilter.use.push(i);
}
if (!filter.age.includes(ag)) {
filter.age.push(ag);
initfilter.age.push(ag);
// if (!filter.age.includes(ag)) {
// filter.age.push(ag);
// initfilter.age.push(ag);
// }
var [d,s,n] = agentParser(ag);
if (!filter.dev.includes(d)) {
filter.dev.push(d);
initfilter.dev.push(d);
}
if (!filter.nav.includes(n)) {
filter.nav.push(n);
initfilter.nav.push(n);
}
}
makeCharts(filter)
}
function agentParser(ag){
var dsn = ag.split(' / ');
if(dsn.length==3) {
var [d,s,n] = dsn;
n = n.replace(/\d|\./g,'').trim();
return [d,s,n]
} else {
console.log("Agent imparsable :",ag)
return [ag,"",""]
}
}
function select(param) {
if ( initfilter.app.includes(param) ) {
if ( filter.app.length == 1 ) filter.app = initfilter.app;
......@@ -77,10 +101,20 @@ function select(param) {
else {
filter.use = [param]
}
} else if ( initfilter.age.includes(param) ) {
if ( filter.age.length == 1 ) filter.age = initfilter.age;
// } else if ( initfilter.age.includes(param) ) {
// if ( filter.age.length == 1 ) filter.age = initfilter.age;
// else {
// filter.age = [param]
// }
} else if ( initfilter.dev.includes(param) ) {
if ( filter.dev.length == 1 ) filter.dev = initfilter.dev;
else {
filter.age = [param]
filter.dev = [param]
}
} else if ( initfilter.nav.includes(param) ) {
if ( filter.nav.length == 1 ) filter.nav = initfilter.nav;
else {
filter.nav = [param]
}
}
updateCharts(filter);
......@@ -92,6 +126,8 @@ var chartPays;
var chartLangues;
var chartUsers;
var chartAgents;
var chartMachines;
var chartNavs;
var chartTime;
function makeCharts(filter) {
......@@ -102,7 +138,9 @@ function makeCharts(filter) {
chartPays = makeChart('chartPays', stats.pay2freq);
chartLangues = makeChart('chartLangues', stats.lan2freq);
chartUsers = makeChart('chartUsers', stats.use2freq, false);
chartAgents = makeChart('chartAgents', stats.age2freq, false);
// chartAgents = makeChart('chartAgents', stats.age2freq, false);
chartMachines = makeChart('chartMachines', stats.dev2freq, false);
chartNavs = makeChart('chartNavs', stats.nav2freq);
chartTime = makeTimeChart('chartTime', stats.day2traces);
}
......@@ -116,7 +154,9 @@ function updateCharts(filter) {
upd(chartPays, stats.pay2freq);
upd(chartLangues, stats.lan2freq);
upd(chartUsers, stats.use2freq);
upd(chartAgents, stats.age2freq);
// upd(chartAgents, stats.age2freq);
upd(chartMachines, stats.dev2freq);
upd(chartNavs, stats.nav2freq);
upd(chartTime, stats.day2traces);
}
......@@ -133,10 +173,13 @@ function summarize(filter, data, day2traces){
var lan2freq = {};
var use2freq = {};
var age2freq = {};
var dev2freq = {};
var nav2freq = {};
var cpt = 0;
for (var {date:d, app:a, module:m, ip:i, agent:ag, country:c, lang:l} of data) {
if (filter.app.includes(a) && filter.mod.includes(m) && filter.pay.includes(c) && filter.lan.includes(l)) {
var [de,s,n] = agentParser(ag);
if (filter.app.includes(a) && filter.mod.includes(m) && filter.pay.includes(c) && filter.lan.includes(l) && filter.use.includes(i) && filter.dev.includes(de) && filter.nav.includes(n)) {
if (!Object.keys(app2freq).includes(a)) app2freq[a]=0;
app2freq[a]++;
......@@ -152,8 +195,14 @@ function summarize(filter, data, day2traces){
if (!Object.keys(use2freq).includes(i)) use2freq[i]=0;
use2freq[i]++;
if (!Object.keys(age2freq).includes(ag)) age2freq[ag]=0;
age2freq[ag]++;
// if (!Object.keys(age2freq).includes(ag)) age2freq[ag]=0;
// age2freq[ag]++;
if (!Object.keys(dev2freq).includes(de)) dev2freq[de]=0;
dev2freq[de]++;
if (!Object.keys(nav2freq).includes(n)) nav2freq[n]=0;
nav2freq[n]++;
var df = d.slice(0,10);
if (Object.keys(day2traces).includes(df)) day2traces[df]++;
......@@ -162,17 +211,21 @@ function summarize(filter, data, day2traces){
}
}
document.getElementById('nbTraces').innerText = cpt;
document.getElementById('nbUsers').innerText = Object.keys(use2freq).length;
return {
'app2freq':app2freq,
'mod2freq':mod2freq,
'pay2freq':pay2freq,
'lan2freq':lan2freq,
'use2freq':use2freq,
'age2freq':age2freq,
// 'age2freq':age2freq,
'dev2freq':dev2freq,
'nav2freq':nav2freq,
'day2traces':day2traces
}
}
function makeChart(canvasName, stats, legend=true) {
var data = {
labels: Object.keys(stats),
......
var code2country = {
"AF":"Afghanistan",
"AL":"Albania",
"DZ":"Algeria",
"AS":"American Samoa",
"AD":"Andorra",
"AO":"Angola",
"AI":"Anguilla",
"AQ":"Antarctica",
"AG":"Antigua and Barbuda",
"AR":"Argentina",
"AM":"Armenia",
"AW":"Aruba",
"AU":"Australia",
"AT":"Austria",
"AZ":"Azerbaijan",
"BS":"Bahamas",
"BH":"Bahrain",
"BD":"Bangladesh",
"BB":"Barbados",
"BY":"Belarus",
"BE":"Belgium",
"BZ":"Belize",
"BJ":"Benin",
"BM":"Bermuda",
"BT":"Bhutan",
"BO":"Bolivia",
"BQ":"Bonaire, Sint Eustatius and Saba",
"BA":"Bosnia and Herzegovina",
"BW":"Botswana",
"BV":"Bouvet Island",
"BR":"Brazil",
"IO":"British Indian Ocean Territory",
"BN":"Brunei Darussalam",
"BG":"Bulgaria",
"BF":"Burkina Faso",
"BI":"Burundi",
"CV":"Cabo Verde",
"KH":"Cambodia",
"CM":"Cameroon",
"CA":"Canada",
"KY":"Cayman Islands",
"CF":"Central African Republic",
"TD":"Chad",
"CL":"Chile",
"CN":"China",
"CX":"Christmas Island",
"CC":"Cocos (Keeling) Islands",
"CO":"Colombia",
"KM":"Comoros",
"CD":"Democratic Republic of the Congo",
"CG":"Congo",
"CK":"Cook Islands",
"CR":"Costa Rica",
"HR":"Croatia",
"CU":"Cuba",
"CW":"Curaçao",
"CY":"Cyprus",
"CZ":"Czechia",
"CI":"Côte d'Ivoire",
"DK":"Denmark",
"DJ":"Djibouti",
"DM":"Dominica",
"DO":"Dominican Republic",
"EC":"Ecuador",
"EG":"Egypt",
"SV":"El Salvador",
"GQ":"Equatorial Guinea",
"ER":"Eritrea",
"EE":"Estonia",
"SZ":"Eswatini",
"ET":"Ethiopia",
"FK":"Falkland Islands",
"FO":"Faroe Islands",
"FJ":"Fiji",
"FI":"Finland",
"FR":"France",
"GF":"French Guiana",
"PF":"French Polynesia",
"TF":"French Southern Territories",
"GA":"Gabon",
"GM":"Gambia",
"GE":"Georgia",
"DE":"Germany",
"GH":"Ghana",
"GI":"Gibraltar",
"GR":"Greece",
"GL":"Greenland",
"GD":"Grenada",
"GP":"Guadeloupe",
"GU":"Guam",
"GT":"Guatemala",
"GG":"Guernsey",
"GN":"Guinea",
"GW":"Guinea-Bissau",
"GY":"Guyana",
"HT":"Haiti",
"HM":"Heard Island and McDonald Islands",
"VA":"Holy See",
"HN":"Honduras",
"HK":"Hong Kong",
"HU":"Hungary",
"IS":"Iceland",
"IN":"India",
"ID":"Indonesia",
"IR":"Iran",
"IQ":"Iraq",
"IE":"Ireland",
"IM":"Isle of Man",
"IL":"Israel",
"IT":"Italy",
"JM":"Jamaica",
"JP":"Japan",
"JE":"Jersey",
"JO":"Jordan",
"KZ":"Kazakhstan",
"KE":"Kenya",
"KI":"Kiribati",
"KP":"North Korea",
"KR":"Korea",
"KW":"Kuwait",
"KG":"Kyrgyzstan",
"LA":"Lao People's Democratic Republic",
"LV":"Latvia",
"LB":"Lebanon",
"LS":"Lesotho",
"LR":"Liberia",
"LY":"Libya",
"LI":"Liechtenstein",
"LT":"Lithuania",
"LU":"Luxembourg",
"MO":"Macao",
"MG":"Madagascar",
"MW":"Malawi",
"MY":"Malaysia",
"MV":"Maldives",
"ML":"Mali",
"MT":"Malta",
"MH":"Marshall Islands",
"MQ":"Martinique",
"MR":"Mauritania",
"MU":"Mauritius",
"YT":"Mayotte",
"MX":"Mexico",
"FM":"Micronesia",
"MD":"Moldova",
"MC":"Monaco",
"MN":"Mongolia",
"ME":"Montenegro",
"MS":"Montserrat",
"MA":"Morocco",
"MZ":"Mozambique",
"MM":"Myanmar",
"NA":"Namibia",
"NR":"Nauru",
"NP":"Nepal",
"NL":"Netherlands",
"NC":"New Caledonia",
"NZ":"New Zealand",
"NI":"Nicaragua",
"NE":"Niger",
"NG":"Nigeria",
"NU":"Niue",
"NF":"Norfolk Island",
"MP":"Northern Mariana Islands",
"NO":"Norway",
"OM":"Oman",
"PK":"Pakistan",
"PW":"Palau",
"PS":"Palestine",
"PA":"Panama",
"PG":"Papua New Guinea",
"PY":"Paraguay",
"PE":"Peru",
"PH":"Philippines",
"PN":"Pitcairn",
"PL":"Poland",
"PT":"Portugal",
"PR":"Puerto Rico",
"QA":"Qatar",
"MK":"Republic of North Macedonia",
"RO":"Romania",
"RU":"Russian Federation",
"RW":"Rwanda",
"RE":"Réunion",
"BL":"Saint Barthélemy",
"SH":"Saint Helena, Ascension and Tristan da Cunha",
"KN":"Saint Kitts and Nevis",
"LC":"Saint Lucia",
"MF":"Saint Martin",
"PM":"Saint Pierre and Miquelon",
"VC":"Saint Vincent and the Grenadines",
"WS":"Samoa",
"SM":"San Marino",
"ST":"Sao Tome and Principe",
"SA":"Saudi Arabia",
"SN":"Senegal",
"RS":"Serbia",
"SC":"Seychelles",
"SL":"Sierra Leone",
"SG":"Singapore",
"SX":"Sint Maarten",
"SK":"Slovakia",
"SI":"Slovenia",
"SB":"Solomon Islands",
"SO":"Somalia",
"ZA":"South Africa",
"GS":"South Georgia and the South Sandwich Islands",
"SS":"South Sudan",
"ES":"Spain",
"LK":"Sri Lanka",
"SD":"Sudan",
"SR":"Suriname",
"SJ":"Svalbard and Jan Mayen",
"SE":"Sweden",
"CH":"Switzerland",
"SY":"Syrian Arab Republic",
"TW":"Taiwan",
"TJ":"Tajikistan",
"TZ":"Tanzania",
"TH":"Thailand",
"TL":"Timor-Leste",
"TG":"Togo",
"TK":"Tokelau",
"TO":"Tonga",
"TT":"Trinidad and Tobago",
"TN":"Tunisia",
"TR":"Turkey",
"TM":"Turkmenistan",
"TC":"Turks and Caicos Islands",
"TV":"Tuvalu",
"UG":"Uganda",
"UA":"Ukraine",
"AE":"United Arab Emirates",
"GB":"UK",
"UM":"United States Minor Outlying Islands",
"US":"USA",
"UY":"Uruguay",
"UZ":"Uzbekistan",
"VU":"Vanuatu",
"VE":"Venezuela",
"VN":"Viet Nam",
"VG":"Virgin Islands (British)",
"VI":"Virgin Islands (U.S.)",
"WF":"Wallis and Futuna",
"EH":"Western Sahara",
"YE":"Yemen",
"ZM":"Zambia",
"ZW":"Zimbabwe",
"AX":"Åland Islands"
}
\ No newline at end of file
......@@ -15,29 +15,45 @@
<div class="container">
<div class="row">
<div class="col myChart">
<div class="appStatChartTitle">Application</div>
<canvas id="chartApps"></canvas>
</div>
<div class="col myChart">
<div class="appStatChartTitle">Module</div>
<canvas id="chartModules"></canvas>
</div>
<div class="col myChart">
<div class="appStatChartTitle">Pays de provenance de la requête</div>
<canvas id="chartPays"></canvas>
</div>
</div>
<div class="row">
<div class="col myChart">
<div class="appStatChartTitle">Langue cible de l'application</div>
<canvas id="chartLangues"></canvas>
</div>
<div class="col myChart">
<div class="appStatChartTitle">Adresse d'origine de la requête</div>
<div class="appStatChartInfo" style='font-style: italic;font-size: .8em;'>(<span id="nbUsers"></span> utilisateurs différents)</div>
<canvas id="chartUsers"></canvas>
</div>
<div class="col myChart">
<!-- <div class="col myChart">
<div class="appStatChartTitle">Machine, système d'exploitation, navigateur</div>
<canvas id="chartAgents"></canvas>
</div> -->
<div class="col myChart">
<div class="appStatChartTitle">Machine</div>
<canvas id="chartMachines"></canvas>
</div>
<div class="col myChart">
<div class="appStatChartTitle">Navigateur</div>
<canvas id="chartNavs"></canvas>
</div>
</div>
</div>
<div style="height: 300px;position:relative">
<div class="appStatChartTitle">Nombre de traces par jour</div>
<canvas id="chartTime"></canvas>
</div>
......@@ -45,6 +61,7 @@
{% block javascript %}
<script type="text/javascript" src="{% static 'js/code2country.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script type="text/javascript" src="{% static 'js/appStatVis.js' %}"></script>
{% endblock %}
\ No newline at end of file
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