runR = "Rscript --no-save --no-restore --verbose"
logAll = "2>&1"

# --- Dictionaries --- #
import glob
import pandas as pd


# files =
input_files = glob.glob('all_speakers/*/summary.csv')
df = pd.DataFrame(input_files,columns=['names'])
df.names = df.names.str.replace('/','_')
df.names = 'plots/' + df.names.str.replace('csv','png')

output_files=df.names


rule all:
    input:
        script = "plot_results.R",
        data = input_files

    output:
        plot = output_files
    log:
        "logs/plotlog.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"



input_files_cons = glob.glob('consecutive_speakers/*/summary.csv')
df_cons = pd.DataFrame(input_files_cons,columns=['names'])
df_cons.names = df_cons.names.str.replace('/','_')
df_cons.names = 'plots/' + df_cons.names.str.replace('csv','png')

output_files_cons=df_cons.names


rule cons:
    input:
        script = "plot_results.R",
        data = input_files_cons

    output:
        plot = output_files_cons
    log:
        "logs/plotlog.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"



input_files_cutoff = glob.glob('cutoff/*/summary.csv')
df_cutoff = pd.DataFrame(input_files_cutoff,columns=['names'])
df_cutoff.names = df_cutoff.names.str.replace('/','_')
df_cutoff.names = 'plots/' + df_cutoff.names.str.replace('csv','png')

output_files_cutoff=df_cutoff.names


rule cutoff:
    input:
        script = "plot_results.R",
        data = input_files_cutoff

    output:
        plot = output_files_cutoff
    log:
        "logs/plotlogcutoff.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"



input_files_def_doc = glob.glob('def_doc/*/summary.csv')
df_def_doc = pd.DataFrame(input_files_def_doc,columns=['names'])
df_def_doc.names = df_def_doc.names.str.replace('/','_')
df_def_doc.names = 'plots/' + df_def_doc.names.str.replace('csv','png')

output_files_def_doc=df_def_doc.names


rule def_doc:
    input:
        script = "plot_results.R",
        data = input_files_def_doc

    output:
        plot = output_files_def_doc
    log:
        "logs/plotlogdef_doc.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"




input_files_cutoff_5gram_10 = glob.glob('cutoff_5-gram_10/*/summary.csv')
df_cutoff_5gram_10 = pd.DataFrame(input_files_cutoff_5gram_10,columns=['names'])
df_cutoff_5gram_10.names = df_cutoff_5gram_10.names.str.replace('/','_')
df_cutoff_5gram_10.names = 'plots/' + df_cutoff_5gram_10.names.str.replace('csv','png')

output_files_cutoff_5gram_10=df_cutoff_5gram_10.names


rule cutoff_5gram_10:
    input:
        script = "plot_results.R",
        data = input_files_cutoff_5gram_10

    output:
        plot = output_files_cutoff_5gram_10
    log:
        "logs/plotlog_cutoff_5gram_10.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"





input_files_noref = glob.glob('noref/*/summary.csv')
df_noref = pd.DataFrame(input_files_noref,columns=['names'])
df_noref.names = df_noref.names.str.replace('/','_')
df_noref.names = 'plots/' + df_noref.names.str.replace('csv','png')

output_files_noref=df_noref.names


rule noref:
    input:
        script = "plot_results.R",
        data = input_files_noref

    output:
        plot = output_files_noref
    log:
        "logs/plotlog_noref.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"


input_files_noref_ext = glob.glob('noref_ext/*/summary.csv')
df_noref_ext = pd.DataFrame(input_files_noref_ext,columns=['names'])
df_noref_ext.names = df_noref_ext.names.str.replace('/','_')
df_noref_ext.names = 'plots/' + df_noref_ext.names.str.replace('csv','png')

output_files_noref_ext=df_noref_ext.names


rule noref_ext:
    input:
        script = "plot_results.R",
        data = input_files_noref_ext

    output:
        plot = output_files_noref_ext
    log:
        "logs/plotlog_noref_ext.txt"
    shell:
     "{runR} {input.script} {input.data} \
        {output.plot}  > {log} {logAll}"


# data   = expand("Data/{iKey}/tfidf/{iKey}_top500_scaled.csv",
#                         iKey = terms),
