Home › Forums › KX Academy › Advanced Capstone 2.4 › Reply To: Advanced Capstone 2.4
-
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
all-
This reply was modified 3 months ago by
moshe-hamaoui.
code.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.
-
This reply was modified 3 months ago by