# Path: orangecontrib/spark/utils/data_utils.py
# def pandas_to_orange(df):
#     domain, attributes, metas = construct_domain(df)
#     orange_table = Orange.data.Table.from_numpy(domain = domain, X = df[attributes].values, Y = None, metas = df[metas].values, W = None)
#     return orange_table


from Orange.data import Table
from PyQt4.QtGui import QSizePolicy
from Orange.widgets import widget, gui
from orangecontrib.spark.utils.data_utils import pandas_to_orange
from Orange.widgets import widget, gui, settings
from pyspark import SparkConf, SparkContext
import pandas
import pyspark
__author__ = 'jamh'


class OWSparkToOrange(widget.OWWidget):
    priority = 9
    name = "to Orange"
    description = "Convert Spark dataframe to Orange Table"
    icon = "../icons/spark.png"

    inputs = [("Sparkdf", pyspark.sql.DataFrame, "get_input", widget.Default)]
    outputs = [("Table", Table, widget.Dynamic)]
    settingsHandler = settings.DomainContextHandler()

    NOTHING = "Nothing on input"

    def __init__(self):
        super().__init__()

        gui.label(self.controlArea, self, "Spark->Orange:")
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)

    def get_input(self, obj):

# Path: orangecontrib/spark/utils/data_utils.py
# def pandas_to_orange(df):
#     domain, attributes, metas = construct_domain(df)
#     orange_table = Orange.data.Table.from_numpy(domain = domain, X = df[attributes].values, Y = None, metas = df[metas].values, W = None)
#     return orange_table


# Path: orangecontrib/spark/widgets/data/spark_to_orange.py
from Orange.data import Table
from PyQt4.QtGui import QSizePolicy
from Orange.widgets import widget, gui
from orangecontrib.spark.utils.data_utils import pandas_to_orange
from Orange.widgets import widget, gui, settings
from pyspark import SparkConf, SparkContext
import pandas
import pyspark

__author__ = 'jamh'


class OWSparkToOrange(widget.OWWidget):
    priority = 9
    name = "to Orange"
    description = "Convert Spark dataframe to Orange Table"
    icon = "../icons/spark.png"

    inputs = [("Sparkdf", pyspark.sql.DataFrame, "get_input", widget.Default)]
    outputs = [("Table", Table, widget.Dynamic)]
    settingsHandler = settings.DomainContextHandler()

    NOTHING = "Nothing on input"

    def __init__(self):
        super().__init__()

        gui.label(self.controlArea, self, "Spark->Orange:")
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)

    def get_input(self, obj):

        df = obj.toPandas()