def logTime(self, task_id, timeLogged, adjustBy=0):
     try:
         task = self.getTask(task_id)
         if adjustBy != 0:
             task.logTime(TimeConvertService.convertToMinutes(adjustBy))
         else:
             task.logTime(TimeConvertService.convertToMinutes(timeLogged))
         self.insertOrUpdateTask(task)
         return True
     except AttributeError:
         return False
     except SQLAlchemyError:
         return False
    def createReportForProject(self, pid):
        if pid == 0 or pid is None:
            return ''

        project = hostService.projectService.getProject(pid)
        userProjectEntities = hostService.userProjectService.getUsersForProject(pid)
        usersInvolved = []
        for user in userProjectEntities:
            usersInvolved.append(user.users.username)
        tasks = hostService.taskService.getTasksForProject(pid)
        nrTasksClosed = len(hostService.taskService.getTasksClosedForProject(pid))
        nrTasksInProgress = len(hostService.taskService.getTasksForProject(pid))
        nrTasksToDO = len(hostService.taskService.getTasksToDoForProject(pid))
        projectHistory = hostService.historyService.getProjectHistory(pid)
        timeRemaining = 0
        totalTime = 0
        # compute time
        for task in tasks:
            timeRemaining += TimeConvertService.convertToMinutes(task.minutes_remaining)
            totalTime += TimeConvertService.convertToMinutes(task.minutes_estimated)

        timeLogged = totalTime - timeRemaining
        users = []
        for event in projectHistory:
            users.append(event.user.username)
        # get fist element
        try:
            activeUser = Counter(users).most_common(1)[0][0]
        except IndexError:
            activeUser = "******"
        return {
            'pid': pid,
            'title': project.title,
            'users': usersInvolved,
            'nrTasksClosed': nrTasksClosed,
            'nrTasksInProgress': nrTasksInProgress,
            'nrTasksToDO': nrTasksToDO,
            'mostActive': activeUser,
            'timeRemaining': TimeConvertService.convertFromMinutes(timeRemaining),
            'timeLogged': TimeConvertService.convertFromMinutes(timeLogged)
        }
 def minutes_remaining(self, minutes_remaining):
     self._minutes_remaining = TimeConvertService.convertToMinutes(minutes_remaining)
 def minutes_remaining(self):
     return TimeConvertService.convertFromMinutes(self._minutes_remaining)
 def minutes_estimated(self, minutes_estimated):
     self._minutes_estimated = TimeConvertService.convertToMinutes(minutes_estimated)
 def minutes_estimated(self):
     return TimeConvertService.convertFromMinutes(self._minutes_estimated)