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

Custom calculator #12

Open
wants to merge 9 commits into
base: monterail
Choose a base branch
from
Open

Custom calculator #12

wants to merge 9 commits into from

Conversation

RubyDiver
Copy link

Description

Please, provide here a short description.
Consider including things like:

  • An overview of why the work is taking place (with any relevant links); don’t assume familiarity with the history.
  • Major changes made and a high-level idea of the chosen approach.
  • All the compromises made (in performance, readability, maintainability etc.)
    to achieve the expected result if any

Checklist

Before you move on, make sure that:

  • No unintended changes are included
  • Spelling is correct
  • There are tests covering new/changed functionality
  • Commits have meaningful names and changes. CR remarks-like commits are squashed.
  • Proper labels assigned. Use WIP label to indicate that state

# Conflicts:
#	app/models/spree/product_decorator.rb
#	app/views/spree/admin/vendors/_form.html.erb
#	db/seeds/002_spree.rb
x = distance.order.variants.all.count

for b in 0...x do
total_weight = distance.order.variants.map do |all|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total += Geocoder::Calculations.distance_between(final_location, start)

store_collection_charge = -0.5
vendors.map { |store_charge| store_collection_charge += 0.5 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

total = total + store_collection_charge
total_price = (total * total_load)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(base_amount + store_collection_charge) * total_weight_factor

def total_product_weight(package)
total_weight = 0

total_weight = package.order.variants.map do |variant|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use inject/reduce here


total_distance += Geocoder::Calculations.distance_between(package.stock_location.to_coordinates, vendor_co[0])

vendor_co[0...-1].each_with_index do |val, index|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://til.hashrocket.com/posts/52tcyljcgl-reducing-with-an-index-in-ruby

I think you can extend vendor_coordinates array in a way you won't have to calculate, total_distance, outside this loop.


def store_collection_charge(package)
vendor_co = vendors_coordinates(package)
vendor_co.inject(-0.5) { |sum, number| sum + 0.5}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be a one-liner vendors_coordinates(package).inject(-0.5) { |sum, number| sum + 0.5}

end

def compute_store_distance(package)
binding.pry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove it

milage_price_band = preferred_base_amount_up_to_9_mi
end

scc = store_collection_charge(package)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls avoid using abbreviations

total_weight = 1.4
end

total_price = (milage_price_band * total_weight) + scc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need total_price at all.

(milage_price_band * weight_factor) + store_collection_charge(package)

total_weight = 1.2
when 36..50
total_weight = 1.4
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are not interested about total_weight but about weight_factor, I would move this logic to the separate method

milage_price_band = preferred_base_amount_up_to_6_mi
when 6.0..9
milage_price_band = preferred_base_amount_up_to_9_mi
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here total_distance is irrelevant, what's important is milage_price_band, based on total_disatance you fit this value into ranges receiving what interests you the respective price for this range. When distance is out of range an error should be raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants