947
Bearbeitungen
Xaver (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „→! @license Copyright 2019 Xaver MIT-licensed (http://opensource.org/licenses/MIT): function _defineProperty(obj,key,value){if(key in obj){Object.defineProp…“) |
Xaver (Diskussion | Beiträge) KKeine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
$.when($.getScript('/wiki/index.php?title=MediaWiki:Dygraph.min.js&action=raw&ctype=text/javascript'),$.getScript('/wiki/index.php?title=MediaWiki:Spieleraktivitaet_data.js&action=raw&ctype=text/javascript')).then(function(){xCreateGraphs();document.getElementById('loadCustomJS').innerHTML='';},function(e){document.getElementById('loadCustomJS').innerHTML='Fehler beim Laden eines Scripts:<br>'+e.message;mw.log.error(e.message);});function xCreateGraphs(){const anonymeSpiele=[34,53,97,178,188,197,245].map((x)=>'alt-'+x);const partnerSpiele=[41,92,176].map((x)=>'alt-'+x);const userData=xData.users;const gamesData=xData.games;const rollenData=xData.rollen;const sortedGames=Object.values(gamesData).sort((a,b)=>a.date<b.date?-1:(a.date>b.date?1:0));let csvActivity='Datum,alle Spieler,aktive Spieler,sehr aktive Spieler,neue Spieler\n';let csvAnzahl='Datum,Nur 1 Spiel,Testphase,Eingespielt,Gut dabei,Pure Sucht\n';const all=new Map();const all25gamesAgo=new Set();const aktive=new Map();const gameCountPerPlayerPerGame=new Map();const filteredGames=sortedGames.filter((game)=>anonymeSpiele.indexOf(game.gamenumber)===-1);filteredGames.forEach(function(game,i){Object.keys(game.players).forEach(function(playerId){mapValueIncrease(all,playerId,1);mapValueIncrease(aktive,playerId,1);const gameCountOfPlayer=gameCountPerPlayerPerGame.get(playerId);if(gameCountOfPlayer===undefined){gameCountPerPlayerPerGame.set(playerId,{[game.date]:1,total:1});}else{gameCountOfPlayer.total+=1;gameCountOfPlayer[game.date]=gameCountOfPlayer.total;}});if(i>=25){prevGame=gamesData[filteredGames[i-25].id];Object.keys(prevGame.players).forEach(function(playerId){all25gamesAgo.add(playerId);const count=aktive.get(playerId);if(count>1){aktive.set(playerId,count-1);}else{aktive.delete(playerId);}});} | |||
let sum1=0,sum2=0,sum3=0;aktive.forEach(function(v,k){sum1+=1;if(v>=5){sum2+=1;if(v>=10){sum3+=1;}}});let eins=0,testphase=0,eingespielt=0,gutDabei=0,pureSucht=0;all.forEach(function(v,k){if(v>=50){pureSucht+=1;}else if(v>=25){gutDabei+=1;}else if(v>=10){eingespielt+=1;}else if(v>=2){testphase+=1;}else{eins+=1;}});csvActivity+=game.date+','+sum1+','+sum2+','+sum3+','+(all.size-all25gamesAgo.size)+'\n';csvAnzahl+=game.date+','+eins+','+testphase+','+eingespielt+','+gutDabei+','+pureSucht+'\n';});new Dygraph(document.getElementById('graphdiv1PlayerActivity'),csvActivity,{legend:'always',width:700});new Dygraph(document.getElementById('graphdiv2PlayerActivity'),csvAnzahl,{legend:'always',width:700});const dygraphData=['Datum'].concat(filteredGames.map((game)=>game.date));gameCountPerPlayerPerGame.forEach(function(value,key){if(value.total>=10){dygraphData[0]+=','+userData[key].name;filteredGames.forEach(function(game,i){dygraphData[i+1]+=','+(value.hasOwnProperty(game.date)?value[game.date]:'');});}});createCustomDygraph('dygraphContainer',dygraphData.join('\n'));function mapValueIncrease(map,key,increaseValue){const value=map.get(key);if(value!==undefined){map.set(key,value+increaseValue);}else{map.set(key,increaseValue);}} | |||
function createCustomDygraph(id,data){const series=[];const legend=document.createElement('div');const tooltip=document.createElement('span');legend.className='dygraph-legend-new';tooltip.className='dygraph-tooltip';document.body.appendChild(tooltip);document.getElementById(id).addEventListener('mouseout',function(ev){tooltip.style.visibility='hidden';});g=new Dygraph(id,data,{legend:'always',width:600,connectSeparatedPoints:true,highlightSeriesOpts:{strokeWidth:3,strokeBorderWidth:1,highlightCircleSize:5},legendFormatter:legendFormatter,highlightCallback:highlightCallback,clickCallback:clickCallback});const oldLegend=document.getElementById(id).getElementsByClassName('dygraph-legend')[0];oldLegend.parentNode.insertBefore(legend,oldLegend.nextSibling);function highlightCallback(ev,x,points,row,seriesName){const index=g.indexFromSetName(seriesName);const serie=series[index-1].serie;tooltip.innerHTML=new Date(x).toLocaleDateString()+' '+serie.dashHTML+seriesName+': '+g.getValue(row,index);tooltip.style.left=ev.pageX+15+'px';tooltip.style.top=ev.pageY-15+'px';tooltip.style.visibility='visible';tooltip.style.borderColor=serie.color;} | |||
function legendFormatter(data){if(data.x===undefined){if(legend.innerHTML.length===0){const docFrag=document.createDocumentFragment();data.series.forEach(function(serie,i){const el=document.createElement('div');el.innerHTML=serie.dashHTML+' '+serie.labelHTML;el.style.color=serie.color;el.className='dygraph-legend-element';el.addEventListener('click',function(ev){series[i].visible=!series[i].visible;g.setVisibility(i,series[i].visible);el.style.opacity=series[i].visible?1:0.6;});el.addEventListener('dblclick',function(ev){g.setVisibility(series.map(function(serie,j){serie.visible=i===j;serie.el.style.opacity=serie.visible?1:0.6;return serie.visible;}));});el.addEventListener('mouseover',function(ev){if(g.visibility()[i]){g.setSelection(0,serie.label,false);}});docFrag.appendChild(el);series.push({serie:serie,el:el,visible:true});});legend.appendChild(docFrag);}} | |||
function createCustomDygraph(id,data){ | |||
function legendFormatter(data){if(data.x===undefined){if(legend.innerHTML.length===0){ | |||
return'0';} | return'0';} | ||
function clickCallback(ev){if(g.isSeriesLocked()){g.clearSelection();}else{g.setSelection(g.getSelection(),g.getHighlightSeries(),true);}}}} | function clickCallback(ev){if(g.isSeriesLocked()){g.clearSelection();}else{g.setSelection(g.getSelection(),g.getHighlightSeries(),true);}}}} |