def get_pending(self, today, action_names): """ returns a generator over tuples (date, action_name) of actions that failed to work before today """ store = self._storage first_date = store['__from__'] for date in dates_between(first_date, today): for action_name in action_names: if action_name not in store: DEBUG(u"Creating filling for new action %s" % (action_name, )) store[action_name] = {} yesterday = today - datetime.timedelta(days=1) for fill_date in dates_between(first_date, yesterday): DEBUG(u"Creating fill for new action %s on date %s" % (action_name, fill_date)) store[action_name][fill_date] = {'done': True, 'created': datetime.datetime.now(), 'times': []} action_store = store[action_name] if date not in action_store: DEBUG(u"Creating a skipped action %s on %s" % (action_name, date)) action_store[date] = {'done': False, 'created': datetime.datetime.now(), 'times': []} yield date, action_name else: entry = action_store[date] if entry['done']: continue else: DEBUG(u'Found failed action %s on %s' % (action_name, date)) yield date, action_name
def _worked_hours(self, date): month_start, month_end = self._get_start_end_of_month(date) holidays = Holiday.all() today = datetime.date.today() count_of_required_month_hours = count_of_required_hours_to_today = 0 for date in dates_between(month_start, month_end): if not Holiday.is_holiday(date, holidays=holidays): count_of_required_month_hours += 8 if date <= today: count_of_required_hours_to_today += 8 return count_of_required_month_hours, count_of_required_hours_to_today
def get_pending(self, today, action_names): """ returns a generator over tuples (date, action_name) of actions that failed to work before today """ store = self._storage first_date = store['__from__'] for date in dates_between(first_date, today): for action_name in action_names: if action_name not in store: DEBUG(u"Creating filling for new action %s" % (action_name, )) store[action_name] = {} yesterday = today - datetime.timedelta(days=1) for fill_date in dates_between(first_date, yesterday): DEBUG(u"Creating fill for new action %s on date %s" % (action_name, fill_date)) store[action_name][fill_date] = { 'done': True, 'created': datetime.datetime.now(), 'times': [] } action_store = store[action_name] if date not in action_store: DEBUG(u"Creating a skipped action %s on %s" % (action_name, date)) action_store[date] = { 'done': False, 'created': datetime.datetime.now(), 'times': [] } yield date, action_name else: entry = action_store[date] if entry['done']: continue else: DEBUG(u'Found failed action %s on %s' % (action_name, date)) yield date, action_name
def _get_burndown(self): """Return a list of total point values per day of sprint""" today = datetime.date.today() sdate = self.sprint.start edate = self.sprint.end if self.sprint.end < today else today if sdate > today: return [] tseries = dict([(cdate, 0) for cdate in h.dates_between(sdate, edate) ]) for bug in self.bugs: if bug.is_closed() or bug.get_status() == 'RESOLVED': for date in tseries.iterkeys(): if date < bug.changeddate.date(): tseries[date] += bug.points else: for date in tseries.iterkeys(): tseries[date] += bug.points tseries = [ (self._date_to_js(v[0]), v[1]) for v in sorted(tseries.iteritems(), key=lambda x: x[0]) ] return tseries
def get(self): month_start, month_end = self._get_month() entries = self.session.query('user_id', 'date', 'time', 'late_count').from_statement(""" SELECT t.user_id as "user_id", t.date as "date", ( SELECT COALESCE(SUM(h.time), 0.0) FROM time_entry h WHERE h.user_id = t.user_id AND h.date = t.date AND h.deleted = FALSE ) as "time", ( SELECT COUNT(*) FROM time_entry s WHERE s.user_id = t.user_id AND s.date = t.date AND DATE(s.modified_ts) > s.date ) as "late_count" FROM time_entry t WHERE t.date >= :month_start AND t.date <= :month_end GROUP BY t.user_id, t.date; """).params(month_start=month_start, month_end=month_end) if not self.request.has_perm('view'): users = [self.request.user] # TODO do we need to constrain entries also? locations= { self.request.user.location: ('', 1) } else: users_w = User.query.filter(User.is_not_client()) \ .filter(User.is_active==True) \ .filter(User.location=='wroclaw') \ .order_by(User.freelancer, User.name) \ .all() users_p = User.query.filter(User.is_not_client()) \ .filter(User.is_active==True) \ .filter(User.location=='poznan') \ .order_by(User.freelancer, User.name) \ .all() locations = { 'wroclaw': [u'Wrocław', len(users_w)], 'poznan': [u'Poznań', len(users_p)], } locations[self.request.user.location][1] -= 1 if self.request.user.location == 'wroclaw': users = users_w users.extend(users_p) else: users = users_p users.extend(users_w) today = datetime.date.today() grouped = defaultdict(lambda: defaultdict(lambda: 0.0)) late = defaultdict(lambda: defaultdict(lambda: False)) sums = defaultdict(lambda: 0.0) daily_sums = defaultdict(lambda: 0.0) for user_id, date, time, late_count in entries: grouped[user_id][date] = time if date <= today: sums[user_id] += time daily_sums[date] += time late[user_id][date] = late_count > 0 holidays = Holiday.all() count_of_required_month_hours = {} count_of_required_hours_to_today = {} for user in users: sftw = user.start_full_time_work or datetime.date(1970, 1, 1) if sftw > month_end: start_work = datetime.date(today.year+10, 1, 1) elif sftw < month_start: start_work = month_start else: start_work = sftw count_of_required_month_hours[user.id] = h.get_working_days(start_work, month_end) * 8 count_of_required_hours_to_today[user.id] = h.get_working_days(start_work, today if today < month_end else month_end) * 8 # move current user to the front of the list current_user_index = None for i, user in enumerate(users): if user.id == self.request.user.id: current_user_index = i users.insert(0, users.pop(current_user_index)) return dict( entries=grouped, users=users, sums=sums, late=late, excuses=excuses.wrongtime(), daily_sums=daily_sums, monthly_sum=sum(daily_sums.values()), dates=__builtin__.list(dates_between(month_start, month_end)), is_holiday=lambda date: Holiday.is_holiday(date, holidays=holidays), month_start=month_start, prev_date=previous_month(month_start), next_date=next_month(month_start), today=today, count_of_required_month_hours=count_of_required_month_hours, count_of_required_hours_to_today=count_of_required_hours_to_today, locations=locations, )
def _get_burndown_axis(self): """Return a list of epoch dates between sprint start and end inclusive""" return [self._date_to_js(cdate) for cdate in h.dates_between(self.sprint.start, self.sprint.end)]
def get(self): month_start, month_end = self._get_month() entries = ( DBSession.query("user_id", "date", "time", "late_count") .from_statement( """ SELECT t.user_id as "user_id", t.date as "date", ( SELECT COALESCE(SUM(h.time), 0.0) FROM time_entry h WHERE h.user_id = t.user_id AND h.date = t.date AND h.deleted = FALSE ) as "time", ( SELECT COUNT(*) FROM time_entry s WHERE s.user_id = t.user_id AND s.date = t.date AND DATE(s.modified_ts) > s.date ) as "late_count" FROM time_entry t WHERE t.date >= :month_start AND t.date <= :month_end GROUP BY t.user_id, t.date; """ ) .params(month_start=month_start, month_end=month_end) ) if not self.request.has_perm("can_see_users_times"): users = [self.request.user] # TODO do we need to constrain entries also? locations = {self.request.user.location: ("", 1)} else: location_names = self.request.user.get_locations() users = {} for name, (fullname, shortcut) in location_names: usersq = ( User.query.filter(User.is_not_client()) .filter(User.is_active == True) .filter(User.location == name) .order_by(User.is_freelancer(), User.name) ) users[name] = usersq.all() locations = {name: [User.LOCATIONS[name][0], len(users)] for name, users in users.iteritems()} locations[self.request.user.location][1] -= 1 ordered_users = [] for name, (fullname, shortcut) in location_names: ordered_users.extend(users[name]) users = ordered_users # move current user to the front of the list current_user_index = None for i, user in enumerate(users): if user.id == self.request.user.id: current_user_index = i users.insert(0, users.pop(current_user_index)) today = datetime.date.today() grouped = defaultdict(lambda: defaultdict(lambda: 0.0)) late = defaultdict(lambda: defaultdict(lambda: False)) sums = defaultdict(lambda: 0.0) daily_sums = defaultdict(lambda: 0.0) for user_id, date, time, late_count in entries: grouped[user_id][date] = time if date <= today: sums[user_id] += time daily_sums[date] += time late[user_id][date] = late_count > 0 holidays = Holiday.all() count_of_required_month_hours = {} count_of_required_hours_to_today = {} for user in users: sftw = user.start_full_time_work if sftw: if sftw > month_end: start_work = datetime.date(today.year + 10, 1, 1) elif sftw < month_start: start_work = month_start else: start_work = sftw month_hours = h.get_working_days(start_work, month_end) * 8 today_ = today if today < month_end else month_end hours_to_today = h.get_working_days(start_work, today_) * 8 count_of_required_month_hours[user.id] = month_hours count_of_required_hours_to_today[user.id] = hours_to_today else: count_of_required_month_hours[user.id] = 0 count_of_required_hours_to_today[user.id] = 0 return dict( entries=grouped, users=users, sums=sums, late=late, excuses=excuses.wrongtime(), daily_sums=daily_sums, monthly_sum=sum(daily_sums.values()), dates=__builtin__.list(dates_between(month_start, month_end)), is_holiday=lambda date: Holiday.is_holiday(date, holidays=holidays), month_start=month_start, prev_date=previous_month(month_start), next_date=next_month(month_start), today=today, count_of_required_month_hours=count_of_required_month_hours, count_of_required_hours_to_today=count_of_required_hours_to_today, locations=locations, )