Skip to content

Commit

Permalink
implements totalProfit and adds sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
kubarium committed Feb 17, 2017
1 parent 06e1222 commit d1a87cc
Show file tree
Hide file tree
Showing 5 changed files with 1,664 additions and 1,491 deletions.
2 changes: 2 additions & 0 deletions dataminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ProductProperty:
PROFIT = "profit"
PRICE = "price"
TOTAL_COST = "totalCost"
TOTAL_PROFIT = "totalProfit"

products = []

Expand Down Expand Up @@ -60,6 +61,7 @@ def prepareProducts():
product[ProductProperty.TOTAL_COST] = totalCost(product[ProductProperty.NAME])
product[ProductProperty.PROFIT] = product[
ProductProperty.PRICE] - totalCost(product[ProductProperty.NAME])
product[ProductProperty.TOTAL_PROFIT] = product[ProductProperty.PROFIT] * product["demand"]
product[ProductProperty.INGREDIENTS_WORTH] = ingredientsWorth(
product[ProductProperty.NAME])
product[ProductProperty.IS_WORTH_IT] = isWorthIt(
Expand Down
4 changes: 2 additions & 2 deletions src/Product.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export default class Product extends Component {
<Col md={3} lg={3} sm={3} xs={3}>
<strong>Total Cost:</strong><Space/><Clearfix visibleXsBlock/>{this.decimalFormatter(this.props.product.totalCost)}</Col>
<Col md={2} lg={2} sm={2} xs={2}>
<strong>Profit:</strong><Space/><Clearfix visibleXsBlock/>{this.decimalFormatter(this.props.product.profit)}</Col>
<strong>Unit Profit:</strong><Space/><Clearfix visibleXsBlock/>{this.decimalFormatter(this.props.product.profit)}</Col>
<Col md={4} lg={4} sm={4} xs={4}>
<strong>Total Profit:</strong><Space/><Clearfix visibleXsBlock/>{this.decimalFormatter(this.props.product.profit * this.props.product.demand)}</Col>
<strong>Total Profit:</strong><Space/><Clearfix visibleXsBlock/>{this.decimalFormatter(this.props.product.totalProfit)}</Col>
<Col md={3} lg={3} sm={3} xs={3}></Col>
</Row>
</Grid>
Expand Down
5 changes: 4 additions & 1 deletion src/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ export default class Products extends Component {
}
}

sortByTotalProfit = (a,b) => {
return a.totalProfit < b.totalProfit ? 1 : a.totalProfit > b.totalProfit ? -1 : 0
}
render() {

let products = Utils.FilterByIngredients(store.getState().ingredients).filter(product => product.date <= store.getState().date)
let products = Utils.FilterByIngredients(store.getState().ingredients).filter(product => product.date <= store.getState().date).sort(this.sortByTotalProfit)
return (
<ListGroup>
{ products
Expand Down
5 changes: 4 additions & 1 deletion src/Reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const reducers = (state, action) => {
})
case ActionTypes.DEMAND_CHANGE:
let products = state.products
products[action.product.index].demand = action.product.demand
let product = products[action.product.index]
product.demand = action.product.demand
product.totalProfit = product.profit * action.product.demand


return Object.assign({},
state
Expand Down
Loading

0 comments on commit d1a87cc

Please sign in to comment.