Esempio n. 1
0
 def __init__(self, infopanel, obj):
   super().__init__(infopanel, obj)
   self.precision = self.obj.get('precision',
       self.ip.DEFAULT_PRECISION)
   self.table = [r for r in self.obj['table']
       if r['values'][0] != '']
   seq = (r['values'][-1] for r in self.table)
   self.timedeltas = timeconv.seq_of_strings_to_timedelta(seq)
   s_hstart = self.obj['followed_start']
   self.hstart = timeconv.string_to_datetime(s_hstart)
   self.punch_time = None
Esempio n. 2
0
def get_punch_obj(punch_timedelta, name, club, head, table,
    timedeltas=None, precision=0):
  htime = timeconv.timedelta_to_string(punch_timedelta,
      precision)
  if timedeltas is None:
    seq = (r['values'][-1] for r in table)
    timedeltas = timeconv.seq_of_strings_to_timedelta(seq)
  i = bisect.bisect_left(timedeltas, punch_timedelta)
  h = [i + 1] + [name, club] + [htime]
  highl = [{'values': h}]
  if i == 0:
    before = []
    after = copy.deepcopy(table[i:i+2])
    punch_pos = 1
  elif i == len(table):
    before = copy.deepcopy(table[i-2:i])
    after = []
    punch_pos = len(before) + 1
  else:
    before = copy.deepcopy(table[i-1:i])
    after = copy.deepcopy(table[i:i+1])
    punch_pos = 2
  table_ = before + highl + after
  seq = (r['values'][-1] for r in table_)
  table_timedeltas = timeconv.seq_of_strings_to_timedelta(seq)
  last_pos = i + 1
  for ti, tr in enumerate(table_):
    if ti == 0:
      tr['values'][0] = last_pos
    elif table_timedeltas[ti] == table_timedeltas[ti-1]:
      tr['values'][0] = ''
    else:
      tr['values'][0] = last_pos
    last_pos += 1
  return {'mode': 'punch', 'head': head, 'table': table_,
      'punch_pos': punch_pos}