Skip to content

Commit

Permalink
Return null series with proper timestamp
Browse files Browse the repository at this point in the history
A bit heavier, but will behave more like other storage engiens.
  • Loading branch information
vladimir-smirnov-sociomantic committed Jan 19, 2015
1 parent e4aa261 commit 555f974
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ceres.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,13 @@ def hasDataForInterval(self, fromTime, untilTime):

def read(self, fromTime, untilTime):
# get biggest timeStep
metadata = None
if self.timeStep is None:
self.readMetadata()
metadata = self.readMetadata()

# Normalize the timestamps to fit proper intervals
fromTime = int(fromTime - (fromTime % self.timeStep) + self.timeStep)
untilTime = int(untilTime - (untilTime % self.timeStep) + self.timeStep)
fromTime = int(fromTime - (fromTime % self.timeStep))
untilTime = int(untilTime - (untilTime % self.timeStep))

sliceBoundary = None # to know when to split up queries across slices
resultValues = []
Expand All @@ -355,7 +356,7 @@ def read(self, fromTime, untilTime):
for slice_tmp in self.slices:
bogus = 0
for item in slices_map.values():
if slice_tmp.startTime > item[0] and slice_tmp.endTime < item[1]:
if (slice_tmp.startTime > item[0] and slice_tmp.endTime < item[1]) or (slice_tmp.startTime > untilTime or slice_tmp.endTime < fromTime):
bogus = 1
if not bogus: slices_arr.append(slice_tmp)

Expand Down Expand Up @@ -402,6 +403,18 @@ def read(self, fromTime, untilTime):

# The end of the requested interval predates all slices
if earliestData is None:
if biggest_timeStep is 1:
now = int(time.time())
try:
biggest_timeStep = metadata["timeStep"]
tmp = 0
for ts in metadata["retentions"]:
tmp += ts[0] * ts[1]
if untilTime > now - tmp:
break
biggest_timeStep = ts[0]
except TypeError:
biggest_timeStep = DEFAULT_TIMESTEP
missing = int(untilTime - fromTime) / biggest_timeStep
resultValues = [None for i in range(missing)]

Expand Down

0 comments on commit 555f974

Please sign in to comment.