アクセスパタンのシミュレーション
増井俊之.icon
Scrapboxへのアクセスパタンをシミュレーションしたい
なるべく簡単な計算にしたいのだが
しかしこれは結果にすぎないので、これから作るのはスジが悪そう
定期的にアクセスされるページもある
バズることもあるかもしれない
案1: 指数分布間隔で次のアクセスがある
乱数を数回掛け算する
その値だけ時間がたったところでアクセスする
案2: ランダムに間隔を増やしていく
code:method1.js
h = []
function setup(){
createCanvas(800,200)
strokeWeight(0)
// いろんな乱数でアクセス履歴データぽいものを作る
setdata1(4,0.02)
// setdata1(3,0.05)
setdata2()
text(h.length,200,15)
}
function draw(){ // 各種視覚化手法を比較
fill('#fff')
rect(0,0,800,400)
posx = 0, posy = 0
draw1()
posx = 0, posy = 30
draw2()
}
function setdata2(){
if(typeof w == 'undefined') w = 1.0
now = new Date().getTime()
access = now - 365 * 24 * 60 * 60 * 0.2
interval = 0
while(access < now){
h.push(access)
interval = 24 * 60 * 60 * 0.03 * random(1) + interval
access += interval
}
}
function setdata1(arg1,arg2){ // 乱数掛け算で冪っぽく
if(typeof w == 'undefined') w = 1.0
now = new Date().getTime()
access = now - 365 * 24 * 60 * 60
while(access < now){
h.push(access)
for(i=0,interval=1.0;i<arg1;i++){
interval *= random(1)
}
interval *= 10 * 24 * 60 * 60 * 2
w += arg2
access += interval
}
}
function draw2(){ // GitHub風
fill('#fff')
rect(posx,posy,200,20)
histogram = []
for(i=0;i<356;i++) histogrami = 0 for(i=0;i<h.length;i++){
days = Math.floor(v / (24 * 60 * 60))
if(days < 0) days = 0
}
for(i=0;i<356;i++){
wday = i % 7
week = Math.floor(i/7)
c = v > 10 ? '#080' :
v > 8 ? '#2a2' :
v > 6 ? '#4b4' :
v > 4 ? '#6c6' :
v > 2 ? '#8d8' :
v > 0 ? '#aea' : '#fff'
fill(c)
rect(posx + (53-week)*3,posy + wday*3,3,3)
}
fill('black')
text('GitHub風リニア表示',posx+240,posy+15)
}
function draw1(){ // 対数棒グラフ
fill('#ffd')
rect(posx,posy,150,20)
histogram = []
for(i=0;i<200;i++) histogrami = 0 for(i=0;i<h.length;i++){
ind = Math.floor(Math.log(d) * 4)
}
for(i=0;i<100;i++){
v = Math.log(v) * 3
fill('blue')
rect(posx+150+170-(i*4),posy+20-v,4,v)
}
fill('black')
text('対数的ヒストグラム表示',posx+240,posy+15)
}