from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

#from __future__ import print_function
from .statements import *

nu = datetime.datetime.now()

class InteractiveChartTest(TestCase):
    def setUp(self):
        redis_connection.publish('tasks','KILL')
        u = User.objects.create_user('john',
                                     'sander@ds.ds',
                                     'koeinsloot')
        r = Rower.objects.create(user=u,gdproptin=True,surveydone=True,
                                 gdproptindate=timezone.now()
        )
        self.nu = datetime.datetime.now()

        self.filename = 'rowers/tests/testdata/testdata.csv'
        self.wotw = Workout.objects.create(name='testworkout',
                                        workouttype='water',
                                        user=r,date=self.nu.strftime('%Y-%m-%d'),
                                        starttime=self.nu.strftime('%H:%M:%S'),
                                        duration="0:55:00",distance=8000,
                                        csvfilename=self.filename)

        self.wote = Workout.objects.create(name='testworkout',
                                        workouttype='Indoor Rower',
                                        user=r,date=self.nu.strftime('%Y-%m-%d'),
                                        starttime=self.nu.strftime('%H:%M:%S'),
                                        duration="0:55:00",distance=8000,
                                        csvfilename=self.filename)


    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    def test_painsled(self, mocked_sqlalchemy, mocked_read_df_sql):
        u = User.objects.get(username='john')
        r = Rower.objects.get(user=u)

        rr = rrower(hrmax=r.max,hrut2=r.ut2,
                    hrut1=r.ut1,hrat=r.at,
                    hrtr=r.tr,hran=r.an,ftp=r.ftp)
        row = rdata(self.filename,rower=rr)

        fig1 = plots.mkplot(row,'test')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart1(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_chart(self.wote.id)

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart2(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_chart(self.wote.id,promember=1)

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    def test_interactive_chart3(self, mocked_sqlalchemy,mocked_read_df_sql):
        res = iplots.interactive_bar_chart(self.wote.id)

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    def test_interactive_chart4(self, mocked_sqlalchemy,mocked_read_df_sql):
        res = iplots.interactive_bar_chart(self.wote.id,promember=1)

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    def test_interactive_chart5(self, mocked_sqlalchemy,mocked_read_df_sql):
        res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
                                             xparam='time',
                                             yparam1='pace',yparam2='hr')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    def test_interactive_chart6(self, mocked_sqlalchemy,mocked_read_df_sql):
        res = iplots.interactive_flex_chart2(self.wote.id,
                                             promember=0,xparam='distance',
                                             yparam1='pace',yparam2='hr')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart7(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,promember=0,
                                             xparam='time',
                                             yparam1='pace',yparam2='spm')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart8(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,
                                             promember=0,xparam='distance',
                                             yparam1='pace',yparam2='spm')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart9(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,
                                             promember=1,xparam='time',
                                             yparam1='pace',yparam2='hr')
    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart10(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,
                                             promember=1,xparam='distance',
                                             yparam1='pace',yparam2='hr')
    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart11(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,
                                             promember=1,xparam='time',
                                             yparam1='pace',yparam2='spm')

    @patch('rowers.dataprep.create_engine')
    @patch('rowers.dataprep.read_df_sql')
    @patch('rowers.dataprep.getsmallrowdata_db',side_effect=mocked_getsmallrowdata_db)
    def test_interactive_chart12(self, mocked_sqlalchemy,mocked_read_df_sql,
                                mocked_getsmallrowdata_db):
        res = iplots.interactive_flex_chart2(self.wote.id,promember=1,
                                             xparam='distance',
                                             yparam1='pace',yparam2='spm')
