Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Automatische Generierung der Charts auf Basis des Time Tracking Tools (
Browse files Browse the repository at this point in the history
  • Loading branch information
benedictweis authored Apr 15, 2024
1 parent 525a450 commit a1f849a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.DS_STORE
1 change: 1 addition & 0 deletions docs/04-timetracking/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KIMAI_API_TOKEN=<insert-token-here>
10 changes: 10 additions & 0 deletions docs/04-timetracking/data/KW15.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Name;Duration
"Benedict Weis";1.00
"Justin Hubert";2.00
"Henry Brink";1.93
"Henry Brink";1.36
"Henry Brink";.23
"Justin Hubert";3.51
"Justin Hubert";1.66
"Luis Bernhardt";1.66
"Benedict Weis";.33
7 changes: 7 additions & 0 deletions docs/04-timetracking/data/KW16.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Name;Duration
"Henry Brink";0
"Benedict Weis";2.10
"Henry Brink";.55
"Henry Brink";.46
"Ingo Neuse";1.16
"Benedict Weis";.36
59 changes: 59 additions & 0 deletions docs/04-timetracking/generate_charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import pandas as pd
import matplotlib.pyplot as plt

def csv_to_bar_chart(csv_file, x_column, y_column, save_path):
# Read CSV file into a DataFrame
data = pd.read_csv(csv_file, delimiter=";")

# Check if specified columns exist in the DataFrame
if x_column not in data.columns or y_column not in data.columns:
print(f"Error: Column '{x_column}' or '{y_column}' not found in {csv_file}")
return

# Extract data for x and y axis
x_data = data[x_column]
y_data = data[y_column]

# Extract filename without extension for title
file_name = os.path.splitext(os.path.basename(csv_file))[0]

# Plotting
plt.figure(figsize=(10, 6))
plt.bar(x_data, y_data, color='skyblue')

# Customize the chart
plt.title(file_name)
plt.xlabel(x_column)
plt.ylabel(y_column)
plt.xticks(rotation=45, ha='right') # Rotate x-axis labels for better visibility

# Save plot as PNG file
plt.tight_layout()
plt.savefig(save_path, dpi=300)
plt.close()

def plot_all_csv_files_in_folder(folder_path, x_column, y_column, output_folder):
# Create output folder if it does not exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)

# Iterate over all files in the folder
for file in os.listdir(folder_path):
if file.endswith('.csv'):
csv_file = os.path.join(folder_path, file)
output_file = os.path.splitext(file)[0] + '.png' # Output file name with .png extension
save_path = os.path.join(output_folder, output_file)

print(f"Plotting data from {csv_file} and saving to {save_path}...")
csv_to_bar_chart(csv_file, x_column, y_column, save_path)
print("\n")

# Example usage
folder_path = 'data' # Replace 'csv_folder' with your folder path containing CSV files
output_folder = 'statistics' # Replace 'output_plots' with the folder where you want to save the plots
x_column = 'Name' # Replace 'X' with the column name for x-axis
y_column = 'Duration' # Replace 'Y' with the column name for y-axis

plot_all_csv_files_in_folder(folder_path, x_column, y_column, output_folder)

38 changes: 38 additions & 0 deletions docs/04-timetracking/get_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Depends on jq

BASE_URL="https://timetracking.henrybrink.de"
PROJECT_ID="1"
WEEKS=$(seq 15 26)
OUTPUT_FOLDER=./data

export "$(cat .env | xargs)"

mkdir -p "$OUTPUT_FOLDER"

TIME_RESPONSE=$(curl -s -X "GET" \
"$BASE_URL/api/timesheets?user=all&project=$PROJECT_ID&full=true" \
-H "accept: application/json" \
-H "Authorization: Bearer $KIMAI_API_TOKEN")


for WEEK in $WEEKS; do
TIMES=$(jq --arg WEEK "$WEEK" '[.[] | select(.begin | strptime("%Y-%m-%dT%H:%M:%S%z") | strftime("%W") as $w|$w==$WEEK)]' <<< "$TIME_RESPONSE")

if [ "$(jq length <<< "$TIMES")" -eq 0 ]; then
continue
fi

FILE="$OUTPUT_FOLDER/KW$WEEK.csv"

echo "Name;Duration" > "$FILE"

echo "$TIMES" | jq -c '.[]' | while read -r ENTRY; do
NAME=$(jq '.user.alias' <<< "$ENTRY")
DURATION=$(jq '.duration' <<< "$ENTRY")

echo "$NAME;$(echo "scale=2; $DURATION / 3600" | bc)" >> "$FILE"

done
done
Binary file added docs/04-timetracking/statistics/KW15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/04-timetracking/statistics/KW16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a1f849a

Please sign in to comment.