Created
April 22, 2015 23:10
-
-
Save Quantium/6dbac3724a2cb1235436 to your computer and use it in GitHub Desktop.
Fuzzy logic timelapse simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fuzzylogic = require('fuzzylogic'), | |
colors = require('colors'); | |
function simulate(ttl){ | |
var timelapse = ttl*1000; | |
var half = timelapse /2; | |
var qrt = half/2; | |
//Cuando se guardó el caché | |
//El tiempo de ahorita menos 3 horas | |
var cached_time = (new Date("09-13-15 22:00:00")).getTime(); | |
var mid_time = cached_time + half+qrt; | |
var expiration_time = cached_time + timelapse; | |
console.log("Simulating :: ", ttl); | |
for(var i = 1; i < 24; i++) { | |
//36 veces cada 5 minutos | |
var request_time = cached_time + (i*(timelapse/24)); | |
var fuzzy = fuzzylogic.trapezoid(request_time, cached_time, cached_time, mid_time, expiration_time); | |
var valid = Boolean(Math.round(fuzzy)); | |
console.log(i.toString(),")Fuzzy ::", fuzzy,". transcurred :: ", (request_time-cached_time)); | |
console.log(i.toString(),")valid ::", valid ? valid.toString().green : valid.toString().red); | |
} | |
console.log("--------".green); | |
} | |
simulate(21600);//6 horas | |
simulate(3600); //1 hora | |
simulate(43200);//12 horas | |
simulate(86400);//1 día |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment