cancel
Showing results for 
Search instead for 
Did you mean: 

PyKX Project - Netflix - Exercise 3

Utsav
New Contributor

Problem - 

### Exercise 3

Create a new table called `nonEngViews` containing the most viewed non-english film or tv series.
Save the table as a variable in the q memory space called `nonEngViews`.

 

Tried Solutions - 

1. Return a single record in output having a tv show or movie with max number of views

nonEngViews = kx.q.qsql.select(views, where=['language<>`english','viewsMillion=max viewsMillion'])
kx.q["nonEngViews"] = nonEngViews
nonEngViews

pykx.Table(pykx.q('
title     category language viewsMillion
----------------------------------------
squidGame tv       korean   142         
'))

2. Return two records in output having a tv show and movie with max number of views

nonEngViews = kx.q('select from viewtab where language<>`english, viewsMillion = (max;viewsMillion) fby category')
nonEngViews = kx.q.qsql.select(views, where=['language<>`english', 'viewsMillion = (max;viewsMillion) fby category'])

kx.q["nonEngViews"] = nonEngViews
nonEngViews

pykx.Table(pykx.q('
title       category language   viewsMillion
--------------------------------------------
squidGame   tv       korean     142         
thePlatform film     portuguese 56          
'))

Test case 3 is failing - 

pykx.Table(pykx.q('
quizItem  success description                                         error
---------------------------------------------------------------------------
exercise3 Pass    "nonEngViews exists in q memory space"              ""   
exercise3 Pass    "nonEngViews should be a q table"                   ""   
exercise3 Fail    "nonEngViews should have correct number of records" ""   
'))

 

4 REPLIES 4

megan_mcp
Community Manager Community Manager
Community Manager

Hi @Utsav,

Thank you for bringing this to our attention. As it stands, the test case looks for the top 10 records and we understand it does not ask this in the question which is leading us to review and update this so that the wording of the question is accurate.

Sorry for the inconvenience,

Megan

Utsav
New Contributor

Thanks for looking into it, megan_mcp.

I can confirm that returning 10 records is solving the issue.

pykx.Table(pykx.q('
quizItem  success description                                         error
---------------------------------------------------------------------------
exercise3 Pass    "nonEngViews exists in q memory space"              ""   
exercise3 Pass    "nonEngViews should be a q table"                   ""   
exercise3 Pass    "nonEngViews should have correct number of records" ""   
'))


However, there is another issue with the notebook -
After all the test cases have been passed when I'm trying to submit answers using 
kx.q("submitAnswers[]")

It is resulting in bellow error - 

---------------------------------------------------------------------------
QError                                    Traceback (most recent call last)
Cell In [5], line 1
----> 1 kx.q("submitAnswers[]")

File /opt/conda/lib/python3.10/site-packages/pykx/embedded_q.py:221, in EmbeddedQ.__call__(self, query, wait, sync, *args)
    219 result = _keval(bytes(wrappers.CharVector(query)), *[wrappers.K(x) for x in args])
    220 if wait is None or wait:
--> 221     return factory(result, False)
    222 return self('::', wait=True)

File /opt/conda/lib/python3.10/site-packages/pykx/_wrappers.pyx:500, in pykx._wrappers._factory()

File /opt/conda/lib/python3.10/site-packages/pykx/_wrappers.pyx:493, in pykx._wrappers.factory()

QError: Please ensure all tests passed before submitting. Not submitted.


Here are all the passed test cases - 

pykx.Table(pykx.q('
quizItem  success description                        error
----------------------------------------------------------
exercise1 Pass    "viewtab exists in q memory space" ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                        error
--------------------------------------------------------------------------
exercise2 Pass    "englishTV exists in q memory space"               ""   
exercise2 Pass    "englishTV should be a python array structure"     ""   
exercise2 Pass    "englishTV should have correct number of TV shows" ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                         error
---------------------------------------------------------------------------
exercise3 Pass    "nonEngViews exists in q memory space"              ""   
exercise3 Pass    "nonEngViews should be a q table"                   ""   
exercise3 Pass    "nonEngViews should have correct number of records" ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                    error
----------------------------------------------------------------------
exercise4 Pass    "totals exists in q memory space"              ""   
exercise4 Pass    "totals should be a q keyed table"             ""   
exercise4 Pass    "totals should have correct number of records" ""   
exercise4 Pass    "totals should have correct results"           ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                          error
----------------------------------------------------------------------------
exercise5 Pass    "summaryViews exists in q memory space"              ""   
exercise5 Pass    "summaryViews should be a q keyed table"             ""   
exercise5 Pass    "summaryViews should have correct number of records" ""   
exercise5 Pass    "summaryViews should have correct columns"           ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                   error
---------------------------------------------------------------------
exercise6 Pass    "category of tv no longer exists in viewtab"  ""   
exercise6 Pass    "records previously tv now updated to series" ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                             error
-------------------------------------------------------------------------------
exercise7 Pass    "views less than 60million no longer exists in viewtab" ""   
'))
pykx.Table(pykx.q('
quizItem  success description                                         error
---------------------------------------------------------------------------
exercise8 Pass    "sortedViews exists in q memory space"              ""   
exercise8 Pass    "sortedViews should be a q table"                   ""   
exercise8 Pass    "sortedViews should have correct number of records" ""   
exercise8 Pass    "sortedViews should have correct columns"           ""   
'))

 

kdbguru
New Contributor II
New Contributor II

Hi Utsav,

Is the issue resolved? Or are you still waiting?

Utsav
New Contributor

Thanks for looking into it, kdbguru.
The issue has been resolved now.