holepunch-hop 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/adapters/sqliteDatabase.js +64 -24
- package/src/bees.js +11 -0
- package/src/drive.js +25 -15
- package/src/fileParser.js +20 -0
- package/src/index.js +2 -0
package/package.json
CHANGED
|
@@ -49,6 +49,29 @@ class SqliteAdapter extends EventEmitter {
|
|
|
49
49
|
return newSqlite
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* setup sqlite db and get tables and columns
|
|
54
|
+
* @method discoverColumns
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
discoverColumns = async function (table) {
|
|
58
|
+
// columns in table
|
|
59
|
+
let header = []
|
|
60
|
+
const res = await new Promise((resolve, reject) => {
|
|
61
|
+
let sqlTableCols = `PRAGMA table_info('` + table + `')`
|
|
62
|
+
this.dataBase.all(sqlTableCols, [], (err, rows) => {
|
|
63
|
+
if (err) {
|
|
64
|
+
reject(err)
|
|
65
|
+
}
|
|
66
|
+
rows.forEach((row) => {
|
|
67
|
+
header.push(row)
|
|
68
|
+
})
|
|
69
|
+
resolve(header)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
return res
|
|
73
|
+
}
|
|
74
|
+
|
|
52
75
|
/**
|
|
53
76
|
* setup sqlite db and get tables and columns
|
|
54
77
|
* @method createDbConnection
|
|
@@ -88,28 +111,6 @@ class SqliteAdapter extends EventEmitter {
|
|
|
88
111
|
return res
|
|
89
112
|
}
|
|
90
113
|
|
|
91
|
-
/**
|
|
92
|
-
* setup sqlite db and get tables and columns
|
|
93
|
-
* @method discoverColumns
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
discoverColumns = async function (table) {
|
|
97
|
-
// columns in table
|
|
98
|
-
let header = []
|
|
99
|
-
const res = await new Promise((resolve, reject) => {
|
|
100
|
-
let sqlTableCols = `PRAGMA table_info('` + table + `')`
|
|
101
|
-
this.dataBase.all(sqlTableCols, [], (err, rows) => {
|
|
102
|
-
if (err) {
|
|
103
|
-
reject(err)
|
|
104
|
-
}
|
|
105
|
-
rows.forEach((row) => {
|
|
106
|
-
header.push(row)
|
|
107
|
-
})
|
|
108
|
-
resolve(header)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
return res
|
|
112
|
-
}
|
|
113
114
|
|
|
114
115
|
/**
|
|
115
116
|
* query a table for data
|
|
@@ -117,11 +118,48 @@ class SqliteAdapter extends EventEmitter {
|
|
|
117
118
|
*
|
|
118
119
|
*/
|
|
119
120
|
queryTable = async function (table) {
|
|
121
|
+
console.log('HP--first SQL query')
|
|
122
|
+
console.log(table)
|
|
123
|
+
let tableName = table.context.deviceTable
|
|
124
|
+
// let devicetableName = table.context.devicetablename
|
|
125
|
+
let tableTimestamp = table.context.timestamp // timecolumn
|
|
126
|
+
let deviceColumn = ''
|
|
127
|
+
if (table?.context?.deviceCol) {
|
|
128
|
+
deviceColumn = table?.context?.deviceCol?.name
|
|
129
|
+
} else {
|
|
130
|
+
deviceColumn = ''
|
|
131
|
+
}
|
|
132
|
+
let queryDevice = 0
|
|
133
|
+
if (table.context?.deviceID) {
|
|
134
|
+
queryDevice = table.context?.deviceID
|
|
135
|
+
} else {
|
|
136
|
+
queryDevice = 1 // table?.context?.device?._id
|
|
137
|
+
}
|
|
138
|
+
let queryLimit = true
|
|
139
|
+
let queryLevel = 1400
|
|
140
|
+
let blindTimestart = 0
|
|
141
|
+
let blindTimeend = 0
|
|
120
142
|
// columns in table
|
|
121
143
|
let data = []
|
|
122
144
|
const res = await new Promise((resolve, reject) => {
|
|
123
|
-
let sqlQuery = `SELECT * FROM
|
|
124
|
-
|
|
145
|
+
let sqlQuery = `SELECT * FROM ` + tableName
|
|
146
|
+
// now build filter of query based on input if any
|
|
147
|
+
if (deviceColumn.length > 0) {
|
|
148
|
+
sqlQuery += ` WHERE ` + deviceColumn + ` = ` + queryDevice
|
|
149
|
+
}
|
|
150
|
+
if (tableTimestamp.length > 0) {
|
|
151
|
+
sqlQuery += ` ORDER BY TIMESTAMP DEC` // + tableTimestamp
|
|
152
|
+
}
|
|
153
|
+
if (blindTimestart) {
|
|
154
|
+
sqlQuery += ` AND TIMESTAMP BETWEEN ` + blindTimestart + ` AND ` + blindTimeend
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
// lastly set hard limit on length
|
|
158
|
+
if (queryLimit) {
|
|
159
|
+
sqlQuery += ` LIMIT ` + queryLevel
|
|
160
|
+
}
|
|
161
|
+
console.log('HP------formed ----------')
|
|
162
|
+
console.log(sqlQuery)
|
|
125
163
|
this.dataBase.all(sqlQuery, [], (err, rows) => {
|
|
126
164
|
if (err) {
|
|
127
165
|
reject(err)
|
|
@@ -135,12 +173,14 @@ class SqliteAdapter extends EventEmitter {
|
|
|
135
173
|
return res
|
|
136
174
|
}
|
|
137
175
|
|
|
176
|
+
|
|
138
177
|
/**
|
|
139
178
|
* query device table
|
|
140
179
|
* @method deviceQuery
|
|
141
180
|
*
|
|
142
181
|
*/
|
|
143
182
|
deviceQuery = async function (table) {
|
|
183
|
+
console.log('HOLEP---adtpSQL--query device SQLite ad')
|
|
144
184
|
let data = []
|
|
145
185
|
const res = await new Promise((resolve, reject) => {
|
|
146
186
|
let sqlQuery = `SELECT * FROM ` + table
|
package/src/bees.js
CHANGED
|
@@ -343,6 +343,17 @@ class HyperBee extends EventEmitter {
|
|
|
343
343
|
return nodeData
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
/**
|
|
347
|
+
* filter peer library to get compute modules with a key
|
|
348
|
+
* @method getPeerLibComputeModules
|
|
349
|
+
*
|
|
350
|
+
*/
|
|
351
|
+
getPeerLibComputeModules = async function () {
|
|
352
|
+
const moduleData = await this.dbPeerLibrary.createHistoryStream({ reverse: true, limit: 10 })
|
|
353
|
+
return moduleData
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
|
|
346
357
|
/**
|
|
347
358
|
* get all kbl entries
|
|
348
359
|
* @method KBLentries
|
package/src/drive.js
CHANGED
|
@@ -300,27 +300,37 @@ class HypDrive extends EventEmitter {
|
|
|
300
300
|
*
|
|
301
301
|
*/
|
|
302
302
|
SQLiteQuery = async function (dataInfo) {
|
|
303
|
+
console.log('HP--DRIVE--sqlite')
|
|
303
304
|
let timestampCol = ''
|
|
304
305
|
// is the sqliite database sill accive?
|
|
305
306
|
// const stream = this.liveDataAPI.DriveFiles.listFilesFolder('sqlite/')
|
|
306
307
|
let dbFile = await this.hyperdriveLocalfile('sqlite/' + dataInfo.file.file)
|
|
307
308
|
let queryData = await this.AdapterSqlite.queryTable(dataInfo)
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
309
|
+
if (queryData.length > 0) {
|
|
310
|
+
let contextKeys = Object.keys(queryData[0])
|
|
311
|
+
timestampCol = contextKeys[dataInfo.context.timestamp]
|
|
312
|
+
// now prepare into data and labels
|
|
313
|
+
let blindData = {}
|
|
314
|
+
let extractCol = []
|
|
315
|
+
let extractLabel = []
|
|
316
|
+
for (let rowi of queryData) {
|
|
317
|
+
extractCol.push(rowi[dataInfo.context.name.name])
|
|
318
|
+
// assume data column for now and parse to mills seconds
|
|
319
|
+
let testCH1 = chrono.parseDate(rowi[timestampCol])
|
|
320
|
+
let parseDate = testCH1 * 1000 // this.testDataExtact(testCH1)
|
|
321
|
+
extractLabel.push(parseDate)
|
|
322
|
+
}
|
|
323
|
+
blindData.data = extractCol
|
|
324
|
+
blindData.label = extractLabel
|
|
325
|
+
return blindData
|
|
326
|
+
} else {
|
|
327
|
+
console.log('no data for that query')
|
|
328
|
+
let blindData = {}
|
|
329
|
+
blindData.data = []
|
|
330
|
+
blindData.label = []
|
|
331
|
+
return blindData
|
|
320
332
|
}
|
|
321
|
-
|
|
322
|
-
blindData.label = extractLabel
|
|
323
|
-
return blindData
|
|
333
|
+
|
|
324
334
|
}
|
|
325
335
|
|
|
326
336
|
|
package/src/fileParser.js
CHANGED
|
@@ -137,6 +137,26 @@ FileParser.prototype.webCSVparse = function (fData) {
|
|
|
137
137
|
// this.convertJSON(o, ws, headerInfo, praser, 'web', fileNewName)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
/**
|
|
141
|
+
* TEMP blind json content
|
|
142
|
+
* @method TEMPwebJSONparse
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
FileParser.prototype.TEMPwebJSONparse = function (fjData) {
|
|
146
|
+
console.log(fjData)
|
|
147
|
+
let extractLabel = []
|
|
148
|
+
let extractCol = []
|
|
149
|
+
for (let df of fjData.content) {
|
|
150
|
+
extractLabel.push(df[fjData.context.timestampname])
|
|
151
|
+
extractCol.push(df[fjData.context.name])
|
|
152
|
+
}
|
|
153
|
+
// extract out price and time
|
|
154
|
+
let extractedPair = {}
|
|
155
|
+
extractedPair.label = extractLabel
|
|
156
|
+
extractedPair.data = extractCol
|
|
157
|
+
return extractedPair
|
|
158
|
+
}
|
|
159
|
+
|
|
140
160
|
/**
|
|
141
161
|
* TEMP blind csv content files from web
|
|
142
162
|
* @method TEMPwebCSVparse
|
package/src/index.js
CHANGED
|
@@ -130,6 +130,8 @@ class HolepunchWorker extends EventEmitter {
|
|
|
130
130
|
this.warmPeers.push(message.data)
|
|
131
131
|
this.Peers.peerJoin(message.data)
|
|
132
132
|
}
|
|
133
|
+
} else if (message.task === 'peer-board') {
|
|
134
|
+
console.log('public board share with peer')
|
|
133
135
|
} else if (message.task === 'peer-write') {
|
|
134
136
|
this.emit('peer-write', message.data)
|
|
135
137
|
} else if (message.task === 'topic') {
|