def getTagList(obj, startJd, endJd): ''' returns a list of (epoch, tag_name) tuples ''' startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) cmd = [ 'git', '--git-dir', join(obj.vcsDir, '.git'), 'tag', ] data = [] for line in Popen(cmd, stdout=PIPE).stdout: tag = line.strip() if not tag: continue line = Popen([ 'git', '--git-dir', join(obj.vcsDir, '.git'), 'log', '-1', tag, '--pretty=%ct', ], stdout=PIPE).stdout.read().strip() epoch = int(line) if epoch < startEpoch: continue if epoch >= endEpoch: break data.append(( epoch, tag, )) return data
def getTagList(obj, startJd, endJd): """ returns a list of (epoch, tag_name) tuples """ startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) cmd = [ "git", "--git-dir", join(obj.vcsDir, ".git"), "tag", ] data = [] for line in Popen(cmd, stdout=PIPE).stdout: tag = line.strip() if not tag: continue line = Popen([ "git", "--git-dir", join(obj.vcsDir, ".git"), "log", "-1", tag, "--pretty=%ct", ], stdout=PIPE).stdout.read().strip() epoch = int(line) if epoch < startEpoch: continue if epoch >= endEpoch: break data.append(( epoch, tag, )) return data
def getCommitList(obj, startJd=None, endJd=None, branch="") -> List[Tuple[int, str]]: """ returns a list of (epoch, commit_id) tuples this function is optimized for recent commits i.e. endJd is either None or recent """ if not branch: branch = "main" startEpoch = None endEpoch = None if startJd is not None: startEpoch = getEpochFromJd(startJd) if endJd is not None: endEpoch = getEpochFromJd(endJd) repo = Repository(obj.vcsDir) data = [] # type: List[Tuple[int, str]] # items of data are (epochTime, commitHash) target = repo.branches[branch].target for commit in repo.walk(target, GIT_SORT_TIME): tm = commit.author.time if endEpoch is not None and tm > endEpoch: continue if startEpoch is not None and tm < startEpoch: break data.append(( tm, commit.id.hex, )) data.reverse() return data
def getTagList(obj, startJd, endJd): """ returns a list of (epoch, tag_name) tuples """ repo = Repository(obj.vcsDir) startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) data = [] for refName in repo.references: if not refName.startswith("refs/tags/"): continue tagName = refName[len("refs/tags/"):] ref = repo.references[refName] tag = repo.get(ref.target) # in some cases, tag is instance of _pygit2.Tag, with tag.author # in other cases, tag is instance of _pygit2.Commit, with tag.author try: author = tag.author except AttributeError: author = tag.tagger epoch = author.time # type: int if epoch < startEpoch: continue if epoch >= endEpoch: break data.append(( epoch, tagName, )) return data
def getCommitListFromEst(obj, startJd, endJd, format_rev_id=None): ''' returns a list of (epoch, rev_id) tuples ''' startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) ### data = [] for t0, t1, rev_id, dt in obj.est.search(startEpoch, endEpoch): if format_rev_id: rev_id = format_rev_id(obj.repo, rev_id) data.append((t0, rev_id)) data.sort(reverse=True) return data
def getLastCommitIdUntilJd(obj, jd): untilEpoch = getEpochFromJd(jd) last = obj.est.getLastBefore(untilEpoch) if not last: return t0, t1, rev_id = last return str(obj.repo.get_revision(rev_id))
def getEpochFromDate(y, m, d, mode): return getEpochFromJd(to_jd( y, m, d, mode, ))
def getTagList(obj, startJd, endJd): ''' returns a list of (epoch, tag_name) tuples ''' if not obj.repo: return [] startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) ### data = [] for tag, rev_id in obj.branch.tags.get_tag_dict().items(): rev = obj.repo.get_revision(rev_id) epoch = rev.timestamp if startEpoch <= epoch < endEpoch: data.append(( epoch, tag, )) data.sort() return data
def getTagList(obj, startJd, endJd): ''' returns a list of (epoch, tag_name) tuples ''' if not obj.repo: return [] startEpoch = getEpochFromJd(startJd) endEpoch = getEpochFromJd(endJd) ### data = [] for tag, unkown in obj.repo.tagslist(): if tag == 'tip': continue epoch = obj.repo[tag].date()[0] if startEpoch <= epoch < endEpoch: data.append(( epoch, tag, )) data.sort() return data
def updateData(self): from scal3.time_utils import getEpochFromJd from scal3.ui_gtk import timeline_box as tbox self.timeStart = getEpochFromJd(self.wcal.status[0].jd) self.pixelPerSec = float(self.get_allocation().height) / self.timeWidth ## pixel/second self.borderTm = 0 ## tbox.boxMoveBorder / self.pixelPerSec ## second self.boxes = tbox.calcEventBoxes( self.timeStart, self.timeStart + self.timeWidth, self.pixelPerSec, self.borderTm, )
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm): timeEnd = timeStart + timeWidth jd0 = getJdFromEpoch(timeStart) jd1 = getJdFromEpoch(timeEnd) widthDays = float(timeWidth) / dayLen dayPixel = dayLen * pixelPerSec ## px #print('dayPixel = %s px'%dayPixel) getEPos = lambda epoch: (epoch - timeStart) * pixelPerSec getJPos = lambda jd: (getEpochFromJd(jd) - timeStart) * pixelPerSec ######################## Holidays holidays = [] if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays: for jd in getHolidaysJdList(jd0, jd1 + 1): holidays.append(getJPos(jd)) ######################## Ticks ticks = [] tickEpochList = [] minStep = minorStepMin / pixelPerSec ## second ################# year0, month0, day0 = jd_to_primary(jd0) year1, month1, day1 = jd_to_primary(jd1) ############ Year minStepYear = minStep // minYearLenSec ## years ## int or iceil? yearPixel = minYearLenSec * pixelPerSec ## pixels for (year, size) in getYearRangeTickValues(year0, year1 + 1, minStepYear): tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary) if tmEpoch in tickEpochList: continue unitSize = size * yearPixel label = formatYear(year) if unitSize >= majorStepMin else '' ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ############ Month monthPixel = avgMonthLen * pixelPerSec ## px minMonthUnit = float(minStep) / avgMonthLen ## month if minMonthUnit <= 3: for ym in range(year0 * 12 + month0 - 1, year1 * 12 + month1 - 1 + 1): ## +1 FIXME if ym % 3 == 0: monthUnit = 3 else: monthUnit = 1 if monthUnit < minMonthUnit: continue y, m = divmod(ym, 12) m += 1 tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary) if tmEpoch in tickEpochList: continue unitSize = monthPixel * monthUnit ticks.append( Tick( tmEpoch, getEPos(tmEpoch), unitSize, getMonthName(calTypes.primary, m) if unitSize >= majorStepMin else '', )) tickEpochList.append(tmEpoch) ################ if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays: wd0 = jwday(jd0) jdw0 = jd0 + (core.firstWeekDay - wd0) % 7 unitSize = dayPixel * 7 if unitSize < majorStepMin: label = '' else: label = core.weekDayNameAb[core.firstWeekDay] for jd in range(jdw0, jd1 + 1, 7): tmEpoch = getEpochFromJd(jd) ticks.append( Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, color=weekStartTickColor, )) #tickEpochList.append(tmEpoch) ############ Day of Month hasMonthName = timeWidth < 5 * dayLen minDayUnit = float(minStep) / dayLen ## days if minDayUnit <= 15: for jd in range(jd0, jd1 + 1): tmEpoch = getEpochFromJd(jd) if tmEpoch in tickEpochList: continue year, month, day = jd_to_primary(jd) if day == 16: dayUnit = 15 elif day in (6, 11, 21, 26): dayUnit = 5 else: dayUnit = 1 if dayUnit < minDayUnit: continue unitSize = dayPixel * dayUnit if unitSize < majorStepMin: label = '' elif hasMonthName: label = _(day) + ' ' + getMonthName(calTypes.primary, month) else: label = _(day) ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ############ Hour, Minute, Second for stepUnit, stepValue in unitSteps: stepSec = stepUnit * stepValue if stepSec < minStep: break unitSize = stepSec * pixelPerSec utcOffset = int(getUtcOffsetCurrent()) firstEpoch = iceil( (timeStart + utcOffset) / stepSec) * stepSec - utcOffset for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec): if tmEpoch in tickEpochList: continue if unitSize < majorStepMin: label = '' else: jd, h, m, s = getJhmsFromEpoch(tmEpoch) if s == 0: label = '%s:%s' % ( _(h), _(m, fillZero=2), ) else: # elif timeWidth < 60 or stepSec < 30: label = addLRM('%s"' % _(s, fillZero=2)) #else: # label = '%s:%s:%s'%( # _(h), # _(m, fillZero=2), # _(s, fillZero=2), # ) ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ######################## Event Boxes data = { 'holidays': holidays, 'ticks': ticks, 'boxes': [], } ### data['boxes'] = calcEventBoxes( timeStart, timeEnd, pixelPerSec, borderTm, ) ### return data
module = calTypes[mode] year, month, day = module.jd_to(jd) yearStartJd = module.to_jd(year, 1, 1) nextYearStartJd = module.to_jd(year + 1, 1, 1) dayOfYear = jd - yearStartJd return year + float(dayOfYear) / (nextYearStartJd - yearStartJd) def getJdFromFloatYear(fyear, mode): module = calTypes[mode] year = int(math.floor(fyear)) yearStartJd = module.to_jd(year, 1, 1) nextYearStartJd = module.to_jd(year + 1, 1, 1) dayOfYear = int((fyear - year) * (nextYearStartJd - yearStartJd)) return yearStartJd + dayOfYear getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode)) def ymdRange(date1, date2, mode=None): y1, m1, d1 = date1 y2, m2, d2 = date2 if y1==y2 and m1==m2: for d in range(d1, d2): yield y1, m1, d if mode==None: mode = DATE_GREG calType = calTypes[mode] j1 = int(calType.to_jd(y1, m1, d1)) j2 = int(calType.to_jd(y2, m2, d2)) for j in range(j1, j2): yield calType.jd_to(j)
yearStartJd = module.to_jd(year, 1, 1) nextYearStartJd = module.to_jd(year + 1, 1, 1) dayOfYear = jd - yearStartJd return year + float(dayOfYear) / (nextYearStartJd - yearStartJd) def getJdFromFloatYear(fyear, mode): module = calTypes[mode] year = int(math.floor(fyear)) yearStartJd = module.to_jd(year, 1, 1) nextYearStartJd = module.to_jd(year + 1, 1, 1) dayOfYear = int((fyear - year) * (nextYearStartJd - yearStartJd)) return yearStartJd + dayOfYear getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode)) def ymdRange(date1, date2, mode=None): y1, m1, d1 = date1 y2, m2, d2 = date2 if y1 == y2 and m1 == m2: for d in range(d1, d2): yield y1, m1, d if mode == None: mode = DATE_GREG calType = calTypes[mode] j1 = int(calType.to_jd(y1, m1, d1)) j2 = int(calType.to_jd(y2, m2, d2)) for j in range(j1, j2): yield calType.jd_to(j)
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm): timeEnd = timeStart + timeWidth jd0 = getJdFromEpoch(timeStart) jd1 = getJdFromEpoch(timeEnd) widthDays = float(timeWidth) / dayLen dayPixel = dayLen * pixelPerSec ## px #print('dayPixel = %s px'%dayPixel) getEPos = lambda epoch: (epoch-timeStart)*pixelPerSec getJPos = lambda jd: (getEpochFromJd(jd)-timeStart)*pixelPerSec ######################## Holidays holidays = [] if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays: for jd in getHolidaysJdList(jd0, jd1+1): holidays.append(getJPos(jd)) ######################## Ticks ticks = [] tickEpochList = [] minStep = minorStepMin / pixelPerSec ## second ################# year0, month0, day0 = jd_to_primary(jd0) year1, month1, day1 = jd_to_primary(jd1) ############ Year minStepYear = minStep // minYearLenSec ## years ## int or iceil? yearPixel = minYearLenSec * pixelPerSec ## pixels for (year, size) in getYearRangeTickValues(year0, year1+1, minStepYear): tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary) if tmEpoch in tickEpochList: continue unitSize = size * yearPixel label = formatYear(year) if unitSize >= majorStepMin else '' ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ############ Month monthPixel = avgMonthLen * pixelPerSec ## px minMonthUnit = float(minStep) / avgMonthLen ## month if minMonthUnit <= 3: for ym in range(year0*12+month0-1, year1*12+month1-1+1):## +1 FIXME if ym%3==0: monthUnit = 3 else: monthUnit = 1 if monthUnit < minMonthUnit: continue y, m = divmod(ym, 12) ; m+=1 tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary) if tmEpoch in tickEpochList: continue unitSize = monthPixel * monthUnit ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, getMonthName(calTypes.primary, m) if unitSize >= majorStepMin else '', )) tickEpochList.append(tmEpoch) ################ if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays: wd0 = jwday(jd0) jdw0 = jd0 + (core.firstWeekDay - wd0) % 7 unitSize = dayPixel * 7 if unitSize < majorStepMin: label = '' else: label = core.weekDayNameAb[core.firstWeekDay] for jd in range(jdw0, jd1+1, 7): tmEpoch = getEpochFromJd(jd) ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, color=weekStartTickColor, )) #tickEpochList.append(tmEpoch) ############ Day of Month hasMonthName = timeWidth < 5 * dayLen minDayUnit = float(minStep) / dayLen ## days if minDayUnit <= 15: for jd in range(jd0, jd1+1): tmEpoch = getEpochFromJd(jd) if tmEpoch in tickEpochList: continue year, month, day = jd_to_primary(jd) if day==16: dayUnit = 15 elif day in (6, 11, 21, 26): dayUnit = 5 else: dayUnit = 1 if dayUnit < minDayUnit: continue unitSize = dayPixel*dayUnit if unitSize < majorStepMin: label = '' elif hasMonthName: label = _(day) + ' ' + getMonthName(calTypes.primary, month) else: label = _(day) ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ############ Hour, Minute, Second for stepUnit, stepValue in unitSteps: stepSec = stepUnit*stepValue if stepSec < minStep: break unitSize = stepSec*pixelPerSec utcOffset = int(getUtcOffsetCurrent()) firstEpoch = iceil((timeStart+utcOffset) / stepSec) * stepSec - utcOffset for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec): if tmEpoch in tickEpochList: continue if unitSize < majorStepMin: label = '' else: jd, h, m, s = getJhmsFromEpoch(tmEpoch) if s==0: label = '%s:%s'%( _(h), _(m, fillZero=2), ) else:# elif timeWidth < 60 or stepSec < 30: label = addLRM('%s"'%_(s, fillZero=2)) #else: # label = '%s:%s:%s'%( # _(h), # _(m, fillZero=2), # _(s, fillZero=2), # ) ticks.append(Tick( tmEpoch, getEPos(tmEpoch), unitSize, label, )) tickEpochList.append(tmEpoch) ######################## Event Boxes data = { 'holidays': holidays, 'ticks': ticks, 'boxes': [], } ### data['boxes'] = calcEventBoxes( timeStart, timeEnd, pixelPerSec, borderTm, ) ### return data
dayOfYear = lambda y, m, d: datesDiff(y, 1, 1, y, m, d) + 1 ## jwday: Calculate day of week from Julian day ## 0 = Sunday ## 1 = Monday jwday = lambda jd: (jd + 1) % 7 def getJdRangeForMonth(year, month, mode): day = getMonthLen(year, month, mode) return ( to_jd(year, month, 1, mode), to_jd(year, month, day, mode) + 1, ) def getFloatYearFromEpoch(epoch, mode): module = calTypes[mode] return float(epoch - module.epoch)/module.avgYearLen + 1 def getEpochFromFloatYear(year, mode): module = calTypes[mode] return module.epoch + (year-1)*module.avgYearLen getFloatYearFromJd = lambda jd, mode: getFloatYearFromEpoch(getEpochFromJd(jd), mode) getJdFromFloatYear = lambda year, mode: getJdFromEpoch(getEpochFromFloatYear(year, mode)) getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode))
def drawAll(self, cr): timeStart = self.timeStart timeWidth = self.timeWidth timeEnd = timeStart + timeWidth #### width = self.get_allocation().width height = self.get_allocation().height pixelPerSec = self.pixelPerSec dayPixel = dayLen * pixelPerSec ## pixel maxTickHeight = maxTickHeightRatio * height ##### cr.rectangle(0, 0, width, height) fillColor(cr, bgColor) ##### setColor(cr, holidayBgBolor) for x in self.data["holidays"]: cr.rectangle(x, 0, dayPixel, height) cr.fill() ##### for tick in self.data["ticks"]: self.drawTick(cr, tick, maxTickHeight) ###### beforeBoxH = maxTickHeight ## FIXME maxBoxH = height - beforeBoxH for box in self.data["boxes"]: box.setPixelValues(timeStart, pixelPerSec, beforeBoxH, maxBoxH) self.drawBox(cr, box) self.drawBoxEditingHelperLines(cr) ###### Show (possible) Daylight Saving change if timeStart > 0 and 2 * 3600 < timeWidth < 30 * dayLen: if getUtcOffsetByEpoch(timeStart) != getUtcOffsetByEpoch(timeEnd): startJd = getJdFromEpoch(timeStart) endJd = getJdFromEpoch(timeEnd) lastOffset = getUtcOffsetByJd(startJd, localTz) dstChangeJd = None deltaSec = 0 for jd in range(startJd + 1, endJd + 1): offset = getUtcOffsetByJd(jd, localTz) deltaSec = offset - lastOffset if deltaSec != 0: dstChangeJd = jd break if dstChangeJd is not None: deltaHour = deltaSec / 3600.0 dstChangeEpoch = getEpochFromJd(dstChangeJd) #print("dstChangeEpoch = %s" % dstChangeEpoch) else: print("dstChangeEpoch not found") ###### Draw Current Time Marker dt = self.currentTime - timeStart if 0 <= dt <= timeWidth: setColor(cr, currentTimeMarkerColor) cr.rectangle( dt * pixelPerSec - currentTimeMarkerWidth / 2.0, 0, currentTimeMarkerWidth, currentTimeMarkerHeightRatio * self.get_allocation().height) cr.fill() ###### for button in self.buttons: button.draw(cr, width, height)