cleaned chart code/added cells chart
This commit is contained in:
7
dist/index.html
vendored
7
dist/index.html
vendored
@@ -222,14 +222,15 @@
|
|||||||
<div id='stats' class='tab'>
|
<div id='stats' class='tab'>
|
||||||
<div class='left-half'>
|
<div class='left-half'>
|
||||||
<h2>Stats</h2>
|
<h2>Stats</h2>
|
||||||
<p id='org-count'>Organism count: </p>
|
<p id='org-count'>Total Population: </p>
|
||||||
<p id='org-record'>Highest count: </p>
|
<p id='species-count'>Number of Species: </p>
|
||||||
|
<p id='largest-org'>Largest Organism Ever: </p>
|
||||||
<p id='avg-mut'>Average Mutation Rate: </p>
|
<p id='avg-mut'>Average Mutation Rate: </p>
|
||||||
<p id='largest-org'>Largest Organism: </p>
|
|
||||||
<label for="chart-option">Chart: </label>
|
<label for="chart-option">Chart: </label>
|
||||||
<select name="chart-option" id="chart-option">
|
<select name="chart-option" id="chart-option">
|
||||||
<option value="population">Population</option>
|
<option value="population">Population</option>
|
||||||
<option value="species">Species</option>
|
<option value="species">Species</option>
|
||||||
|
<option value="mut-rate">Organism Size</option>
|
||||||
<option value="mut-rate">Mutation Rate</option>
|
<option value="mut-rate">Mutation Rate</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
2
dist/js/bundle.js
vendored
2
dist/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
@@ -176,6 +176,9 @@ class ControlPanel {
|
|||||||
$('#remove-prob').val(Hyperparams.removeProb);
|
$('#remove-prob').val(Hyperparams.removeProb);
|
||||||
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
|
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
|
||||||
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
|
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
|
||||||
|
$('#food-drop-rate').val(Hyperparams.foodDropProb);
|
||||||
|
$('#look-range').val(Hyperparams.lookRange);
|
||||||
|
|
||||||
if (!Hyperparams.useGlobalMutability) {
|
if (!Hyperparams.useGlobalMutability) {
|
||||||
$('.global-mutation-in').css('display', 'none');
|
$('.global-mutation-in').css('display', 'none');
|
||||||
$('#avg-mut').css('display', 'block');
|
$('#avg-mut').css('display', 'block');
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class WorldEnvironment extends Environment{
|
|||||||
this.largest_cell_count = 0;
|
this.largest_cell_count = 0;
|
||||||
this.reset_count = 0;
|
this.reset_count = 0;
|
||||||
this.total_ticks = 0;
|
this.total_ticks = 0;
|
||||||
|
this.total_cells = 0;
|
||||||
this.data_update_rate = 100;
|
this.data_update_rate = 100;
|
||||||
FossilRecord.setEnv(this);
|
FossilRecord.setEnv(this);
|
||||||
}
|
}
|
||||||
@@ -52,6 +53,7 @@ class WorldEnvironment extends Environment{
|
|||||||
removeOrganisms(org_indeces) {
|
removeOrganisms(org_indeces) {
|
||||||
for (var i of org_indeces.reverse()){
|
for (var i of org_indeces.reverse()){
|
||||||
this.total_mutability -= this.organisms[i].mutability;
|
this.total_mutability -= this.organisms[i].mutability;
|
||||||
|
this.total_cells -= this.organisms[i].anatomy.cells.length;
|
||||||
this.organisms.splice(i, 1);
|
this.organisms.splice(i, 1);
|
||||||
}
|
}
|
||||||
if (this.organisms.length == 0 && this.auto_reset){
|
if (this.organisms.length == 0 && this.auto_reset){
|
||||||
@@ -76,6 +78,7 @@ class WorldEnvironment extends Environment{
|
|||||||
this.organisms.push(organism);
|
this.organisms.push(organism);
|
||||||
if (organism.anatomy.cells.length > this.largest_cell_count)
|
if (organism.anatomy.cells.length > this.largest_cell_count)
|
||||||
this.largest_cell_count = organism.anatomy.cells.length;
|
this.largest_cell_count = organism.anatomy.cells.length;
|
||||||
|
this.total_cells += organism.anatomy.cells.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
averageMutability() {
|
averageMutability() {
|
||||||
@@ -122,12 +125,13 @@ class WorldEnvironment extends Environment{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(clear_walls=true) {
|
reset() {
|
||||||
this.organisms = [];
|
this.organisms = [];
|
||||||
this.grid_map.fillGrid(CellStates.empty);
|
this.grid_map.fillGrid(CellStates.empty);
|
||||||
this.renderer.renderFullGrid(this.grid_map.grid);
|
this.renderer.renderFullGrid(this.grid_map.grid);
|
||||||
this.total_mutability = 0;
|
this.total_mutability = 0;
|
||||||
this.total_ticks = 0;
|
this.total_ticks = 0;
|
||||||
|
this.total_cells = 0;
|
||||||
FossilRecord.clear_record();
|
FossilRecord.clear_record();
|
||||||
this.OriginOfLife();
|
this.OriginOfLife();
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/Stats/Charts/CellsChart.js
Normal file
51
src/Stats/Charts/CellsChart.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
const CellStates = require("../../Organism/Cell/CellStates");
|
||||||
|
const FossilRecord = require("../FossilRecord");
|
||||||
|
const ChartController = require("./ChartController");
|
||||||
|
|
||||||
|
class CellsChart extends ChartController {
|
||||||
|
constructor() {
|
||||||
|
super("Organism Size / Composition");
|
||||||
|
}
|
||||||
|
|
||||||
|
setData() {
|
||||||
|
this.clear();
|
||||||
|
//this.mouth, this.producer, this.mover, this.killer, this.armor, this.eye
|
||||||
|
this.data.push({
|
||||||
|
type: "line",
|
||||||
|
markerType: "none",
|
||||||
|
color: 'black',
|
||||||
|
showInLegend: true,
|
||||||
|
name: "pop1",
|
||||||
|
legendText: "Avg. organism size",
|
||||||
|
dataPoints: []
|
||||||
|
}
|
||||||
|
);
|
||||||
|
for (var c of CellStates.living) {
|
||||||
|
this.data.push({
|
||||||
|
type: "line",
|
||||||
|
markerType: "none",
|
||||||
|
color: c.color,
|
||||||
|
showInLegend: true,
|
||||||
|
name: c.name,
|
||||||
|
legendText: "Avg. " + c.name + " cells",
|
||||||
|
dataPoints: []
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.addAllDataPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
addDataPoint(i) {
|
||||||
|
var t = FossilRecord.tick_record[i];
|
||||||
|
var p = FossilRecord.av_cells[i];
|
||||||
|
this.data[0].dataPoints.push({x:t, y:p});
|
||||||
|
var j=1;
|
||||||
|
for (var name in FossilRecord.av_cell_counts[i]) {
|
||||||
|
var count = FossilRecord.av_cell_counts[i][name];
|
||||||
|
this.data[j].dataPoints.push({x:t,y:count})
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CellsChart;
|
||||||
@@ -18,6 +18,12 @@ class ChartController {
|
|||||||
alert("Must override updateData!");
|
alert("Must override updateData!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAllDataPoints(){
|
||||||
|
for (var i in FossilRecord.tick_record) {
|
||||||
|
this.addDataPoint(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.chart.render();
|
this.chart.render();
|
||||||
}
|
}
|
||||||
@@ -39,11 +45,18 @@ class ChartController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addNewest() {
|
addNewest() {
|
||||||
alert("Must override addNewest!");
|
var i = FossilRecord.tick_record.length-1;
|
||||||
|
this.addDataPoint(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
addDataPoint(i) {
|
||||||
|
alert("Must override addDataPoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
removeOldest() {
|
removeOldest() {
|
||||||
alert("Must override addNewest!");
|
for (var dps of this.data) {
|
||||||
|
dps.dataPoints.shift();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
|||||||
@@ -18,24 +18,14 @@ class MutationChart extends ChartController {
|
|||||||
dataPoints: []
|
dataPoints: []
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
for (var i in FossilRecord.tick_record) {
|
this.addAllDataPoints();
|
||||||
var t = FossilRecord.tick_record[i];
|
|
||||||
var p = FossilRecord.av_mut_rates[i];
|
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
|
||||||
}
|
|
||||||
// console.log(this.data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewest() {
|
addDataPoint(i) {
|
||||||
var i = FossilRecord.tick_record.length-1;
|
|
||||||
var t = FossilRecord.tick_record[i];
|
var t = FossilRecord.tick_record[i];
|
||||||
var p = FossilRecord.av_mut_rates[i];
|
var p = FossilRecord.av_mut_rates[i];
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
this.data[0].dataPoints.push({x:t, y:p});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeOldest() {
|
|
||||||
this.data[0].dataPoints.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MutationChart;
|
module.exports = MutationChart;
|
||||||
@@ -18,24 +18,14 @@ class PopulationChart extends ChartController {
|
|||||||
dataPoints: []
|
dataPoints: []
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
for (var i in FossilRecord.tick_record) {
|
this.addAllDataPoints();
|
||||||
var t = FossilRecord.tick_record[i];
|
|
||||||
var p = FossilRecord.pop_counts[i];
|
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
|
||||||
}
|
|
||||||
// console.log(this.data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewest() {
|
addDataPoint(i) {
|
||||||
var i = FossilRecord.tick_record.length-1;
|
|
||||||
var t = FossilRecord.tick_record[i];
|
var t = FossilRecord.tick_record[i];
|
||||||
var p = FossilRecord.pop_counts[i];
|
var p = FossilRecord.pop_counts[i];
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
this.data[0].dataPoints.push({x:t, y:p});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeOldest() {
|
|
||||||
this.data[0].dataPoints.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = PopulationChart;
|
module.exports = PopulationChart;
|
||||||
@@ -18,23 +18,14 @@ class SpeciesChart extends ChartController {
|
|||||||
dataPoints: []
|
dataPoints: []
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
for (var i in FossilRecord.tick_record) {
|
this.addAllDataPoints();
|
||||||
var t = FossilRecord.tick_record[i];
|
|
||||||
var p = FossilRecord.species_counts[i];
|
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewest() {
|
addDataPoint(i) {
|
||||||
var i = FossilRecord.tick_record.length-1;
|
|
||||||
var t = FossilRecord.tick_record[i];
|
var t = FossilRecord.tick_record[i];
|
||||||
var p = FossilRecord.species_counts[i];
|
var p = FossilRecord.species_counts[i];
|
||||||
this.data[0].dataPoints.push({x:t, y:p});
|
this.data[0].dataPoints.push({x:t, y:p});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeOldest() {
|
|
||||||
this.data[0].dataPoints.shift();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SpeciesChart;
|
module.exports = SpeciesChart;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const CellStates = require("../Organism/Cell/CellStates");
|
||||||
const Species = require("./Species");
|
const Species = require("./Species");
|
||||||
|
|
||||||
const FossilRecord = {
|
const FossilRecord = {
|
||||||
@@ -9,11 +10,11 @@ const FossilRecord = {
|
|||||||
this.min_discard = 10;
|
this.min_discard = 10;
|
||||||
|
|
||||||
this.record_size_limit = 500; // store this many data points
|
this.record_size_limit = 500; // store this many data points
|
||||||
this.setData();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setEnv: function(env) {
|
setEnv: function(env) {
|
||||||
this.env = env;
|
this.env = env;
|
||||||
|
this.setData();
|
||||||
},
|
},
|
||||||
|
|
||||||
addSpecies: function(org, ancestor) {
|
addSpecies: function(org, ancestor) {
|
||||||
@@ -66,9 +67,10 @@ const FossilRecord = {
|
|||||||
// all parallel arrays
|
// all parallel arrays
|
||||||
this.tick_record = [0];
|
this.tick_record = [0];
|
||||||
this.pop_counts = [1];
|
this.pop_counts = [1];
|
||||||
this.av_pop_counts = [1]
|
|
||||||
this.species_counts = [1];
|
this.species_counts = [1];
|
||||||
this.av_mut_rates = [5];
|
this.av_mut_rates = [5];
|
||||||
|
this.av_cells = [3];
|
||||||
|
this.av_cell_counts = [this.calcCellCountAverages()];
|
||||||
},
|
},
|
||||||
|
|
||||||
updateData() {
|
updateData() {
|
||||||
@@ -77,15 +79,41 @@ 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());
|
||||||
|
let av_cell = 0;
|
||||||
|
if (this.env.organisms.length > 0) {
|
||||||
|
av_cell = this.env.total_cells / this.env.organisms.length;
|
||||||
|
}
|
||||||
|
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();
|
||||||
this.pop_counts.shift();
|
this.pop_counts.shift();
|
||||||
this.av_pop_counts.shift();
|
|
||||||
this.species_counts.shift();
|
this.species_counts.shift();
|
||||||
this.av_mut_rates.shift();
|
this.av_mut_rates.shift();
|
||||||
|
this.av_cells.shift();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
calcCellCountAverages() {
|
||||||
|
var total_org = this.env.organisms.length;
|
||||||
|
var cell_counts = {};
|
||||||
|
for (let c of CellStates.living) {
|
||||||
|
cell_counts[c.name] = 0;
|
||||||
|
}
|
||||||
|
for (let s of this.extant_species) {
|
||||||
|
for (let name in s.cell_counts) {
|
||||||
|
cell_counts[name] += s.cell_counts[name] * s.population;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (total_org == 0)
|
||||||
|
return cell_counts;
|
||||||
|
for (let c in cell_counts) {
|
||||||
|
cell_counts[c] /= total_org;
|
||||||
|
}
|
||||||
|
return cell_counts;
|
||||||
|
},
|
||||||
|
|
||||||
clear_record: function() {
|
clear_record: function() {
|
||||||
this.extant_species = [];
|
this.extant_species = [];
|
||||||
this.extinct_species = [];
|
this.extinct_species = [];
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const CellStates = require("../Organism/Cell/CellStates");
|
||||||
|
|
||||||
class Species {
|
class Species {
|
||||||
constructor(anatomy, ancestor, start_tick) {
|
constructor(anatomy, ancestor, start_tick) {
|
||||||
this.anatomy = anatomy;
|
this.anatomy = anatomy;
|
||||||
@@ -14,6 +16,18 @@ class Species {
|
|||||||
}
|
}
|
||||||
this.name = '_' + Math.random().toString(36).substr(2, 9);
|
this.name = '_' + Math.random().toString(36).substr(2, 9);
|
||||||
this.extinct = false;
|
this.extinct = false;
|
||||||
|
this.calcAnatomyDetails();
|
||||||
|
}
|
||||||
|
|
||||||
|
calcAnatomyDetails() {
|
||||||
|
var cell_counts = {};
|
||||||
|
for (let c of CellStates.living) {
|
||||||
|
cell_counts[c.name] = 0;
|
||||||
|
}
|
||||||
|
for (let cell of this.anatomy.cells) {
|
||||||
|
cell_counts[cell.state.name]+=1;
|
||||||
|
}
|
||||||
|
this.cell_counts=cell_counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
addPop() {
|
addPop() {
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
const PopulationChart = require("./Charts/PopulationChart");
|
const PopulationChart = require("./Charts/PopulationChart");
|
||||||
const SpeciesChart = require("./Charts/SpeciesChart");
|
const SpeciesChart = require("./Charts/SpeciesChart");
|
||||||
const MutationChart = require("./Charts/MutationChart");
|
const MutationChart = require("./Charts/MutationChart");
|
||||||
|
const CellsChart = require("./Charts/CellsChart");
|
||||||
|
const FossilRecord = require("./FossilRecord");
|
||||||
|
|
||||||
|
|
||||||
const ChartSelections = [PopulationChart, SpeciesChart, MutationChart];
|
const ChartSelections = [PopulationChart, SpeciesChart, CellsChart, MutationChart];
|
||||||
|
|
||||||
class StatsPanel {
|
class StatsPanel {
|
||||||
constructor(env) {
|
constructor(env) {
|
||||||
@@ -47,12 +49,11 @@ class StatsPanel {
|
|||||||
|
|
||||||
updateDetails() {
|
updateDetails() {
|
||||||
var org_count = this.env.organisms.length;
|
var org_count = this.env.organisms.length;
|
||||||
$('#org-count').text("Organism count: " + org_count);
|
$('#org-count').text("Total Population: " + org_count);
|
||||||
if (org_count > this.organism_record)
|
$('#species-count').text("Number of Species: " + FossilRecord.extant_species.length);
|
||||||
this.organism_record = org_count;
|
$('#largest-org').text("Largest Organism Ever: " + this.env.largest_cell_count + " cells");
|
||||||
$('#org-record').text("Highest count: " + this.env.organism_record);
|
|
||||||
$('#avg-mut').text("Average Mutation Rate: " + Math.round(this.env.averageMutability() * 100) / 100);
|
$('#avg-mut').text("Average Mutation Rate: " + Math.round(this.env.averageMutability() * 100) / 100);
|
||||||
$('#largest-org').text("Largest Organism: " + this.env.largest_cell_count + " cells");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user