# Path: twip/constant.py
# DATA_PATH = os.path.abspath(os.path.join(BASE_PATH, '..', 'data'))
# 
# IMAGES_PATH = os.path.abspath(os.path.join(DOCS_PATH, 'images'))


import json
import os
import logging
import datetime
import pandas as pd
from collections import Mapping
from itertools import product
from pandas.tools.plotting import scatter_matrix
from matplotlib import pyplot as plt
from twip.constant import DATA_PATH, IMAGES_PATH


def scatmat(df, category=None, colors='rgob',
            num_plots=4, num_topics=100, num_columns=4,
            show=False, block=False, data_path=DATA_PATH, save=False, verbose=1):
    """FIXME: empty plots that dont go away, Plot and/save scatter matrix in groups of num_columns topics"""

    if category is None:
        category = list(df.columns)[-1]
    if category in df.columns:
        category = df[category]
    else:
        category = pd.Series(category)

    suffix = compose_suffix(len(df), num_topics, save)
    save = bool(save)
    for i in range(min(num_plots * num_columns, num_topics) / num_plots):
        scatter_matrix(df[df.columns[i * num_columns:(i + 1) * num_columns]],
                       marker='+', c=[colors[int(x) % len(colors)] for x in category.values],
                       figsize=(18, 12))
        if save:
            name = 'scatmat_topics_{}-{}.jpg'.format(i * num_columns, (i + 1) * num_columns) + suffix
            plt.savefig(os.path.join(data_path, name + '.jpg'))
        if show:
            if block:
                plt.show()
            else:
                plt.show(block=False)



# Path: twip/constant.py
# DATA_PATH = os.path.abspath(os.path.join(BASE_PATH, '..', 'data'))
# 
# IMAGES_PATH = os.path.abspath(os.path.join(DOCS_PATH, 'images'))


# Path: twip/plot.py
import json
import os
import logging
import datetime
import pandas as pd
from collections import Mapping
from itertools import product
from pandas.tools.plotting import scatter_matrix
from matplotlib import pyplot as plt
from twip.constant import DATA_PATH, IMAGES_PATH



def scatmat(df, category=None, colors='rgob',
            num_plots=4, num_topics=100, num_columns=4,
            show=False, block=False, data_path=DATA_PATH, save=False, verbose=1):
    """FIXME: empty plots that dont go away, Plot and/save scatter matrix in groups of num_columns topics"""

    if category is None:
        category = list(df.columns)[-1]
    if category in df.columns:
        category = df[category]
    else:
        category = pd.Series(category)

    suffix = compose_suffix(len(df), num_topics, save)
    save = bool(save)
    for i in range(min(num_plots * num_columns, num_topics) / num_plots):
        scatter_matrix(df[df.columns[i * num_columns:(i + 1) * num_columns]],
                       marker='+', c=[colors[int(x) % len(colors)] for x in category.values],
                       figsize=(18, 12))
        if save:
            name = 'scatmat_topics_{}-{}.jpg'.format(i * num_columns, (i + 1) * num_columns) + suffix
            plt.savefig(os.path.join(data_path, name + '.jpg'))
        if show:
            if block:
                plt.show()
            else:
                plt.show(block=False)



def summarize_topics(f='lsi_topics.json', num_topics=1000, num_tokens=10, column_width=10, do_print=True, justify=True, data_path=DATA_PATH):