json Jolt变换规范中的值相乘

zyfwsgd6  于 2023-02-01  发布在  其他
关注(0)|答案(1)|浏览(161)

我的输入如下所示,如果timeMeasurementUnitCode="DAY",则值需要计算为value*24*60,如果timeMeasurementUnitCode="HOUR",则值为value*60
我发现人们正在寻找一个类似的用例the ticket is opened on Jul 17, 2019https://github.com/bazaarvoice/jolt/issues/832
问题832现在似乎仍处于打开状态
输入:

{
  "freightCharacteristics": {
    "transitDuration": {
      "timeMeasurementUnitCode": "DAY",
      "value": 6
    },
    "loadingDuration": {
      "timeMeasurementUnitCode": "HOUR",
      "value": 6
    }
  }
}

预期产出:根据输入中提供的常量DAYHOUR,我需要乘以no.of days*hours*minutes才能达到如下所示的要求。

{
  "transitDurationInMinutes" : 8640,
  "loadingDurationInMinutes" : 360
}

]
根据@mattyb的建议,我使用了除法函数来实现乘法所要实现的功能,逻辑更新如下。

[
  {
    "operation": "shift",
    "spec": {
      "freightCharacteristics": {
        "transitDuration": {
          "timeMeasurementUnitCode": {
            "DAY": {
              "@(2,value)": "transitDurationInMinutes"
            },
            "*": {
              "@(2,value)": "transitDurationInMinutes"
            }
          }
        },
        "loadingDuration": {
          "timeMeasurementUnitCode": {
            "HOUR": {
              "@(2,value)": "loadingDurationInMinutes"
            },
            "*": {
              "@(2,value)": "loadingDurationInMinutes"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "transitDurationInMinutes": "=divide(@(1,transitDurationInMinutes),0.00069444444)",
      "loadingDurationInMinutes": "=divide(@(1,loadingDurationInMinutes),0.01666666666)"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "transitDurationInMinutes": "=toInteger",
      "loadingDurationInMinutes": "=toInteger"
    }
  }
]
46qrfjad

46qrfjad1#

另一个选项是分别使DAYHOUR文字对象键,以便在下一步中有条件地选取它们,例如

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "value": "@(1,timeMeasurementUnitCode).&"
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "DAY": {
        "val": "=divide(1,@(1,value))",// 1/6 will be used to simulate a multiplication
        "div": "=divide(1440,@(1,val))",
        "transitDurationInMinutes": "=toInteger(@(1,div))"// to eliminate decimal representation which ends with ".0"
      },
      "HOUR": {
        "val": "=divide(1,@(1,value))",
        "div": "=divide(60,@(1,val))",
        "loadingDurationInMinutes": "=toInteger(@(1,div))"
      }
    }
  },
  {// get rid of object keys
    "operation": "shift",
    "spec": {
      "*": {
        "*Duration*": "&"
      }
    }
  }
]

http://jolt-demo.appspot.com/站点上的***演示***是

相关问题