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 Reply To: Advanced Capstone 2.4

  • 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