<commit_before>import App from "../app";
import { pubsub } from "../helpers/subscriptionManager.js";
import throttle from "../helpers/throttle";
import uuid from "uuid";

const throttles = {};
const heatThrottles = {};
const powerThrottles = {};
const triggerWarning = sys => {
  if (!throttles[sys.id]) {
    throttles[sys.id] = throttle(sys => {
      pubsub.publish("notify", {
        id: uuid.v4(),
        simulatorId: sys.simulatorId,
        type: "Reactor",
        station: "Core",
        title: `Dilithium Crystal Stress`,
        body: "",
        color: "danger"
      });
      App.handleEvent(
        {
          simulatorId: sys.simulatorId,
          component: "ReactorControlCore",
          title: `Dilithium Crystal Stress`,
          body: null,
          color: "danger"
        },
        "addCoreFeed"
      );
    }, 15 * 1000);
  }
  return throttles[sys.id];
};

const triggerHeatWarning = sys => {
  if (!heatThrottles[sys.id]) {
    heatThrottles[sys.id] = throttle(sys => {
      const simulator = App.simulators.find(s => s.id === sys.simulatorId);
      const stations = simulator.stations.filter(s =>
        s.cards.find(c => c.component === "ReactorControl")
      );
      stations.forEach(s =>
        pubsub.publish("notify", {
          id: uuid.v4(),
          simulatorId: sys.simulatorId,
          type: "Reactor",
          station: s.name,
          title: `Reactor Overheating`,
          body: "Please cool the main reactor.",
          color: "danger",
          relevantCards: ["ReactorControl"]
        })
      );

      pubsub.publish("notify", {
        id: uuid.v4(),
        simulatorId: sys.simulatorId,
        type: "Reactor",
        station: "Core",
        title: `Reactor Overheating`,
        body: "",
        color: "danger"
      });
      App.handleEvent(
        {
          simulatorId: sys.simulatorId,
          component: "HeatCore",
          title: `Reactor Overheating`,
          body: null,
          color: "danger"
        },
        "addCoreFeed"
      );
    }, 15 * 1000);
  }
  return heatThrottles[sys.id];
};
const triggerPowerWarning = sys => {
  if (!powerThrottles[sys.id]) {
    powerThrottles[sys.id] = throttle(
      sys => {
        const simulator = App.simulators.find(s => s.id === sys.simulatorId);
        const stations = simulator.stations.filter(s =>
          s.cards.find(c => c.component === "PowerDistribution")
        );
        stations.forEach(s =>
          pubsub.publish("notify", {
            id: uuid.v4(),
            simulatorId: sys.simulatorId,
            type: "Reactor",
            station: s.name,
            title: `Power Imbalance`,
            body: "Please balance your power.",
            color: "danger",
            relevantCards: ["PowerDistribution"]
          })<commit_msg>Fixes an issue that caused the server to crash. Closes #1852<commit_after>import App from "../app";
import { pubsub } from "../helpers/subscriptionManager.js";
import throttle from "../helpers/throttle";
import uuid from "uuid";

const throttles = {};
const heatThrottles = {};
const powerThrottles = {};
const triggerWarning = sys => {
  if (!throttles[sys.id]) {
    throttles[sys.id] = throttle(sys => {
      pubsub.publish("notify", {
        id: uuid.v4(),
        simulatorId: sys.simulatorId,
        type: "Reactor",
        station: "Core",
        title: `Dilithium Crystal Stress`,
        body: "",
        color: "danger"
      });
      App.handleEvent(
        {
          simulatorId: sys.simulatorId,
          component: "ReactorControlCore",
          title: `Dilithium Crystal Stress`,
          body: null,
          color: "danger"
        },
        "addCoreFeed"
      );
    }, 15 * 1000);
  }
  return throttles[sys.id];
};

const triggerHeatWarning = sys => {
  if (!heatThrottles[sys.id]) {
    heatThrottles[sys.id] = throttle(sys => {
      const simulator = App.simulators.find(s => s.id === sys.simulatorId);
      if (!simulator) return;
      const stations = simulator.stations.filter(s =>
        s.cards.find(c => c.component === "ReactorControl")
      );
      stations.forEach(s =>
        pubsub.publish("notify", {
          id: uuid.v4(),
          simulatorId: sys.simulatorId,
          type: "Reactor",
          station: s.name,
          title: `Reactor Overheating`,
          body: "Please cool the main reactor.",
          color: "danger",
          relevantCards: ["ReactorControl"]
        })
      );

      pubsub.publish("notify", {
        id: uuid.v4(),
        simulatorId: sys.simulatorId,
        type: "Reactor",
        station: "Core",
        title: `Reactor Overheating`,
        body: "",
        color: "danger"
      });
      App.handleEvent(
        {
          simulatorId: sys.simulatorId,
          component: "HeatCore",
          title: `Reactor Overheating`,
          body: null,
          color: "danger"
        },
        "addCoreFeed"
      );
    }, 15 * 1000);
  }
  return heatThrottles[sys.id];
};
const triggerPowerWarning = sys => {
  if (!powerThrottles[sys.id]) {
    powerThrottles[sys.id] = throttle(
      sys => {
        const simulator = App.simulators.find(s => s.id === sys.simulatorId);
        if (!simulator) return;
        const stations = simulator.stations.filter(s =>
          s.cards.find(c => c.component === "PowerDistribution")
        );
        stations.forEach(s =>
          pubsub.publish("notify", {
            id: uuid.v4(),
            simulatorId: sys.simulatorId,
            type: "Reactor",
            station: s.name,
            title: `Power Imbalance`,
            body: "Please balance your power.",
            color: "danger",
            relevantCards: ["PowerDistribution"]
          })
{'fraction_non_alphanumeric': 0.14193548387096774, 'fraction_numerical': 0.006277244986922406, 'mean_word_length': 1.9658738366080661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '6488866', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1729, 'n_words': 370}