|
1 | 1 | // Type Conversion Functions
|
2 |
| -// Copyright (c) 2015 - 2017 Sport Trades Ltd |
| 2 | +// Copyright (c) 2015 - 2020 Sport Trades Ltd |
3 | 3 |
|
4 | 4 | // Documentation: https://github.com/BuaBook/kdb-common/wiki/convert.q
|
5 | 5 |
|
6 | 6 | .require.lib `type;
|
7 | 7 |
|
| 8 | + |
8 | 9 | / @returns (Timespan) The supplied milliseconds in timespan form
|
9 | 10 | .convert.msToTimespan:{
|
10 | 11 | :`timespan$1e6*x;
|
|
53 | 54 | .convert.genericListToString:{[list]
|
54 | 55 | :(raze/) .type.ensureString@/:list;
|
55 | 56 | };
|
| 57 | + |
| 58 | +/ Converts a kdb table into a HTML <table> representation of it |
| 59 | +/ @param tbl (Table) A table with all values of the table convertable to string by '.type.ensureString' |
| 60 | +/ @returns (String) A HTML version of the table |
| 61 | +/ @throws IllegalArgumentException If the parameter is not a table |
| 62 | +/ @throws MixedListColumnsNotSupportedException If any mixed list columns are present in the table |
| 63 | +/ @see .type.ensureString |
| 64 | +.convert.tableToHtml:{[tbl] |
| 65 | + if[not .type.isTable tbl; |
| 66 | + '"IllegalArgumentException"; |
| 67 | + ]; |
| 68 | + |
| 69 | + if[.type.isKeyedTable tbl; |
| 70 | + tbl:0!tbl; |
| 71 | + ]; |
| 72 | + |
| 73 | + badColumns:where .type.isMixedList each .Q.V tbl; |
| 74 | + badColumns:badColumns except where .type.isString each badColumns#first tbl; |
| 75 | + |
| 76 | + if[0 < count badColumns; |
| 77 | + '"MixedListColumnsNotSupportedException (Columns: ",.convert.listToString[badColumns],")"; |
| 78 | + ]; |
| 79 | + |
| 80 | + header:.h.htc[`thead;] .h.htc[`tr;] raze .h.htc[`th;] each .type.ensureString each cols tbl; |
| 81 | + |
| 82 | + body:"\n" sv { .h.htc[`tr;] raze .h.htc[`td;] each .type.ensureString each x } each tbl; |
| 83 | + |
| 84 | + :"\n",.h.htc[`table;] header,"\n",body; |
| 85 | + }; |
| 86 | + |
0 commit comments