"text": "# Condition construction\n\n### General Condition\n```\nCondition =\n IndexCondition -> conditions on the row index\n|| RecursiveCondition -> (set of) conditions on column values\n```\n\n### IndexCondition\n```\nIndexCondition =\n rowIndex:number -> true if row index matches\n```\n\n### RecursiveCondition\n```\nRecursiveCondition =\n OrCondition -> OR: true if any compound condition is true\n|| AndCondition -> AND: true if all compound conditions are true\n\nOrCondition = -> OR: true if\n AndCondition[] -> any of the AndConditions are true\n|| IndexCondition[] -> any of thr IndexConditions are true\n\nAndCondition = -> AND: true if\n SetAndCondition -> all SetAndConditions are true\n|| TermAndCondition -> or if all TermAndConditions are true\n\nSetAndCondition = { -> AND: true if all sub-conditions are true\n 'or': RecursiveCondition -> true if any RecursiveCondition is true\n|| 'and': RecursiveCondition -> true if all RecursiveCondition are true\n|| 'not': RecursiveCondition -> true if the condition is false\n\nTermAndCondition = { -> Terminal AND: true if all terminal sub-conditions are true\n colDesc:colValue -> true if colValue matches\n|| colDesc:[colValue, ...] -> true if any of the colValues match\n|| colDesc:function(value,row) -> true if function returns true\n}\n\ncolDesc = either column name or index\n```\n\n### Practical Tips\n```\n {'or': [recurCond, ...]} -> OR, same as [recurCond, ...]\n|| {'or': {SetCond, ...}} -> OR, same as [SetCond, ...]\n|| {'and': [recurCond, ...]} -> AND, true if all recurCond are true\n|| {'and': {SetCond, ...}} -> AND, same as {SetCond, ...}\n|| {'not': {SetCond, ...}} -> NAND: true if the SetCond are true\n|| {'not': [recurCond, ...]} -> NOR: true if any of the recurCond are true\n```\n\n# Example\n<example height=1000px libs={hsDatab:hsDatab}>\n<file name=\"script.js\">\nconst colNames = ['Name', 'Value', 'Start', 'End'];\nconst rows = [\n ['Harry', '100', '3/1/14', '11/20/14'],\n ['Mary', '1500', '7/1/14', '9/30/14'],\n ['Peter', '400', '5/20/14', '4/30/15'],\n ['Jane', '700', '11/13/14', '8/15/15']\n]\nconst data = new hsDatab.Data({colNames:colNames, rows:rows});\n\nqueries = [\n ['0', undefined, 'undefined query => pass all'],\n ['1', [], 'empty OR: [] => fail all'],\n ['2', {}, 'empty AND: {} => pass all'],\n ['3', 1, '2nd row: pass row 1'],\n ['4', [1,3], '2nd+4th: pass rows: 1 and 3'],\n ['5', {Name:\"Jane\"}, 'Name is Jane'],\n ['6', {1:1500}, 'Column 2 is 1500'],\n ['7', {Name:[\"Peter\", \"Jane\"]}, 'Name is Peter or Jane'],\n ['8', [{Name:\"Peter\"}, {Value:1500}], 'Name is Peter or Value is 1500'],\n ['9', {or:{Name:\"Peter\", Value:1500}}, 'OR: same as 8:'],\n ['A', {or:[{Name:\"Peter\"}, {Value:1500}]}, 'OR: [{Name is Peter}, {Value is 1500}]'],\n ['B', {Name:\"Peter\", Value:400}, 'Name is Peter and Value is 400'],\n ['C', {and:{Name:\"Peter\", Value:400}}, 'AND: {Name is Peter, Value is 400}'],\n ['D', {and:{Name:\"Peter\", Value:1500}}, 'AND: {Name is Peter, Value is 1500}'],\n ['E', {and:[{Name:\"Peter\"}, {Value:400}]}, 'AND:[{Name is Peter}, {Value is 400}]'],\n ['F', {and:[{Name:\"Peter\"}, {Value:1500}]},'AND:[{Name is Peter}, {Value is 1500}]'],\n ['G', {not:{Name:\"Peter\", Value:400}}, 'NAND: not {Name is Peter and Value is 400}'],\n ['H', {not:{Name:\"Peter\", Value:1500}}, 'NAND: not {Name is Peter and Value is 1500}'],\n ['I', {not:[{Name:\"Peter\"}, {Value:1500}]},'NOR: not [{Name is Peter} or {Value is 1500}]'],\n ['J', {Name:(v) => v.length===4}, 'Name has 4 letters']\n];\n\nm.mount(root, {\n view:() => m('', [\n m('h3', 'Given the data set:'),\n m('table#data', [\n m('tr', colNames.map(n => m('th', n))),\n ...rows.map(row => m('tr', [m('td', row[0]),m('td', row[1]),m('td', row[2].toDateString()),m('td', row[3].toDateString())]))\n ]),\n m('h3', 'The following queries yield:'),\n m('table', [\n m('tr', [m('th','#'), m('th','Query'), m('th',\"Live Result, by 'Name' field\")]),\n ...queries.map(q => {\n const result = data.filter(q[1]).getColumn('Name').join(', ');\n return m('tr', [m('td',`${q[0]}:`), m('td',`${q[2]}`), m('td',`[ ${result} ]`)]);\n })\n ])\n ])\n});\n</file>\n<file name='style.css'>\n $exampleID { height: 600px; }\n #data th { width:15%; }\n table {\n font-size: 10pt;\n margin-left: 10px;\n }\n</file>\n</example>\n"
0 commit comments