Skip to content

Commit

Permalink
Inline aggregate_value function
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkedev committed Jul 29, 2019
1 parent fcf0816 commit 3c8afb8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions mpr/cash_index/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ def format_column(column: Tuple[str, int]) -> str:
return f"{Arrangement(arrangement).name} {field}".replace('_', ' ').title()


def aggregate_value(head_count: Series, carcass_weight: Series, net_price: Series) -> DataFrame:
weight = total_weight(head_count=head_count, weight=carcass_weight).rename('weight')
value = total_value(weight=weight, price=net_price).rename('value')

return pd.pivot_table(create_table(weight, value), index='date')


def cash_index_report(slaughter: Iterator[Slaughter]) -> DataFrame:
records = to_array(filter_arrangement(slaughter))
columns = ['date', 'arrangement', 'head_count', 'carcass_weight', 'net_price']
Expand All @@ -61,10 +54,13 @@ def cash_index_report(slaughter: Iterator[Slaughter]) -> DataFrame:
carcass_weight = data.carcass_weight
net_price = data.net_price

totals = aggregate_value(head_count, carcass_weight, net_price)
daily_price, daily_change = with_change(weighted_price(**totals))
weight = total_weight(head_count=head_count, weight=carcass_weight).rename('weight')
value = total_value(weight=weight, price=net_price).rename('value')

total_values = pd.pivot_table(create_table(weight, value), index='date')
daily_price, daily_change = with_change(weighted_price(**total_values))

rolling_totals = totals.rolling(2).sum().dropna()
rolling_totals = total_values.rolling(2).sum().dropna()
cme_index, index_change = with_change(weighted_price(**rolling_totals))

return create_table(
Expand Down

0 comments on commit 3c8afb8

Please sign in to comment.