skyffire пре 1 година
родитељ
комит
e76c876890
2 измењених фајлова са 81 додато и 1 уклоњено
  1. 77 0
      utils/time-kit.js
  2. 4 1
      十面埋伏分析.js

+ 77 - 0
utils/time-kit.js

@@ -0,0 +1,77 @@
+module.exports = class TimeKit {
+  static dateToTimestamp (str) {
+    let [a, b] = str.split(' ')
+    let [year, month, day] = a.split('/')
+    let [hour, minute, second] = b.split(':')
+
+    return new Date(year, month - 1, day, hour, minute, second).getTime() / 1000
+  }
+
+  // 时间戳转换chart时间
+  static getTime (timestamp) {
+    // 组织日期格式并返回
+    return this.dateFormat('YYYY-mm-dd HH:MM:SS:sss', new Date(timestamp * 1000))
+  }
+
+  static dateFormat(fmt, date) {
+    let ret;
+    const opt = {
+      "Y+": date.getFullYear().toString(),        // 年
+      "m+": (date.getMonth() + 1).toString(),     // 月
+      "d+": date.getDate().toString(),            // 日
+      "H+": date.getHours().toString(),           // 时
+      "M+": date.getMinutes().toString(),         // 分
+      "S+": date.getSeconds().toString(),         // 秒
+      "s+": date.getMilliseconds().toString()     // 毫秒
+      // 有其他格式化字符需求可以继续添加,必须转化成字符串
+    };
+    for (let k in opt) {
+      ret = new RegExp("(" + k + ")").exec(fmt);
+      if (ret) {
+        fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
+      }
+    }
+    return fmt;
+  }
+
+  /**
+   * 毫秒级时间戳转换
+   *
+   * @param timestamp
+   * @returns {*}
+   */
+  static getTimeByMillisecond = function (timestamp) {
+    // 组织日期格式并返回
+    return TimeKit.dateFormat('YYYY-mm-dd HH:MM:SS', new Date(timestamp))
+  }
+
+  /**
+   * 毫秒级时间戳转换,但只保留日期
+   *
+   * @param timestamp
+   * @returns {*}
+   */
+  static getDateByMillisecond = function (timestamp) {
+    // 组织日期格式并返回
+    return TimeKit.dateFormat('YYYY-mm-dd', new Date(timestamp))
+  }
+
+  /**
+   * 秒级时间戳转换
+   *
+   * @param timestamp
+   * @returns {*}
+   */
+  static getTimeBySecond = function (timestamp) {
+    // 组织日期格式并返回
+    return TimeKit.dateFormat('YYYY-mm-dd HH:MM:SS', new Date(timestamp * 1000))
+  }
+
+  static sleep = function (time) {
+    return new Promise(function (resolve) {
+      setTimeout(function () {
+        resolve(true)
+      }, time)
+    })
+  }
+}

+ 4 - 1
十面埋伏分析.js

@@ -1,5 +1,6 @@
 const logger = require("./utils/logger");
 const NumKit = require('./utils/num-kit')
+const TimeKit = require('./utils/time-kit')
 const fs = require('fs').promises;
 
 async function readData() {
@@ -89,7 +90,9 @@ async function main() {
     let synProfit = NumKit.getSubFloat(expFakeProfit + expRealProfit, 2)
     let avgProfit = NumKit.getSubFloat(synProfit / (realLength + fakeLength), 2)
 
-    logger.info(`${i}日(${realLength + fakeLength}只),真龙榜(${realLength}只)利润${realDragonProfit}%`
+    let index = kLinesMap['BTC_USDT'].length - (i + 1)
+    let dateStr = TimeKit.getDateByMillisecond(kLinesMap['BTC_USDT'][index].Time)
+    logger.info(`${i}日(${dateStr}, ${realLength + fakeLength}只),真龙榜(${realLength}只)利润${realDragonProfit}%`
       + `,假龙榜(${fakeLength}只)利润${fakeDragonProfit}%`
       + `,真龙期望利润${expRealProfit}%,假龙期望利润${expFakeProfit}%,综合利润${synProfit}%,平均每只利润${avgProfit}%`
     )