Skip to content

Commit

Permalink
balance
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnkunstman committed Jun 7, 2020
1 parent ba191d1 commit efc23d8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
34 changes: 22 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var World = /** @class */ (function () {
function World(width, height, denisty, framerate, personSize) {
this.graphData = [];
this.first = 0;
this.width = width;
this.height = height;
this.denisty = denisty;
Expand Down Expand Up @@ -99,12 +100,19 @@ var World = /** @class */ (function () {
var person = new Person(randomIntFromInterval(0, this.width), randomIntFromInterval(0, this.height), this.width, this.height, this.infection, this.mobility, "uninfected", this.personSize);
this.persons.push(person);
}
this.persons[0].state = "infected";
this.animationStep();
};
World.prototype.animationStep = function () {
var _this = this;
var runAnimation = false;
this.first++;
if (this.first == 2) {
this.persons[0].state = "infected";
}
//
if (this.first < 3) {
runAnimation = true;
}
//
var uninfected = 0;
var infected = 0;
Expand Down Expand Up @@ -153,11 +161,12 @@ var World = /** @class */ (function () {
deceasedArray.push(this.graphData[a].deceased);
recoveredArray.push(this.graphData[a].recovered);
}
labels = convertArrayLenght(labels, 20);
uninfectedArray = convertArrayLenght(uninfectedArray, 20);
infectedArray = convertArrayLenght(infectedArray, 20);
deceasedArray = convertArrayLenght(deceasedArray, 20);
recoveredArray = convertArrayLenght(recoveredArray, 20);
var xaxisstep = 15;
labels = convertArrayLenght(labels, xaxisstep);
uninfectedArray = convertArrayLenght(uninfectedArray, xaxisstep);
infectedArray = convertArrayLenght(infectedArray, xaxisstep);
deceasedArray = convertArrayLenght(deceasedArray, xaxisstep);
recoveredArray = convertArrayLenght(recoveredArray, xaxisstep);
this.chart.data.labels = labels;
this.chart.data.datasets[0].data = uninfectedArray;
this.chart.data.datasets[1].data = infectedArray;
Expand Down Expand Up @@ -288,20 +297,21 @@ function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function convertArrayLenght(inputArray, length) {
return inputArray;
//return inputArray
var myNewArray = [];
for (var a = 0; a < length; a++) {
myNewArray.push(inputArray[Math.round(a / length * inputArray.length)]);
myNewArray.push(inputArray[Math.floor(a / length * inputArray.length)]);
}
myNewArray.push(inputArray[Math.ceil(inputArray.length - 1)]);
return myNewArray;
}
//
// let's do it...
//
var framerate = 15;
var personSize = 20;
var world = new World(700, 700, 0.0001, framerate, personSize); // width, height, density, framerate, personSize
var infection = new Infection(200, 0.15, 50); // duration, mortality, reach
var framerate = 30;
var personSize = 3;
var world = new World(700, 700, 0.002, framerate, personSize); // width, height, density, framerate, personSize
var infection = new Infection(200, 0.15, 10); // duration, mortality, reach
var mobility = new Mobility(1, 50); // speed, distance
world.infection = infection;
world.mobility = mobility;
Expand Down
49 changes: 30 additions & 19 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class World {
private personCount: number
private persons: any
private graphData: any = []
private first: number = 0
public chart: Chart

constructor(width: number, height: number, denisty: number, framerate: number, personSize: number) {
Expand Down Expand Up @@ -39,15 +40,15 @@ class World {
data: {
datasets: [{
barPercentage: 1,
lineTension: 0,
lineTension: 0,
pointRadius: 0,
label: 'uninfected',
data: [],
backgroundColor: '#0000ff'
},
{
barPercentage: 1,
lineTension: 0,
lineTension: 0,
pointRadius: 0,
label: 'infected',
data: [],
Expand All @@ -56,15 +57,15 @@ class World {

{
barPercentage: 1,
lineTension: 0,
lineTension: 0,
pointRadius: 0,
label: 'deceased',
data: [],
backgroundColor: '#ff0000'
},
{
barPercentage: 1,
lineTension: 0,
lineTension: 0,
pointRadius: 0,
label: 'recovered',
data: [],
Expand All @@ -80,9 +81,9 @@ class World {
},
elements: {
line: {
cubicInterpolationMode: 'monotone'
cubicInterpolationMode: 'monotone'
}
},
},
responsiveAnimationDuration: 0,
responsive: false,
scales: {
Expand Down Expand Up @@ -111,11 +112,20 @@ class World {
let person = new Person(randomIntFromInterval(0, this.width), randomIntFromInterval(0, this.height), this.width, this.height, this.infection, this.mobility, "uninfected", this.personSize)
this.persons.push(person)
}
this.persons[0].state = "infected"
this.animationStep()
}
animationStep() {
let runAnimation = false
this.first++;
if (this.first==2)
{
this.persons[0].state = "infected"
}
//
if (this.first<3)
{
runAnimation = true
}
//
let uninfected = 0
let infected = 0
Expand Down Expand Up @@ -165,12 +175,12 @@ class World {
deceasedArray.push(this.graphData[a].deceased)
recoveredArray.push(this.graphData[a].recovered)
}

labels = convertArrayLenght(labels, 20)
uninfectedArray = convertArrayLenght(uninfectedArray, 20)
infectedArray = convertArrayLenght(infectedArray, 20)
deceasedArray = convertArrayLenght(deceasedArray, 20)
recoveredArray = convertArrayLenght(recoveredArray, 20)
let xaxisstep = 15;
labels = convertArrayLenght(labels, xaxisstep)
uninfectedArray = convertArrayLenght(uninfectedArray, xaxisstep)
infectedArray = convertArrayLenght(infectedArray, xaxisstep)
deceasedArray = convertArrayLenght(deceasedArray, xaxisstep)
recoveredArray = convertArrayLenght(recoveredArray, xaxisstep)

this.chart.data.labels = labels
this.chart.data.datasets[0].data = uninfectedArray
Expand Down Expand Up @@ -319,20 +329,21 @@ function randomIntFromInterval(min: number, max: number) { // min and max includ

function convertArrayLenght(inputArray: any, length: number): any {

return inputArray
//return inputArray
let myNewArray: any = []
for (let a = 0; a < length; a++) {
myNewArray.push(inputArray[Math.round(a / length * inputArray.length)])
myNewArray.push(inputArray[Math.floor(a / length * inputArray.length)])
}
myNewArray.push(inputArray[Math.ceil(inputArray.length - 1)])
return myNewArray
}
//
// let's do it...
//
let framerate: number = 15
let personSize: number = 20;
let world = new World(700, 700, 0.0001, framerate, personSize) // width, height, density, framerate, personSize
let infection = new Infection(200, 0.15, 50) // duration, mortality, reach
let framerate: number = 30
let personSize: number = 3;
let world = new World(700, 700, 0.002, framerate, personSize) // width, height, density, framerate, personSize
let infection = new Infection(200, 0.15, 10) // duration, mortality, reach
let mobility = new Mobility(1, 50) // speed, distance
world.infection = infection
world.mobility = mobility
Expand Down

0 comments on commit efc23d8

Please sign in to comment.