fb.k 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // The code is difficult to read;
  2. // feels like there is a lot of scalar indexing code, but perhaps not
  3. // Every function should have a comment describing it
  4. // and ideally illusrate a simple input and output
  5. // Every variable which isn't obvious should be described by a comment
  6. // such as \\ c is circumference of a cirlce radius r
  7. // Given SS are described as sheet of rows by cols of cells likely sheet or cells is a better name
  8. // than table?
  9. // Functions which are long should be split as separate statements
  10. \d u // What is this???
  11. \l utils.k
  12. \d csv // what is this if comment those things which people may not know if not on the same line on a previous line
  13. \l ngnk-libs/csv/csv.k
  14. \d .
  15. \l excelpm.k // what functions are you using
  16. \d .
  17. /helpers can describe them in comments here or have comment with each helper
  18. / e exclusive // what is "exclusive"
  19. slice: {[l;s;e] s_(e)#l}; / brief comment
  20. listize: {1_(,/(";",)'{"(",x,")"}'x)}; // brief comment
  21. split: {[l;di]
  22. idx: (-1,&(di~'l)),(#l); // brief comment
  23. {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))}; // brief comment
  24. s2n: {[s] `i$s;}; // string to number`
  25. parseidx: {core: slice[x;1;#x]; split[core;";"]}; // brief comment what is core?
  26. gi: {[r;c;rb;cb] // what is gi? rb, cb
  27. i: r#(,!c)
  28. i: ((!r)+rb) {x,'y}'(i+cb);
  29. :i
  30. }; // brief comment I don't think functions require a closing ; unless ngnk does?
  31. // decode excel formula
  32. mc: {[c;i] // brief comment
  33. i: gi[(#table);i+1;0;c];
  34. :i
  35. };
  36. mr: {[r;i] // brief comment
  37. i: gi[i+1;(#table[0]);r;0];
  38. :i
  39. };
  40. drr: {[s;e] // brief comment
  41. r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]];
  42. :r
  43. };
  44. dre: {[s;e] // brief comment
  45. :gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]]
  46. };
  47. dr: {[s;e] // decode range
  48. ln: (s[0]<0) | (s[1]<0);
  49. rn: (e[0]<0) | (e[1]<0);
  50. :$[ln|rn;drr[s;e];dre[s;e]] // brief comment
  51. };
  52. dbit: {[b] // brief comment
  53. ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index
  54. ri: (`i$(b@&(pat.test0t9'b)))-49; // row index
  55. ci: $[(#ci)>0;*ci;-1];
  56. ri: $[(#ri)>0;*ri;-1];
  57. :(ri;ci)
  58. };
  59. lr: {[f] // brief comment
  60. ci: *&(":"~'f);
  61. l: slice[f;0;ci];
  62. r: slice[f;ci+1;#f];
  63. lb: dbit[l];
  64. rb: dbit[r];
  65. :(lb;rb);
  66. };
  67. de:{[idx;cell] // brief comment
  68. ci: cell[0];
  69. cell: cell[1];
  70. idx: (*idx); // what is ix
  71. f: slice[cell;idx[0];idx[1]]; // What is f
  72. l: slice[cell;0;idx[0]]; // What is l
  73. r: slice[cell;idx[1];#cell];
  74. u.ppr (l;r); // what is u.ppr
  75. u.ppr table[ci[0];ci[1]];
  76. (fl;fr): lr[f]; // brief comment
  77. r: dr[fl;fr];
  78. i: (ci[0]*3) + ci[1];
  79. {
  80. i:(*y);
  81. i: (i[0]*3)+i[1];
  82. deps[x;i]: 1;
  83. }[(ci[0]*3)+ci[1];]'r;
  84. }; // brief comment
  85. /:parseidx["[1;2]"];
  86. /:split["1;2;3";";"];
  87. tstkey: "States/Events"; / key indicating start of transition section // SS dpn't have States/Events"
  88. cstkey: "Events"; / key indicating start of events condition section
  89. astkey: "Actions"; / key indicating start of actions section
  90. sectionkeys: (tstkey;cstkey;astkey);
  91. lines: {x,"\n",y}/(0: "SS.csv");
  92. table:: csv.csv[lines];
  93. d: (#table)*(#table[0]);
  94. deps:: (d;d)#0; / brief comment
  95. / excel patterns
  96. :pats: pat.run''table;
  97. u.ppr'table;
  98. / u.ppr'pats;
  99. // start with last to maintain prior index accuracy
  100. lasts:{:((#x[0])-1)_x[0]}''pats;
  101. firsts:{:$[(#x[0])>1;((#x[0])-1)#x[0];0]}''pats;
  102. f: pats {
  103. :$[x[2]=5;y;0]
  104. }''lasts;
  105. ti: gi[#table;#table[0];0;0];
  106. table::ti {(,x),,y}''table;
  107. table {
  108. :$[y~0;0;de[y;x]]
  109. }''f; // brief comment
  110. table {
  111. :$[y~0;0;de[y;x]]
  112. }''firsts; // brief comment