Skip to content

A basic CLI-based Habit Tracking Backend. (Developed in the course of a portfolio task for my study at IUBH).

License

Notifications You must be signed in to change notification settings

anjakuchenbecker/oofpp_habits_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

*~HaTraBa~* Version 1.0.0

A basic CLI-based Habit Tracking Backend.

(Developed in the course of a portfolio task for my study at IUBH).

Table of Contents

HaTraBa in a nutshell

  • 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.

Supported basic functionality scenarios

Use Case Diagram

Setup Guide

Prerequisites

Python 3.8.3 or later

Installation

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

Command Output

Installation procedure is finished.

Now, you can

Run test cases

(1) Ensure that you are in the habittracker folder

(2) Run tests

(env) $ pytest ../tests

(3) You should now see something like this

Command Output

Usage Guide

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.

Overview of commands

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.

Management of Habits

create


Description

Creates a habit with given details and returns created habit.

Options
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
Output

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.
Example

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": []
}

checkoff


Description

Checks off given habit with given timestamp and returns checked off habit.

Options
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
Output

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.
Example

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"
    ]
}

delete


Description

Deletes given habit and returns id of deleted habit.

Options
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
Output

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.
Example

Command

(env) $ python habit_tracker.py delete –h 54befadbfe874f5c9d5cad6b1d67c4a3

Output

{
"id": "54befadbfe874f5c9d5cad6b1d67c4a3"
}

Analytics of Habits

list-habits


Description

Returns a list of all currently tracked habits.

The habits are returned sorted by creation date, with the most recently created habit appearing first.

Options
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
Output

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.
Example

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"
        ]
    },...
]

list-habits-by-periodicity


Description

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.

Options
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
Output

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.
Example

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"
        ]
    },...
]

get-longest-streak


Description

Return the longest streak of all currently tracked habits.

Options
Option Description Required
-o, --output [JSON|HUMAN] Output format. Default JSON. No
--help Show this message and exit. No
Output

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.
Example

Command

(env) $ python habit_tracker.py get-longest-streak

Output

{
    "longest_streak": 11
}

get-longest-streak-for-habit


Description

Returns the longest streak for the given habit.

Options
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
Output

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.
Example

Command

(env) $ python habit_tracker.py get-longest-streak-for-habit -h 54befadbfe874f5c9d5cad6b1d67c4a3

Output

{
    "id": "54befadbfe874f5c9d5cad6b1d67c4a3",
    "name": "Meditating",
    "longest_streak": 11
}

Behind the scenes

Components

HaTraBa consists of the following components:

Component Diagram

Process Create Habit

The interaction between the components is as follows:

Sequence Diagram Create Habit

Process Checkoff Habit

The interaction between the components is as follows:

Sequence Diagram Checkoff Habit

Process Delete Habit

The interaction between the components is as follows:

Sequence Diagram Delete Habit

Process List Habits

The interaction between the components is as follows:

Sequence Diagram List Habits

Process List Habits by periodicity

The interaction between the components is as follows:

Sequence Diagram List Habits by periodicity

Process Get longest Streak

The interaction between the components is as follows:

Sequence Diagram Get longest Streak

Process Get longest Streak for Habit

The interaction between the components is as follows:

Sequence Diagram Get longest Streak for Habit

License

MIT © Anja Kuchenbecker

About

A basic CLI-based Habit Tracking Backend. (Developed in the course of a portfolio task for my study at IUBH).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages