本文整理汇总了Python中ephemeris.Ephemeris.julianDayToDatetime方法的典型用法代码示例。如果您正苦于以下问题:Python Ephemeris.julianDayToDatetime方法的具体用法?Python Ephemeris.julianDayToDatetime怎么用?Python Ephemeris.julianDayToDatetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ephemeris.Ephemeris
的用法示例。
在下文中一共展示了Ephemeris.julianDayToDatetime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processPCDD
# 需要导入模块: from ephemeris import Ephemeris [as 别名]
# 或者: from ephemeris.Ephemeris import julianDayToDatetime [as 别名]
def processPCDD(pcdd, tag):
"""Module for drawing two veritcal lines (line segments) at 1/3
and 2/3 of the way through the price chart. The lines will have a
tag str matching the given tag parameter.
Arguments:
pcdd - PriceChartDocumentData object that will be modified.
tag - str containing the tag.
Returns:
0 if the changes are to be saved to file.
1 if the changes are NOT to be saved to file.
"""
# Return value.
rv = 0
# Check input.
if tag == None or tag == "":
log.error("Must specify a non-empty tag str value.")
rv = 1
return rv
# Get the earliest and latest PriceBar.
earliestPriceBar = None
latestPriceBar = None
lowestPrice = None
highestPrice = None
for pb in pcdd.priceBars:
if earliestPriceBar == None:
earliestPriceBar = pb
elif pb.timestamp < earliestPriceBar.timestamp:
earliestPriceBar = pb
if latestPriceBar == None:
latestPriceBar = pb
elif pb.timestamp > latestPriceBar.timestamp:
latestPriceBar = pb
if lowestPrice == None:
lowestPrice = pb.low
elif pb.low < lowestPrice:
lowestPrice = pb.low
if highestPrice == None:
highestPrice = pb.high
elif pb.high > highestPrice:
highestPrice = pb.high
if earliestPriceBar == None or \
latestPriceBar == None or \
lowestPrice == None or \
highestPrice == None:
log.info("No pricebars were found in the document. " + \
"Not doing anything.")
rv = 1
return rv
# Convert the datetimes to julian day.
earliestPriceBarJd = \
Ephemeris.datetimeToJulianDay(earliestPriceBar.timestamp)
latestPriceBarJd = \
Ephemeris.datetimeToJulianDay(latestPriceBar.timestamp)
log.debug("earliestPriceBar.timestamp == {}".\
format(Ephemeris.datetimeToStr(earliestPriceBar.timestamp)))
log.debug("latestPriceBar.timestamp == {}".\
format(Ephemeris.datetimeToStr(latestPriceBar.timestamp)))
log.debug("earliestPriceBarJd == {}".format(earliestPriceBarJd))
log.debug("latestPriceBarJd == {}".format(latestPriceBarJd))
diff = latestPriceBarJd - earliestPriceBarJd
jdLine1 = earliestPriceBarJd + (diff / 3)
jdLine2 = earliestPriceBarJd + ((diff / 3) * 2)
dtLine1 = Ephemeris.julianDayToDatetime(jdLine1)
dtLine2 = Ephemeris.julianDayToDatetime(jdLine2)
log.debug("Creating scene...")
# Scene for conversion functions.
scene = PriceBarChartGraphicsScene()
log.debug("Converting dt to x...")
line1X = scene.datetimeToSceneXPos(dtLine1)
line2X = scene.datetimeToSceneXPos(dtLine2)
log.debug("Converting price to y...")
lowY = scene.priceToSceneYPos(lowestPrice)
highY = scene.priceToSceneYPos(highestPrice)
log.debug("Creating line1 artifact ...")
line1Artifact = PriceBarChartLineSegmentArtifact()
#.........这里部分代码省略.........