<commit_before>

console.log("hi yinger");

var model;
start();
async function start() {
    //arabic or english

    var testarray = [[[[1,0,0],[0,0,0],[0,0,0]],[[0,0,0],[0,-1,0],[0,0,0]]]];

    const test = tf.tensor(testarray,[,2,3,3]);
    //load the model
    model = await tf.loadModel('model/model.json');

    //warm up
    const output = model.predict(test);
    console.log(output)
}

// var x = "/krestik.gif";
// var o = "/nolik.gif";
// var blank = "/blank.jpg";
// var pause = 0;
// var all = 0;
// var a = 0;
// var b = 0;
// var c = 0;
// var d = 0;
// var e = 0;
// var f = 0;
// var g = 0;
// var h = 0;
// var i = 0;
// var temp="";
// var ok = 0;
// var cf = 0;
// var choice=9;
// var aRandomNumber = 0;
// var comp = 0;
// var t = 0;
// var wn = 0;
// var ls = 0;
// var ts = 0;
// function logicOne() {
//   if ((a==1)&&(b==1)&&(c==1)) all=1;
//   if ((a==1)&&(d==1)&&(g==1)) all=1;
//   if ((a==1)&&(e==1)&&(i==1)) all=1;
//   if ((b==1)&&(e==1)&&(h==1)) all=1;
//   if ((d==1)&&(e==1)&&(f==1)) all=1;
//   if ((g==1)&&(h==1)&&(i==1)) all=1;
//   if ((c==1)&&(f==1)&&(i==1)) all=1;
//   if ((g==1)&&(e==1)&&(c==1)) all=1;
//   if ((a==2)&&(b==2)&&(c==2)) all=2;
//   if ((a==2)&&(d==2)&&(g==2)) all=2;
//   if ((a==2)&&(e==2)&&(i==2)) all=2;
//   if ((b==2)&&(e==2)&&(h==2)) all=2;
//   if ((d==2)&&(e==2)&&(f==2)) all=2;
//   if ((g==2)&&(h==2)&&(i==2)) all=2;
//   if ((c==2)&&(f==2)&&(i==2)) all=2;
//   if ((g==2)&&(e==2)&&(c==2)) all=2;
//   if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
// }
// function logicTwo() {
//   if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
//   if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
//   if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
//   if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
//   if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
//   if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
//   if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
//   if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
//   if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
//   if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
//   if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
//   if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
//   if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
//   if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
//   if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
//   if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
//   if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
// }
// function logicThree() {
//   if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
//   if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
//   if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
//   if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
//   if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
//   if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
//   if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
//   if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
//   if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
//   if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
//   if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
//   if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
//   if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
//   if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
//   if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
//   if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
// }
// function clearOut() {
//   document.game.you.value="0";
//   document.game.computer.value="0";
//   document.game.ties.value="0";
// }
// function checkSpace() {
//   if ((temp=="A")&&(a==0)) {
//     ok=1;
//     if (cf==0) a=1;
//     if (cf==1) a=2;
//   }
//   if ((temp=="B")&&(b==0)) {
//     ok=1;
//     if (cf==0) b=1;
//     if (cf==1) b=2;
//   }
//   if ((temp=="C")&&(c==0)) {
//     ok=1;
//     if (cf==0) c=1;
//     if (cf==1) c=2;
//   }
//   if ((temp=="D")&&(d==0)) {
//     ok=1;
//     if (cf==0) d=1;
//     if (cf==1) d=2;
//   }
//   if ((temp=="E")&&(e==0)) {
//     ok=1;
//     if (cf==0) e=1;
//     if (cf==1) e=2;
//   }
//   if ((temp=="F")&&(f==0)) {
//     ok=1
//     if (cf==0) f=1;
//     if (cf==1) f=2;
//   }
//   if ((temp=="G")&&(g==0)) {
//     ok=1
//     if (cf==0) g=1;
//     if (cf==1) g=2;
//   }
//   if ((temp=="H")&&(h==0)) {
//     ok=1;
//     if (cf==0) h=1;
//     if (cf==1) h=2;
//   }
//   if ((temp=="I")&&(i==0)) {
//     ok=1;
//     if (cf==0) i=1;
//     if (cf==1) i=2;
//   }
// }
// function yourChoice(chName) {
//   pause = 0;
//   if (all!=0) ended();
//   if (all==0) {
//     cf = 0;
//     ok = 0;
//     temp=chName;
//     checkSpace();
//     if (ok==1) {
//       document.images[chName].src = x;
//     }
//     if (ok==0)taken();
//     process();
//     if ((all==0)&&(pause==0)) myChoice();
//   }
// }
// function taken() {
//   alert("This cell in not empty! Try another")
//   pause=1;
// }
// function myChoice() {
//   temp="";
//   ok = 0;
//   cf=1;
//   logicTwo();
//   logicThree();
//   checkSpace();
//   while(ok==0) {
//     aRandomNumber=Math.random()
//     comp=Math.round((choice-1)*aRandomNumber)+1;
//     if (comp==1) temp="A";
//     if (comp==2) temp="B";
//     if (comp==3) temp="C";
//     if (comp==4) temp="D";
//     if (comp==5) temp="E";
//     if (comp==6) temp="F";
//     if (comp==7) temp="G";
//     if (comp==8) temp="H";
//     if (comp==9) temp="I";
//     checkSpace();
//   }
//   document.images[temp].src= o;
//   process();
// }
// function ended() {
//   alert("Game over! To play once more press a button 'New Game'")
// }
// function process() {
//   logicOne();
//   if (all==1){ alert("You win!"); wn++; }
//   if (all==2){ alert("You lose!"); ls++; }
//   if (all==3){ alert("Draw!"); ts++; }
//   if (all!=0) {
//     document.game.you.value = wn;
//     document.game.computer.value = ls;
//     document.game.ties.value = ts;
//   }
// }
// function playAgain() {
//   if (all==0) {
//     if(confirm("Âû óâåðåíû ?")) reset();
//   }
//   if (all>0) reset();
// }
// function reset() {
//   all = 0;
//   a = 0;
//   b = 0;
//   c = 0;
//   d = 0;
//   e = 0;
//   f = 0;
//   g = 0;
//   h = 0;
//   i = 0;
//   temp="";
//   ok = 0;
//   cf = 0;
//   choice=9;
//   aRandomNumber = 0;
//   comp = 0;
//   document.images.A.src= blank;
//   document.images.B.src= blank;
//   document.images.C.src= blank;
//   document.images.D.src= blank;
//   document.images.E.src= blank;
//   document.images.F.src= blank;
//   document.images.G.src= blank;
//   document.images.H.src= blank;
//   document.images.I.src= blank;
//   if (t==0) { t=2; myChoice(); }
//   t--;
// }
// var ie4 = (document.all) ? true : false;
// var nn4 = (document.layers) ? true : false;

// document.getElementById("A").onclick = function() {yourChoice('A')};
// document.getElementById("B").onclick = function() {yourChoice('B')};
// document.getElementById("C").onclick = function() {yourChoice('C')};
// document.getElementById("D").onclick = function() {yourChoice('D')};
// document.getElementById("E").onclick = function() {yourChoice('E')};
// document.getElementById("F").onclick = function() {yourChoice('F')};
// document.getElementById("G").onclick = function() {yourChoice('G')};
// document.getElementById("H").onclick = function() {yourChoice('H')};
// document.getElementById("I").onclick = function() {yourChoice('I')};
// document.getElementById("button").onclick = function() {playAgain()};

// async function setupMnistTransferCNN() {
//   const button = document.getElementById('load-pretrained-remote');
//   button.addEventListener('click', async () => {
//       yourChoice('A')
//   });
// }

// setupMnistTransferCNN();<commit_msg>added diemension<commit_after>

console.log("hi yinger");

var model;
start();
async function start() {
    //arabic or english

    var testarray = [[[1,0,0],[0,0,0],[0,0,0]],[[0,0,0],[0,-1,0],[0,0,0]]];

    const test = tf.tensor(testarray,[,2,3,3]);
    //load the model
    model = await tf.loadModel('model/model.json');

    //warm up
    const output = model.predict(test);
    console.log(output)
}

// var x = "/krestik.gif";
// var o = "/nolik.gif";
// var blank = "/blank.jpg";
// var pause = 0;
// var all = 0;
// var a = 0;
// var b = 0;
// var c = 0;
// var d = 0;
// var e = 0;
// var f = 0;
// var g = 0;
// var h = 0;
// var i = 0;
// var temp="";
// var ok = 0;
// var cf = 0;
// var choice=9;
// var aRandomNumber = 0;
// var comp = 0;
// var t = 0;
// var wn = 0;
// var ls = 0;
// var ts = 0;
// function logicOne() {
//   if ((a==1)&&(b==1)&&(c==1)) all=1;
//   if ((a==1)&&(d==1)&&(g==1)) all=1;
//   if ((a==1)&&(e==1)&&(i==1)) all=1;
//   if ((b==1)&&(e==1)&&(h==1)) all=1;
//   if ((d==1)&&(e==1)&&(f==1)) all=1;
//   if ((g==1)&&(h==1)&&(i==1)) all=1;
//   if ((c==1)&&(f==1)&&(i==1)) all=1;
//   if ((g==1)&&(e==1)&&(c==1)) all=1;
//   if ((a==2)&&(b==2)&&(c==2)) all=2;
//   if ((a==2)&&(d==2)&&(g==2)) all=2;
//   if ((a==2)&&(e==2)&&(i==2)) all=2;
//   if ((b==2)&&(e==2)&&(h==2)) all=2;
//   if ((d==2)&&(e==2)&&(f==2)) all=2;
//   if ((g==2)&&(h==2)&&(i==2)) all=2;
//   if ((c==2)&&(f==2)&&(i==2)) all=2;
//   if ((g==2)&&(e==2)&&(c==2)) all=2;
//   if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
// }
// function logicTwo() {
//   if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
//   if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
//   if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
//   if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
//   if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
//   if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
//   if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
//   if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
//   if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
//   if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
//   if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
//   if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
//   if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
//   if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
//   if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
//   if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
//   if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
// }
// function logicThree() {
//   if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
//   if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
//   if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
//   if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
//   if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
//   if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
//   if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
//   if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
//   if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
//   if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
//   if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
//   if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
//   if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
//   if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
//   if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
//   if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
// }
// function clearOut() {
//   document.game.you.value="0";
//   document.game.computer.value="0";
//   document.game.ties.value="0";
// }
// function checkSpace() {
//   if ((temp=="A")&&(a==0)) {
//     ok=1;
//     if (cf==0) a=1;
//     if (cf==1) a=2;
//   }
//   if ((temp=="B")&&(b==0)) {
//     ok=1;
//     if (cf==0) b=1;
//     if (cf==1) b=2;
//   }
//   if ((temp=="C")&&(c==0)) {
//     ok=1;
//     if (cf==0) c=1;
//     if (cf==1) c=2;
//   }
//   if ((temp=="D")&&(d==0)) {
//     ok=1;
//     if (cf==0) d=1;
//     if (cf==1) d=2;
//   }
//   if ((temp=="E")&&(e==0)) {
//     ok=1;
//     if (cf==0) e=1;
//     if (cf==1) e=2;
//   }
//   if ((temp=="F")&&(f==0)) {
//     ok=1
//     if (cf==0) f=1;
//     if (cf==1) f=2;
//   }
//   if ((temp=="G")&&(g==0)) {
//     ok=1
//     if (cf==0) g=1;
//     if (cf==1) g=2;
//   }
//   if ((temp=="H")&&(h==0)) {
//     ok=1;
//     if (cf==0) h=1;
//     if (cf==1) h=2;
//   }
//   if ((temp=="I")&&(i==0)) {
//     ok=1;
//     if (cf==0) i=1;
//     if (cf==1) i=2;
//   }
// }
// function yourChoice(chName) {
//   pause = 0;
//   if (all!=0) ended();
//   if (all==0) {
//     cf = 0;
//     ok = 0;
//     temp=chName;
//     checkSpace();
//     if (ok==1) {
//       document.images[chName].src = x;
//     }
//     if (ok==0)taken();
//     process();
//     if ((all==0)&&(pause==0)) myChoice();
//   }
// }
// function taken() {
//   alert("This cell in not empty! Try another")
//   pause=1;
// }
// function myChoice() {
//   temp="";
//   ok = 0;
//   cf=1;
//   logicTwo();
//   logicThree();
//   checkSpace();
//   while(ok==0) {
//     aRandomNumber=Math.random()
//     comp=Math.round((choice-1)*aRandomNumber)+1;
//     if (comp==1) temp="A";
//     if (comp==2) temp="B";
//     if (comp==3) temp="C";
//     if (comp==4) temp="D";
//     if (comp==5) temp="E";
//     if (comp==6) temp="F";
//     if (comp==7) temp="G";
//     if (comp==8) temp="H";
//     if (comp==9) temp="I";
//     checkSpace();
//   }
//   document.images[temp].src= o;
//   process();
// }
// function ended() {
//   alert("Game over! To play once more press a button 'New Game'")
// }
// function process() {
//   logicOne();
//   if (all==1){ alert("You win!"); wn++; }
//   if (all==2){ alert("You lose!"); ls++; }
//   if (all==3){ alert("Draw!"); ts++; }
//   if (all!=0) {
//     document.game.you.value = wn;
//     document.game.computer.value = ls;
//     document.game.ties.value = ts;
//   }
// }
// function playAgain() {
//   if (all==0) {
//     if(confirm("Âû óâåðåíû ?")) reset();
//   }
//   if (all>0) reset();
// }
// function reset() {
//   all = 0;
//   a = 0;
//   b = 0;
//   c = 0;
//   d = 0;
//   e = 0;
//   f = 0;
//   g = 0;
//   h = 0;
//   i = 0;
//   temp="";
//   ok = 0;
//   cf = 0;
//   choice=9;
//   aRandomNumber = 0;
//   comp = 0;
//   document.images.A.src= blank;
//   document.images.B.src= blank;
//   document.images.C.src= blank;
//   document.images.D.src= blank;
//   document.images.E.src= blank;
//   document.images.F.src= blank;
//   document.images.G.src= blank;
//   document.images.H.src= blank;
//   document.images.I.src= blank;
//   if (t==0) { t=2; myChoice(); }
//   t--;
// }
// var ie4 = (document.all) ? true : false;
// var nn4 = (document.layers) ? true : false;

// document.getElementById("A").onclick = function() {yourChoice('A')};
// document.getElementById("B").onclick = function() {yourChoice('B')};
// document.getElementById("C").onclick = function() {yourChoice('C')};
// document.getElementById("D").onclick = function() {yourChoice('D')};
// document.getElementById("E").onclick = function() {yourChoice('E')};
// document.getElementById("F").onclick = function() {yourChoice('F')};
// document.getElementById("G").onclick = function() {yourChoice('G')};
// document.getElementById("H").onclick = function() {yourChoice('H')};
// document.getElementById("I").onclick = function() {yourChoice('I')};
// document.getElementById("button").onclick = function() {playAgain()};

// async function setupMnistTransferCNN() {
//   const button = document.getElementById('load-pretrained-remote');
//   button.addEventListener('click', async () => {
//       yourChoice('A')
//   });
// }

// setupMnistTransferCNN();<|endoftext|>


<commit_before>function colors(i) {
  switch (i) {
    case "IllegalDumping":
      return "#e30000";
      break;
    case "BuildingMaintenance":
      return "#A7DBD8";
      break;
    case "Electrical":
      return "#4285f4";
      break;
    case "StreetSweeping":
      return "#F38630";
      break;
    case "RoadRepair":
      return "#FA6900";
      break;
    case "VegetationControl":
      return "#03070b";
      break;
    case "Graffiti":
      return "#768294";
      break;
    case "Survey":
      return "#c0d530";
      break;
    case "Drainage":
      return "#00ff7f";
      break;
    case "StreetLights":
      return "#01aebf";
      break;

      return "Pink";
  };
}

var splitCsv = function(data) {
  var lines = data
    .split("\n");
  lines = lines.map(function(line, i) {
    return line.split(",");
  });
  return {
    headers: lines.shift(),
    lines: lines
  };
};

var avgDayOptions = {
  chart: {
    type: 'bar',
    marginLeft: 120
  },
  title: {
    text: 'Average Days to Respond Per Category'
  },
  legend: {
    enabled: false,
  },
  xAxis: {
    title: {
      align: 'high',
      offset: 0,
      text: 'Problem Type',
      rotation: 0,
      y: -10
    }
  },
  yAxis: {
    showEmpty: true,
    labels: {
      enabled: false
    },
    gridLineWidth: 0
  }
}

// Average Days Set up
$.getJSON("_data/avgdays.json", function(jsondata) {
  // Get our Series Categories
  var cats = jsondata.map(function(val) {
    return val.name;
  });
  // Map the data to a better series format
  var data = jsondata.map(function(val, i) {
    return {
      color: colors(val.name),
      y: val.data,
      name: val.name,
      dataLabels: {
        enabled: true,
      }
    }
  });

  // Set our options
  avgDayOptions.xAxis.categories = cats;
  avgDayOptions.series = [{
    data: data
  }];
  $('#daystoclose').highcharts(avgDayOptions);

});

// handle comparison graphs

var overTimeOptions = function() {
  return {
    chart: {
      type: 'column'
    },
    title: {
      text: 'Total Number of Complaints by Type'
    },
    legend: {
      enabled: false,
    },
    xAxis: {
      title: {
        align: 'high',
        offset: 0,
        text: 'Problem Type',
        rotation: 0,
        y: -10
      }
    },
    plotOptions: {
      column: {
        stacking: 'normal'
      }
    },
    yAxis: {}
  };
};

$.get("_data/cityfixitdata.csv", function(data) {
  // split the csv by line("\n"), remove header, sort
  var csv = splitCsv(data);
  var otOp = overTimeOptions();

  var year_index = csv.headers.indexOf('Year');
  var prob_index = csv.headers.indexOf('ProblemType');
  var num_index = csv.headers.indexOf('NumRequests');
  var app_index = csv.headers.indexOf('%ReportedBySeeClickFix');
  var year_data = {};

  csv.lines.map(function(line) {
    if (line[year_index] !== undefined) {

      if (line[year_index] in year_data) {
        year_data[line[year_index]].push(line);
      } else {
        year_data[line[year_index]] = [line];
      }
    };
  });

  otOp.xAxis.categories = Object.keys(year_data);

  var series = [];
  var total, fromApp, intTotal, intFromApp;

  for (var i = 0; i <= 4; i++) {
    total = [];
    fromApp = [];
    for (var year in year_data) {
      intTotal = parseInt(year_data[year][i][num_index]);
      intFromApp = intTotal * parseFloat(year_data[year][i][app_index]) / 100;
      total.push(intTotal - intFromApp);
      fromApp.push(intFromApp);
    }
    series.push({
      name: 'Not From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: total
    });
    series.push({
      name: 'From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: fromApp
    });
  }
  otOp.series = series;
  console.log(series);
  $('#comp1').highcharts(otOp);
});

$.get("_data/cityfixitdata.csv", function(data) {
  // split the csv by line("\n"), remove header, sort
  var csv = splitCsv(data);
  var otOp = overTimeOptions();

  var year_index = csv.headers.indexOf('Year');
  var prob_index = csv.headers.indexOf('ProblemType');
  var num_index = csv.headers.indexOf('NumRequests');
  var app_index = csv.headers.indexOf('%ReportedBySeeClickFix');
  var year_data = {};

  csv.lines.map(function(line) {
    if (line[year_index] !== undefined) {

      if (line[year_index] in year_data) {
        year_data[line[year_index]].push(line);
      } else {
        year_data[line[year_index]] = [line];
      }
    };
  });

  otOp.xAxis.categories = Object.keys(year_data);

  var series = [];
  var total, fromApp, intTotal, intFromApp;

  for (var i = 5; i <= 9; i++) {
    total = [];
    fromApp = [];
    for (var year in year_data) {
      intTotal = parseInt(year_data[year][i][num_index]);
      intFromApp = intTotal * parseFloat(year_data[year][i][app_index]) / 100;
      total.push(intTotal - intFromApp);
      fromApp.push(intFromApp);
    }
    series.push({
      name: 'Not From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: total
    });
    series.push({
      name: 'From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: fromApp
    });
  }
  otOp.series = series;
  console.log(series);
  $('#comp2').highcharts(otOp);
});
<commit_msg>Changed colors<commit_after>function colors(i) {
  switch (i) {
    case "IllegalDumping":
      return "#e30000";
      break;
    case "BuildingMaintenance":
      return "#A7DBD8";
      break;
    case "Electrical":
      return "#4285f4";
      break;
    case "StreetSweeping":
      return "#F38630";
      break;
    case "RoadRepair":
      return "#00ff7f";
      break;
    case "VegetationControl":
      return "#03070b";
      break;
    case "Graffiti":
      return "#768294";
      break;
    case "Survey":
      return "#c0d530";
      break;
    case "Drainage":
      return "#FA6900";
      break;
    case "StreetLights":
      return "#01aebf";
      break;

      return "Pink";
  };
}
var splitCsv = function(data) {
  var lines = data
    .split("\n");
  lines = lines.map(function(line, i) {
    return line.split(",");
  });
  return {
    headers: lines.shift(),
    lines: lines
  };
};

var avgDayOptions = {
  chart: {
    type: 'bar',
    marginLeft: 120
  },
  title: {
    text: 'Average Days to Respond Per Category'
  },
  legend: {
    enabled: false,
  },
  xAxis: {
    title: {
      align: 'high',
      offset: 0,
      text: 'Problem Type',
      rotation: 0,
      y: -10
    }
  },
  yAxis: {
    showEmpty: true,
    labels: {
      enabled: false
    },
    gridLineWidth: 0
  }
}

// Average Days Set up
$.getJSON("_data/avgdays.json", function(jsondata) {
  // Get our Series Categories
  var cats = jsondata.map(function(val) {
    return val.name;
  });
  // Map the data to a better series format
  var data = jsondata.map(function(val, i) {
    return {
      color: colors(val.name),
      y: val.data,
      name: val.name,
      dataLabels: {
        enabled: true,
      }
    }
  });

  // Set our options
  avgDayOptions.xAxis.categories = cats;
  avgDayOptions.series = [{
    data: data
  }];
  $('#daystoclose').highcharts(avgDayOptions);

});

// handle comparison graphs

var overTimeOptions = function() {
  return {
    chart: {
      type: 'column'
    },
    title: {
      text: 'Total Number of Complaints by Type'
    },
    legend: {
      enabled: false,
    },
    xAxis: {
      title: {
        align: 'high',
        offset: 0,
        text: 'Problem Type',
        rotation: 0,
        y: -10
      }
    },
    plotOptions: {
      column: {
        stacking: 'normal'
      }
    },
    yAxis: {}
  };
};

$.get("_data/cityfixitdata.csv", function(data) {
  // split the csv by line("\n"), remove header, sort
  var csv = splitCsv(data);
  var otOp = overTimeOptions();

  var year_index = csv.headers.indexOf('Year');
  var prob_index = csv.headers.indexOf('ProblemType');
  var num_index = csv.headers.indexOf('NumRequests');
  var app_index = csv.headers.indexOf('%ReportedBySeeClickFix');
  var year_data = {};

  csv.lines.map(function(line) {
    if (line[year_index] !== undefined) {

      if (line[year_index] in year_data) {
        year_data[line[year_index]].push(line);
      } else {
        year_data[line[year_index]] = [line];
      }
    };
  });

  otOp.xAxis.categories = Object.keys(year_data);

  var series = [];
  var total, fromApp, intTotal, intFromApp;

  for (var i = 0; i <= 4; i++) {
    total = [];
    fromApp = [];
    for (var year in year_data) {
      intTotal = parseInt(year_data[year][i][num_index]);
      intFromApp = intTotal * parseFloat(year_data[year][i][app_index]) / 100;
      total.push(intTotal - intFromApp);
      fromApp.push(intFromApp);
    }
    series.push({
      name: 'Not From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: total
    });
    series.push({
      name: 'From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: fromApp
    });
  }
  otOp.series = series;
  console.log(series);
  $('#comp1').highcharts(otOp);
});

$.get("_data/cityfixitdata.csv", function(data) {
  // split the csv by line("\n"), remove header, sort
  var csv = splitCsv(data);
  var otOp = overTimeOptions();

  var year_index = csv.headers.indexOf('Year');
  var prob_index = csv.headers.indexOf('ProblemType');
  var num_index = csv.headers.indexOf('NumRequests');
  var app_index = csv.headers.indexOf('%ReportedBySeeClickFix');
  var year_data = {};

  csv.lines.map(function(line) {
    if (line[year_index] !== undefined) {

      if (line[year_index] in year_data) {
        year_data[line[year_index]].push(line);
      } else {
        year_data[line[year_index]] = [line];
      }
    };
  });

  otOp.xAxis.categories = Object.keys(year_data);

  var series = [];
  var total, fromApp, intTotal, intFromApp;

  for (var i = 5; i <= 9; i++) {
    total = [];
    fromApp = [];
    for (var year in year_data) {
      intTotal = parseInt(year_data[year][i][num_index]);
      intFromApp = intTotal * parseFloat(year_data[year][i][app_index]) / 100;
      total.push(intTotal - intFromApp);
      fromApp.push(intFromApp);
    }
    series.push({
      name: 'Not From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: total
    });
    series.push({
      name: 'From App',
      stack: year_data[2009][i][prob_index],
      color: colors(year_data[2009][i][prob_index]),
      data: fromApp
    });
  }
  otOp.series = series;
  console.log(series);
  $('#comp2').highcharts(otOp);
});
<|endoftext|>


<commit_before>function drawMutationDiagram(mutationDiagram)
{
  domainColors = [ "rgb(166, 206, 227)", "rgb(31, 120, 180)", "rgb(178, 223, 138)", "rgb(51, 160, 44)" ];
  domainStrokeColors = [ "rgb(145, 181, 199)", "rgb(27, 105, 158)", "rgb(156, 195, 121)", "rgb(44, 140, 38)" ];
  mutationColors = [ "rgb(251, 154, 153)", "rgb(227, 26, 28)", "rgb(253, 191, 111)", "rgb(255, 127, 0)" ];

  x = 40;
  y = 0;
  w = 700 - (2 * x);
  h = 220;
  c = (2 * h) / 3;
  l = mutationDiagram.length;

  var div = d3.select("#mutation_diagram_" + mutationDiagram.id)
    .append("div");

  var svg = div.append("svg:svg")
    .attr("width", 700)
    .attr("height", 220);

  // label
  svg.append("svg:text")
    .attr("x", "10")
    .attr("y", "26")
    .attr("text-anchor", "start")
    .style("font-size", "16px")
    .style("font-family", "sans-serif")
    .text(mutationDiagram.label);

  // sequence
  svg.append("svg:rect")
    .attr("x", x)
    .attr("y", c - 6)
    .attr("width", scaleHoriz(mutationDiagram.length, w, l))
    .attr("height", 13)
    .attr("class", "sequence")
    .attr("title", mutationDiagram.label + " (1 - " + mutationDiagram.length + ")")
    .style("fill", "rgb(120, 120, 120)")
    .style("stroke", "none")
    //.append("svg:title")
    //  .text(mutationDiagram.label + " (1 - " + mutationDiagram.length + ")");

  // domains
  for (i = 0, size = mutationDiagram.domains.length; i < size; i++)
  {
    domainX = x + scaleHoriz(mutationDiagram.domains[i].start, w, l);
    domainY = c - 10;
    domainW = scaleHoriz(mutationDiagram.domains[i].end - mutationDiagram.domains[i].start, w, l);
    domainH = 20;

    svg.append("svg:rect")
      .attr("x", domainX)
      .attr("y", domainY)
      .attr("width", domainW)
      .attr("height", domainH)
      .attr("class", "domain")
      .attr("title", mutationDiagram.domains[i].label + " (" + mutationDiagram.domains[i].start + " - " + mutationDiagram.domains[i].end + ")")
      .style("fill", domainColors[i % 4])
      .style("stroke-width", "1")
      .style("stroke", domainStrokeColors[i % 4])
      //.append("svg:title")
      //  .text(mutationDiagram.domains[i].label + " (" + mutationDiagram.domains[i].start + " - " + mutationDiagram.domains[i].end + ")");

    svg.append("svg:text")
      .attr("x", domainX + (domainW / 2))
      .attr("y", domainY + domainH + 14)
      .attr("text-anchor", "middle")
      .style("font-size", "11px")
      .style("font-family", "sans-serif")
      .text(mutationDiagram.domains[i].label);
  }

  // mutation scale
  maxCount = 0;
  for (i = 0, size = mutationDiagram.mutations.length; i < size; i++)
  {
    if (mutationDiagram.mutations[i].count > maxCount)
    {
      maxCount = mutationDiagram.mutations[i].count;
    }
  }

  scaleX = x - 15;
  scaleY = c - 12;
  per = (h / 3) / maxCount;
  scaleH = maxCount * per;
  scaleW = scaleHoriz(8, w, l);

  if (maxCount > 4)
  {
    svg.append("svg:line")
      .attr("x1", scaleX)
      .attr("y1", scaleY)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW)
      .attr("y1", scaleY)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - scaleH)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW)
      .attr("y1", scaleY - scaleH)
      .attr("x2", scaleX)
      .attr("y2", scaleY - scaleH)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    // scale major ticks
    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 4)
      .attr("y1", scaleY - (maxCount / 2) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - (maxCount / 2) * per)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    // scale minor ticks
    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 2)
      .attr("y1", scaleY - (maxCount / 4) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - (maxCount / 4) * per)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 2)
      .attr("y1", scaleY - ((3 * maxCount) / 4) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - ((3 * maxCount) / 4) * per)
      .style("stroke", "rgb(80, 80, 80")
      .style("stroke-width", 1);

    // scale labels
    svg.append("svg:text")
      .attr("x", scaleX - 8)
      .attr("y", scaleY + 4)
      .attr("text-anchor", "middle")
      .style("fill", "rgb(80, 80, 80)")
      .style("font-size", "11px")
      .style("font-family", "sans-serif")
      .text("0");

    svg.append("svg:text")
      .attr("x", scaleX - 8)
      .attr("y", scaleY + 4 - (maxCount * per))
      .attr("text-anchor", "middle")
      .style("fill", "rgb(80, 80, 80)")
      .style("font-size", "11px")
      .style("font-family", "sans-serif")
      .text(maxCount);
  }

  // mutation histograms/pileups
  for (i = 0, size = mutationDiagram.mutations.length; i < size; i++)
  {
    x1 = x + scaleHoriz(mutationDiagram.mutations[i].location, w, l);
    y1 = c - 12;
    x2 = x1;
    y2 = c - 12 - (per * mutationDiagram.mutations[i].count);

    if (maxCount > 4)
    {
      svg.append("svg:line")
        .attr("x1", x1)
        .attr("y1", y1)
        .attr("x2", x2)
        .attr("y2", y2)
        .attr("class", "mutation")
        .attr("title", mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")")
        .style("stroke", mutationColors[i % 4])
        .style("stroke-width", 2)
        //.append("svg:title")
        //  .text(mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")");
    }
    else
    {
      per = (h / 3) / 8;
      y2 = c - 12 - (per * mutationDiagram.mutations[i].count);
      for (j = 0, count = mutationDiagram.mutations[i].count; j < count; j++)
      {
        svg.append("svg:circle")
          .attr("cx", x2)
          .attr("cy", y1 - (j * per) - per/2)
          .attr("r", per/2)
          .attr("class", "mutation")
          .attr("title", mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")")
          .style("fill", mutationColors[i % 4])
          //.append("svg:title")
          //  .text(mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")");
      }
    }

    if (mutationDiagram.mutations[i].label && (maxCount == mutationDiagram.mutations[i].count))
    {
      svg.append("svg:text")
        .attr("x", x1)
        .attr("y", y2 - 4)
        .attr("text-anchor", "middle")
        .style("fill", mutationColors[i % 4])
        .style("font-size", "11px")
        .style("font-family", "sans-serif")
        .text(mutationDiagram.mutations[i].label);
    }
  }

  $(".sequence").tipTip();
  $(".domain").tipTip();
  $(".mutation").tipTip();
}

function scaleHoriz(x, w, l)
{
  return x * (w/l);
}<commit_msg>Issue 239, Issue 254 ; adding sequence scale along x-axis, adding alternating 100 aa dark/light grey on sequence rect, moving domain labels to inside domain rect, only show domain labels if they will fit, rolling back tip tip tool tips<commit_after>function drawMutationDiagram(mutationDiagram)
{
  sequenceColors = [ "rgb(211, 215, 207)", "rgb(186, 189, 182)" ];
  scaleColors = [ "rgb(85, 87, 83)", "rgb(46, 52, 54)" ];
  domainColors = [ "rgb(166, 206, 227)", "rgb(31, 120, 180)", "rgb(178, 223, 138)", "rgb(51, 160, 44)" ];
  domainStrokeColors = [ "rgb(145, 181, 199)", "rgb(27, 105, 158)", "rgb(156, 195, 121)", "rgb(44, 140, 38)" ];
  mutationColors = [ "rgb(251, 154, 153)", "rgb(227, 26, 28)", "rgb(253, 191, 111)", "rgb(255, 127, 0)" ];

  x = 40;
  y = 0;
  w = 700 - (2 * x);
  h = 220;
  c = (2 * h) / 3;
  l = mutationDiagram.length;

  var div = d3.select("#mutation_diagram_" + mutationDiagram.id)
    .append("div");

  var svg = div.append("svg:svg")
    .attr("width", 700)
    .attr("height", 220);

  // label
  svg.append("svg:text")
    .attr("x", "10")
    .attr("y", "26")
    .attr("text-anchor", "start")
    .style("font-size", "16px")
    .style("font-family", "sans-serif")
    .text(mutationDiagram.label);

  // sequence
  svg.append("svg:rect")
   .attr("x", x)
   .attr("y", c - 6)
   .attr("width", scaleHoriz(Math.max(l, 100), w, l))
   .attr("height", 13)
   //.attr("class", "sequence")
   //.attr("title", mutationDiagram.label + " (1 - " + mutationDiagram.length + ")")
   .style("fill", sequenceColors[0])
   .style("stroke", "none")
   .append("svg:title")
     .text(mutationDiagram.label + " (1 - " + l + ")");

  for (i = 100; i < l; i += 200) {
    svg.append("svg:rect")
      .attr("x", x + scaleHoriz(i, w, l))
      .attr("y", c - 6)
      .attr("width", scaleHoriz(Math.min(l - i, 100), w, l))
      .attr("height", 13)
      //.attr("class", "sequence")
      //.attr("title", mutationDiagram.label + " (1 - " + mutationDiagram.length + ")")
      .style("fill", sequenceColors[1])
      .style("stroke", "none")
      .append("svg:title")
        .text(mutationDiagram.label + " (1 - " + l + ")");
  }

  // sequence scale
  sequenceScaleY = c + 20;

  svg.append("svg:line")
    .attr("x1", x)
    .attr("y1", sequenceScaleY + 4)
    .attr("x2", x)
    .attr("y2", sequenceScaleY)
    .style("stroke", scaleColors[0])
    .style("stroke-width", 1);

  svg.append("svg:line")
    .attr("x1", x)
    .attr("y1", sequenceScaleY)
    .attr("x2", x + scaleHoriz(l, w, l))
    .attr("y2", sequenceScaleY)
    .style("stroke", scaleColors[0])
    .style("stroke-width", 1);

  svg.append("svg:line")
    .attr("x1", x + scaleHoriz(l, w, l))
    .attr("y1", sequenceScaleY)
    .attr("x2", x + scaleHoriz(l, w, l))
    .attr("y2", sequenceScaleY + 4)
    .style("stroke", scaleColors[0])
    .style("stroke-width", 1);

  for (i = 0; i < l; i += 100) {
    svg.append("svg:line")
      .attr("x1", x + scaleHoriz(i, w, l))
      .attr("y1", sequenceScaleY)
      .attr("x2", x + scaleHoriz(i, w, l))
      .attr("y2", sequenceScaleY + 2)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);
  }

  svg.append("svg:text")
    .attr("x", x + scaleHoriz(l, w, l))
    .attr("y", sequenceScaleY + 16)
    .attr("text-anchor", "middle")
    .style("fill", scaleColors[1])
    .style("font-size", "11px")
    .style("font-family", "sans-serif")
    .text(l + " aa");

  // domains
  for (i = 0, size = mutationDiagram.domains.length; i < size; i++)
  {
    domainX = x + scaleHoriz(mutationDiagram.domains[i].start, w, l);
    domainY = c - 10;
    domainW = scaleHoriz(mutationDiagram.domains[i].end - mutationDiagram.domains[i].start, w, l);
    domainH = 20;
    label = mutationDiagram.domains[i].label;

    svg.append("svg:rect")
      .attr("x", domainX)
      .attr("y", domainY)
      .attr("width", domainW)
      .attr("height", domainH)
      //.attr("class", "domain")
      //.attr("title", mutationDiagram.domains[i].label + " (" + mutationDiagram.domains[i].start + " - " + mutationDiagram.domains[i].end + ")")
      .style("fill", domainColors[i % 4])
      .style("stroke-width", "1")
      .style("stroke", domainStrokeColors[i % 4])
      .append("svg:title")
        .text(label + " domain (" + mutationDiagram.domains[i].start + " - " + mutationDiagram.domains[i].end + ")");

    if ((label.length * 5) < domainW) {
      svg.append("svg:text")
        .attr("x", domainX + (domainW / 2))
        //.attr("y", domainY + domainH + 14)
        .attr("y", domainY + domainH - 5)
        .attr("text-anchor", "middle")
        .style("font-size", "11px")
        .style("font-family", "sans-serif")
        .text(label)
        .append("svg:title")
          .text(label + " domain (" + mutationDiagram.domains[i].start + " - " + mutationDiagram.domains[i].end + ")");
    }
  }

  // mutation scale
  maxCount = 0;
  for (i = 0, size = mutationDiagram.mutations.length; i < size; i++)
  {
    if (mutationDiagram.mutations[i].count > maxCount)
    {
      maxCount = mutationDiagram.mutations[i].count;
    }
  }

  scaleX = x - 15;
  scaleY = c - 12;
  per = (h / 3) / maxCount;
  scaleH = maxCount * per;
  scaleW = scaleHoriz(8, w, l);

  if (maxCount > 4)
  {
    svg.append("svg:line")
      .attr("x1", scaleX)
      .attr("y1", scaleY)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW)
      .attr("y1", scaleY)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - scaleH)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW)
      .attr("y1", scaleY - scaleH)
      .attr("x2", scaleX)
      .attr("y2", scaleY - scaleH)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    // scale major ticks
    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 4)
      .attr("y1", scaleY - (maxCount / 2) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - (maxCount / 2) * per)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    // scale minor ticks
    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 2)
      .attr("y1", scaleY - (maxCount / 4) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - (maxCount / 4) * per)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    svg.append("svg:line")
      .attr("x1", scaleX + scaleW - 2)
      .attr("y1", scaleY - ((3 * maxCount) / 4) * per)
      .attr("x2", scaleX + scaleW)
      .attr("y2", scaleY - ((3 * maxCount) / 4) * per)
      .style("stroke", scaleColors[0])
      .style("stroke-width", 1);

    // scale labels
    svg.append("svg:text")
      .attr("x", scaleX - 8)
      .attr("y", scaleY + 4)
      .attr("text-anchor", "middle")
      .style("fill", scaleColors[1])
      .style("font-size", "11px")
      .style("font-family", "sans-serif")
      .text("0");

    svg.append("svg:text")
      .attr("x", scaleX - 8)
      .attr("y", scaleY + 4 - (maxCount * per))
      .attr("text-anchor", "middle")
      .style("fill", scaleColors[1])
      .style("font-size", "11px")
      .style("font-family", "sans-serif")
      .text(maxCount);
  }

  // mutation histograms/pileups
  for (i = 0, size = mutationDiagram.mutations.length; i < size; i++)
  {
    x1 = x + scaleHoriz(mutationDiagram.mutations[i].location, w, l);
    y1 = c - 12;
    x2 = x1;
    y2 = c - 12 - (per * mutationDiagram.mutations[i].count);

    if (maxCount > 4)
    {
      svg.append("svg:line")
        .attr("x1", x1)
        .attr("y1", y1)
        .attr("x2", x2)
        .attr("y2", y2)
        //.attr("class", "mutation")
        //.attr("title", mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")")
        .style("stroke", mutationColors[i % 4])
        .style("stroke-width", 2)
        .append("svg:title")
          .text(mutationDiagram.mutations[i].label + " mutation (" + mutationDiagram.mutations[i].count + ")");
    }
    else
    {
      per = (h / 3) / 8;
      y2 = c - 12 - (per * mutationDiagram.mutations[i].count);
      for (j = 0, count = mutationDiagram.mutations[i].count; j < count; j++)
      {
        svg.append("svg:circle")
          .attr("cx", x2)
          .attr("cy", y1 - (j * per) - per/2)
          .attr("r", per/2)
          //.attr("class", "mutation")
          //.attr("title", mutationDiagram.mutations[i].label + " (" + mutationDiagram.mutations[i].count + ")")
          .style("fill", mutationColors[i % 4])
          .append("svg:title")
            .text(mutationDiagram.mutations[i].label + " mutation (" + mutationDiagram.mutations[i].count + ")");
      }
    }

    if (mutationDiagram.mutations[i].label && (maxCount == mutationDiagram.mutations[i].count))
    {
      svg.append("svg:text")
        .attr("x", x1)
        .attr("y", y2 - 4)
        .attr("text-anchor", "middle")
        .style("fill", mutationColors[i % 4])
        .style("font-size", "11px")
        .style("font-family", "sans-serif")
        .text(mutationDiagram.mutations[i].label);
    }
  }

  //$(".sequence").tipTip();
  //$(".domain").tipTip();
  //$(".mutation").tipTip();
}

function scaleHoriz(x, w, l)
{
  return x * (w/l);
}<|endoftext|>


<commit_before>// Part of <http://miracle.systems/p/h5.modbus> licensed under <MIT>

'use strict';

const buffers = require('h5.buffers');
const helpers = require('../helpers');
const FunctionCode = require('../FunctionCode');
const Response = require('../Response');

/**
 * The read coils response (code 0x01).
 *
 * A binary representation of this response varies in length and consists of:
 *
 *   - a function code (1 byte),
 *   - a byte count `n` (1 byte),
 *   - coil states (`n` bytes).
 */
class ReadCoilsResponse extends Response
{
  /**
   * @param {Array<boolean>} states States of the coils. An array of 1 to 2000 truthy or falsy elements.
   * @throws {Error} If the `states` array is empty or has more than 2000 elements.
   */
  constructor(states)
  {
    super(FunctionCode.ReadCoils);

    if (states.length === 0 || states.length > 2000)
    {
      throw new Error(`Invalid states array. Expected length between 1 and 2000, got [${states.length}].`);
    }

    /**
     * States of the coils. An array of 1 to 2000 truthy or falsy elements.
     *
     * @readonly
     * @type {Array<boolean>}
     */
    this.states = states;
  }

  /**
   * Creates a new response from the specified `options`.
   *
   * @param {Object} options
   * @param {Array<boolean>} options.states An array of coil states. Must have between 1 and 2000 elements.
   * @returns {ReadCoilsResponse}
   * @throws {Error} If any of the specified `options` are invalid.
   */
  static fromOptions(options)
  {
    return new ReadCoilsResponse(options.states);
  }

  /**
   * Creates a new response from its binary representation.
   *
   * @param {Buffer} buffer A binary representation of this response.
   * @returns {ReadCoilsResponse}
   * @throws {Error} If the specified `buffer` is not a valid binary representation of this response.
   */
  static fromBuffer(buffer)
  {
    helpers.assertFunctionCode(buffer[0], FunctionCode.ReadCoils);

    const reader = new buffers.BufferReader(buffer);
    const states = reader.readBits(2, buffer[1] * 8);

    return new ReadCoilsResponse(states);
  }

  /**
   * A number of coils.
   *
   * @type {number}
   */
  get quantity()
  {
    return this.states.length;
  }

  /**
   * Returns a binary representation of this response.
   *
   * @returns {Buffer}
   */
  toBuffer()
  {
    return new buffers.BufferBuilder()
      .pushByte(this.functionCode)
      .pushByte(Math.ceil(this.states.length / 8))
      .pushBits(this.states)
      .toBuffer();
  }

  /**
   * Returns a string representation of this response.
   *
   * @returns {string}
   */
  toString()
  {
    return helpers.formatResponse(this, `${this.quantity} coils: ${this.states.map(Number).join(', ')}`);
  }

  /**
   * Determines whether a coil at the specified `offset` is on (i.e. has a truthy values).
   *
   * @param {number} offset
   * @returns {boolean}
   * @throws {Error} If the specified `offset` is out of bounds.
   */
  isOn(offset)
  {
    if (offset < 0 || offset >= this.states.length)
    {
      throw new RangeError(`Offset out of bounds: ${offset}`);
    }

    return !!this.states[offset];
  }

  /**
   * Determines whether a coil at the specified `offset` is off (i.e. has a falsy values).
   *
   * @param {number} offset
   * @returns {boolean}
   * @throws {Error} If the specified `offset` is out of bounds.
   */
  isOff(offset)
  {
    if (offset < 0 || offset >= this.states.length)
    {
      throw new RangeError(`Offset out of bounds: ${offset}`);
    }

    return !this.states[offset];
  }
}

module.exports = ReadCoilsResponse;
<commit_msg>ReadCoilsResponse: use the `toBitArray()` helper instead of the `h5.buffers.BufferReader` in the `fromBuffer()` constructor.<commit_after>// Part of <http://miracle.systems/p/h5.modbus> licensed under <MIT>

'use strict';

const buffers = require('h5.buffers');
const helpers = require('../helpers');
const FunctionCode = require('../FunctionCode');
const Response = require('../Response');

/**
 * The read coils response (code 0x01).
 *
 * A binary representation of this response varies in length and consists of:
 *
 *   - a function code (1 byte),
 *   - a byte count `n` (1 byte),
 *   - coil states (`n` bytes).
 */
class ReadCoilsResponse extends Response
{
  /**
   * @param {Array<boolean>} states States of the coils. An array of 1 to 2000 truthy or falsy elements.
   * @throws {Error} If the `states` array is empty or has more than 2000 elements.
   */
  constructor(states)
  {
    super(FunctionCode.ReadCoils);

    if (states.length === 0 || states.length > 2000)
    {
      throw new Error(`Invalid states array. Expected length between 1 and 2000, got [${states.length}].`);
    }

    /**
     * States of the coils. An array of 1 to 2000 truthy or falsy elements.
     *
     * @readonly
     * @type {Array<boolean>}
     */
    this.states = states;
  }

  /**
   * Creates a new response from the specified `options`.
   *
   * @param {Object} options
   * @param {Array<boolean>} options.states An array of coil states. Must have between 1 and 2000 elements.
   * @returns {ReadCoilsResponse}
   * @throws {Error} If any of the specified `options` are invalid.
   */
  static fromOptions(options)
  {
    return new ReadCoilsResponse(options.states);
  }

  /**
   * Creates a new response from its binary representation.
   *
   * @param {Buffer} buffer A binary representation of this response.
   * @returns {ReadCoilsResponse}
   * @throws {Error} If the specified `buffer` is not a valid binary representation of this response.
   */
  static fromBuffer(buffer)
  {
    helpers.assertFunctionCode(buffer[0], FunctionCode.ReadCoils);

    const states = helpers.toBitArray(buffer, 2, buffer[1] * 8);

    return new ReadCoilsResponse(states);
  }

  /**
   * A number of coils.
   *
   * @type {number}
   */
  get quantity()
  {
    return this.states.length;
  }

  /**
   * Returns a binary representation of this response.
   *
   * @returns {Buffer}
   */
  toBuffer()
  {
    return new buffers.BufferBuilder()
      .pushByte(this.functionCode)
      .pushByte(Math.ceil(this.states.length / 8))
      .pushBits(this.states)
      .toBuffer();
  }

  /**
   * Returns a string representation of this response.
   *
   * @returns {string}
   */
  toString()
  {
    return helpers.formatResponse(this, `${this.quantity} coils: ${this.states.map(Number).join(', ')}`);
  }

  /**
   * Determines whether a coil at the specified `offset` is on (i.e. has a truthy values).
   *
   * @param {number} offset
   * @returns {boolean}
   * @throws {Error} If the specified `offset` is out of bounds.
   */
  isOn(offset)
  {
    if (offset < 0 || offset >= this.states.length)
    {
      throw new RangeError(`Offset out of bounds: ${offset}`);
    }

    return !!this.states[offset];
  }

  /**
   * Determines whether a coil at the specified `offset` is off (i.e. has a falsy values).
   *
   * @param {number} offset
   * @returns {boolean}
   * @throws {Error} If the specified `offset` is out of bounds.
   */
  isOff(offset)
  {
    if (offset < 0 || offset >= this.states.length)
    {
      throw new RangeError(`Offset out of bounds: ${offset}`);
    }

    return !this.states[offset];
  }
}

module.exports = ReadCoilsResponse;
<|endoftext|>


<commit_before>

console.log("fuck me");

const model = tf.loadModel('model/model.json');
// var x = "/krestik.gif";
// var o = "/nolik.gif";
// var blank = "/blank.jpg";
// var pause = 0;
// var all = 0;
// var a = 0;
// var b = 0;
// var c = 0;
// var d = 0;
// var e = 0;
// var f = 0;
// var g = 0;
// var h = 0;
// var i = 0;
// var temp="";
// var ok = 0;
// var cf = 0;
// var choice=9;
// var aRandomNumber = 0;
// var comp = 0;
// var t = 0;
// var wn = 0;
// var ls = 0;
// var ts = 0;
// function logicOne() {
//   if ((a==1)&&(b==1)&&(c==1)) all=1;
//   if ((a==1)&&(d==1)&&(g==1)) all=1;
//   if ((a==1)&&(e==1)&&(i==1)) all=1;
//   if ((b==1)&&(e==1)&&(h==1)) all=1;
//   if ((d==1)&&(e==1)&&(f==1)) all=1;
//   if ((g==1)&&(h==1)&&(i==1)) all=1;
//   if ((c==1)&&(f==1)&&(i==1)) all=1;
//   if ((g==1)&&(e==1)&&(c==1)) all=1;
//   if ((a==2)&&(b==2)&&(c==2)) all=2;
//   if ((a==2)&&(d==2)&&(g==2)) all=2;
//   if ((a==2)&&(e==2)&&(i==2)) all=2;
//   if ((b==2)&&(e==2)&&(h==2)) all=2;
//   if ((d==2)&&(e==2)&&(f==2)) all=2;
//   if ((g==2)&&(h==2)&&(i==2)) all=2;
//   if ((c==2)&&(f==2)&&(i==2)) all=2;
//   if ((g==2)&&(e==2)&&(c==2)) all=2;
//   if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
// }
// function logicTwo() {
//   if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
//   if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
//   if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
//   if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
//   if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
//   if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
//   if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
//   if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
//   if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
//   if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
//   if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
//   if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
//   if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
//   if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
//   if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
//   if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
//   if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
// }
// function logicThree() {
//   if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
//   if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
//   if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
//   if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
//   if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
//   if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
//   if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
//   if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
//   if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
//   if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
//   if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
//   if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
//   if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
//   if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
//   if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
//   if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
// }
// function clearOut() {
//   document.game.you.value="0";
//   document.game.computer.value="0";
//   document.game.ties.value="0";
// }
// function checkSpace() {
//   if ((temp=="A")&&(a==0)) {
//     ok=1;
//     if (cf==0) a=1;
//     if (cf==1) a=2;
//   }
//   if ((temp=="B")&&(b==0)) {
//     ok=1;
//     if (cf==0) b=1;
//     if (cf==1) b=2;
//   }
//   if ((temp=="C")&&(c==0)) {
//     ok=1;
//     if (cf==0) c=1;
//     if (cf==1) c=2;
//   }
//   if ((temp=="D")&&(d==0)) {
//     ok=1;
//     if (cf==0) d=1;
//     if (cf==1) d=2;
//   }
//   if ((temp=="E")&&(e==0)) {
//     ok=1;
//     if (cf==0) e=1;
//     if (cf==1) e=2;
//   }
//   if ((temp=="F")&&(f==0)) {
//     ok=1
//     if (cf==0) f=1;
//     if (cf==1) f=2;
//   }
//   if ((temp=="G")&&(g==0)) {
//     ok=1
//     if (cf==0) g=1;
//     if (cf==1) g=2;
//   }
//   if ((temp=="H")&&(h==0)) {
//     ok=1;
//     if (cf==0) h=1;
//     if (cf==1) h=2;
//   }
//   if ((temp=="I")&&(i==0)) {
//     ok=1;
//     if (cf==0) i=1;
//     if (cf==1) i=2;
//   }
// }
// function yourChoice(chName) {
//   pause = 0;
//   if (all!=0) ended();
//   if (all==0) {
//     cf = 0;
//     ok = 0;
//     temp=chName;
//     checkSpace();
//     if (ok==1) {
//       document.images[chName].src = x;
//     }
//     if (ok==0)taken();
//     process();
//     if ((all==0)&&(pause==0)) myChoice();
//   }
// }
// function taken() {
//   alert("This cell in not empty! Try another")
//   pause=1;
// }
// function myChoice() {
//   temp="";
//   ok = 0;
//   cf=1;
//   logicTwo();
//   logicThree();
//   checkSpace();
//   while(ok==0) {
//     aRandomNumber=Math.random()
//     comp=Math.round((choice-1)*aRandomNumber)+1;
//     if (comp==1) temp="A";
//     if (comp==2) temp="B";
//     if (comp==3) temp="C";
//     if (comp==4) temp="D";
//     if (comp==5) temp="E";
//     if (comp==6) temp="F";
//     if (comp==7) temp="G";
//     if (comp==8) temp="H";
//     if (comp==9) temp="I";
//     checkSpace();
//   }
//   document.images[temp].src= o;
//   process();
// }
// function ended() {
//   alert("Game over! To play once more press a button 'New Game'")
// }
// function process() {
//   logicOne();
//   if (all==1){ alert("You win!"); wn++; }
//   if (all==2){ alert("You lose!"); ls++; }
//   if (all==3){ alert("Draw!"); ts++; }
//   if (all!=0) {
//     document.game.you.value = wn;
//     document.game.computer.value = ls;
//     document.game.ties.value = ts;
//   }
// }
// function playAgain() {
//   if (all==0) {
//     if(confirm("Âû óâåðåíû ?")) reset();
//   }
//   if (all>0) reset();
// }
// function reset() {
//   all = 0;
//   a = 0;
//   b = 0;
//   c = 0;
//   d = 0;
//   e = 0;
//   f = 0;
//   g = 0;
//   h = 0;
//   i = 0;
//   temp="";
//   ok = 0;
//   cf = 0;
//   choice=9;
//   aRandomNumber = 0;
//   comp = 0;
//   document.images.A.src= blank;
//   document.images.B.src= blank;
//   document.images.C.src= blank;
//   document.images.D.src= blank;
//   document.images.E.src= blank;
//   document.images.F.src= blank;
//   document.images.G.src= blank;
//   document.images.H.src= blank;
//   document.images.I.src= blank;
//   if (t==0) { t=2; myChoice(); }
//   t--;
// }
// var ie4 = (document.all) ? true : false;
// var nn4 = (document.layers) ? true : false;

// document.getElementById("A").onclick = function() {yourChoice('A')};
// document.getElementById("B").onclick = function() {yourChoice('B')};
// document.getElementById("C").onclick = function() {yourChoice('C')};
// document.getElementById("D").onclick = function() {yourChoice('D')};
// document.getElementById("E").onclick = function() {yourChoice('E')};
// document.getElementById("F").onclick = function() {yourChoice('F')};
// document.getElementById("G").onclick = function() {yourChoice('G')};
// document.getElementById("H").onclick = function() {yourChoice('H')};
// document.getElementById("I").onclick = function() {yourChoice('I')};
// document.getElementById("button").onclick = function() {playAgain()};

// async function setupMnistTransferCNN() {
//   const button = document.getElementById('load-pretrained-remote');
//   button.addEventListener('click', async () => {
//       yourChoice('A')
//   });
// }

// setupMnistTransferCNN();<commit_msg>working so far<commit_after>

console.log("getting better?");

const model = tf.loadModel('model/model.json');
// var x = "/krestik.gif";
// var o = "/nolik.gif";
// var blank = "/blank.jpg";
// var pause = 0;
// var all = 0;
// var a = 0;
// var b = 0;
// var c = 0;
// var d = 0;
// var e = 0;
// var f = 0;
// var g = 0;
// var h = 0;
// var i = 0;
// var temp="";
// var ok = 0;
// var cf = 0;
// var choice=9;
// var aRandomNumber = 0;
// var comp = 0;
// var t = 0;
// var wn = 0;
// var ls = 0;
// var ts = 0;
// function logicOne() {
//   if ((a==1)&&(b==1)&&(c==1)) all=1;
//   if ((a==1)&&(d==1)&&(g==1)) all=1;
//   if ((a==1)&&(e==1)&&(i==1)) all=1;
//   if ((b==1)&&(e==1)&&(h==1)) all=1;
//   if ((d==1)&&(e==1)&&(f==1)) all=1;
//   if ((g==1)&&(h==1)&&(i==1)) all=1;
//   if ((c==1)&&(f==1)&&(i==1)) all=1;
//   if ((g==1)&&(e==1)&&(c==1)) all=1;
//   if ((a==2)&&(b==2)&&(c==2)) all=2;
//   if ((a==2)&&(d==2)&&(g==2)) all=2;
//   if ((a==2)&&(e==2)&&(i==2)) all=2;
//   if ((b==2)&&(e==2)&&(h==2)) all=2;
//   if ((d==2)&&(e==2)&&(f==2)) all=2;
//   if ((g==2)&&(h==2)&&(i==2)) all=2;
//   if ((c==2)&&(f==2)&&(i==2)) all=2;
//   if ((g==2)&&(e==2)&&(c==2)) all=2;
//   if ((a != 0)&&(b != 0)&&(c != 0)&&(d != 0)&&(e != 0)&&(f != 0)&&(g != 0)&&(h != 0)&&(i != 0)&&(all == 0)) all = 3;
// }
// function logicTwo() {
//   if ((a==2)&&(b==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((a==2)&&(b== 0)&&(c==2)&&(temp=="")) temp="B";
//   if ((a== 0)&&(b==2)&&(c==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(d==2)&&(g== 0)&&(temp=="")) temp="G";
//   if ((a==2)&&(d== 0)&&(g==2)&&(temp=="")) temp="D";
//   if ((a== 0)&&(d==2)&&(g==2)&&(temp=="")) temp="A";
//   if ((a==2)&&(e==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((a==2)&&(e== 0)&&(i==2)&&(temp=="")) temp="E";
//   if ((a== 0)&&(e==2)&&(i==2)&&(temp=="")) temp="A";
//   if ((b==2)&&(e==2)&&(h== 0)&&(temp=="")) temp="H";
//   if ((b==2)&&(e== 0)&&(h==2)&&(temp=="")) temp="E";
//   if ((b== 0)&&(e==2)&&(h==2)&&(temp=="")) temp="B";
//   if ((d==2)&&(e==2)&&(f== 0)&&(temp=="")) temp="F";
//   if ((d==2)&&(e== 0)&&(f==2)&&(temp=="")) temp="E";
//   if ((d== 0)&&(e==2)&&(f==2)&&(temp=="")) temp="D";
//   if ((g==2)&&(h==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((g==2)&&(h== 0)&&(i==2)&&(temp=="")) temp="H";
//   if ((g== 0)&&(h==2)&&(i==2)&&(temp=="")) temp="G";
//   if ((c==2)&&(f==2)&&(i== 0)&&(temp=="")) temp="I";
//   if ((c==2)&&(f== 0)&&(i==2)&&(temp=="")) temp="F";
//   if ((c== 0)&&(f==2)&&(i==2)&&(temp=="")) temp="C";
//   if ((g==2)&&(e==2)&&(c== 0)&&(temp=="")) temp="C";
//   if ((g==2)&&(e== 0)&&(c==2)&&(temp=="")) temp="E";
//   if ((g== 0)&&(e==2)&&(c==2)&&(temp=="")) temp="G";
// }
// function logicThree() {
//   if ((a==1)&&(b==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((a==1)&&(b==0)&&(c==1)&&(temp=="")) temp="B";
//   if ((a==0)&&(b==1)&&(c==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(d==1)&&(g==0)&&(temp=="")) temp="G";
//   if ((a==1)&&(d==0)&&(g==1)&&(temp=="")) temp="D";
//   if ((a==0)&&(d==1)&&(g==1)&&(temp=="")) temp="A";
//   if ((a==1)&&(e==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((a==1)&&(e==0)&&(i==1)&&(temp=="")) temp="E";
//   if ((a==0)&&(e==1)&&(i==1)&&(temp=="")) temp="A";
//   if ((b==1)&&(e==1)&&(h==0)&&(temp=="")) temp="H";
//   if ((b==1)&&(e==0)&&(h==1)&&(temp=="")) temp="E";
//   if ((b==0)&&(e==1)&&(h==1)&&(temp=="")) temp="B";
//   if ((d==1)&&(e==1)&&(f==0)&&(temp=="")) temp="F";
//   if ((d==1)&&(e==0)&&(f==1)&&(temp=="")) temp="E";
//   if ((d==0)&&(e==1)&&(f==1)&&(temp=="")) temp="D";
//   if ((g==1)&&(h==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((g==1)&&(h==0)&&(i==1)&&(temp=="")) temp="H";
//   if ((g==0)&&(h==1)&&(i==1)&&(temp=="")) temp="G";
//   if ((c==1)&&(f==1)&&(i==0)&&(temp=="")) temp="I";
//   if ((c==1)&&(f==0)&&(i==1)&&(temp=="")) temp="F";
//   if ((c==0)&&(f==1)&&(i==1)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==1)&&(c==0)&&(temp=="")) temp="C";
//   if ((g==1)&&(e==0)&&(c==1)&&(temp=="")) temp="E";
//   if ((g==0)&&(e==1)&&(c==1)&&(temp=="")) temp="G";
// }
// function clearOut() {
//   document.game.you.value="0";
//   document.game.computer.value="0";
//   document.game.ties.value="0";
// }
// function checkSpace() {
//   if ((temp=="A")&&(a==0)) {
//     ok=1;
//     if (cf==0) a=1;
//     if (cf==1) a=2;
//   }
//   if ((temp=="B")&&(b==0)) {
//     ok=1;
//     if (cf==0) b=1;
//     if (cf==1) b=2;
//   }
//   if ((temp=="C")&&(c==0)) {
//     ok=1;
//     if (cf==0) c=1;
//     if (cf==1) c=2;
//   }
//   if ((temp=="D")&&(d==0)) {
//     ok=1;
//     if (cf==0) d=1;
//     if (cf==1) d=2;
//   }
//   if ((temp=="E")&&(e==0)) {
//     ok=1;
//     if (cf==0) e=1;
//     if (cf==1) e=2;
//   }
//   if ((temp=="F")&&(f==0)) {
//     ok=1
//     if (cf==0) f=1;
//     if (cf==1) f=2;
//   }
//   if ((temp=="G")&&(g==0)) {
//     ok=1
//     if (cf==0) g=1;
//     if (cf==1) g=2;
//   }
//   if ((temp=="H")&&(h==0)) {
//     ok=1;
//     if (cf==0) h=1;
//     if (cf==1) h=2;
//   }
//   if ((temp=="I")&&(i==0)) {
//     ok=1;
//     if (cf==0) i=1;
//     if (cf==1) i=2;
//   }
// }
// function yourChoice(chName) {
//   pause = 0;
//   if (all!=0) ended();
//   if (all==0) {
//     cf = 0;
//     ok = 0;
//     temp=chName;
//     checkSpace();
//     if (ok==1) {
//       document.images[chName].src = x;
//     }
//     if (ok==0)taken();
//     process();
//     if ((all==0)&&(pause==0)) myChoice();
//   }
// }
// function taken() {
//   alert("This cell in not empty! Try another")
//   pause=1;
// }
// function myChoice() {
//   temp="";
//   ok = 0;
//   cf=1;
//   logicTwo();
//   logicThree();
//   checkSpace();
//   while(ok==0) {
//     aRandomNumber=Math.random()
//     comp=Math.round((choice-1)*aRandomNumber)+1;
//     if (comp==1) temp="A";
//     if (comp==2) temp="B";
//     if (comp==3) temp="C";
//     if (comp==4) temp="D";
//     if (comp==5) temp="E";
//     if (comp==6) temp="F";
//     if (comp==7) temp="G";
//     if (comp==8) temp="H";
//     if (comp==9) temp="I";
//     checkSpace();
//   }
//   document.images[temp].src= o;
//   process();
// }
// function ended() {
//   alert("Game over! To play once more press a button 'New Game'")
// }
// function process() {
//   logicOne();
//   if (all==1){ alert("You win!"); wn++; }
//   if (all==2){ alert("You lose!"); ls++; }
//   if (all==3){ alert("Draw!"); ts++; }
//   if (all!=0) {
//     document.game.you.value = wn;
//     document.game.computer.value = ls;
//     document.game.ties.value = ts;
//   }
// }
// function playAgain() {
//   if (all==0) {
//     if(confirm("Âû óâåðåíû ?")) reset();
//   }
//   if (all>0) reset();
// }
// function reset() {
//   all = 0;
//   a = 0;
//   b = 0;
//   c = 0;
//   d = 0;
//   e = 0;
//   f = 0;
//   g = 0;
//   h = 0;
//   i = 0;
//   temp="";
//   ok = 0;
//   cf = 0;
//   choice=9;
//   aRandomNumber = 0;
//   comp = 0;
//   document.images.A.src= blank;
//   document.images.B.src= blank;
//   document.images.C.src= blank;
//   document.images.D.src= blank;
//   document.images.E.src= blank;
//   document.images.F.src= blank;
//   document.images.G.src= blank;
//   document.images.H.src= blank;
//   document.images.I.src= blank;
//   if (t==0) { t=2; myChoice(); }
//   t--;
// }
// var ie4 = (document.all) ? true : false;
// var nn4 = (document.layers) ? true : false;

// document.getElementById("A").onclick = function() {yourChoice('A')};
// document.getElementById("B").onclick = function() {yourChoice('B')};
// document.getElementById("C").onclick = function() {yourChoice('C')};
// document.getElementById("D").onclick = function() {yourChoice('D')};
// document.getElementById("E").onclick = function() {yourChoice('E')};
// document.getElementById("F").onclick = function() {yourChoice('F')};
// document.getElementById("G").onclick = function() {yourChoice('G')};
// document.getElementById("H").onclick = function() {yourChoice('H')};
// document.getElementById("I").onclick = function() {yourChoice('I')};
// document.getElementById("button").onclick = function() {playAgain()};

// async function setupMnistTransferCNN() {
//   const button = document.getElementById('load-pretrained-remote');
//   button.addEventListener('click', async () => {
//       yourChoice('A')
//   });
// }

// setupMnistTransferCNN();<|endoftext|>


<commit_before>/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */
import * as posedetection from '@tensorflow-models/posedetection';

import * as params from './params';
import {isMobile} from './util';

export class Camera {
  constructor() {
    this.video = document.getElementById('video');
    this.canvas = document.getElementById('output');
    this.ctx = this.canvas.getContext('2d');

    // The video frame rate may be lower than the browser animate frame
    // rate. We use this to avoid processing the same frame twice.
    this.lastVideoTime = 0;
  }

  /**
   * Initiate a Camera instance and wait for the camera stream to be ready.
   * @param cameraParam From app `STATE.camera`.
   */
  static async setupCamera(cameraParam) {
    const {targetFPS, sizeOption} = cameraParam;
    const $size = params.VIDEO_SIZE[sizeOption];
    const videoConfig = {
      'audio': false,
      'video': {
        facingMode: 'user',
        // Only setting the video to a specified size for large screen, on
        // mobile devices accept the default size.
        width: isMobile() ? undefined : $size.width,
        height: isMobile() ? undefined : $size.height,
        frameRate: {
          ideal: targetFPS,
        }
      }
    };

    const stream = await navigator.mediaDevices.getUserMedia(videoConfig);

    const camera = new Camera();
    camera.video.srcObject = stream;

    await new Promise((resolve) => {
      camera.video.onloadedmetadata = () => {
        resolve(video);
      };
    });

    camera.video.play();

    const videoWidth = camera.video.videoWidth;
    const videoHeight = camera.video.videoHeight;
    // Must set below two lines, otherwise video element doesn't show.
    camera.video.width = videoWidth;
    camera.video.height = videoHeight;

    camera.canvas.width = videoWidth;
    camera.canvas.height = videoHeight;
    const canvasContainer = document.querySelector('.canvas-wrapper');
    canvasContainer.style = `width: ${videoWidth}px; height: ${videoHeight}px`;

    // Because the image from camera is mirrored, need to flip horizontally.
    camera.ctx.translate(camera.video.videoWidth, 0);
    camera.ctx.scale(-1, 1);

    return camera;
  }

  drawCtx() {
    this.ctx.drawImage(
        this.video, 0, 0, this.video.videoWidth, this.video.videoHeight);
  }

  clearCtx() {
    this.ctx.clearRect(0, 0, this.video.videoWidth, this.video.videoHeight);
  }

  drawResult(pose, shouldScale = false) {
    if (pose.keypoints != null) {
      const scaleX = shouldScale ? this.video.videoWidth : 1;
      const scaleY = shouldScale ? this.video.videoHeight : 1;

      this.drawKeypoints(pose.keypoints, scaleY, scaleX);
      this.drawSkeleton(pose.keypoints, scaleY, scaleX);
    }
  }

  /**
   * Draw the keypoints on the video.
   * @param keypoints A list of keypoints, may be normalized.
   * @param shouldScale If the keypoints are normalized, shouldScale should be
   *     set to true.
   */
  drawKeypoints(keypoints, scaleY, scaleX) {
    const keypointInd =
        posedetection.util.getKeypointIndexBySide(params.STATE.model.model);
    this.ctx.fillStyle = 'White';
    this.ctx.strokeStyle = 'White';
    this.ctx.lineWidth = params.DEFAULT_LINE_WIDTH;

    keypointInd.middle.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));

    this.ctx.fillStyle = 'Green';
    keypointInd.left.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));

    this.ctx.fillStyle = 'Orange';
    keypointInd.right.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));
  }

  drawKeypoint(keypoint, scaleY, scaleX) {
    // If score is null, just show the keypoint.
    const score = keypoint.score != null ? keypoint.score : 1;
    const scoreThreshold =
        params.STATE.model[params.STATE.model.model].scoreThreshold || 0;

    if (score >= scoreThreshold) {
      const circle = new Path2D();
      circle.arc(
          keypoint.x * scaleX, keypoint.y * scaleY, params.DEFAULT_RADIUS, 0,
          2 * Math.PI);
      this.ctx.fill(circle);
      this.ctx.stroke(circle);
    }
  }

  drawSkeleton(keypoints, scaleY, scaleX) {
    this.ctx.fillStyle = 'White';
    this.ctx.strokeStyle = 'White';
    this.ctx.lineWidth = params.DEFAULT_LINE_WIDTH;

    posedetection.util.getAdjacentPairs(params.STATE.model.model)
        .forEach(([i, j]) => {
          const kp1 = keypoints[i];
          const kp2 = keypoints[j];

          // If score is null, just show the keypoint.
          const score1 = kp1.score != null ? kp1.score : 1;
          const score2 = kp2.score != null ? kp2.score : 1;
          const scoreThreshold =
              params.STATE.model[params.STATE.model.model].scoreThreshold || 0;

          if (score1 >= scoreThreshold && score2 >= scoreThreshold) {
            this.ctx.beginPath();
            this.ctx.moveTo(kp1.x * scaleX, kp1.y * scaleY);
            this.ctx.lineTo(kp2.x * scaleX, kp2.y * scaleY);
            this.ctx.stroke();
          }
        });
  }
}
<commit_msg>[pose-detection]Update demo doccomment. (#631)<commit_after>/**
 * @license
 * Copyright 2021 Google LLC. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * =============================================================================
 */
import * as posedetection from '@tensorflow-models/posedetection';

import * as params from './params';
import {isMobile} from './util';

export class Camera {
  constructor() {
    this.video = document.getElementById('video');
    this.canvas = document.getElementById('output');
    this.ctx = this.canvas.getContext('2d');

    // The video frame rate may be lower than the browser animate frame
    // rate. We use this to avoid processing the same frame twice.
    this.lastVideoTime = 0;
  }

  /**
   * Initiate a Camera instance and wait for the camera stream to be ready.
   * @param cameraParam From app `STATE.camera`.
   */
  static async setupCamera(cameraParam) {
    const {targetFPS, sizeOption} = cameraParam;
    const $size = params.VIDEO_SIZE[sizeOption];
    const videoConfig = {
      'audio': false,
      'video': {
        facingMode: 'user',
        // Only setting the video to a specified size for large screen, on
        // mobile devices accept the default size.
        width: isMobile() ? undefined : $size.width,
        height: isMobile() ? undefined : $size.height,
        frameRate: {
          ideal: targetFPS,
        }
      }
    };

    const stream = await navigator.mediaDevices.getUserMedia(videoConfig);

    const camera = new Camera();
    camera.video.srcObject = stream;

    await new Promise((resolve) => {
      camera.video.onloadedmetadata = () => {
        resolve(video);
      };
    });

    camera.video.play();

    const videoWidth = camera.video.videoWidth;
    const videoHeight = camera.video.videoHeight;
    // Must set below two lines, otherwise video element doesn't show.
    camera.video.width = videoWidth;
    camera.video.height = videoHeight;

    camera.canvas.width = videoWidth;
    camera.canvas.height = videoHeight;
    const canvasContainer = document.querySelector('.canvas-wrapper');
    canvasContainer.style = `width: ${videoWidth}px; height: ${videoHeight}px`;

    // Because the image from camera is mirrored, need to flip horizontally.
    camera.ctx.translate(camera.video.videoWidth, 0);
    camera.ctx.scale(-1, 1);

    return camera;
  }

  drawCtx() {
    this.ctx.drawImage(
        this.video, 0, 0, this.video.videoWidth, this.video.videoHeight);
  }

  clearCtx() {
    this.ctx.clearRect(0, 0, this.video.videoWidth, this.video.videoHeight);
  }

  /**
   * Draw the keypoints and skeleton on the video.
   * @param pose A pose with keypoints to render.
   * @param shouldScale If the keypoints are normalized, shouldScale should be
   *     set to true.
   */
  drawResult(pose, shouldScale = false) {
    if (pose.keypoints != null) {
      const scaleX = shouldScale ? this.video.videoWidth : 1;
      const scaleY = shouldScale ? this.video.videoHeight : 1;

      this.drawKeypoints(pose.keypoints, scaleY, scaleX);
      this.drawSkeleton(pose.keypoints, scaleY, scaleX);
    }
  }

  /**
   * Draw the keypoints on the video.
   * @param keypoints A list of keypoints, may be normalized.
   * @param scaleY If keypoints are normalized, y needs to be scaled back based
   *     on the scaleY.
   * @param scaleX If keypoints are normalized, x needs to be scaled back based
   *     on the scaleX..
   */
  drawKeypoints(keypoints, scaleY, scaleX) {
    const keypointInd =
        posedetection.util.getKeypointIndexBySide(params.STATE.model.model);
    this.ctx.fillStyle = 'White';
    this.ctx.strokeStyle = 'White';
    this.ctx.lineWidth = params.DEFAULT_LINE_WIDTH;

    keypointInd.middle.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));

    this.ctx.fillStyle = 'Green';
    keypointInd.left.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));

    this.ctx.fillStyle = 'Orange';
    keypointInd.right.forEach(
        i => this.drawKeypoint(keypoints[i], scaleY, scaleX));
  }

  drawKeypoint(keypoint, scaleY, scaleX) {
    // If score is null, just show the keypoint.
    const score = keypoint.score != null ? keypoint.score : 1;
    const scoreThreshold =
        params.STATE.model[params.STATE.model.model].scoreThreshold || 0;

    if (score >= scoreThreshold) {
      const circle = new Path2D();
      circle.arc(
          keypoint.x * scaleX, keypoint.y * scaleY, params.DEFAULT_RADIUS, 0,
          2 * Math.PI);
      this.ctx.fill(circle);
      this.ctx.stroke(circle);
    }
  }

  /**
   * Draw the skeleton of a body on the video.
   * @param keypoints A list of keypoints, may be normalized.
   * @param scaleY If keypoints are normalized, y needs to be scaled back based
   *     on the scaleY.
   * @param scaleX If keypoints are normalized, x needs to be scaled back based
   *     on the scaleX..
   */
  drawSkeleton(keypoints, scaleY, scaleX) {
    this.ctx.fillStyle = 'White';
    this.ctx.strokeStyle = 'White';
    this.ctx.lineWidth = params.DEFAULT_LINE_WIDTH;

    posedetection.util.getAdjacentPairs(params.STATE.model.model)
        .forEach(([i, j]) => {
          const kp1 = keypoints[i];
          const kp2 = keypoints[j];

          // If score is null, just show the keypoint.
          const score1 = kp1.score != null ? kp1.score : 1;
          const score2 = kp2.score != null ? kp2.score : 1;
          const scoreThreshold =
              params.STATE.model[params.STATE.model.model].scoreThreshold || 0;

          if (score1 >= scoreThreshold && score2 >= scoreThreshold) {
            this.ctx.beginPath();
            this.ctx.moveTo(kp1.x * scaleX, kp1.y * scaleY);
            this.ctx.lineTo(kp2.x * scaleX, kp2.y * scaleY);
            this.ctx.stroke();
          }
        });
  }
}
<|endoftext|>


<commit_before>var DockerFile = function() {

	// Require
	var Builder = require("node-dockerfile");
	var dockerFile = new Builder();

	// Function
	var _createDockerFile = function(nginx, mysql, dev_mode, callback) {
		// Initial
		myFile = dockerFile
			.comment("START")
			.from("ubuntu:16.04")
			.maintainer('Nitai Aventaggiato "https://twitter.com/thenitai"')
			.newLine()
			.comment("ADD MULTIVERSE")
			.run('echo "deb http://archive.ubuntu.com/ubuntu/ xenial multiverse" >> /etc/apt/sources.list')
			.run('echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial multiverse" >> /etc/apt/sources.list')
			.run('echo "deb http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse" >> /etc/apt/sources.list')
			.run('echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse" >> /etc/apt/sources.list')
			.newLine()
			.comment("UPDATE")
			.run("apt-get update")
			.newLine()
			.comment("SET ENV NONINTERACTIVE")
			.env("DEBIAN_FRONTEND", "noninteractive")
			.newLine()
			.comment("INSTALL")
			.run("apt-get install -y software-properties-common python-software-properties apt-utils vim")
			.newLine()
			.comment("GIT")
			.run("apt-get install -y git")
			.newLine()
			.comment("MEMCACHED")
			.run("apt-get -y install memcached");

		// MySQL
		if (mysql === 'yes') {
			myFile = dockerFile
				.newLine()
				.comment("MySQL")
				.run("apt-get -y install mysql-server")
				.newLine()
				.comment("MySQL Configuration")
				.run("echo mysql-server mysql-server/root_password password razuna | /usr/bin/debconf-set-selections")
				.run("echo mysql-server mysql-server/root_password_again password razuna | /usr/bin/debconf-set-selections");
		}

		// Nginx
		if (mysql === 'yes') {
			myFile = dockerFile
				.newLine()
				.comment("NGINX")
				.run([
					"add-apt-repository -y ppa:nginx/stable",
					"apt-get update",
					"apt-get install -y nginx",
					"rm -rf /var/lib/apt/lists/*",
					"chown -R www-data:www-data /var/lib/nginx"
				])
				.run('echo "\\ndaemon off;" >> /etc/nginx/nginx.conf')
				.expose(80)
				.expose(443);
		}

		myFile = dockerFile
			.newLine()
			.comment("IMAGEMAGICK")
			.run("apt-get update")
			.run("apt-get -y install imagemagick")
			.newLine()
			.comment("DCRAW / UFRAW")
			.run([
				"apt-get -y install dcraw",
				"apt-get -y install ufraw"
			])
			.newLine()
			.comment("MP4BOX")
			.run("apt-get -y install gpac")
			.newLine()
			.comment("SSH")
			.add("authorized_keys", "/root/.ssh/authorized_keys")
			.add("install-ssh", "/tmp/install-ssh")
			.run("/tmp/install-ssh")
			.env("NOTVISIBLE", "in users profile")
			.newLine()
			.comment("JAVA")
			.add("install-java", "/tmp/install-java")
			.run("/tmp/install-java")
			.newLine()
			.comment("FFMPEG")
			.add("install-ffmpeg", "/tmp/install-ffmpeg")
			.run("/tmp/install-ffmpeg")
			.newLine()
			.comment("EXIFTOOL")
			.add("install-exiftool", "/tmp/install-exiftool")
			.run("/tmp/install-exiftool")
			.newLine()
			.comment("GHOSTSCRIPT")
			.add("install-ghostscript", "/tmp/install-ghostscript")
			.run("/tmp/install-ghostscript")
			.newLine()
			.comment("TOMCAT")
			.add("install-tomcat", "/tmp/install-tomcat")
			.run("/tmp/install-tomcat");

		// Do not install Razuna in container if in dev_mode
		if (!dev_mode) {
			myFile = dockerFile
				.newLine()
				.comment("RAZUNA")
				.add("install-razuna", "/tmp/install-razuna")
				.run("/tmp/install-razuna");
		}

		myFile = dockerFile
			.newLine()
			.comment("COPY FILES AROUND")
			.copy("setenv.sh", "/opt/tomcat/bin/setenv.sh")
			.copy("permgen.sh", "/opt/tomcat/bin/permgen.sh")
			.copy("tomcat", "/etc/init.d/tomcat")
			.copy("razuna-server.xml", "/opt/tomcat/bin/razuna-server.xml")
			.copy("tomcat-users.xml", "/opt/tomcat/conf/tomcat-users.xml")
			.copy("start.sh", "/opt/start.sh")
			.newLine()
			.comment("SET TOMCAT TO START ON REBOOT")
			.run("update-rc.d tomcat defaults")
			.newLine()
			.comment("SET PERMISSIONS")
			.run([
				"chmod +x /opt/tomcat/bin/setenv.sh",
				"chmod +x /opt/tomcat/bin/permgen.sh",
				"chmod +x /etc/init.d/tomcat",
				"chmod +x /opt/start.sh"
			])
			.newLine()
			.comment("CLEAN UP TASKS")
			.run([
				"apt-get -y autoclean && apt-get -y autoremove",
				"rm -r /tmp/*",
				"rm /opt/*.gz",
				"rm /opt/*.tgz"
			])
			.newLine()
			.comment("START SERVICES")
			.expose(8080)
			.expose(22)
			.cmd("/opt/start.sh");

		// Callback for write
		// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above.
		var cb = function(err, content) {
			callback();
		};

		// Finally write the file
		myFile.write("./image", true, cb);
	};

	// exposed members
	return {
		createDockerFile : _createDockerFile
	};
}();
module.exports = DockerFile;
<commit_msg>Fix for nginx variable<commit_after>var DockerFile = function() {

	// Require
	var Builder = require("node-dockerfile");
	var dockerFile = new Builder();

	// Function
	var _createDockerFile = function(nginx, mysql, dev_mode, callback) {
		// Initial
		myFile = dockerFile
			.comment("START")
			.from("ubuntu:16.04")
			.maintainer('Nitai Aventaggiato "https://twitter.com/thenitai"')
			.newLine()
			.comment("ADD MULTIVERSE")
			.run('echo "deb http://archive.ubuntu.com/ubuntu/ xenial multiverse" >> /etc/apt/sources.list')
			.run('echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial multiverse" >> /etc/apt/sources.list')
			.run('echo "deb http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse" >> /etc/apt/sources.list')
			.run('echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse" >> /etc/apt/sources.list')
			.newLine()
			.comment("UPDATE")
			.run("apt-get update")
			.newLine()
			.comment("SET ENV NONINTERACTIVE")
			.env("DEBIAN_FRONTEND", "noninteractive")
			.newLine()
			.comment("INSTALL")
			.run("apt-get install -y software-properties-common python-software-properties apt-utils vim")
			.newLine()
			.comment("GIT")
			.run("apt-get install -y git")
			.newLine()
			.comment("MEMCACHED")
			.run("apt-get -y install memcached");

		// MySQL
		if (mysql === 'yes') {
			myFile = dockerFile
				.newLine()
				.comment("MySQL")
				.run("apt-get -y install mysql-server")
				.newLine()
				.comment("MySQL Configuration")
				.run("echo mysql-server mysql-server/root_password password razuna | /usr/bin/debconf-set-selections")
				.run("echo mysql-server mysql-server/root_password_again password razuna | /usr/bin/debconf-set-selections");
		}

		// Nginx
		if (nginx === 'yes') {
			myFile = dockerFile
				.newLine()
				.comment("NGINX")
				.run([
					"add-apt-repository -y ppa:nginx/stable",
					"apt-get update",
					"apt-get install -y nginx",
					"rm -rf /var/lib/apt/lists/*",
					"chown -R www-data:www-data /var/lib/nginx"
				])
				.run('echo "\\ndaemon off;" >> /etc/nginx/nginx.conf')
				.expose(80)
				.expose(443);
		}

		myFile = dockerFile
			.newLine()
			.comment("IMAGEMAGICK")
			.run("apt-get update")
			.run("apt-get -y install imagemagick")
			.newLine()
			.comment("DCRAW / UFRAW")
			.run([
				"apt-get -y install dcraw",
				"apt-get -y install ufraw"
			])
			.newLine()
			.comment("MP4BOX")
			.run("apt-get -y install gpac")
			.newLine()
			.comment("SSH")
			.add("authorized_keys", "/root/.ssh/authorized_keys")
			.add("install-ssh", "/tmp/install-ssh")
			.run("/tmp/install-ssh")
			.env("NOTVISIBLE", "in users profile")
			.newLine()
			.comment("JAVA")
			.add("install-java", "/tmp/install-java")
			.run("/tmp/install-java")
			.newLine()
			.comment("FFMPEG")
			.add("install-ffmpeg", "/tmp/install-ffmpeg")
			.run("/tmp/install-ffmpeg")
			.newLine()
			.comment("EXIFTOOL")
			.add("install-exiftool", "/tmp/install-exiftool")
			.run("/tmp/install-exiftool")
			.newLine()
			.comment("GHOSTSCRIPT")
			.add("install-ghostscript", "/tmp/install-ghostscript")
			.run("/tmp/install-ghostscript")
			.newLine()
			.comment("TOMCAT")
			.add("install-tomcat", "/tmp/install-tomcat")
			.run("/tmp/install-tomcat");

		// Do not install Razuna in container if in dev_mode
		if (!dev_mode) {
			myFile = dockerFile
				.newLine()
				.comment("RAZUNA")
				.add("install-razuna", "/tmp/install-razuna")
				.run("/tmp/install-razuna");
		}

		myFile = dockerFile
			.newLine()
			.comment("COPY FILES AROUND")
			.copy("setenv.sh", "/opt/tomcat/bin/setenv.sh")
			.copy("permgen.sh", "/opt/tomcat/bin/permgen.sh")
			.copy("tomcat", "/etc/init.d/tomcat")
			.copy("razuna-server.xml", "/opt/tomcat/bin/razuna-server.xml")
			.copy("tomcat-users.xml", "/opt/tomcat/conf/tomcat-users.xml")
			.copy("start.sh", "/opt/start.sh")
			.newLine()
			.comment("SET TOMCAT TO START ON REBOOT")
			.run("update-rc.d tomcat defaults")
			.newLine()
			.comment("SET PERMISSIONS")
			.run([
				"chmod +x /opt/tomcat/bin/setenv.sh",
				"chmod +x /opt/tomcat/bin/permgen.sh",
				"chmod +x /etc/init.d/tomcat",
				"chmod +x /opt/start.sh"
			])
			.newLine()
			.comment("CLEAN UP TASKS")
			.run([
				"apt-get -y autoclean && apt-get -y autoremove",
				"rm -r /tmp/*",
				"rm /opt/*.gz",
				"rm /opt/*.tgz"
			])
			.newLine()
			.comment("START SERVICES")
			.expose(8080)
			.expose(22)
			.cmd("/opt/start.sh");

		// Callback for write
		// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above.
		var cb = function(err, content) {
			callback();
		};

		// Finally write the file
		myFile.write("./image", true, cb);
	};

	// exposed members
	return {
		createDockerFile : _createDockerFile
	};
}();
module.exports = DockerFile;
<|endoftext|>


<commit_before>'use strict';
/*
 * Init the app dependency with requirejs
 */
/* global requirejs */

requirejs.config({
    baseUrl: 'assets',
    paths: {
        app: 'js',
        lib: 'lib',
        cordova: '../cordova',
        jquery: 'lib/jquery/jquery.min',
        pouchdb: 'lib/pouchdb/pouchdb.min',
        "pouchdb-authentication": 'lib/pouchdb-authentication/pouchdb.authentication.min',
        vue: 'lib/vue/vue.min',
        "vue-router": 'lib/vue-router/vue-router.min',
        promise: 'lib/requirejs-promise/requirejs-promise'
                /*
                 browser: 'platform/browser',
                 android: 'platform/android',
                 ios: 'platform/ios'
                 */
    },
    shim: {
        cordova: {
            exports: 'cordova'
        },
        jquery: {
            exports: '$'
        },
        pouchdb: {
            exports: 'PouchDB'
        }
    }
});
//TODO use more modular form with dependencie
requirejs(['cordova', 'jquery', 'vue', 'vue-router', 'pouchdb', 'app/sofia.polyfill'], function (cordova, $, Vue, VueRouter, PouchDB) {
    Vue.use(VueRouter);
    window.PouchDB = PouchDB; //Force PouchDB to DOM
    console.log(PouchDB);
    window.Vue = Vue; //Force Vue to DOM
    window.VueRouter = VueRouter; //Force VueRouter to DOM
    requirejs(['pouchdb-authentication', 'app/sofia.tool', 'app/sofia.template', 'app/sofia.config'], function () {
        $("head").append('<link rel="stylesheet" type="text/css" href="assets/platform/' + cordova.platformId + '/css/style.css">');
        requirejs(['platform/' + cordova.platformId + '/init', 'app/sofia.db'], function () {
            requirejs(['app/sofia.vue', 'app/sofia.data', 'app/sofia.user', 'app/sofia.app'], function () {
                S.app.initialize();
            });
        });
    });
});
<commit_msg>Permit local running.<commit_after>'use strict';
/*
 * Init the app dependency with requirejs
 */
/* global requirejs */
var S = S || {};

requirejs.config({
    baseUrl: 'assets',
    paths: {
        app: 'js',
        lib: 'lib',
        cordova: '../cordova',
        jquery: 'lib/jquery/jquery.min',
        pouchdb: 'lib/pouchdb/pouchdb.min',
        "pouchdb-authentication": 'lib/pouchdb-authentication/pouchdb.authentication.min',
        vue: 'lib/vue/vue.min',
        "vue-router": 'lib/vue-router/vue-router.min',
        promise: 'lib/requirejs-promise/requirejs-promise'
                /*
                 browser: 'platform/browser',
                 android: 'platform/android',
                 ios: 'platform/ios'
                 */
    },
    shim: {
        cordova: {
            exports: 'cordova'
        },
        jquery: {
            exports: '$'
        },
        pouchdb: {
            exports: 'PouchDB'
        }
    }
});

//var base = ;
//base.unshift();
S.init = function(cordova){
  requirejs(['jquery', 'vue', 'vue-router', 'pouchdb', 'app/sofia.polyfill'], function ($, Vue, VueRouter, PouchDB) {
      Vue.use(VueRouter);
      window.PouchDB = PouchDB; //Force PouchDB to DOM
      console.log(PouchDB);
      window.Vue = Vue; //Force Vue to DOM
      window.VueRouter = VueRouter; //Force VueRouter to DOM
      requirejs(['pouchdb-authentication', 'app/sofia.tool', 'app/sofia.template', 'app/sofia.config'], function () {
          $("head").append('<link rel="stylesheet" type="text/css" href="assets/platform/' + cordova.platformId + '/css/style.css">');
          requirejs(['platform/' + cordova.platformId + '/init', 'app/sofia.db'], function () {
              requirejs(['app/sofia.vue', 'app/sofia.data', 'app/sofia.user', 'app/sofia.app'], function () {
                  S.app.initialize();
              });
          });
      });
  });
};

requirejs(['cordova'], S.init , function (err) {
  //Handle error for example if cordova isn't here
  console.log(err.requireModules, err.requireType);
  if(err && err.requireModules.length === 1 && err.requireModules[0] === "cordova" && err.requireType === "scripterror"){ //Cordova fail to load
    //Ignoring and mocking
    window.cordova = {
      is_mock: true,
      platformId : "browser"
    }
    S.init(window.cordova);
  } else {
    throw err;
  }
});
<|endoftext|>