KX Community

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

Home Forums KX Academy Advanced Capstone 2.4

  • Advanced Capstone 2.4

    Posted by moshe-hamaoui on June 6, 2024 at 11:11 pm

    Hello,

    I have the function working properly, and the error output (in an orange banner) identical to what the question and section test dictate, but I’m still failing the second test 2.4.

    See attached screenshot.

    Thank you

    moshe-hamaoui replied 5 months, 2 weeks ago 2 Members · 4 Replies
  • 4 Replies
  • megan_mcp

    Administrator
    June 7, 2024 at 10:18 am

    Hi @moshe-hamaoui

    Your error message seems to be correct.

    Can you send me your full .f1.checkSensor function in normal text (without the code tag)?

    Thanks,

    Megan

    • moshe-hamaoui

      Member
      June 7, 2024 at 3:33 pm

      Certainly! See below:

      (One thing I would like to add, btw, is that 2.3 specifically instructs which lines need to be modified, but does not include changing the join from a left to an inner, a requirement to pass two of the 2.3 tests.)

      I apologize for the formatting. I don’t know why it pasted like that.

      // @fileOverview A function to check the results against average benchmark results to see if the results are within a cetain threshold

      // @param raceTab {table} A table that has columns sensorIdtimelapIdunitssensorValuesession

      // @param lapTable {table} A table that has columns datesensorIdsessionlapIdtimeendTimesensorValue

      // @returns {table} Aggregated sensor values per lap derived using window join

      {[raceTab;lapTab;mysensor]

      // Create dictionary mapping

      sensorDict:temptyrewindall!("temp*";"tyre*";"wind*";"*");

      sensorFilter:sensorDict[mysensor];

      // Error trap

      if[0b=mysensor in key sensorDict;'string[mysensor], " is not a valid option for mysensor – valid options includetemptyrewindall" ];

      // Get avg benchmark values from historical lap data

      benchmark: ?[lapTab;();enlist[sensorId]!enlist[sensorId];(enlist[benchmarkValue])!enlist(avg;sensorValue)];

      // Calculate avg value as well as standard deviation from new sensor data (from raceTab)

      chk: ?[raceTab;enlist(like;sensorId;(enlist sensorFilter));enlist[sensorId]!enlist[sensorId];avgValuestdDevValue!((avg;sensorValue);(dev;sensorValue))];

      // Get avg benchmark values from historical lap data // THESE

      // benchmark:select benchmarkValue:avg sensorValue by sensorId from lapTab; // LINES

      // Calculate avg value as well as standard deviation from new sensor data (from raceTab) // TO BE

      // chk:select avgValue:avg sensorValue, // REPLACED

      // stdDevValue:dev sensorValue // IN .f1.checkSensorFunc

      // by sensorId from raceTab; // INTO THEIR FUNCTIONAL FORM

      // Join historical benchmarks to new data and calculate diff

      chk:update diffValue:”F”$.Q.f'[5;abs[benchmarkValue-avgValue]]

      from benchmark ij 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

      }

      // REPLACE LINES 6-11 from .f1.checkSensor

      // 1. Define dictionary of mapping of mysensor options

      // | temp | sensorId’s like “temp*” |

      // | tyre | sensorId’s like “tyre*” |

      // | wind | sensorId’s like “wind*” |

      // | all | all sensorId’s in table |

      // 2. Define variable sensorFilter as value from dictionary in 1 – will be variable depending on mysensor

      // 3. Functional form of select for line #7 in .f1.checkSensor (HINT – https://code.kx.com/q/ref/parse/#qsql) passing sensorFilter as a new where constraint

      // 4. Functional form of select for lines #9-11 in .f1.checkSensor again passing sensorFilter as a new where constraint

      // Function will take third @param mysensor {symbol} One of the following: temptyrewindall

      • megan_mcp

        Administrator
        June 10, 2024 at 1:47 pm

        Hi @moshe-hamaoui

        I have sourced the issue and apologies that it is so minor.

        When I tested your code, I was receiving the error you had mentioned above however when I replaced the message with one that is provided in the project file, the test case passed.

        I believe it was the format of the hyphen that caused this issue.

        As you can see in screenshot_1 (provided below) the hyphen used in your code is slightly thinner than the hyphen used in the message provided (screenshot_2).

        The test case must have picked up as a different character, hence why the test case failed.

        If you have any further questions please let me know.

        Thanks,

        Megan

  • moshe-hamaoui

    Member
    June 10, 2024 at 2:07 pm

    Megan,

    Thank you very much!

    – Moshe

Log in to reply.