Ejemplo n.º 1
0
def status(click, **kwargs):
    config = Config()
    path_profile = get_profile_and_projects_from_path(config.root_dir())
    db = Database()
    _sum = db.get_sum_by_profile_project(
        path_profile['profile'], path_profile['current_project'])
    open_timer = db.open_timer()
    text = f"Status: \nDurations: \n"
    
    text += f"{_sum}\n"
    if not open_timer.empty:
      text += f'Open Timer: \n{open_timer}'
    else:
      text += f'No open timer.'
    click.echo(text)
Ejemplo n.º 2
0
def stop(click, **kwargs):
    config = Config()
    path_profile = get_profile_and_projects_from_path(config.root_dir())

    entry = {
        'timestamp':
        datetime.now(),
        'profile':
        kwargs.get('profile', path_profile['profile'])
        or path_profile['profile'],
        'project':
        kwargs.get('project', path_profile['current_project'])
        or path_profile['current_project'],
        'path':
        getcwd(),
        'message':
        kwargs.get('message'),
        'service':
        kwargs.get('service') or config.default_service()['id'],
        'action':
        ACTION_TYPES['end']
    }
    Database().insert(entry)
    click.echo(
        f"Stopped timer for {path_profile['profile']}/{'/'.join(path_profile['projects'])}"
    )
    log.debug('starting timer call')
Ejemplo n.º 3
0
class Stats:
    def __init__(self):
        self.db = Database()
        

    def filtered(self):
        return self.db.get()

    def duration_sum_by_key(self, key='project'):
        data = self.filtered()
        print(data)
Ejemplo n.º 4
0
def start(click, **kwargs):
    config = Config()
    db = Database()
    path_profile = get_profile_and_projects_from_path(config.root_dir())
    project = path_profile['current_project']
    # Check if timers are still open in same profile
    open_timer = db.open_timer()
    if not open_timer.empty:
        sure = click.confirm(
            f'{open_timer.to_string()}\n These timers are still open. Would you like to stop them?'
        )
        if sure:
            # Stop timer
            for index, entry in open_timer.iterrows():
                del entry['id']
                _entry = {
                    **entry, 'timestamp': datetime.now(),
                    'action': ACTION_TYPES['end']
                }
                db.insert(_entry)

    if kwargs.get('ago'):
        time = pd.Timestamp('now') - pd.Timedelta(kwargs.get('ago'))
    else:
        time = datetime.now()
    entry = {
        'timestamp':
        time,
        'profile':
        kwargs.get('profile', path_profile['profile'])
        or path_profile['profile'],
        'project':
        kwargs.get('project', project) or project,
        'path':
        getcwd(),
        'message':
        kwargs.get('message'),
        'service':
        kwargs.get('service') or config.default_service()['id'],
        'action':
        ACTION_TYPES['start']
    }
    db.insert(entry)
    click.echo(
        f"Started timer for {path_profile['profile']}/{'/'.join(path_profile['projects'])} on {time}"
    )
    log.debug('starting timer call')
    pass
Ejemplo n.º 5
0
 def __init__(self):
     self.db = Database()
Ejemplo n.º 6
0
 def __init__(self):
     self.project = Project().current_project
     self.account = Project().current_account
     self.current_path = Project().current_path
     self.config = Config()
     self.db = Database()
Ejemplo n.º 7
0
class Timer:
    def __init__(self):
        self.project = Project().current_project
        self.account = Project().current_account
        self.current_path = Project().current_path
        self.config = Config()
        self.db = Database()

    def entry(self, action, *args, **kwargs):
        timestamp = pd.Timestamp.now()
        df = pd.DataFrame({
            'project': [kwargs.get('project', self.project)],
            'account': [kwargs.get('account', self.account)],
            'path': [kwargs.get('path', self.current_path)],
            'service':
            [kwargs.get('service',
                        self.config.default_service()['id'])],
            'message': [kwargs.get('message', None)],
            'timestamp': [timestamp],
            'action': [action],
        })
        return df

    def end_timer(self):
        # First end all open timer
        timers = self.db.open_timer()
        if not timers.empty:
            if len(timers.index) > 1:
                for index, timer in timers.reset_index().iterrows():
                    entry = self.entry(END_TIMER_ACTION,
                                       project=timer['project'],
                                       account=timer['account'],
                                       path=timer['path'])
                    self.db.insert(entry)
            else:
                val = timers.reset_index().iloc[0]
                self.db.insert(
                    self.entry(END_TIMER_ACTION,
                               project=val['project'],
                               account=val['account'],
                               path=val['path']))
            return timers.reset_index().to_dict('records')
        else:
            log.debug(f'No timer was started for {self.current_path}')

    def start_time(self, message, service, account, project):
        # Close all timer
        self.end_timer()

        params = {}

        if message:
            params['message'] = message
        if service:
            params['service'] = service
        if account:
            params['account'] = account
        if project:
            params['project'] = project

        entry = self.entry(START_TIMER_ACTION, **params)
        try:
            self.db.insert(entry)
        except:
            self.db.save(entry)

        return {
            'project': self.project,
            'account': self.account,
            'path': self.current_path,
            'timestamp': entry['timestamp']
        }