<commit_before>import * as rx from 'rxjs/Rx';
import {fromEventSource} from './rx-sse';
import LineChart from './LineChart';
import * as stock from './Stock';


window["toggle"]  = function(code : string) : void {
  if (window["cleanUp"]) {
    window["cleanUp"]();
  }

  const quoteEventSource = new EventSource(`http://localhost:8081?code=${code}`);
  const quoteObservable
    = stock.parseRawStream(
        fromEventSource(quoteEventSource, 'message')
          .pluck<string>('data')
      );

  const lineChart = new LineChart("#spotGraph", `${code} spot`);
  const chartSubscription = quoteObservable.pluck('quote').subscribe(lineChart.getObserver());
  const labelSubscription = stock.detectTrends(quoteObservable).subscribe(q => {
    document.getElementById("currentStock").innerHTML = `Last quote: <span style="background: ${q.color}">${q.quote.quote.toFixed(4)}</span> EUR`
  })

  const minSubscription = stock.minFromPrevious(quoteObservable, 10).subscribe(q => {
    document.getElementById("minStock").innerHTML = `Min: ${q.toFixed(4)} EUR`
  })
  const maxSubscription = stock.maxFromPrevious(quoteObservable, 10).subscribe(q => {
    document.getElementById("maxStock").innerHTML = `Max: ${q.toFixed(4)} EUR`
  })

  const vwapEventSource = new EventSource(`http://localhost:8082?code=${code}`);
  const vwapObservable
    = stock.parseRawVwapStream(
        fromEventSource(vwapEventSource, 'message')
          .pluck<string>('data')
      ).pluck<number>('vwap');

  const vwapLineChart = new LineChart("#vwapGraph", `${code} vwap`);
  const vwapChartSubscription = vwapObservable.subscribe(vwapLineChart.getObserver());
  const vwapLabelSubscription = vwapObservable.subscribe(v => {
    document.getElementById("currentVwap").innerHTML = `Vwap: ${v.toFixed(4)}$`
  })

  window["cleanUp"] = function() : void {
    chartSubscription.unsubscribe();
    labelSubscription.unsubscribe();
    minSubscription.unsubscribe();
    maxSubscription.unsubscribe();
    vwapChartSubscription.unsubscribe();
    vwapLabelSubscription.unsubscribe();
    quoteEventSource.close();
    vwapEventSource.close();
    document.getElementById("currentStock").innerHTML = "";
    document.getElementById("minStock").innerHTML = "";
    document.getElementById("maxStock").innerHTML = "";
    document.getElementById("spotGraph").innerHTML = "";
    document.getElementById("vwapGraph").innerHTML = "";

  }

}

const activeStocksEventSource = new EventSource('http://localhost:8083');
const stockStaticDataObservable
  = stock.parseStaticDataRawStream(
      fromEventSource(activeStocksEventSource, 'message')
        .pluck<string>('data')
  );

stockStaticDataObservable.subscribe(st => {
  document.getElementById("activeStocks").innerHTML += `<a href="#" onclick="toggle('${st.code}')">${st.code}</a> - ${st.companyName} - ${st.market}<br/>`
});<commit_msg>Add message on connection close<commit_after>import * as rx from 'rxjs/Rx';
import {fromEventSource} from './rx-sse';
import LineChart from './LineChart';
import * as stock from './Stock';


window["toggle"]  = function(code : string) : void {
  if (window["cleanUp"]) {
    window["cleanUp"]();
  }

  const quoteEventSource = new EventSource(`http://localhost:8081?code=${code}`);
  const quoteObservable
    = stock.parseRawStream(
        fromEventSource(quoteEventSource, 'message')
          .pluck<string>('data')
      );

  const lineChart = new LineChart("#spotGraph", `${code} spot`);
  const chartSubscription = quoteObservable.pluck('quote').subscribe(lineChart.getObserver());
  const labelSubscription = stock.detectTrends(quoteObservable).subscribe(q => {
    document.getElementById("currentStock").innerHTML = `Last quote: <span style="background: ${q.color}">${q.quote.quote.toFixed(4)}</span> EUR`
  })

  const minSubscription = stock.minFromPrevious(quoteObservable, 10).subscribe(q => {
    document.getElementById("minStock").innerHTML = `Min: ${q.toFixed(4)} EUR`
  })
  const maxSubscription = stock.maxFromPrevious(quoteObservable, 10).subscribe(q => {
    document.getElementById("maxStock").innerHTML = `Max: ${q.toFixed(4)} EUR`
  })

  const vwapEventSource = new EventSource(`http://localhost:8082?code=${code}`);
  const vwapObservable
    = stock.parseRawVwapStream(
        fromEventSource(vwapEventSource, 'message')
          .pluck<string>('data')
      ).pluck<number>('vwap');

  const vwapLineChart = new LineChart("#vwapGraph", `${code} vwap`);
  const vwapChartSubscription = vwapObservable.subscribe(vwapLineChart.getObserver());
  const vwapLabelSubscription = vwapObservable.subscribe(v => {
    document.getElementById("currentVwap").innerHTML = `Vwap: ${v.toFixed(4)}$`
  })

  window["cleanUp"] = function() : void {
    chartSubscription.unsubscribe();
    labelSubscription.unsubscribe();
    minSubscription.unsubscribe();
    maxSubscription.unsubscribe();
    vwapChartSubscription.unsubscribe();
    vwapLabelSubscription.unsubscribe();
    quoteEventSource.close();
    vwapEventSource.close();
    document.getElementById("currentStock").innerHTML = "";
    document.getElementById("minStock").innerHTML = "";
    document.getElementById("maxStock").innerHTML = "";
    document.getElementById("spotGraph").innerHTML = "";
    document.getElementById("vwapGraph").innerHTML = "";

  }

}

const activeStocksEventSource = new EventSource('http://localhost:8083');
const stockStaticDataObservable
  = stock.parseStaticDataRawStream(
      fromEventSource(activeStocksEventSource, 'message')
        .pluck<string>('data')
  );

stockStaticDataObservable.subscribe(st => {
  document.getElementById("activeStocks").innerHTML += `<a href="#" onclick="toggle('${st.code}')">${st.code}</a> - ${st.companyName} - ${st.market}<br/>`
},
error => console.log("Stocks connection stopped"));
{'fraction_non_alphanumeric': 0.16267447871790452, 'fraction_numerical': 0.006892986386351887, 'mean_word_length': 5.12882787750792, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 32, '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': '2129362', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1724, 'n_words': 266}