diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f7f405 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.DS_STORE \ No newline at end of file diff --git a/docs/04-timetracking/.example.env b/docs/04-timetracking/.example.env new file mode 100644 index 0000000..0b20562 --- /dev/null +++ b/docs/04-timetracking/.example.env @@ -0,0 +1 @@ +KIMAI_API_TOKEN= \ No newline at end of file diff --git a/docs/04-timetracking/data/KW15.csv b/docs/04-timetracking/data/KW15.csv new file mode 100644 index 0000000..3c7688e --- /dev/null +++ b/docs/04-timetracking/data/KW15.csv @@ -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 diff --git a/docs/04-timetracking/data/KW16.csv b/docs/04-timetracking/data/KW16.csv new file mode 100644 index 0000000..cce7f56 --- /dev/null +++ b/docs/04-timetracking/data/KW16.csv @@ -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 diff --git a/docs/04-timetracking/generate_charts.py b/docs/04-timetracking/generate_charts.py new file mode 100644 index 0000000..a2d35c6 --- /dev/null +++ b/docs/04-timetracking/generate_charts.py @@ -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) + diff --git a/docs/04-timetracking/get_data.sh b/docs/04-timetracking/get_data.sh new file mode 100644 index 0000000..bfbed22 --- /dev/null +++ b/docs/04-timetracking/get_data.sh @@ -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 \ No newline at end of file diff --git a/docs/04-timetracking/statistics/KW15.png b/docs/04-timetracking/statistics/KW15.png new file mode 100644 index 0000000..b453084 Binary files /dev/null and b/docs/04-timetracking/statistics/KW15.png differ diff --git a/docs/04-timetracking/statistics/KW16.png b/docs/04-timetracking/statistics/KW16.png new file mode 100644 index 0000000..2990fd9 Binary files /dev/null and b/docs/04-timetracking/statistics/KW16.png differ