Skip to content

Commit e4ab095

Browse files
committed
chore(justworks): notebook to explore weekly rollup
1 parent 646f766 commit e4ab095

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __pycache__
99
*.egg-info
1010
notebooks/data/*
1111
!notebooks/data/harvest-sample.csv
12+
!notebooks/data/justworks-sample.csv
1213
!notebooks/data/toggl-project-info-sample.json
1314
!notebooks/data/toggl-sample.csv
1415
!notebooks/data/toggl-user-info-sample.json
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
First Name,Last Name,Work Email,Start Date,End Date,Regular Hours
2+
Aymer,Hauck,aymer@compiler.la,2023-01-01,2023-01-07,23.9
3+
Aymer,Hauck,aymer@compiler.la,2023-01-08,2023-01-14,28.3
4+
Aymer,Hauck,aymer@compiler.la,2023-01-15,2023-01-21,20.5
5+
Aymer,Hauck,aymer@compiler.la,2023-01-22,2023-01-28,19.7
6+
Aymer,Hauck,aymer@compiler.la,2023-01-29,2023-02-04,4.1
7+
Gusella,Swaile,gusella@compiler.la,2023-01-01,2023-01-07,23.9
8+
Gusella,Swaile,gusella@compiler.la,2023-01-08,2023-01-14,29.9
9+
Gusella,Swaile,gusella@compiler.la,2023-01-15,2023-01-21,11.7
10+
Gusella,Swaile,gusella@compiler.la,2023-01-22,2023-01-28,36.3
11+
Gusella,Swaile,gusella@compiler.la,2023-01-29,2023-02-04,10.2
12+
Hetti,Becken,hetti@compiler.la,2023-01-01,2023-01-07,24.1
13+
Hetti,Becken,hetti@compiler.la,2023-01-08,2023-01-14,26.2
14+
Hetti,Becken,hetti@compiler.la,2023-01-15,2023-01-21,34.2
15+
Hetti,Becken,hetti@compiler.la,2023-01-22,2023-01-28,34.0
16+
Hetti,Becken,hetti@compiler.la,2023-01-29,2023-02-04,4.4
17+
Sawyer,Berrey,sawyer@compiler.la,2023-01-01,2023-01-07,19.6
18+
Sawyer,Berrey,sawyer@compiler.la,2023-01-08,2023-01-14,22.8
19+
Sawyer,Berrey,sawyer@compiler.la,2023-01-15,2023-01-21,17.7
20+
Sawyer,Berrey,sawyer@compiler.la,2023-01-22,2023-01-28,15.9
21+
Sawyer,Berrey,sawyer@compiler.la,2023-01-29,2023-02-04,3.7
22+
Silas,Idenden,silas@compiler.la,2023-01-01,2023-01-07,26.4
23+
Silas,Idenden,silas@compiler.la,2023-01-08,2023-01-14,19.8
24+
Silas,Idenden,silas@compiler.la,2023-01-15,2023-01-21,30.6
25+
Silas,Idenden,silas@compiler.la,2023-01-22,2023-01-28,25.1
26+
Silas,Idenden,silas@compiler.la,2023-01-29,2023-02-04,5.4

notebooks/toggl-to-justworks.ipynb

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Toggl to Justworks conversion\n",
8+
"\n",
9+
"This notebook explores a conversion process for Toggl hours into a format for import into Justworks.\n",
10+
"\n",
11+
"Toggl hours are tracked daily, and we can export a report of each entry in Toggl.\n",
12+
"\n",
13+
"Justworks expects a rollup of total hours per-person per-week."
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"import pandas as pd\n",
23+
"\n",
24+
"from compiler_admin.services.toggl import _prepare_input\n",
25+
"from compiler_admin.services import files"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": null,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"renames = {\n",
35+
" \"Email\": \"Work Email\",\n",
36+
" \"First name\": \"First Name\",\n",
37+
" \"Hours\": \"Regular Hours\",\n",
38+
" \"Last name\": \"Last Name\",\n",
39+
" \"Start date\": \"Start Date\"\n",
40+
"}\n",
41+
"df = _prepare_input(\"./data/toggl-sample.csv\", column_renames=renames)\n",
42+
"df.head()"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"cols = [\"Work Email\", \"First Name\", \"Last Name\", \"Start Date\"]\n",
52+
"df_people = df.sort_values(cols).groupby(cols, observed=False)\n",
53+
"df_people_agg = df_people.agg({\"Regular Hours\": \"sum\"})\n",
54+
"df_people_agg.reset_index(inplace=True)\n",
55+
"df_people_agg.head()"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"cols = [\"Work Email\", \"First Name\", \"Last Name\"]\n",
65+
"weekly_agg = df_people_agg.groupby(cols).resample(\"W\", label=\"left\", on=\"Start Date\")\n",
66+
"weekly_agg = weekly_agg[\"Regular Hours\"].sum().round(1).reset_index()\n",
67+
"weekly_agg.head()"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"weekly_agg[\"End Date\"] = weekly_agg[\"Start Date\"] + pd.Timedelta(days=6)\n",
77+
"weekly_agg.head()"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"files.write_csv(\"./data/justworks-sample.csv\", weekly_agg, columns=[\"First Name\", \"Last Name\", \"Work Email\", \"Start Date\", \"End Date\", \"Regular Hours\"])"
87+
]
88+
}
89+
],
90+
"metadata": {
91+
"kernelspec": {
92+
"display_name": "Python 3",
93+
"language": "python",
94+
"name": "python3"
95+
},
96+
"language_info": {
97+
"codemirror_mode": {
98+
"name": "ipython",
99+
"version": 3
100+
},
101+
"file_extension": ".py",
102+
"mimetype": "text/x-python",
103+
"name": "python",
104+
"nbconvert_exporter": "python",
105+
"pygments_lexer": "ipython3",
106+
"version": "3.11.11"
107+
}
108+
},
109+
"nbformat": 4,
110+
"nbformat_minor": 2
111+
}

0 commit comments

Comments
 (0)