<commit_before>(function() {
var teams = ['<NAME>', '<NAME>', 'Santa Destroy Warriors', 'New New York Yankees', 'North Shore High Lions'];
var sports = ['Airball', 'Blernsball', 'Brockian Ultra-Cricket', 'Chess', 'Dungeons & Dungeons', 'Laserball', 'Quidditch'];

var residentMultiplier = 1.05;
var commerceMultiplier = 1.1;
var industryMultiplier = 1.1;

var format = function(amount, symbol) {
  if (amount > 9) {
    amount = Math.floor(amount);
  } else {
    amount = Math.floor(amount * 100) / 100;
  }
  if (amount > 9999999) {
    amount = amount.toExponential(2);
  }
  return amount + (symbol || '&curren;');
};

var formatTime = function(city, cost) {
  var time = Math.max(0, Math.ceil((cost - city.currency) / city.tax));
  return format(time, time == 1 ? ' second' : ' seconds');
}

var output = function(element, attributes, head) {
  var html = [];
  if (head) {
    html.push('<b>' + head + '</b>');
  }
  for (var k in attributes) {
    html.push(k + ': <b>' + attributes[k] + '</b>');
  }
  element.innerHTML = html.join('<br>');
};

var Zone = function(city, type, symbol, load) {
  load = load || {};
  this.sizes = [];
  var delta = 10;
  for (var i = 1; i <= 10; i++) {
    var label = symbol;
    if (i <= 3) {
      for (var j = 0; j < i - 1; j++) {
        label += symbol;
      }
    } else {
      label += 'x' + i;
    }
    this.sizes.push({
      amount: 0,
      built: 0,
      density: Math.pow(10, .5 * i * i + .5 * i),
      label: label
    });
  }
  this.city = city;
  this.type = type;
  this.symbol = symbol;
  this.tax = load.tax || 10;
  this.demand = 0;

  var container = document.createElement('div');
  container.className = 'panel ' + type.toLowerCase();
  container.innerHTML = '<h1>' + type + '</h1>';
  for (var i = 0; i < this.sizes.length; i++) {
    var data = this.sizes[i];
    if (load[i]) {
      data.amount = load[i].amount || 0;
      data.built = load[i].built || 0;
    }
    data.button = document.createElement('button');
    data.button.innerHTML = 'Zone ' + data.label;
    data.button.addEventListener('click', this.buy.bind(this, i));
    data.button.style.display = 'none';
    data.alt = document.createElement('div');
    data.alt.className = 'alt';
    data.status = document.createElement('div');
    data.status.style.display = 'none';
    container.appendChild(data.status);
    container.appendChild(data.button);
    container.appendChild(data.alt);
  }
  this.city.container.appendChild(container);
  this.city.items.push(this);
};

Zone.prototype.buy = function(size) {
  if (this.city.spend(this.price(size))) {
    this.sizes[size].amount++;
    this.city.update();
  }
};

Zone.prototype.capacity = function() {
  var total = 0;
  for (var i = 0; i < this.sizes.length; i++) {
    total += this.sizes[i].built * this.sizes[i].density;
  }
  return total;
};

Zone.prototype.data = function() {
  var serial = {tax: this.tax}
  for (var i = 0; i < this.sizes.length; i++) {
    serial[i] = {};
    serial[i].amount = this.sizes[i].amount;
    serial[i].built = this.sizes[i].built;
  }
  return serial;
};

Zone.prototype.income = function(tax) {
  return (tax || this.tax) / 100 * this.capacity() / 10;
}

Zone.prototype.price = function(size) {
  return Math.floor(this.sizes[size].density *
      Math.pow(1.1, this.sizes[size].amount));
};

Zone.prototype.update = function() {
  var visible = true;
  for (var i = 0; i < this.sizes.length; i++) {
    var data = this.sizes[i];
    var cost = this.price(i);
    output(data.status, {
      Price: format(cost),
      Built: data.built + ' / ' + data.amount,
    });
    output(data.alt, {
      'Zone capacity': format(data.density, this.symbol),
      'Current demand': format(this.demand, this.symbol),
      'Total built': format(this.capacity(), this.symbol),
      'Total zoned': format(this.zoned(), this.symbol),
      'Type income': format(this.income()),
      'Time to purchase': formatTime(this.city, cost),
    }, 'Add ' + this.type + ' Zones');
    data.button.disabled = cost > this.city.currency;
    if (data.built < this.demand / data.density && data.built < data.amount) {
      data.built++;
    }
    data.button.style.display = visible ? '' : 'none';
    data.status.style.display = visible ? '' : 'none';
    visible = !!data.amount;
  }
};

Zone.prototype.zoned = function() {
  var total = 0;
  for (var i = 0; i < this.sizes.length; i++) {
    total += this.sizes[i].amount * this.sizes[i].density;
  }
  return total;
};

var Update = function(city, level, cost, scale, message, levels, stats) {
  this.city = city;<commit_msg>Fix demand calculation.<commit_after>(function() {
var teams = ['<NAME>', '<NAME>', 'Santa Destroy Warriors', 'New New York Yankees', 'North Shore High Lions'];
var sports = ['Airball', 'Blernsball', 'Brockian Ultra-Cricket', 'Chess', 'Dungeons & Dungeons', 'Laserball', 'Quidditch'];

var residentMultiplier = 1.05;
var commerceMultiplier = 1.1;
var industryMultiplier = 1.1;

var format = function(amount, symbol) {
  if (amount > 9) {
    amount = Math.floor(amount);
  } else {
    amount = Math.floor(amount * 100) / 100;
  }
  if (amount > 9999999) {
    amount = amount.toExponential(2);
  }
  return amount + (symbol || '&curren;');
};

var formatTime = function(city, cost) {
  var time = Math.max(0, Math.ceil((cost - city.currency) / city.tax));
  return format(time, time == 1 ? ' second' : ' seconds');
}

var output = function(element, attributes, head) {
  var html = [];
  if (head) {
    html.push('<b>' + head + '</b>');
  }
  for (var k in attributes) {
    html.push(k + ': <b>' + attributes[k] + '</b>');
  }
  element.innerHTML = html.join('<br>');
};

var Zone = function(city, type, symbol, load) {
  load = load || {};
  this.sizes = [];
  var delta = 10;
  for (var i = 1; i <= 10; i++) {
    var label = symbol;
    if (i <= 3) {
      for (var j = 0; j < i - 1; j++) {
        label += symbol;
      }
    } else {
      label += 'x' + i;
    }
    this.sizes.push({
      amount: 0,
      built: 0,
      density: Math.pow(10, .5 * i * i + .5 * i),
      label: label
    });
  }
  this.city = city;
  this.type = type;
  this.symbol = symbol;
  this.tax = load.tax || 10;
  this.demand = 0;

  var container = document.createElement('div');
  container.className = 'panel ' + type.toLowerCase();
  container.innerHTML = '<h1>' + type + '</h1>';
  for (var i = 0; i < this.sizes.length; i++) {
    var data = this.sizes[i];
    if (load[i]) {
      data.amount = load[i].amount || 0;
      data.built = load[i].built || 0;
    }
    data.button = document.createElement('button');
    data.button.innerHTML = 'Zone ' + data.label;
    data.button.addEventListener('click', this.buy.bind(this, i));
    data.button.style.display = 'none';
    data.alt = document.createElement('div');
    data.alt.className = 'alt';
    data.status = document.createElement('div');
    data.status.style.display = 'none';
    container.appendChild(data.status);
    container.appendChild(data.button);
    container.appendChild(data.alt);
  }
  this.city.container.appendChild(container);
  this.city.items.push(this);
};

Zone.prototype.buy = function(size) {
  if (this.city.spend(this.price(size))) {
    this.sizes[size].amount++;
    this.city.update();
  }
};

Zone.prototype.capacity = function() {
  var total = 0;
  for (var i = 0; i < this.sizes.length; i++) {
    total += this.sizes[i].built * this.sizes[i].density;
  }
  return total;
};

Zone.prototype.data = function() {
  var serial = {tax: this.tax}
  for (var i = 0; i < this.sizes.length; i++) {
    serial[i] = {};
    serial[i].amount = this.sizes[i].amount;
    serial[i].built = this.sizes[i].built;
  }
  return serial;
};

Zone.prototype.income = function(tax) {
  return (tax || this.tax) / 100 * this.capacity() / 10;
}

Zone.prototype.price = function(size) {
  return Math.floor(this.sizes[size].density *
      Math.pow(1.1, this.sizes[size].amount));
};

Zone.prototype.update = function() {
  var visible = true;
  var demand = this.demand;
  for (var i = this.sizes.length - 1; i >= 0; i--) {
    var data = this.sizes[i];
    demand -= data.built * data.density;
  }
  for (var i = 0; i < this.sizes.length; i++) {
    var data = this.sizes[i];
    var cost = this.price(i);
    output(data.status, {
      Price: format(cost),
      Built: data.built + ' / ' + data.amount,
    });
    output(data.alt, {
      'Zone capacity': format(data.density, this.symbol),
      'Current demand': format(this.demand, this.symbol),
      'Total built': format(this.capacity(), this.symbol),
      'Total zoned': format(this.zoned(), this.symbol),
      'Type income': format(this.income()),
      'Time to purchase': formatTime(this.city, cost),
    }, 'Add ' + this.type + ' Zones');
    data.button.disabled = cost > this.city.currency;
    if (demand > 0 && data.built < data.amount) {
      data.built++;
      demand -= data.density;
    }
    data.button.style.display = visible ? '' : 'none';
    data.status.style.display = visible ? '' : 'none';
    visible = !!data.amount;
  }
};

Zone.prototype.zoned = function() {
  var total = 0;
  for (var i = 0; i < this.sizes.length; i++) {
    total += this.sizes[i].amount * this.sizes[i].density;
  }
  return total;
};

var Update = function(city, level, cost, scale, message, levels, stats) {
  this.city = city;
{'fraction_non_alphanumeric': 0.18669091687172354, 'fraction_numerical': 0.012945330052423237, 'mean_word_length': 2.932688262515776, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7262202', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3247, 'n_words': 755}