cleaned chart code/added cells chart

This commit is contained in:
Max Robinson
2021-02-11 13:24:42 -07:00
parent 7b19798be9
commit 9626cd54d6
12 changed files with 137 additions and 51 deletions

7
dist/index.html vendored
View File

@@ -222,14 +222,15 @@
<div id='stats' class='tab'>
<div class='left-half'>
<h2>Stats</h2>
<p id='org-count'>Organism count: </p>
<p id='org-record'>Highest count: </p>
<p id='org-count'>Total Population: </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='largest-org'>Largest Organism: </p>
<label for="chart-option">Chart: </label>
<select name="chart-option" id="chart-option">
<option value="population">Population</option>
<option value="species">Species</option>
<option value="mut-rate">Organism Size</option>
<option value="mut-rate">Mutation Rate</option>
</select>

2
dist/js/bundle.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -176,6 +176,9 @@ class ControlPanel {
$('#remove-prob').val(Hyperparams.removeProb);
$('#movers-produce').prop('checked', Hyperparams.moversCanProduce);
$('#food-blocks').prop('checked', Hyperparams.foodBlocksReproduction);
$('#food-drop-rate').val(Hyperparams.foodDropProb);
$('#look-range').val(Hyperparams.lookRange);
if (!Hyperparams.useGlobalMutability) {
$('.global-mutation-in').css('display', 'none');
$('#avg-mut').css('display', 'block');

View File

@@ -22,6 +22,7 @@ class WorldEnvironment extends Environment{
this.largest_cell_count = 0;
this.reset_count = 0;
this.total_ticks = 0;
this.total_cells = 0;
this.data_update_rate = 100;
FossilRecord.setEnv(this);
}
@@ -52,6 +53,7 @@ class WorldEnvironment extends Environment{
removeOrganisms(org_indeces) {
for (var i of org_indeces.reverse()){
this.total_mutability -= this.organisms[i].mutability;
this.total_cells -= this.organisms[i].anatomy.cells.length;
this.organisms.splice(i, 1);
}
if (this.organisms.length == 0 && this.auto_reset){
@@ -76,6 +78,7 @@ class WorldEnvironment extends Environment{
this.organisms.push(organism);
if (organism.anatomy.cells.length > this.largest_cell_count)
this.largest_cell_count = organism.anatomy.cells.length;
this.total_cells += organism.anatomy.cells.length;
}
averageMutability() {
@@ -122,12 +125,13 @@ class WorldEnvironment extends Environment{
}
}
reset(clear_walls=true) {
reset() {
this.organisms = [];
this.grid_map.fillGrid(CellStates.empty);
this.renderer.renderFullGrid(this.grid_map.grid);
this.total_mutability = 0;
this.total_ticks = 0;
this.total_cells = 0;
FossilRecord.clear_record();
this.OriginOfLife();
}

View 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;

View File

@@ -18,6 +18,12 @@ class ChartController {
alert("Must override updateData!");
}
addAllDataPoints(){
for (var i in FossilRecord.tick_record) {
this.addDataPoint(i)
}
}
render() {
this.chart.render();
}
@@ -39,11 +45,18 @@ class ChartController {
}
addNewest() {
alert("Must override addNewest!");
var i = FossilRecord.tick_record.length-1;
this.addDataPoint(i);
}
addDataPoint(i) {
alert("Must override addDataPoint")
}
removeOldest() {
alert("Must override addNewest!");
for (var dps of this.data) {
dps.dataPoints.shift();
}
}
clear() {

View File

@@ -18,24 +18,14 @@ class MutationChart extends ChartController {
dataPoints: []
}
);
for (var i in FossilRecord.tick_record) {
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)
this.addAllDataPoints();
}
addNewest() {
var i = FossilRecord.tick_record.length-1;
addDataPoint(i) {
var t = FossilRecord.tick_record[i];
var p = FossilRecord.av_mut_rates[i];
this.data[0].dataPoints.push({x:t, y:p});
}
removeOldest() {
this.data[0].dataPoints.shift();
}
}
module.exports = MutationChart;

View File

@@ -18,24 +18,14 @@ class PopulationChart extends ChartController {
dataPoints: []
}
);
for (var i in FossilRecord.tick_record) {
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)
this.addAllDataPoints();
}
addNewest() {
var i = FossilRecord.tick_record.length-1;
addDataPoint(i) {
var t = FossilRecord.tick_record[i];
var p = FossilRecord.pop_counts[i];
this.data[0].dataPoints.push({x:t, y:p});
}
removeOldest() {
this.data[0].dataPoints.shift();
}
}
module.exports = PopulationChart;

View File

@@ -18,23 +18,14 @@ class SpeciesChart extends ChartController {
dataPoints: []
}
);
for (var i in FossilRecord.tick_record) {
var t = FossilRecord.tick_record[i];
var p = FossilRecord.species_counts[i];
this.data[0].dataPoints.push({x:t, y:p});
}
this.addAllDataPoints();
}
addNewest() {
var i = FossilRecord.tick_record.length-1;
addDataPoint(i) {
var t = FossilRecord.tick_record[i];
var p = FossilRecord.species_counts[i];
this.data[0].dataPoints.push({x:t, y:p});
}
removeOldest() {
this.data[0].dataPoints.shift();
}
}
module.exports = SpeciesChart;

View File

@@ -1,3 +1,4 @@
const CellStates = require("../Organism/Cell/CellStates");
const Species = require("./Species");
const FossilRecord = {
@@ -9,11 +10,11 @@ const FossilRecord = {
this.min_discard = 10;
this.record_size_limit = 500; // store this many data points
this.setData();
},
setEnv: function(env) {
this.env = env;
this.setData();
},
addSpecies: function(org, ancestor) {
@@ -66,9 +67,10 @@ const FossilRecord = {
// all parallel arrays
this.tick_record = [0];
this.pop_counts = [1];
this.av_pop_counts = [1]
this.species_counts = [1];
this.av_mut_rates = [5];
this.av_cells = [3];
this.av_cell_counts = [this.calcCellCountAverages()];
},
updateData() {
@@ -77,15 +79,41 @@ const FossilRecord = {
this.pop_counts.push(this.env.organisms.length);
this.species_counts.push(this.extant_species.length);
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) {
this.tick_record.shift();
this.pop_counts.shift();
this.av_pop_counts.shift();
this.species_counts.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() {
this.extant_species = [];
this.extinct_species = [];

View File

@@ -1,3 +1,5 @@
const CellStates = require("../Organism/Cell/CellStates");
class Species {
constructor(anatomy, ancestor, start_tick) {
this.anatomy = anatomy;
@@ -14,6 +16,18 @@ class Species {
}
this.name = '_' + Math.random().toString(36).substr(2, 9);
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() {

View File

@@ -1,9 +1,11 @@
const PopulationChart = require("./Charts/PopulationChart");
const SpeciesChart = require("./Charts/SpeciesChart");
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 {
constructor(env) {
@@ -47,12 +49,11 @@ class StatsPanel {
updateDetails() {
var org_count = this.env.organisms.length;
$('#org-count').text("Organism count: " + org_count);
if (org_count > this.organism_record)
this.organism_record = org_count;
$('#org-record').text("Highest count: " + this.env.organism_record);
$('#org-count').text("Total Population: " + org_count);
$('#species-count').text("Number of Species: " + FossilRecord.extant_species.length);
$('#largest-org').text("Largest Organism Ever: " + this.env.largest_cell_count + " cells");
$('#avg-mut').text("Average Mutation Rate: " + Math.round(this.env.averageMutability() * 100) / 100);
$('#largest-org').text("Largest Organism: " + this.env.largest_cell_count + " cells");
}