timelog

GTimeLog compatible command line tools
git clone https://git.ce9e.org/timelog.git

commit
b765bbabf0f0702dc4dc0496faecfac865ddd30d
parent
a200c59b906294246b9f90dc7580585175dce56c
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2022-02-25 14:47
refactor Query

Diffstat

M vtimelog 26 ++++++++++++++------------

1 files changed, 14 insertions, 12 deletions


diff --git a/vtimelog b/vtimelog

@@ -107,30 +107,32 @@ def timedelta2str(delta):
  107   107 
  108   108 class Query:
  109   109 	def __init__(self, timelog):
  110    -1 		self.data = range(len(timelog))
   -1   110 		self.start = 0
   -1   111 		self.stop = len(timelog)
  111   112 		self.timelog = timelog
  112   113 
  113   114 	def split(self, dt, after):
  114    -1 		low = 0
  115    -1 		high = len(self.data) - 1
   -1   115 		low = self.start
   -1   116 		high = self.stop - 1
  116   117 
  117    -1 		def get(i):
  118    -1 			return self.timelog[self.data[i]]['dt']
  119    -1 
  120    -1 		if (after and get(low) > dt) or (not after and get(high) < dt):
  121    -1 			return
   -1   118 		if after:
   -1   119 			if self.timelog[low]['dt'] > dt:
   -1   120 				return
   -1   121 		else:
   -1   122 			if self.timelog[high]['dt'] < dt:
   -1   123 				return
  122   124 
  123   125 		while high - low > 1:
  124   126 			new = int((low + high) / 2)
  125    -1 			if get(new) <= dt:
   -1   127 			if self.timelog[new]['dt'] <= dt:
  126   128 				low = new
  127   129 			else:
  128   130 				high = new
  129   131 
  130   132 		if after:
  131    -1 			self.data = self.data[high:]
   -1   133 			self.start = high
  132   134 		else:
  133    -1 			self.data = self.data[:high]
   -1   135 			self.stop = high
  134   136 
  135   137 	def before(self, dt):
  136   138 		self.split(dt, False)
@@ -163,7 +165,7 @@ class Query:
  163   165 		self.before(datetime_add(start, years=offset + 1))
  164   166 
  165   167 	def all(self):
  166    -1 		return tuple(self.timelog[i] for i in self.data)
   -1   168 		return [self.timelog[i] for i in range(self.start, self.stop)]
  167   169 
  168   170 
  169   171 class Extractor: