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 *


class EmpowerTest(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,rowerplan='coach',gdproptin=True,surveydone=True,
                                 gdproptindate=timezone.now())
        self.c = Client()

        self.nu = datetime.datetime.now()
        filename = 'rowers/tests/testdata/testdata.csv'
        otwfilename = 'rowers/tests/testdata/empower.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=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=otwfilename)

        powerperc = 100*np.array([r.pw_ut2,
                                  r.pw_ut1,
                                  r.pw_at,
                                  r.pw_tr,r.pw_an])/r.ftp


        self.hrdata = {
            'hrmax':r.max,
            'hrut2':r.ut2,
            'hrut1':r.ut1,
            'hrat':r.at,
            'hrtr':r.tr,
            'hran':r.an,
            'ftp':r.ftp,
            'powerperc':serialize_list(powerperc),
            'powerzones':serialize_list(r.powerzones),
        }

    @patch('rowers.dataprep.create_engine')
    def test_workflow_map_view(self, mocked_sqlalchemy):
        login = self.c.login(username='john',password='koeinsloot')
        self.assertTrue(login)
        encodedid = str(encoder.encode_hex(self.wote.id))

        url = '/rowers/workout/{id}/workflow/'.format(
            id = encodedid
            )

        response = self.c.get(url)

        self.assertEqual(response.status_code, 200)
