2021.03.15 12:32 PM
q)requests:((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))
I then have a function that creates all dates in between the start date and end date, then fills a table:
q)fillDates:{[a;b;c;d] f:a + til (b - a) + 1;([]Date:`date$(f);CrewID:`int$(c);Status:`symbol$(d))}
q)fillDates[2021.06.07;2021.06.09;53696;`Sent]
Date CrewID Status
------------------------
2021.06.07 53696 Sent
2021.06.08 53696 Sent
2021.06.09 53696 Sent
Where I am having difficulty is trying to process all items in the requests list, something like:
fillDates[ ] each requests
Such that the result would look like this:
Date CrewID Status
------------------------
2021.06.07 53696 Sent
2021.06.08 53696 Sent
2021.06.09 53696 Sent
2021.06.12 81840 Sent
2021.06.13 81840 Sent
2021.06.14 81840 Sent
When I try:
q)fillDates[requests]
{[a;b;c;d] f:a + til (b - a) + 1;([]Date:`date$(f);CrewID:`int$(c);Status:`symbol$(d))}[((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))]
q)type fillDates[requests]
104h
I get a projection of the function and I am not sure how to proceed.
I would be grateful if somebody could point out a better way than my tortured approach.
Many thanks
Dean
2021.03.15 01:19 PM
You want . (index/apply)
https://code.kx.com/q/ref/apply/
and /: (each-right)
https://code.kx.com/q/ref/maps/
and raze
https://code.kx.com/q/ref/raze/
Combining these three to end up with:
q)requests:((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))
q)fillDates:{[a;b;c;d] f:a + til (b - a) + 1;([]Date:`date$(f);CrewID:`int$(c);Status:`symbol$(d))}
q)raze fillDates ./: requests
Date CrewID Status
------------------------
2021.06.07 53696 Sent
2021.06.08 53696 Sent
2021.06.09 53696 Sent
2021.06.12 81840 Sent
2021.06.13 81840 Sent
2021.06.14 81840 Sent
q)
From: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com]
On Behalf Of Dean Williams
Sent: Monday, March 15, 2021 12:33 PM
To: Kdb+ Personal Developers <personal-kdbplus@googlegroups.com>
Subject: [personal kdb+] Function within a function
CAUTION: External email. Do not click links or open attachments unless you recognize the sender and know the content is safe.
I am struggling with how to map a list into a function.
Each item in the list, consists of a start date, end date, int and symbol.
q)requests:((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))
I then have a function that creates all dates in between the start date and end date, then fills a table:
q)fillDates:{[a;b;c;d] f:a + til (b - a) + 1;([]Date:`date$(f);CrewID:`int$(c);Status:`symbol$(d))}
q)fillDates[2021.06.07;2021.06.09;53696;`Sent]
Date CrewID Status
------------------------
2021.06.07 53696 Sent
2021.06.08 53696 Sent
2021.06.09 53696 Sent
Where I am having difficulty is trying to process all items in the requests list, something like:
fillDates[ ] each requests
Such that the result would look like this:
Date CrewID Status
------------------------
2021.06.07 53696 Sent
2021.06.08 53696 Sent
2021.06.09 53696 Sent
2021.06.12 81840 Sent
2021.06.13 81840 Sent
2021.06.14 81840 Sent
When I try:
q)fillDates[requests]
{[a;b;c;d] f:a + til (b - a) + 1;([]Date:`date$(f);CrewID:`int$(c);Status:`symbol$(d))}[((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))]
q)type fillDates[requests]
104h
I get a projection of the function and I am not sure how to proceed.
I would be grateful if somebody could point out a better way than my tortured approach.
Many thanks
Dean
--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
personal-kdbplus+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/personal-kdbplus/f055dbdc-0b3b-426c-8c07-2a42c29fb26dn%40googlegr....
2021.03.15 01:25 PM
2021.03.15 01:47 PM
2021.03.15 02:17 PM
requests:1000000#((2021.06.07;2021.06.09;53696;`Sent);(2021.06.12;2021.06.14;81840;`Sent))
\t a:raze fillDates ./: requests
2346
fillDates2:{[a;b;c;d]dt:a+til each 1+b-a;cnt:count each dt;data:raze each(dt;cnt#'c;cnt#'d);([]Date:data 0;CrewID:`int$data 1;Status:data 2)}
\t b:fillDates2 . flip requests
1215
a~b
1b
2021.03.15 05:51 PM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.