Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill gaps #17

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ooui/graph/timerange.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def fill_gaps_in_timerange_data(values, timerange, interval):
unique_values = get_unique_values_grouped_by(values, 'type-stacked')

for key, values_for_key in unique_values.items():
values_for_key = sorted(values_for_key, key=lambda k: k['x'])
for i in range(len(values_for_key)):
value = values_for_key[i]
final_values.append(value)
Expand Down
53 changes: 52 additions & 1 deletion spec/graph/timerange_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
with description('Testing process_timerange_data') as self:

with context('when processing time range data'):
with it('should return the final combined and filled values'):
with it('should return the final combined and filled values by day'):
values_data = [
{'x': '2024-05-01', 'type': 'Revenue', 'stacked': 'A',
'value': 100, 'operator': '+'},
Expand All @@ -289,3 +289,54 @@
{'x': '2024-05-05', 'type': 'Revenue', 'stacked': 'A', 'value': 200, 'operator': '+'},
{'x': '2024-06-01', 'type': 'Profit', 'stacked': 'B', 'value': 300, 'operator': '+'}
))

with it('should return the final combined and filled values by month'):
values_data = [
{'x': '2024-01', 'type': 'Revenue', 'stacked': None,
'value': 100, 'operator': '+'},
{'x': '2024-01', 'type': 'Profit', 'stacked': None,
'value': 50, 'operator': '+'},
{'x': '2024-02', 'type': 'Revenue', 'stacked': None,
'value': 200, 'operator': '+'},
{'x': '2024-02', 'type': 'Profit', 'stacked': None,
'value': 100, 'operator': '+'},
{'x': '2024-03', 'type': 'Revenue', 'stacked': None,
'value': 300, 'operator': '+'},
{'x': '2024-03', 'type': 'Profit', 'stacked': None,
'value': 150, 'operator': '+'},
{'x': '2024-04', 'type': 'Profit', 'stacked': None,
'value': 400, 'operator': '+'},
{'x': '2024-05', 'type': 'Profit', 'stacked': None,
'value': 500, 'operator': '+'},
{'x': '2024-06', 'type': 'Profit', 'stacked': None,
'value': 600, 'operator': '+'},
{'x': '2024-06', 'type': 'Revenue', 'stacked': None,
'value': 300, 'operator': '+'},
]

result = process_timerange_data(values_data, 'month')

expect(result).to(contain_only(
{'stacked': None, 'operator': '+', 'x': '2024-01',
'type': 'Profit', 'value': 50.0},
{'stacked': None, 'operator': '+', 'x': '2024-01',
'type': 'Revenue', 'value': 100.0},
{'stacked': None, 'operator': '+', 'x': '2024-02', 'type': 'Profit',
'value': 100.0},
{'stacked': None, 'operator': '+', 'x': '2024-02',
'type': 'Revenue', 'value': 200.0},
{'stacked': None, 'operator': '+', 'x': '2024-03', 'type': 'Profit',
'value': 150.0},
{'stacked': None, 'operator': '+', 'x': '2024-03',
'type': 'Revenue', 'value': 300.0},
{'stacked': None, 'operator': '+', 'x': '2024-04', 'type': 'Profit',
'value': 400.0},
{'x': '2024-04', 'type': 'Revenue', 'stacked': None, 'value': 0},
{'stacked': None, 'operator': '+', 'x': '2024-05', 'type': 'Profit',
'value': 500.0},
{'x': '2024-05', 'type': 'Revenue', 'stacked': None, 'value': 0},
{'stacked': None, 'operator': '+', 'x': '2024-06', 'type': 'Profit',
'value': 600.0},
{'stacked': None, 'operator': '+', 'x': '2024-06',
'type': 'Revenue', 'value': 300.0},
))
Loading