MediaWiki:Spieleraktivitaet.js: Unterschied zwischen den Versionen

Aus Werwolf Online
(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…“)
(kein Unterschied)

Version vom 18. November 2019, 23:00 Uhr

/*! @license Copyright 2019 Xaver MIT-licensed (http://opensource.org/licenses/MIT) */
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}
$.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(){document.getElementById('loadCustomJS').innerHTML='';xCreateGraphs();},function(e){document.getElementById('loadCustomJS').innerHTML='Fehler beim Laden eines Scripts:<br>'+e.message;mw.log.error(e.message);});function xCreateGraphs(){var anonymeSpiele=[34,53,97,178,188,197,245].map(function(x){return'alt-'+x;});var partnerSpiele=[41,92,176].map(function(x){return'alt-'+x;});var userData=xData.users;var gamesData=xData.games;var rollenData=xData.rollen;var sortedGames=Object.values(gamesData).sort(function(a,b){return a.date<b.date?-1:a.date>b.date?1:0;});var csvActivity='Datum,alle Spieler,aktive Spieler,sehr aktive Spieler,neue Spieler\n';var csvAnzahl='Datum,Nur 1 Spiel,Testphase,Eingespielt,Gut dabei,Pure Sucht\n';var all=new Map();var all25gamesAgo=new Set();var aktive=new Map();var gameCountPerPlayerPerGame=new Map();var filteredGames=sortedGames.filter(function(game){return 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);var gameCountOfPlayer=gameCountPerPlayerPerGame.get(playerId);if(gameCountOfPlayer===undefined){var _gameCountPerPlayerPe;gameCountPerPlayerPerGame.set(playerId,(_gameCountPerPlayerPe={},_defineProperty(_gameCountPerPlayerPe,game.date,1),_defineProperty(_gameCountPerPlayerPe,"total",1),_gameCountPerPlayerPe));}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);var count=aktive.get(playerId);if(count>1){aktive.set(playerId,count-1);}else{aktive.delete(playerId);}});}
var sum1=0,sum2=0,sum3=0;aktive.forEach(function(v,k){sum1+=1;if(v>=5){sum2+=1;if(v>=10){sum3+=1;}}});var 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});var dygraphData=['Datum'].concat(filteredGames.map(function(game){return 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){var value=map.get(key);if(value!==undefined){map.set(key,value+increaseValue);}else{map.set(key,increaseValue);}}
function createCustomDygraph(id,data){var series=[];var legend=document.createElement('div');var 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});var oldLegend=document.getElementById(id).getElementsByClassName('dygraph-legend')[0];oldLegend.parentNode.insertBefore(legend,oldLegend.nextSibling);function highlightCallback(ev,x,points,row,seriesName){var index=g.indexFromSetName(seriesName);var 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){var docFrag=document.createDocumentFragment();data.series.forEach(function(serie,i){var 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);}}
return'0';}
function clickCallback(ev){if(g.isSeriesLocked()){g.clearSelection();}else{g.setSelection(g.getSelection(),g.getHighlightSeries(),true);}}}}