screeps-timeseries 0.0.2 → 0.0.3
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/engine.ts +27 -3
package/package.json
CHANGED
package/src/engine.ts
CHANGED
|
@@ -196,6 +196,28 @@ export class TimeSeriesDataEngine<T extends SingleTypedTreeData<SingleData<numbe
|
|
|
196
196
|
if (seriesDataNodeList[key] && value?.exp !== seriesDataNodeList[key]?.exp) {
|
|
197
197
|
seriesDataNodeList[key].exp = value?.exp;
|
|
198
198
|
}
|
|
199
|
+
|
|
200
|
+
if (seriesDataNodeList[key] && value.depth !== seriesDataNodeList[key].depth) {
|
|
201
|
+
// 深度改变了。需要对本segment内的该条数据做处理保证兼容。
|
|
202
|
+
const newDepth = value.depth;
|
|
203
|
+
const oldDepth = seriesDataNodeList[key].depth;
|
|
204
|
+
const oldCodec = new UTF15({ depth: oldDepth, array: true, meta: true });
|
|
205
|
+
const oldNumberList = oldCodec.decode(seriesDataNodeList[key].data);
|
|
206
|
+
const oldNullValue = POWERS_OF_2[oldDepth] - 1;
|
|
207
|
+
const newCodec = new UTF15({ depth: newDepth, array: true, meta: true });
|
|
208
|
+
seriesDataNodeList[key].data = newCodec.encode(
|
|
209
|
+
oldNumberList.map(oldNumber => {
|
|
210
|
+
if (oldNumber === oldNullValue) {
|
|
211
|
+
return nullValue;
|
|
212
|
+
}
|
|
213
|
+
if (oldNumber > nullValue) {
|
|
214
|
+
return nullValue - 1;
|
|
215
|
+
}
|
|
216
|
+
return oldNumber;
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
199
221
|
// console.log(key);
|
|
200
222
|
let valueToStore = value.data;
|
|
201
223
|
if (isNull(value.data) || isNaN(value.data) || isUndefined(value.data)) {
|
|
@@ -461,12 +483,14 @@ export class TimeSeriesDataEngine<T extends SingleTypedTreeData<SingleData<numbe
|
|
|
461
483
|
}
|
|
462
484
|
}
|
|
463
485
|
|
|
464
|
-
public rawDataNodeListReadCache: string[] =
|
|
486
|
+
public rawDataNodeListReadCache: string[] = new Array(100).fill("");
|
|
465
487
|
public rawDataReadNextIdList: number[] = [];
|
|
466
488
|
public rawDataReadEnd = false;
|
|
467
489
|
|
|
468
490
|
/**
|
|
469
491
|
* 获取segment的原始数据,用于外部解析数据。第一次执行应传入start为true。需要每个tick连续调用,直到返回数据为止。
|
|
492
|
+
*
|
|
493
|
+
* 返回的是类似segment的数组。数据被存储在对应的位置上,以便于外部解析。
|
|
470
494
|
*/
|
|
471
495
|
public readRawData(start: boolean): string[] | false | null {
|
|
472
496
|
if (this.timeData.getWritingIdTick !== -1) {
|
|
@@ -478,7 +502,7 @@ export class TimeSeriesDataEngine<T extends SingleTypedTreeData<SingleData<numbe
|
|
|
478
502
|
this.opts.segmentManager
|
|
479
503
|
);
|
|
480
504
|
if (start) {
|
|
481
|
-
this.rawDataNodeListReadCache =
|
|
505
|
+
this.rawDataNodeListReadCache = new Array(100).fill("");
|
|
482
506
|
this.rawDataReadNextIdList = this.getNextSegmentIdList(
|
|
483
507
|
this.timeData.activeId,
|
|
484
508
|
this.opts.readDataBatchSize,
|
|
@@ -496,7 +520,7 @@ export class TimeSeriesDataEngine<T extends SingleTypedTreeData<SingleData<numbe
|
|
|
496
520
|
if (rawSeriesDataHere === null || isEmpty(rawSeriesDataHere)) {
|
|
497
521
|
return;
|
|
498
522
|
}
|
|
499
|
-
this.rawDataNodeListReadCache
|
|
523
|
+
this.rawDataNodeListReadCache[dataId] = rawSeriesDataHere;
|
|
500
524
|
});
|
|
501
525
|
}
|
|
502
526
|
|