Giter VIP home page Giter VIP logo

worklog's Introduction

Worklog - Simple CLI util to track work hours

Documentation Status codecov License: GPL v3

Worklog is a simple and straight-forward tool to track working times via CLI. It uses a plain text file as its storage backend which makes it easy to process the logged information with other tools.

Getting started

You need to have Python >= 3.6 installed.

pip install dcs-worklog

Please follow the documentation on readthedocs to learn how to use the CLI tool.

Development

Clone this repository and install the development version:

pip install -e ".[develop]"

Run tests via

pytest --cov worklog

Create a release

Attention: This should not be needed. Releases are auto-generated from the *GitHub CI. See the configuration file.

To create a release use git flow, update the version number in setup.py first. Then execute the following commands:

python setup.py sdist bdist_wheel
twine upload --skip-existing -r pypi dist/*

worklog's People

Contributors

dotcs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

haro87

worklog's Issues

Report breaks due to resample

Some reports (w.g. wl report --date-from 2020-10 --date-to 2020-11) fail with an error message TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got on instance of 'Index'. It seems that this is the case if one week is without a single entry, but I have to further investigate.

`wl report` does not work when `.worklog` is empty

In a new installation without having a .worklog (or an empty one), I get the following error:

user@host: ~ $ wl report
Traceback (most recent call last):
  File "/home/user/.local/bin/wl", line 8, in <module>
    sys.exit(run())
  File "/home/user/.local/lib/python3.8/site-packages/worklog/__init__.py", line 53, in run
    dispatch(log, parser, cli_args, cfg)
  File "/home/user/.local/lib/python3.8/site-packages/worklog/dispatcher.py", line 65, in dispatch
    log.report(cli_args.date_from, cli_args.date_to)
  File "/home/user/.local/lib/python3.8/site-packages/worklog/log.py", line 151, in report
    df_day = self._aggregate_time(time_mask & session_mask, resample="D")
  File "/home/user/.local/lib/python3.8/site-packages/worklog/log.py", line 553, in _aggregate_time
    df.set_index(wc.COL_LOG_DATETIME)
  File "/home/user/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 8074, in resample
    return get_resampler(
  File "/home/user/.local/lib/python3.8/site-packages/pandas/core/resample.py", line 1269, in get_resampler
    return tg._get_resampler(obj, kind=kind)
  File "/home/user/.local/lib/python3.8/site-packages/pandas/core/resample.py", line 1434, in _get_resampler
    raise TypeError(
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'

`wl status` does not work

wl status
Traceback (most recent call last):
  File "/opt/anaconda3/envs/worklog/bin/wl", line 8, in <module>
    sys.exit(run())
  File "/opt/anaconda3/envs/worklog/lib/python3.7/site-packages/worklog/__init__.py", line 46, in run
    dispatch(log, parser, cli_args, cfg)
  File "/opt/anaconda3/envs/worklog/lib/python3.7/site-packages/worklog/dispatcher.py", line 52, in dispatch
    log.status(hours_target, hours_max, query_date=query_date, fmt=fmt)
  File "/opt/anaconda3/envs/worklog/lib/python3.7/site-packages/worklog/log.py", line 256, in status
    + "]",
  File "/opt/anaconda3/envs/worklog/lib/python3.7/site-packages/worklog/log.py", line 253, in <listcomp>
    for k, v in all_touched_tasks.items()
  File "/opt/anaconda3/envs/worklog/lib/python3.7/site-packages/worklog/utils/formatting.py", line 16, in format_timedelta
    raise ValueError("value must be either a Python or a numpy timedelta instance")
ValueError: value must be either a Python or a numpy timedelta instance

Auto-close of tasks broken

wl task start foobar    # okay
wl task start foobar2 -ac
Traceback (most recent call last):
  File "/home/dotcs/code/private/worklog-cli/.conda-env/bin/wl", line 11, in <module>
    load_entry_point('dcs-worklog', 'console_scripts', 'wl')()
  File "/home/dotcs/code/private/worklog-cli/worklog/__init__.py", line 46, in run
    dispatch(log, parser, cli_args, cfg)
  File "/home/dotcs/code/private/worklog-cli/worklog/dispatcher.py", line 31, in dispatch
    log.stop_active_tasks(commit_dt)
  File "/home/dotcs/code/private/worklog-cli/worklog/log.py", line 264, in stop_active_tasks
    active_task_ids = get_active_task_ids(self._log_df[date_mask])
  File "/home/dotcs/code/private/worklog-cli/worklog/utils/tasks.py", line 57, in get_active_task_ids
    wc.COL_TASK_IDENTIFIER
TypeError: '<' not supported between instances of 'str' and 'float'

Change CLI API

The CLI API is inconsistent in some places which should be adjusted:

  • wl commit start|stop should be named wl session start|stop instead
  • Flag --auto-close at wl task start should be renamed to --auto-stop
  • Format options for wl status --fmt should be improved. The naming is inconsistent and more options should be provided, e.g. touched tasks without the time information
  • Documentation must be updated

Tasks can be started without a running session

Currently it's possible to start a task without having a running session. This should be impossible. Either a new session needs to be created on-the-fly or it the wl task start --id my-id task should throw an error.

`wl status` fails if there is no entry at all

When running wl status for the first time, it fails if no entry is created so far.

pip install dcs-worklog
> wl status # fine
Fatal: No log data available. Start a new log entry with 'wl commit start'.
> wl commit start -t 08:05
> wl status                                                                                                                                                                                           20-08-31 10:16
Traceback (most recent call last):
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2889, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 97, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'time'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/brn2rng/anaconda3/envs/worklog/bin/wl", line 8, in <module>
    sys.exit(run())
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/worklog/__init__.py", line 46, in run
    dispatch(log, parser, cli_args, cfg)
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/worklog/dispatcher.py", line 52, in dispatch
    log.status(hours_target, hours_max, query_date=query_date, fmt=fmt)
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/worklog/log.py", line 223, in status
    all_touched_tasks = get_all_task_ids_with_duration(self._log_df[sel_task_mask])
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/worklog/utils/tasks.py", line 42, in get_all_task_ids_with_duration
    s = df_h["time"]
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/pandas/core/frame.py", line 2902, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/home/brn2rng/anaconda3/envs/worklog/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2891, in get_loc
    raise KeyError(key) from err
KeyError: 'time'

`wl report` broken when never having used tasks

Currently I just use the worklog for simple time tracking (wl session start, wl session stop). I'm not using fine-grained task tracking.

When I try to get a report (wl report), I get the following error:

Traceback (most recent call last):
  File "/home/edgar/.local/bin/wl", line 8, in <module>
    sys.exit(run())
  File "/home/edgar/.local/lib/python3.8/site-packages/worklog/__init__.py", line 53, in run
    dispatch(log, parser, cli_args, cfg)
  File "/home/edgar/.local/lib/python3.8/site-packages/worklog/dispatcher.py", line 65, in dispatch
    log.report(cli_args.date_from, cli_args.date_to)
  File "/home/edgar/.local/lib/python3.8/site-packages/worklog/log.py", line 168, in report
    df_tasks = self._aggregate_tasks(time_mask & task_mask)
  File "/home/edgar/.local/lib/python3.8/site-packages/worklog/log.py", line 560, in _aggregate_tasks
    df.set_index(wc.COL_LOG_DATETIME)
  File "/home/edgar/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 4550, in set_index
    raise KeyError(f"None of {missing} are in the columns")

As soon as I start some task (wl task start something), the report works.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.