KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy Advanced capstone project exercise 2.4 and 2.5

  • Advanced capstone project exercise 2.4 and 2.5

    Posted by monikagel on October 22, 2023 at 12:00 am

    Hi there,
    I was wondering if I could receive some help regarding my code for the advanced capstone project.

    I am running into issues when trying to implement the error trapping part for the function .f1.checkSensor. I added the code for my version of the function below. In here, mysensordic is a global dictionary I wrote outside the function. While I know this is not the expected practice, it does work and I don’t have any issues when I pass the expected parameters for mysensor variable. I pass all the tests except the ones for error trapping. It also does not work in the code, as it just returns an empty table, so my function does not break when it is supposed to. Could someone please help me figure out where I am going wrong?

    {[raceTab;lapTab;mysensor] if[0b=mysensor in key mysensordic;.Q.trp[{`$(mysensor),” is not a valid option for mysensor – valid options include `temp`tyre`wind`all” }]]; // Get avg benchmark values from historical lap data benchmark: ?[lapTab; enlist(in;`sensorId;(mysensordic;enlist mysensor)); (enlist `sensorId)!enlist `sensorId; (enlist `benchmarkValue)!enlist (avg;`sensorValue)]; chk: ?[raceTab; (enlist(in;`sensorId;(mysensordic;enlist mysensor))); (enlist `sensorId)! enlist `sensorId; `avgValue`stdDevValue!((avg;`sensorValue);(dev;`sensorValue))]; // Join historical benchmarks to new data and calculate diff chk:update diffValue:”F”$.Q.f'[5;abs[benchmarkValue-avgValue]] from benchmark lj chk; // Add flags if difference between old vs new data >1 and if standard deviation>1.5 chk:update diffFlag:?[(diffValue>1);0b;1b], stdFlag:?[(stdDevValue>1.5);0b;1b] from chk; chk }

     

    quizItem success description                                     error

    ———————————————————————————

    exercise2.1 Pass “check if race day in process”        “”

    exercise2.1 Pass “have correct schema”                    “”

    exercise2.2 Pass “check if lap table in process”      “”

    exercise2.2 Pass “only contains data for 2nd Jan 2020” “”

    exercise2.2 Pass “contain all columns for 2nd Jan 2020” “”

    exercise2.3 Pass “not allowed to use select keyword” “”

    exercise 2.3 Pass “return correct values for temp” “”

    exercise2.3 Pass “return correct values for wind”  “”

    exercise2.3 Pass “return correct values for all”      “”

    exercise2.4 Fail “when given the wrong option return error “<mysensor> is not a valid option for mysensor – valid options include `temp`tyre`wind`all”” “”

    exercise2.5 Fail “func should return same result as before” “”

    exercise2.5 Pass “.viz.createDashboard should run in half the time” “”

     

    monikagel replied 9 months, 3 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • megan_mcp

    Administrator
    October 23, 2023 at 12:00 am

    Hi  !

    From what I can see the problem is in line 3. If you replace:

    .Q.trp[{`$(mysensor),

    With:

    'string[mysensor],

    Your function should work fine.

    If you have any other issues please feel free to let me know,

    Megan

  • monikagel

    Member
    October 23, 2023 at 12:00 am

    Hi Megan,

    This did work indeed! Thank you very much for your help.

Log in to reply.