<commit_before>import xs from "xstream"
import { div, i, ul, li, p, input, button, span, a } from "@cycle/dom"
import { loggerFactory } from "../utils/logger"
import delay from "xstream/extra/delay"
import sampleCombine from "xstream/extra/sampleCombine"
import { convertToCSV } from "../utils/export"

function intent(domSource$) {
  const exportLinkTrigger$ = domSource$.select(".export-clipboard-link").events("click")
  const exportSignatureTrigger$ = domSource$.select(".export-clipboard-signature").events("click")
  const exportPlotsTrigger$ = domSource$.select(".export-clipboard-plots").events("click")
  const exportHeadTableTrigger$ = domSource$.select(".export-clipboard-headTable").events("click")
  const exportTailTableTrigger$ = domSource$.select(".export-clipboard-tailTable").events("click")

  const modalTrigger$ = domSource$.select(".modal-open-btn").events("click")
  const modalCloseTrigger$ = domSource$.select(".export-close").events("click")

  return {
    exportLinkTrigger$: exportLinkTrigger$,
    exportSignatureTrigger$: exportSignatureTrigger$,
    exportPlotsTrigger$: exportPlotsTrigger$,
    exportHeadTableTrigger$: exportHeadTableTrigger$,
    exportTailTableTrigger$: exportTailTableTrigger$,
    modalTrigger$: modalTrigger$,
    modalCloseTrigger$: modalCloseTrigger$,
  }
}

function model(actions, state$) {
  
  const openModal$ = actions.modalTrigger$
    .map(_ => ({ el: '#modal-exporter', state: 'open' }))
  const closeModal$ = actions.modalCloseTrigger$
    .map(_ => ({ el: '#modal-exporter', state: 'close' }))
  
  function notEmpty(data) {
    return data != undefined && data != ""
  }

  const signaturePresent$ = state$.map((state) => notEmpty(state.form.signature.output)).startWith(false)
  const plotsPresent$ = xs.of(true)
  const headTablePresent$ = state$.map((state) => notEmpty(state.headTable.data)).startWith(false)
  const tailTablePresent$ = state$.map((state) => notEmpty(state.tailTable.data)).startWith(false)

  const url$ = state$.map((state) => state.routerInformation.pageStateURL).startWith("")
  const signature$ = state$.map((state) => state.form.signature.output).startWith("")
  const plots$ = xs.of("<KEY>////////////////////////////////////////////////////////////////<KEY>

  const headTableCsv$ = state$.map((state) => state.headTable.data)
    .filter((data) => notEmpty(data))
    .map((data) => convertToCSV(data))
    .startWith("")
  
  const tailTableCsv$ = state$.map((state) => state.tailTable.data)
    .filter((data) => notEmpty(data))
    .map((data) => convertToCSV(data))
    .startWith("")

  const clipboardLink$ = actions.exportLinkTrigger$
    .compose(sampleCombine(url$))
    .map(([_, url]) => url)
    .remember()

  const clipboardSignature$ = actions.exportSignatureTrigger$
    .compose(sampleCombine(signature$))
    .map(([_, signature]) => signature)
    .remember()

  // not yet functional, uses static content
  const clipboardPlots$ = actions.exportPlotsTrigger$
    .compose(sampleCombine(plots$))
    .map(([_, plots]) => {

      const byteCharacters = atob(plots);
      const byteNumbers = new Array(byteCharacters.length);<commit_msg>change notEmpty to notEmptyOrUndefined and support arrays<commit_after>import xs from "xstream"
import { div, i, ul, li, p, input, button, span, a } from "@cycle/dom"
import { isEmpty } from "ramda"
import { loggerFactory } from "../utils/logger"
import delay from "xstream/extra/delay"
import sampleCombine from "xstream/extra/sampleCombine"
import { convertToCSV } from "../utils/export"

function intent(domSource$) {
  const exportLinkTrigger$ = domSource$.select(".export-clipboard-link").events("click")
  const exportSignatureTrigger$ = domSource$.select(".export-clipboard-signature").events("click")
  const exportPlotsTrigger$ = domSource$.select(".export-clipboard-plots").events("click")
  const exportHeadTableTrigger$ = domSource$.select(".export-clipboard-headTable").events("click")
  const exportTailTableTrigger$ = domSource$.select(".export-clipboard-tailTable").events("click")

  const modalTrigger$ = domSource$.select(".modal-open-btn").events("click")
  const modalCloseTrigger$ = domSource$.select(".export-close").events("click")

  return {
    exportLinkTrigger$: exportLinkTrigger$,
    exportSignatureTrigger$: exportSignatureTrigger$,
    exportPlotsTrigger$: exportPlotsTrigger$,
    exportHeadTableTrigger$: exportHeadTableTrigger$,
    exportTailTableTrigger$: exportTailTableTrigger$,
    modalTrigger$: modalTrigger$,
    modalCloseTrigger$: modalCloseTrigger$,
  }
}

function model(actions, state$) {
  
  const openModal$ = actions.modalTrigger$
    .map(_ => ({ el: '#modal-exporter', state: 'open' }))
  const closeModal$ = actions.modalCloseTrigger$
    .map(_ => ({ el: '#modal-exporter', state: 'close' }))
  
  function notEmptyOrUndefined(data) {
    return data != undefined && !isEmpty(data)
  }

  const signaturePresent$ = state$.map((state) => notEmptyOrUndefined(state.form.signature.output)).startWith(false)
  const plotsPresent$ = state$.map((state) => notEmptyOrUndefined(state.plots.data)).startWith(false)
  const headTablePresent$ = state$.map((state) => notEmptyOrUndefined(state.headTable.data)).startWith(false)
  const tailTablePresent$ = state$.map((state) => notEmptyOrUndefined(state.tailTable.data)).startWith(false)

  const url$ = state$.map((state) => state.routerInformation.pageStateURL).startWith("")
  const signature$ = state$.map((state) => state.form.signature.output).startWith("")
  const plots$ = xs.of("<KEY>ICA<KEY>

  const headTableCsv$ = state$.map((state) => state.headTable.data)
    .filter((data) => notEmptyOrUndefined(data))
    .map((data) => convertToCSV(data))
    .startWith("")
  
  const tailTableCsv$ = state$.map((state) => state.tailTable.data)
    .filter((data) => notEmptyOrUndefined(data))
    .map((data) => convertToCSV(data))
    .startWith("")

  const clipboardLink$ = actions.exportLinkTrigger$
    .compose(sampleCombine(url$))
    .map(([_, url]) => url)
    .remember()

  const clipboardSignature$ = actions.exportSignatureTrigger$
    .compose(sampleCombine(signature$))
    .map(([_, signature]) => signature)
    .remember()

  // not yet functional, uses static content
  const clipboardPlots$ = actions.exportPlotsTrigger$
    .compose(sampleCombine(plots$))
    .map(([_, plots]) => {

      const byteCharacters = atob(plots);
      const byteNumbers = new Array(byteCharacters.length);
{'fraction_non_alphanumeric': 0.1666408788488318, 'fraction_numerical': 0.0, 'mean_word_length': 4.792114695340501, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '3284055', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1893, 'n_words': 358}