add new ip array

This commit is contained in:
rloukil 2019-01-01 16:25:00 +01:00
parent 692291bb04
commit eaf8822510
2 changed files with 37 additions and 28 deletions

62
app.js
View file

@ -3,7 +3,7 @@ const regex = RegExp(/^((([09A-Fa-f]{1,4}:){7}[09A-Fa-f]{1,4})|(([09A-F
var addresses = [] var addresses = []
var date = [] var date = []
var ipv4_v6 = [] var ipv4_v6 = [[], [] , []]
//colors object for different graphs //colors object for different graphs
var chartColors = { var chartColors = {
@ -19,12 +19,15 @@ var chartColors = {
//test function for ip addresses //test function for ip addresses
function Ip4OrIp6(ipAddress){ function Ip4OrIp6(ipAddress){
if(ipAddress.length == 39){ if(ipAddress.length == 39){
ipv4_v6.push(1); return 1;
}else{ }else{
ipv4_v6.push(-1); return -1;
} }
} }
var randomScalingFactor = function() {
return (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
}
// Refactor getStudents and getScores to return Promise for their response bodies // Refactor getStudents and getScores to return Promise for their response bodies
function getData(){ function getData(){
@ -37,10 +40,24 @@ function getData(){
}; };
getData().then((data)=>{ getData().then((data)=>{
data.forEach(element => { //pushing the dates
date.push(element.date); data[0].forEach(element => {
date.push(element.date)
// Ip4OrIp6(element.ip); // Ip4OrIp6(element.ip);
// }); });
data.forEach((element ,i) =>{
element.map((e) =>{
ipv4_v6[i].push(Ip4OrIp6(e.ip));
})
})
// data[1].forEach(element =>{
// ipv4_v6[1].push(Ip4OrIp6(element.ip))
// })
// data[2].forEach(element =>{
// ipv4_v6[2].push(Ip4OrIp6(element.ip))
// })
// console.log(date); // console.log(date);
// console.log(ipv4_v6); // console.log(ipv4_v6);
@ -55,36 +72,27 @@ getData().then((data)=>{
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
type: 'line', type: 'line',
data: { data: {
labels:date , labels:date,
datasets: [ datasets: [
{ {
label: "My First dataset", label: "My First dataset",
backgroundColor: chartColors.red, // backgroundColor: chartColors.red,
borderColor: chartColors.red, borderColor: chartColors.red,
data: [ data:ipv4_v6[0],
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor(),
randomScalingFactor()
],
fill: false, fill: false,
}, { }, {
label: "My Second dataset", label: "My Second dataset",
fill: false, fill: false,
backgroundColor: chartColors.blue, // backgroundColor: chartColors.blue,
borderColor: chartColors.blue, borderColor: chartColors.blue,
data: [ data:ipv4_v6[1],
randomScalingFactor(), },
randomScalingFactor(), {
randomScalingFactor(), label: "My Second dataset",
randomScalingFactor(), fill: false,
randomScalingFactor(), // backgroundColor: chartColors.orange,
randomScalingFactor(), borderColor: chartColors.orange,
randomScalingFactor() data: ipv4_v6[2],
],
} }
] ]
}, },

View file

@ -1,3 +1,4 @@
#myChart { #myChart {
height: 85vh!important; margin:10% 0;
height: 60vh!important;
} }