This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatische Generierung der Charts auf Basis des Time Tracking Tools (…
- Loading branch information
1 parent
525a450
commit a1f849a
Showing
8 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
.DS_STORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
KIMAI_API_TOKEN=<insert-token-here> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.