Skip to content

Commit 756ca13

Browse files
committed
chore: rename input/output columns to match system
1 parent e2c3173 commit 756ca13

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

compiler_admin/commands/time/convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import pandas as pd
44

55
from compiler_admin import RESULT_SUCCESS
6-
from compiler_admin.services.harvest import INPUT_COLUMNS as TOGGL_COLUMNS, convert_to_toggl
7-
from compiler_admin.services.toggl import INPUT_COLUMNS as HARVEST_COLUMNS, convert_to_harvest
6+
from compiler_admin.services.harvest import HARVEST_COLUMNS, convert_to_toggl
7+
from compiler_admin.services.toggl import TOGGL_COLUMNS, convert_to_harvest
88

99

1010
def _get_source_converter(source):
1111
columns = pd.read_csv(source, nrows=0).columns.tolist()
1212

1313
if set(HARVEST_COLUMNS) <= set(columns):
14-
return convert_to_harvest
15-
elif set(TOGGL_COLUMNS) <= set(columns):
1614
return convert_to_toggl
15+
elif set(TOGGL_COLUMNS) <= set(columns):
16+
return convert_to_harvest
1717
else:
1818
raise NotImplementedError("A converter for the given source data does not exist.")
1919

compiler_admin/commands/time/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from argparse import Namespace
22

33
from compiler_admin import RESULT_SUCCESS
4-
from compiler_admin.services.toggl import INPUT_COLUMNS as TOGGL_COLUMNS, download_time_entries
4+
from compiler_admin.services.toggl import TOGGL_COLUMNS, download_time_entries
55

66

77
def download(args: Namespace, *extras):

compiler_admin/services/harvest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import compiler_admin.services.files as files
99

1010
# input CSV columns needed for conversion
11-
INPUT_COLUMNS = ["Date", "Client", "Project", "Notes", "Hours", "First name", "Last name"]
11+
HARVEST_COLUMNS = ["Date", "Client", "Project", "Notes", "Hours", "First name", "Last name"]
1212

1313
# default output CSV columns
14-
OUTPUT_COLUMNS = ["Email", "Start date", "Start time", "Duration", "Project", "Task", "Client", "Billable", "Description"]
14+
TOGGL_COLUMNS = ["Email", "Start date", "Start time", "Duration", "Project", "Task", "Client", "Billable", "Description"]
1515

1616

1717
def _calc_start_time(group: pd.DataFrame):
@@ -34,7 +34,7 @@ def convert_to_toggl(
3434
source_path: str | TextIO = sys.stdin,
3535
output_path: str | TextIO = sys.stdout,
3636
client_name: str = None,
37-
output_cols: list[str] = OUTPUT_COLUMNS,
37+
output_cols: list[str] = TOGGL_COLUMNS,
3838
):
3939
"""Convert Harvest formatted entries in source_path to equivalent Toggl formatted entries.
4040
@@ -52,7 +52,7 @@ def convert_to_toggl(
5252
client_name = _toggl_client_name()
5353

5454
# read CSV file, parsing dates
55-
source = files.read_csv(source_path, usecols=INPUT_COLUMNS, parse_dates=["Date"], cache_dates=True)
55+
source = files.read_csv(source_path, usecols=HARVEST_COLUMNS, parse_dates=["Date"], cache_dates=True)
5656

5757
# rename columns that can be imported as-is
5858
source.rename(columns={"Project": "Task", "Notes": "Description", "Date": "Start date"}, inplace=True)

compiler_admin/services/toggl.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212

1313
# cache of previously seen user information, keyed on email
1414
USER_INFO = files.JsonFileCache("TOGGL_USER_INFO")
15-
NOT_FOUND = "NOT FOUND"
1615

17-
# input CSV columns needed for conversion
18-
INPUT_COLUMNS = ["Email", "Project", "Client", "Start date", "Start time", "Duration", "Description"]
16+
# input columns needed for conversion
17+
TOGGL_COLUMNS = ["Email", "Project", "Client", "Start date", "Start time", "Duration", "Description"]
1918

20-
# default output CSV columns
21-
OUTPUT_COLUMNS = ["Date", "Client", "Project", "Task", "Notes", "Hours", "First name", "Last name"]
19+
# default output CSV columns for Harvest
20+
HARVEST_COLUMNS = ["Date", "Client", "Project", "Task", "Notes", "Hours", "First name", "Last name"]
2221

2322

2423
def _get_first_name(email: str) -> str:
@@ -59,7 +58,7 @@ def convert_to_harvest(
5958
source_path: str | TextIO = sys.stdin,
6059
output_path: str | TextIO = sys.stdout,
6160
client_name: str = None,
62-
output_cols: list[str] = OUTPUT_COLUMNS,
61+
output_cols: list[str] = HARVEST_COLUMNS,
6362
):
6463
"""Convert Toggl formatted entries in source_path to equivalent Harvest formatted entries.
6564
@@ -79,7 +78,7 @@ def convert_to_harvest(
7978
client_name = os.environ.get("HARVEST_CLIENT_NAME")
8079

8180
# read CSV file, parsing dates and times
82-
source = files.read_csv(source_path, usecols=INPUT_COLUMNS, parse_dates=["Start date"], cache_dates=True)
81+
source = files.read_csv(source_path, usecols=TOGGL_COLUMNS, parse_dates=["Start date"], cache_dates=True)
8382
source["Start time"] = source["Start time"].apply(_str_timedelta)
8483
source["Duration"] = source["Duration"].apply(_str_timedelta)
8584
source.sort_values(["Start date", "Start time", "Email"], inplace=True)
@@ -109,7 +108,7 @@ def download_time_entries(
109108
start_date: datetime,
110109
end_date: datetime,
111110
output_path: str | TextIO = sys.stdout,
112-
output_cols: list[str] | None = INPUT_COLUMNS,
111+
output_cols: list[str] | None = TOGGL_COLUMNS,
113112
**kwargs,
114113
):
115114
"""Download a CSV report from Toggl of detailed time entries for the given date range.

tests/services/test_harvest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from compiler_admin.services.harvest import (
1111
__name__ as MODULE,
1212
files,
13-
INPUT_COLUMNS,
14-
OUTPUT_COLUMNS,
13+
HARVEST_COLUMNS,
14+
TOGGL_COLUMNS,
1515
_calc_start_time,
1616
_duration_str,
1717
_toggl_client_name,
@@ -81,14 +81,14 @@ def test_convert_to_toggl_mocked(harvest_file, spy_files, mock_toggl_client_name
8181
spy_files.read_csv.assert_called_once()
8282
call_args = spy_files.read_csv.call_args
8383
assert (harvest_file,) in call_args
84-
assert call_args.kwargs["usecols"] == INPUT_COLUMNS
84+
assert call_args.kwargs["usecols"] == HARVEST_COLUMNS
8585
assert call_args.kwargs["parse_dates"] == ["Date"]
8686
assert call_args.kwargs["cache_dates"] is True
8787

8888
spy_files.write_csv.assert_called_once()
8989
call_args = spy_files.write_csv.call_args
9090
assert call_args[0][0] == sys.stdout
91-
assert call_args[0][2] == OUTPUT_COLUMNS
91+
assert call_args[0][2] == TOGGL_COLUMNS
9292

9393

9494
def test_convert_to_toggl_sample(harvest_file, toggl_file):
@@ -100,7 +100,7 @@ def test_convert_to_toggl_sample(harvest_file, toggl_file):
100100

101101
assert output
102102
assert isinstance(output, str)
103-
assert ",".join(OUTPUT_COLUMNS) in output
103+
assert ",".join(TOGGL_COLUMNS) in output
104104

105105
order = ["Start date", "Start time", "Email"]
106106
sample_output_df = pd.read_csv(toggl_file).sort_values(order)

tests/services/test_toggl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from compiler_admin.services.toggl import (
1212
__name__ as MODULE,
1313
files,
14-
INPUT_COLUMNS,
15-
OUTPUT_COLUMNS,
14+
TOGGL_COLUMNS,
15+
HARVEST_COLUMNS,
1616
_get_first_name,
1717
_get_last_name,
1818
_str_timedelta,
@@ -145,14 +145,14 @@ def test_convert_to_harvest_mocked(toggl_file, spy_files, mock_google_user_info)
145145
spy_files.read_csv.assert_called_once()
146146
call_args = spy_files.read_csv.call_args
147147
assert (toggl_file,) in call_args
148-
assert call_args.kwargs["usecols"] == INPUT_COLUMNS
148+
assert call_args.kwargs["usecols"] == TOGGL_COLUMNS
149149
assert call_args.kwargs["parse_dates"] == ["Start date"]
150150
assert call_args.kwargs["cache_dates"] is True
151151

152152
spy_files.write_csv.assert_called_once()
153153
call_args = spy_files.write_csv.call_args
154154
assert sys.stdout in call_args[0]
155-
assert call_args.kwargs["columns"] == OUTPUT_COLUMNS
155+
assert call_args.kwargs["columns"] == HARVEST_COLUMNS
156156

157157

158158
def test_convert_to_harvest_sample(toggl_file, harvest_file, mock_google_user_info):
@@ -165,7 +165,7 @@ def test_convert_to_harvest_sample(toggl_file, harvest_file, mock_google_user_in
165165

166166
assert output
167167
assert isinstance(output, str)
168-
assert ",".join(OUTPUT_COLUMNS) in output
168+
assert ",".join(HARVEST_COLUMNS) in output
169169

170170
order = ["Date", "First name", "Hours"]
171171
sample_output_df = pd.read_csv(harvest_file).sort_values(order)

0 commit comments

Comments
 (0)