Skip to content

Instantly share code, notes, and snippets.

@mdimai666
Created April 18, 2018 07:53
Show Gist options
  • Save mdimai666/ecc44e12a62f5eb919b55271ad5b6212 to your computer and use it in GitHub Desktop.
Save mdimai666/ecc44e12a62f5eb919b55271ad5b6212 to your computer and use it in GitHub Desktop.
[
{
"id": "82919dfb.c477c",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "",
"topic": "",
"payload": "ARR",
"payloadType": "global",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 114,
"y": 63,
"wires": [
[
"d5ef454e.f48808"
]
]
},
{
"id": "387fc19.413213e",
"type": "sqldbs",
"z": "826a56c3.fa3198",
"mydb": "c260e1e9.519d1",
"querytype": "select",
"name": "",
"x": 802,
"y": 65,
"wires": [
[
"6ab70642.e27f78"
]
]
},
{
"id": "f180cb11.4c1e58",
"type": "template",
"z": "826a56c3.fa3198",
"name": "complete",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Complete {{payload}} : {{duraliration}}!",
"output": "str",
"x": 585,
"y": 125,
"wires": [
[
"766eb528.ae303c",
"89357019.76d13"
]
]
},
{
"id": "766eb528.ae303c",
"type": "debug",
"z": "826a56c3.fa3198",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 762,
"y": 197,
"wires": []
},
{
"id": "f9232501.b2ed78",
"type": "function",
"z": "826a56c3.fa3198",
"name": "",
"func": "let ZZ = 1000;\n\n//uuid генератор\nvar uuid = global.get('uuid');\n//safe stringify OBJ to JSON\nvar jj = global.get('jj');\n\n//это массив из слов случайных\nlet arr = msg.payload;\n\n//получение случайного объекта\nlet sql = '';\nsql+= getSQLtext(); //1\n\n// msg.payload = sql;\nvar aSql = [];\nfor(var i=0;i<ZZ;i++)\n aSql.push(getSQL(E())); //1\n // aSql.push(getSQL2(E())); //2\n \nsql = sql + aSql.join(','); //1\n// sql = sql + aSql.join('\\n'); //2\n \nreturn {payload: sql};\n\n\nfunction R(n){\n return Math.random()*n | 0;\n}\n\nfunction Rf(arr,s1,s2){\n let len = R(s2-s1)+s1;\n let pos = R(arr.length-len);\n return arr.slice(pos,pos+len).join(' ');\n}\n\nfunction E(){\n let e = {\n code: R(50),\n type: R(100),\n source: Rf(arr,2),\n title: Rf(arr,2,6),\n deleted: false,\n checked: false,\n body: Rf(arr,10,30),\n json: {a:1, b:2},\n uid: uuid(),\n }\n return e;\n}\n\nfunction getSQLtext(){\n let sql = `INSERT INTO list (code,type,source,title,deleted,checked,body,json,uid) VALUES `;\n return sql;\n}\n\nfunction ojo(e){\n let a = [e.code,\n e.type,\n e.source,\n e.title,\n e.deleted,\n e.checked,\n e.body,\n jj(e.json),\n e.uid];\n a = a.map(s=>`'${s}'`).join(',');\n return a;\n}\n\nfunction getSQL(e){\n let sql = ``;\n let a = ojo(e);\n sql+=`(${a})`;\n return sql;\n}\n\nfunction getSQL2(e){\n let sql = getSQLtext();\n let a = ojo(e);\n sql+=`(${a});`;\n return sql;\n}\n\n// id serial NOT NULL,\n// code integer DEFAULT 0,\n// type integer DEFAULT 0,\n// source character varying(255),\n// title character varying(255),\n// deleted boolean DEFAULT false,\n// checked boolean DEFAULT false,\n// body text,\n// json json,\n// dt_insert timestamp with time zone DEFAULT now(),\n// dt_checked timestamp with time zone DEFAULT now(),\n// screenshot character varying(255),\n// uid uuid,",
"outputs": 1,
"noerr": 0,
"x": 434,
"y": 64,
"wires": [
[
"b289ff2c.79484"
]
]
},
{
"id": "5ba0062e.ecb2d8",
"type": "function",
"z": "826a56c3.fa3198",
"name": "gen textas array",
"func": "var rtext = msg.payload.text;\nif(!rtext) return node.error('PAYLOAD is emty');\n\nrtext = (rtext+'').split(/[ ,.-]+/);\n\n\n\n\nfunction R(n){\n return Math.random()*n | 0;\n}\n\nmsg.payload= rtext;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 380,
"y": 750,
"wires": [
[
"a44371a8.78997",
"22f5895.d4e7076"
]
]
},
{
"id": "97425a28.8e1258",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "get random text",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 148,
"y": 692,
"wires": [
[
"276c9af.3fd7366"
]
]
},
{
"id": "8c0f8ccd.bd493",
"type": "http request",
"z": "826a56c3.fa3198",
"name": "$post",
"method": "POST",
"ret": "txt",
"url": "",
"tls": "",
"x": 478.5,
"y": 686,
"wires": [
[
"eaffa7e9.c17ec8"
]
]
},
{
"id": "276c9af.3fd7366",
"type": "function",
"z": "826a56c3.fa3198",
"name": "random url",
"func": "msg.url = 'http://randomtextgenerator.com/';\n\nmsg.payload = {\n text_mode: 'plain',\n language:'en',\n Go:'Go'\n}\nmsg.headers = {'Accept-Language':'en'};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 326,
"y": 690,
"wires": [
[
"8c0f8ccd.bd493"
]
]
},
{
"id": "a44371a8.78997",
"type": "debug",
"z": "826a56c3.fa3198",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"x": 593,
"y": 751,
"wires": []
},
{
"id": "966c4d93.297ec",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "text generate function",
"topic": "",
"payload": "ahefui hahfp adfjoaejf opaef",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 164,
"y": 746,
"wires": [
[
"5ba0062e.ecb2d8"
]
]
},
{
"id": "eaffa7e9.c17ec8",
"type": "cheerio",
"z": "826a56c3.fa3198",
"name": "",
"tag": "body",
"ret": "object",
"as": "multi",
"map": [
{
"search": "#generatedtext",
"ret": "text",
"replace": "text",
"attr": ""
}
],
"xmlMode": false,
"decodeEntities": false,
"lowerCaseTags": false,
"lowerCaseAttributeNames": false,
"recognizeCDATA": false,
"recognizeSelfClosing": false,
"x": 605,
"y": 685,
"wires": [
[
"5ba0062e.ecb2d8"
]
]
},
{
"id": "45a0ed9a.b31684",
"type": "comment",
"z": "826a56c3.fa3198",
"name": "generate emails",
"info": "",
"x": 129,
"y": 604,
"wires": []
},
{
"id": "d5ef454e.f48808",
"type": "function",
"z": "826a56c3.fa3198",
"name": "x10",
"func": "let ZZ = 100;\nlet ZZc = ZZ;\nlet startTime = new Date();\nmsg.startTime = startTime;\nmsg.count = 0;\nmsg.max = ZZc;\nZ();\n\nlet task1 = {\n count: ZZc,\n index: 0,\n startTime:startTime,\n}\n\nflow.set('task1', task1);\n\nfunction Z(){\n ZZ--;\n if(ZZ<1) return complete();\n setTimeout(Z,5);\n node.send([msg,null]);\n let p = ZZc-ZZ+1;\n \n if((new Date()) - startTime > 250){\n node.status({text:`${p}/${ZZc}`});\n startTime = new Date();\n }\n}\n\nfunction complete(){\n let dt = (new Date() - startTime)/1000;\n node.status({text:`${ZZc}/${ZZc} : ${dt}s`});\n node.send([null,msg]); \n}\n\nreturn msg;",
"outputs": 2,
"noerr": 0,
"x": 274,
"y": 72,
"wires": [
[
"f9232501.b2ed78"
],
[
"42394e52.6ba6a"
]
]
},
{
"id": "6f4b41a4.1d5b4",
"type": "sqldbs",
"z": "826a56c3.fa3198",
"mydb": "c260e1e9.519d1",
"querytype": "select",
"name": "",
"x": 509,
"y": 248,
"wires": [
[
"2345e4fe.6dae0c"
]
]
},
{
"id": "42394e52.6ba6a",
"type": "template",
"z": "826a56c3.fa3198",
"name": "",
"field": "topic",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "SELECT reltuples::bigint AS count FROM pg_class where relname='list';",
"output": "str",
"x": 436,
"y": 270,
"wires": [
[
"6f4b41a4.1d5b4"
]
]
},
{
"id": "2345e4fe.6dae0c",
"type": "change",
"z": "826a56c3.fa3198",
"name": "[0][0]",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload[0][0].count",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 595,
"y": 265,
"wires": [
[
"8672d38e.9352"
]
]
},
{
"id": "b2f1f1a5.7ed76",
"type": "file",
"z": "826a56c3.fa3198",
"name": "",
"filename": "C:\\\\tmp\\\\randomtext\\\\randomtext.txt",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"x": 661,
"y": 842,
"wires": []
},
{
"id": "22f5895.d4e7076",
"type": "function",
"z": "826a56c3.fa3198",
"name": "msg.",
"func": "msg.payload = msg.payload.join(' ');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 424,
"y": 835,
"wires": [
[
"b2f1f1a5.7ed76"
]
]
},
{
"id": "979241e5.6d807",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 154,
"y": 1002,
"wires": [
[
"f737add1.fd578"
]
]
},
{
"id": "f737add1.fd578",
"type": "template",
"z": "826a56c3.fa3198",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "df daf a\nadsf daf\n\nzxzx zx\n\n\n\nvxbxvb",
"output": "str",
"x": 373,
"y": 1004,
"wires": [
[]
]
},
{
"id": "bc8edcd8.0d79e",
"type": "debug",
"z": "826a56c3.fa3198",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 666,
"y": 996,
"wires": []
},
{
"id": "4c5a66fd.29f338",
"type": "file in",
"z": "826a56c3.fa3198",
"name": "txt",
"filename": "C:\\\\tmp\\\\randomtext\\\\randomtext.txt",
"format": "utf8",
"chunk": false,
"sendError": false,
"x": 161,
"y": 880,
"wires": [
[
"4a7d6f92.f9d6c"
]
]
},
{
"id": "4a7d6f92.f9d6c",
"type": "function",
"z": "826a56c3.fa3198",
"name": "join \\s",
"func": "msg.payload = msg.payload.split(/\\s/);//.join(' ');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 276.5,
"y": 912,
"wires": [
[
"bb6b2448.e943c8"
]
]
},
{
"id": "d056b367.51727",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "set global ARR",
"topic": "",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 111,
"y": 829,
"wires": [
[
"4c5a66fd.29f338"
]
]
},
{
"id": "bb6b2448.e943c8",
"type": "function",
"z": "826a56c3.fa3198",
"name": "se tglobal arr",
"func": "global.set('ARR',msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 419,
"y": 926,
"wires": [
[]
]
},
{
"id": "b289ff2c.79484",
"type": "change",
"z": "826a56c3.fa3198",
"name": "",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": " ",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 622,
"y": 65,
"wires": [
[
"387fc19.413213e"
]
]
},
{
"id": "8672d38e.9352",
"type": "function",
"z": "826a56c3.fa3198",
"name": "time",
"func": "let startTime = msg.startTime;\nlet dt = (new Date() - startTime)/1000;\nmsg.duraliration = dt + 's';\ndelete msg.topic;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 534,
"y": 173,
"wires": [
[
"f180cb11.4c1e58"
]
]
},
{
"id": "e214486f.963088",
"type": "change",
"z": "826a56c3.fa3198",
"name": "ARR",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "ARR",
"tot": "global"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 181,
"y": 204,
"wires": [
[]
]
},
{
"id": "78e6567f.d15a08",
"type": "comment",
"z": "826a56c3.fa3198",
"name": "Вставка в БД генерированных данных",
"info": "",
"x": 191,
"y": 28,
"wires": []
},
{
"id": "1c3d40bc.e5986f",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 119,
"y": 400,
"wires": [
[
"458e9cc2.5e6144"
]
]
},
{
"id": "458e9cc2.5e6144",
"type": "template",
"z": "826a56c3.fa3198",
"name": "db 'bigdata' size",
"field": "topic",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "select t1.datname AS db_name, \n pg_size_pretty(pg_database_size(t1.datname)) as db_size\nfrom pg_database t1\nWHERE t1.datname = 'bigdata'\norder by pg_database_size(t1.datname) desc;",
"output": "str",
"x": 318,
"y": 401,
"wires": [
[
"24131e25.3ac972"
]
]
},
{
"id": "24131e25.3ac972",
"type": "sqldbs",
"z": "826a56c3.fa3198",
"mydb": "c260e1e9.519d1",
"querytype": "select",
"name": "",
"x": 530,
"y": 408,
"wires": [
[
"47ede16c.86fcc"
]
]
},
{
"id": "47ede16c.86fcc",
"type": "function",
"z": "826a56c3.fa3198",
"name": "",
"func": "var v = msg.payload[0][0];\nnode.status({});\nsetTimeout(function(){\n node.status({text: `db ${v.db_name} = ${v.db_size}`});\n},10)\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 690,
"y": 411,
"wires": [
[]
]
},
{
"id": "89357019.76d13",
"type": "function",
"z": "826a56c3.fa3198",
"name": "",
"func": "node.status({text: msg.payload});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 759,
"y": 128,
"wires": [
[]
]
},
{
"id": "2ba15e.3ecaaea2",
"type": "inject",
"z": "826a56c3.fa3198",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 130,
"y": 461,
"wires": [
[
"5d6b1e44.e354c"
]
]
},
{
"id": "5d6b1e44.e354c",
"type": "template",
"z": "826a56c3.fa3198",
"name": "rows count",
"field": "topic",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "SELECT reltuples::bigint AS count FROM pg_class where relname='list';\n",
"output": "str",
"x": 357,
"y": 464,
"wires": [
[
"4a482d74.bafb74"
]
]
},
{
"id": "4a482d74.bafb74",
"type": "sqldbs",
"z": "826a56c3.fa3198",
"mydb": "c260e1e9.519d1",
"querytype": "select",
"name": "",
"x": 508,
"y": 461,
"wires": [
[
"b1a7cc28.3adab"
]
]
},
{
"id": "6ab70642.e27f78",
"type": "function",
"z": "826a56c3.fa3198",
"name": "count++",
"func": "msg.topic = '++';\nlet t = flow.get('task1');\n\nt.index++;\n\nflow.set('task1',t);\n\nlet startTime = t.startTime;\nlet dt = (new Date() - startTime)/1000;\nlet duraliration = dt + 's';\n\nlet text = `${t.index}/${t.count} : ${duraliration}`;\n\nif(t.index>=t.count){\n node.status({text:text});\n node.send(msg);\n}\nelse\n node.status({});\n\n",
"outputs": 1,
"noerr": 0,
"x": 251,
"y": 144,
"wires": [
[]
]
},
{
"id": "ac5b2bbe.5d5ca8",
"type": "comment",
"z": "826a56c3.fa3198",
"name": "размер таблицы",
"info": "",
"x": 126,
"y": 357,
"wires": []
},
{
"id": "b1a7cc28.3adab",
"type": "function",
"z": "826a56c3.fa3198",
"name": "",
"func": "var v = msg.payload[0][0];\nnode.status({});\nsetTimeout(function(){\n node.status({text: `count: ${v.count}`});\n},10)\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 682,
"y": 470,
"wires": [
[]
]
},
{
"id": "c260e1e9.519d1",
"type": "sqldbsdatabase",
"z": "",
"host": "127.0.0.1",
"port": "5432",
"db": "bigdata",
"dialect": "postgres"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment