无法将python数组转换为java数组

时间:2017-06-01 01:48:05

标签: java python arrays

我正在将一段python代码转换为java。代码决定太阳和月亮的上升和设定时间 95%的代码转换很好,但我坚持将python数组 moonArray 转换为java,因为它没有意义。编写java版本是一项繁琐的任务,不需要帮助,只需了解python数组正在做什么。

PYTHON CODE:

def riseSetString(self, dis, utcdis):
    moonArray = self.risesetlist(dis, utcdis)
    moonString = "moonrise time is " + moonArray[0]
    moonString += "\nmoonset time is " + moonArray[1]
    moonString += "\n{} iterations".format(moonArray[2])
    print(moonString)

def risesetlist(self, dis, utcdis):
    y = datetime.datetime.utcnow().year
    m = datetime.datetime.utcnow().month
    d = datetime.datetime.utcnow().day + dis
    h = datetime.datetime.utcnow().hour
    mins = datetime.datetime.utcnow().minute
    second = datetime.datetime.utcnow().second
    moonArray = self.calculate(y, m, d, h, mins, second)
    msd = moonArray[8]
    mra = moonArray[5]
    mdecl = moonArray[6]
    gmsto = moonArray[11]
    hmm = radians(-0.583) - msd
    numerator = (sin(hmm) - sin(radians(self.localLat)) * sin(mdecl))
    divisor = (cos(radians(self.localLat)) * cos(mdecl))
    mlha = numerator / divisor
    mlha = acos(mlha) * 12 * 15.0 / (15.04107 * pi)
    utcmoon = (degrees(mra) - gmsto * 15 - self.localLong) / 15
    a = mlha
    c = 1
    ff = 0
    while abs(c) > 0.000001:
        y = datetime.datetime.utcnow().year
        m = datetime.datetime.utcnow().month
        d = datetime.datetime.utcnow().day + dis
        h = utcmoon + a
        moonArray = self.calculate(y, m, d, h, 0, 0)
        msd = moonArray[8]
        mra = moonArray[5]
        mdecl = moonArray[6]
        gmsto = moonArray[11]
        hmm = radians(-0.583) - msd
        numerator = (sin(hmm) - sin(radians(self.localLat)) * sin(mdecl))
        divisor = (cos(radians(self.localLat)) * cos(mdecl))
        mlha = numerator / divisor
        mlha = acos(mlha) * 12 * 15.0 / (15.04107 * pi)
        utcmoon = (degrees(mra) - gmsto * 15 - self.localLong) / 15
        b = mlha
        c = abs(b - a)
        a = mlha
        ff += 1
        if ff >= 100:
            break

    moonset = mlha + utcmoon
    c = 1

    while abs(c) > 0.000001:
        y = datetime.datetime.utcnow().year
        m = datetime.datetime.utcnow().month
        d = datetime.datetime.utcnow().day + dis
        h = utcmoon - a
        moonArray = self.calculate(y, m, d, h, 0, 0)
        msd = moonArray[8]
        mra = moonArray[5]
        mdecl = moonArray[6]
        gmsto = moonArray[11]

        hmm = radians(-0.583) - msd
        numerator = (sin(hmm) - sin(radians(self.localLat)) * sin(mdecl))
        divisor = (cos(radians(self.localLat)) * cos(mdecl))
        mlha = numerator / divisor
        mlha = acos(mlha) * 12 * 15.0 / (15.04107 * pi)
        utcmoon = (degrees(mra) - gmsto * 15 - self.localLong) / 15
        b = mlha
        c = b - a
        a = mlha
        ff += 1
        if ff >= 200:
            break

    moonrise = utcmoon - mlha
    moonrise = timeadjust(moonrise, utcdis)
    moonrise2 = decimaltominsecs(moonrise)
    moonset = timeadjust(moonset, utcdis)
    moonset2 = decimaltominsecs(moonset)

    return ["{}:{}:{}".format(floor(moonrise),
                              moonrise2[0], moonrise2[1]),
            "{}:{}:{}".format(floor(moonset),
                              moonset2[0], moonset2[1]),
            ff, [moonrise, moonrise2, moonset, moonset2]]

在risesetlist函数中,moonArray的调用方式如下:

moonArray = self.calculate(y, m, d, h, mins, second)

和while循环

moonArray = self.calculate(y, m, d, h, 0, 0)

那么如何从数组位置分配变量[8],[6],[11],因为在两个数组构造函数中只有0..5存在?

msd = moonArray[8]
mra = moonArray[5]
mdecl = moonArray[6]
gmsto = moonArray[11]

所以,我只需要知道moonArray在python中做了什么,所以我可以编写java版本。任何帮助将不胜感激。

0 个答案:

没有答案