A basic CLI-based Habit Tracking Backend.
(Developed in the course of a portfolio task for my study at IUBH).
- HaTraBa in a nutshell
- Supported basic functionality scenarios
- Setup Guide
- Run test cases
- Usage Guide
- Behind the scenes
- License
- Habit tracking backend that enables human users as well as system users (e.g. technical clients with an user interface to a human user) to manage and analyze habits.
- Command line interface application where users interact entirely through their terminal.
- Accepts a set of commands and returns JSON output per default which can be further processed by the user. In addition and if desired, a more human readable output format can be forced.
- “Ready-to-use” with 5 predefined habits and example tracking data for period of one month.
Python 3.8.3 or later
Note: Installation routine under Windows 10 is described here. Please adapt shell commands in case of you're running another operating system.
(1) Download the development version (current master is V1.0.0) to any wished location
https://github.com/anjakuchenbecker/oofpp_habits_project/archive/main.zip
(2) Open the cmd
and go to the download location
(3) Unzip the downloaded file
$ tar -xf oofpp_habits_project-main.zip
(4) Switch to oofpp_habits_project-main
folder
$ cd oofpp_habits_project-main
(5) Create virtual environment
$ python -m venv env
(6) Activate virtual environment
$ .\env\Scripts\activate
(7) Install requirements
(env) $ pip install -r requirements.txt
(8) Switch to habittracker
folder
(env) $ cd habittracker
(9) Perform a tiny smoke test
(env) $ python habit_tracker.py
You should see something like this
Installation procedure is finished.
Now, you can
- Run the test cases, to check whether everything is ok
- or directly start using HaTraBa, please refer to the Usage Guide
(1) Ensure that you are in the habittracker
folder
(2) Run tests
(env) $ pytest ../tests
(3) You should now see something like this
Ensure that you are in the habittracker
folder, before you running commands!
The general usage pattern is:
(env) $ python habit_tracker.py [OPTIONS] COMMAND [ARGS]
Use python habit_tracker.py COMMAND --help
for information on a specific command.
The following commands are supported:
Command | Description | Category |
---|---|---|
create | Create habit with given details. | Management of habits |
checkoff | Check off given habit. | Management of Habits |
delete | Delete given habit. | Management of Habits |
list-habits | Return a list of all currently tracked habits. | Analytics of Habits |
list-habits-by-periodicity | Return a list of all currently tracked habits filtered according to given periodicity. | Analytics of Habits |
get-longest-streak | Return the longest streak of all currently tracked habits. | Analytics of Habits |
get-longest-streak-for-habit | Return the longest streak for the given habit. | Analytics of Habits |
Please refer to the subsequent chapters to get more details for each command.
Creates a habit with given details and returns created habit.
Option | Description | Required |
---|---|---|
-n, --name TEXT | Name of habit. | Yes |
-d, --description TEXT | Description of habit. | Yes |
-p, --periodicity [DAILY|WEEKLY] | Periodicity of habit. | Yes |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
name | string | Name of the habit. |
description | string | Description of the habit. |
periodicity | string | Periodicity of the habit. |
created | string | Creation timestamp of the habit. |
checkoffs | array | List of all check offs. |
Command
(env) $ python habit_tracker.py create -n "name" -d "desc" -p DAILY
Output
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3",
"name": "name",
"description": "description",
"periodicity": "DAILY",
"created": "2021-01-01 01:01:01.418133",
"checkoffs": []
}
Checks off given habit with given timestamp and returns checked off habit.
Option | Description | Required |
---|---|---|
-h, --habit-id TEXT | Id of habit that has to be checked off. | Yes |
-t, --timestamp TEXT | Check off timestamp, format YYYY-MM-DD HH:MM:SS.f. | Yes |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
name | string | Name of the habit. |
description | string | Description of the habit. |
periodicity | string | Periodicity of the habit. |
created | string | Creation timestamp of the habit. |
checkoffs | array | List of all check offs. |
Command
(env) $ python habit_tracker.py checkoff –h 54befadbfe874f5c9d5cad6b1d67c4a3 –t "2021-01-02 14:00:01.518133"
Output
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3",
"name": "name",
"description": "description",
"periodicity": "DAILY",
"created": "2020-12-31 01:01:01.418133",
"checkoffs": [
"2021-01-02 14:00:01.518133"
]
}
Deletes given habit and returns id of deleted habit.
Option | Description | Required |
---|---|---|
-h, --habit-id TEXT | Id of habit that has to be deleted. | Yes |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
Command
(env) $ python habit_tracker.py delete –h 54befadbfe874f5c9d5cad6b1d67c4a3
Output
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3"
}
Returns a list of all currently tracked habits.
The habits are returned sorted by creation date, with the most recently created habit appearing first.
Option | Description | Required |
---|---|---|
-l, --limit INTEGER | A limit on the number of objects to be returned, must be positive. Default is no limit. | No |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
List (array) of habit objects, each of the following element:
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
name | string | Name of the habit. |
description | string | Description of the habit. |
periodicity | string | Periodicity of the habit. |
created | string | Creation timestamp of the habit. |
checkoffs | array | List of all check offs. |
Command
(env) $ python habit_tracker.py list-habits –l 3
Output
[
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3",
"name": "name",
"description": "description",
"periodicity": "DAILY",
"created": "2020-12-31 01:01:01.418133",
"checkoffs": [
"2021-01-02 14:00:01.518133"
]
},...
]
Returns a list of all currently tracked habits filtered according to given periodicity.
The habits are returned sorted by creation date, with the most recently created habit appearing first.
Option | Description | Required |
---|---|---|
-p, --periodicity [DAILY|WEEKLY] | Periodicity of habit. Default is 'DAILY'. | No |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
-l, --limit INTEGER | A limit on the number of objects to be returned, must be positive. Default is no limit. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
List (array) of habit objects, each of the following element:
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
name | string | Name of the habit. |
description | string | Description of the habit. |
periodicity | string | Periodicity of the habit. |
created | string | Creation timestamp of the habit. |
checkoffs | array | List of all check offs. |
Command
(env) $ python habit_tracker.py list-habits-by-periodicity –p DAILY –l 3
Output
[
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3",
"name": "name",
"description": "description",
"periodicity": "DAILY",
"created": "2020-12-31 01:01:01.418133",
"checkoffs": [
"2021-01-02 14:00:01.518133"
]
},...
]
Return the longest streak of all currently tracked habits.
Option | Description | Required |
---|---|---|
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
Element | Type | Description |
---|---|---|
longest_streak | integer | Longest streak value. |
Command
(env) $ python habit_tracker.py get-longest-streak
Output
{
"longest_streak": 11
}
Returns the longest streak for the given habit.
Option | Description | Required |
---|---|---|
-h, --habit-id TEXT | Id of habit that has to be analyzed for longest streak. | Yes |
-o, --output [JSON|HUMAN] | Output format. Default JSON. | No |
--help | Show this message and exit. | No |
JSON Document, per default.
(Use option -o HUMAN
to force a more human readable output format.)
Element | Type | Description |
---|---|---|
id | string | Unique identifier of the habit. |
name | string | Name of the habit. |
longest_streak | integer | Longest streak value. |
Command
(env) $ python habit_tracker.py get-longest-streak-for-habit -h 54befadbfe874f5c9d5cad6b1d67c4a3
Output
{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3",
"name": "Meditating",
"longest_streak": 11
}
HaTraBa consists of the following components:
The interaction between the components is as follows:
The interaction between the components is as follows:
The interaction between the components is as follows:
The interaction between the components is as follows:
The interaction between the components is as follows:
The interaction between the components is as follows:
The interaction between the components is as follows:
MIT © Anja Kuchenbecker