Made cell stats more efficient
This commit is contained in:
1
dist/index.html
vendored
1
dist/index.html
vendored
@@ -233,6 +233,7 @@
|
|||||||
<option value="mut-rate">Organism Size</option>
|
<option value="mut-rate">Organism Size</option>
|
||||||
<option value="mut-rate">Mutation Rate</option>
|
<option value="mut-rate">Mutation Rate</option>
|
||||||
</select>
|
</select>
|
||||||
|
<p id='chart-note'></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class='right-half'>
|
<div class='right-half'>
|
||||||
|
|||||||
2
dist/js/bundle.js
vendored
2
dist/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -4,7 +4,8 @@ const ChartController = require("./ChartController");
|
|||||||
|
|
||||||
class CellsChart extends ChartController {
|
class CellsChart extends ChartController {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("Organism Size / Composition");
|
super("Organism Size / Composition",
|
||||||
|
"Note: to maintain efficiency, species with very small populations are discarded when collecting cell statistics.");
|
||||||
}
|
}
|
||||||
|
|
||||||
setData() {
|
setData() {
|
||||||
@@ -33,6 +34,8 @@ class CellsChart extends ChartController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.addAllDataPoints();
|
this.addAllDataPoints();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addDataPoint(i) {
|
addDataPoint(i) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const FossilRecord = require("../FossilRecord");
|
const FossilRecord = require("../FossilRecord");
|
||||||
|
|
||||||
class ChartController {
|
class ChartController {
|
||||||
constructor(title) {
|
constructor(title, note="") {
|
||||||
this.data = [];
|
this.data = [];
|
||||||
this.chart = new CanvasJS.Chart("chartContainer", {
|
this.chart = new CanvasJS.Chart("chartContainer", {
|
||||||
zoomEnabled: true,
|
zoomEnabled: true,
|
||||||
@@ -11,7 +11,7 @@ class ChartController {
|
|||||||
data: this.data
|
data: this.data
|
||||||
});
|
});
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
this.data
|
$('#chart-note').text(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
setData() {
|
setData() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const FossilRecord = {
|
|||||||
|
|
||||||
// if an organism has fewer than this cumulative pop, discard them on extinction
|
// if an organism has fewer than this cumulative pop, discard them on extinction
|
||||||
this.min_discard = 10;
|
this.min_discard = 10;
|
||||||
|
this.total_relavent_organisms = 0; // organisms with greater than ^ cumulative pop
|
||||||
|
|
||||||
this.record_size_limit = 500; // store this many data points
|
this.record_size_limit = 500; // store this many data points
|
||||||
},
|
},
|
||||||
@@ -79,12 +80,12 @@ const FossilRecord = {
|
|||||||
this.pop_counts.push(this.env.organisms.length);
|
this.pop_counts.push(this.env.organisms.length);
|
||||||
this.species_counts.push(this.extant_species.length);
|
this.species_counts.push(this.extant_species.length);
|
||||||
this.av_mut_rates.push(this.env.averageMutability());
|
this.av_mut_rates.push(this.env.averageMutability());
|
||||||
|
this.av_cell_counts.push(this.calcCellCountAverages());
|
||||||
let av_cell = 0;
|
let av_cell = 0;
|
||||||
if (this.env.organisms.length > 0) {
|
if (this.total_relavent_organisms > 0) {
|
||||||
av_cell = this.env.total_cells / this.env.organisms.length;
|
av_cell = this.env.total_cells / this.total_relavent_organisms;
|
||||||
}
|
}
|
||||||
this.av_cells.push(av_cell);
|
this.av_cells.push(av_cell);
|
||||||
this.av_cell_counts.push(this.calcCellCountAverages())
|
|
||||||
|
|
||||||
if (this.tick_record.length > this.record_size_limit) {
|
if (this.tick_record.length > this.record_size_limit) {
|
||||||
this.tick_record.shift();
|
this.tick_record.shift();
|
||||||
@@ -92,25 +93,33 @@ const FossilRecord = {
|
|||||||
this.species_counts.shift();
|
this.species_counts.shift();
|
||||||
this.av_mut_rates.shift();
|
this.av_mut_rates.shift();
|
||||||
this.av_cells.shift();
|
this.av_cells.shift();
|
||||||
|
this.av_cell_counts.shift();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
calcCellCountAverages() {
|
calcCellCountAverages() {
|
||||||
var total_org = this.env.organisms.length;
|
var total_org = 0;
|
||||||
var cell_counts = {};
|
var cell_counts = {};
|
||||||
for (let c of CellStates.living) {
|
for (let c of CellStates.living) {
|
||||||
cell_counts[c.name] = 0;
|
cell_counts[c.name] = 0;
|
||||||
}
|
}
|
||||||
|
var first=true;
|
||||||
for (let s of this.extant_species) {
|
for (let s of this.extant_species) {
|
||||||
|
if (s.cumulative_pop < this.min_discard && !first){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for (let name in s.cell_counts) {
|
for (let name in s.cell_counts) {
|
||||||
cell_counts[name] += s.cell_counts[name] * s.population;
|
cell_counts[name] += s.cell_counts[name] * s.population;
|
||||||
}
|
}
|
||||||
|
total_org += s.population;
|
||||||
|
first=false;
|
||||||
}
|
}
|
||||||
if (total_org == 0)
|
if (total_org == 0)
|
||||||
return cell_counts;
|
return cell_counts;
|
||||||
for (let c in cell_counts) {
|
for (let c in cell_counts) {
|
||||||
cell_counts[c] /= total_org;
|
cell_counts[c] /= total_org;
|
||||||
}
|
}
|
||||||
|
this.total_relavent_organisms = total_org;
|
||||||
return cell_counts;
|
return cell_counts;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user