@icgio/icg-utils 1.9.67 → 1.9.68

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/lib/influxdb.js CHANGED
@@ -5,6 +5,15 @@ const { parse } = require('csv-parse')
5
5
  const { InfluxDB, Point } = require('@influxdata/influxdb-client')
6
6
  const { BucketsAPI } = require('@influxdata/influxdb-client-apis')
7
7
 
8
+ const reported_schema_gaps = new Set()
9
+
10
+ function report_schema_gap(key, ...message) {
11
+ if (!reported_schema_gaps.has(key)) {
12
+ reported_schema_gaps.add(key)
13
+ console.error(...message)
14
+ }
15
+ }
16
+
8
17
  function fields_check(fields) {
9
18
  let result = true
10
19
  for (let key in fields) {
@@ -58,12 +67,29 @@ class Influx {
58
67
  this.bucket_exist = true
59
68
  }
60
69
  }
70
+ let dropped_points = 0
71
+ let dropped_fields = 0
61
72
  points = points
73
+ .map((point) => {
74
+ if (typeof point.timestamp === 'number' || typeof point.timestamp === 'string') {
75
+ const timestamp = new Date(point.timestamp)
76
+ if (!_.isNaN(timestamp.getTime())) {
77
+ return { ...point, timestamp }
78
+ }
79
+ }
80
+ return point
81
+ })
62
82
  .filter((point) => {
83
+ if (!_.get(this.schema, [point.measurement, 'fields'])) {
84
+ report_schema_gap(point.measurement, 'influx unknown measurement, points dropped:', point.measurement)
85
+ dropped_points++
86
+ return false
87
+ }
63
88
  if (fields_check(point.fields) && (!point.timestamp || point.timestamp instanceof Date)) {
64
89
  return true
65
90
  } else {
66
91
  console.error('influx check_points', point)
92
+ dropped_points++
67
93
  return false
68
94
  }
69
95
  })
@@ -80,6 +106,9 @@ class Influx {
80
106
  p_temp = p_temp.intField(field, p.fields[field])
81
107
  } else if (field_type === 'string') {
82
108
  p_temp = p_temp.stringField(field, p.fields[field])
109
+ } else {
110
+ report_schema_gap(p.measurement + '.' + field, 'influx unknown field, dropped:', p.measurement, field)
111
+ dropped_fields++
83
112
  }
84
113
  }
85
114
  if (p.timestamp) {
@@ -91,7 +120,7 @@ class Influx {
91
120
  write_api
92
121
  .close()
93
122
  .then(() => {
94
- cb({ success: true, body: points.length })
123
+ cb({ success: true, body: points.length, dropped_points, dropped_fields })
95
124
  })
96
125
  .catch((err) => {
97
126
  cb({ success: false, body: err })
package/lib/rates.js CHANGED
@@ -16,7 +16,12 @@ function get_forex_rate_usd(curs, cb) {
16
16
  if (body && body.usd) {
17
17
  let rates = {}
18
18
  for (let cur of curs) {
19
- rates[cur] = 1 / body.usd[cur.toLowerCase()]
19
+ const rate = body.usd[cur.toLowerCase()]
20
+ if (rate > 0) {
21
+ rates[cur] = 1 / rate
22
+ } else {
23
+ console.error('forex_rate missing:', cur)
24
+ }
20
25
  }
21
26
  cb(rates)
22
27
  } else {
package/lib/utils.js CHANGED
@@ -446,7 +446,7 @@ function vol_position_combined(input_array, vol_target) {
446
446
  break
447
447
  }
448
448
  }
449
- avg_price = sum / vol ? sum / vol : price
449
+ let avg_price = sum / vol ? sum / vol : price
450
450
  return { price, price_exchange, avg_price, vol, vol_exchange, sum, sum_exchange, pos, pos_exchange }
451
451
  }
452
452
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.9.67",
3
+ "version": "1.9.68",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {