Home › Forums › KX Academy › Advanced Capstone 2.4
-
Advanced Capstone 2.4
Posted by moshe-hamaoui on June 6, 2024 at 11:11 pmHello,
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
-
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
-
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
sensorId
timelapId
unitssensorValue
session// @param lapTable {table} A table that has columns
date
sensorIdsession
lapIdtime
endTimesensorValue
// @returns {table} Aggregated sensor values per lap derived using window join
{[raceTab;lapTab;mysensor]
// Create dictionary mapping
sensorDict:temp
tyre
windall!("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 includetemp
tyre
windall" ];
// 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];avgValue
stdDevValue!((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:
temp
tyrewind
allcode.kx.com
parse | Reference | kdb+ and q documentation - kdb+ and q documentation
parse is a q keyword that returns a parse tree for a string expression.
-
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
-
-
Log in to reply.