SS.k 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. \d u
  2. \l utils.k
  3. \d csv
  4. \l ngnk-libs/csv/csv.k
  5. \d .
  6. \l excelpm.k
  7. \d .
  8. /helpers
  9. / e exclusive
  10. slice: {[l;s;e] s_(e)#l};
  11. listize: {1_(,/(";",)'{"(",x,")"}'x)};
  12. split: {[l;di] idx: (-1,&(di~'l)),(#l); {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))};
  13. s2n: {[s] `i$s;}; // string to number
  14. parseidx: {core: slice[x;1;#x]; split[core;";"]};
  15. gi: {[r;c;rb;cb]
  16. i: r#(,!c)
  17. i: ((!r)+rb) {x,'y}'(i+cb);
  18. :i
  19. };
  20. // decode excel formula
  21. // fill these ==========
  22. mc: {[c;i]
  23. i: gi[(#table);i+1;0;c];
  24. :i
  25. };
  26. mr: {[r;i]
  27. i: gi[i+1;(#table[0]);r;0];
  28. :i
  29. };
  30. // =====================
  31. drr: {[s;e]
  32. r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]];
  33. :r
  34. };
  35. dre: {[s;e]
  36. :gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]]
  37. };
  38. dr: {[s;e] // decode range
  39. ln: (s[0]<0) | (s[1]<0);
  40. rn: (e[0]<0) | (e[1]<0);
  41. :$[ln|rn;drr[s;e];dre[s;e]]
  42. };
  43. dbit: {[b]
  44. ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index
  45. ri: (`i$(b@&(pat.test0t9'b)))-49; // row index
  46. ci: $[(#ci)>0;*ci;-1];
  47. ri: $[(#ri)>0;*ri;-1];
  48. :(ri;ci)
  49. };
  50. lr: {[f]
  51. ci: *&(":"~'f);
  52. l: slice[f;0;ci];
  53. r: slice[f;ci+1;#f];
  54. lb: dbit[l];
  55. rb: dbit[r];
  56. :(lb;rb);
  57. };
  58. de:{[idx;cell]
  59. ci: cell[0];
  60. cell: cell[1];
  61. idx: (*idx);
  62. f: slice[cell;idx[0];idx[1]];
  63. l: slice[cell;0;idx[0]];
  64. r: slice[cell;idx[1];#cell];
  65. (fl;fr): lr[f];
  66. deps[ci[0];ci[1]]:: (1;1);
  67. u.ppr "de: ", f;
  68. u.ppr (fl;fr);
  69. u.ppr'deps;
  70. };
  71. /:parseidx["[1;2]"];
  72. /:split["1;2;3";";"];
  73. tstkey: "States/Events"; / key indicating start of transition section
  74. cstkey: "Events"; / key indicating start of events condition section
  75. astkey: "Actions"; / key indicating start of actions section
  76. sectionkeys: (tstkey;cstkey;astkey);
  77. lines: {x,"\n",y}/(0: "SS.csv");
  78. table:: csv.csv[lines];
  79. deps:: (#table;#table[0])#0;
  80. / excel patterns
  81. pats: pat.run''table;
  82. u.ppr'table;
  83. / u.ppr'pats;
  84. // start with last to maintain prior index accuracy
  85. lasts:{:((#x[0])-1)_x[0]}''pats;
  86. f: pats {
  87. :$[x[2]=5;y;0]
  88. }''lasts;
  89. ti: gi[#table;#table[0];0;0];
  90. table :ti {(,x),,y}''table;
  91. / table {
  92. / :$[y~0;0;de[y;x]]
  93. / }''f