Created
          December 2, 2013 22:16 
        
      - 
      
- 
        Save lucasrenan/7760095 to your computer and use it in GitHub Desktop. 
    shitty code
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def create_calculations_by_product_ids(ids) | |
| actual_product_ids = product_ids | |
| destroy_product_ids = (actual_product_ids - ids).uniq | |
| calculations.in(product_id: destroy_product_ids).destroy_all | |
| new_product_ids = (ids - actual_product_ids).uniq | |
| new_products = Product.find(new_product_ids) | |
| new_products.each do |product| | |
| done_lamps = [] # TODO: remove this work around (it is here to avoid duplicated calculation entries)! | |
| product.lamps.each do |lip| | |
| next if done_lamps.include? lip.id # TODO: remove this work around (it is here to avoid duplicated calculation entries)! | |
| calculation = calculations.build({product_id: product.id, lamp_in_product_id: lip.id}) | |
| calculation.save_and_update_cache | |
| done_lamps << lip.id # TODO: remove this work around (it is here to avoid duplicated calculation entries)! | |
| end | |
| end | |
| end | |
| def utilization_coefficient | |
| surface_colors = @ambient.surface_colors | |
| utilization_coefficients = @product.photometric_sheets | |
| .where(lamp_id: @lamp.id) | |
| .first | |
| .utilization_coefficients | |
| photo_sheet = LightingCalculator::PhotometricSheet.new(surface_colors, | |
| utilization_coefficients) | |
| lower_uc = photo_sheet.utilization_coefficient_for_rcl(@ambient.rcl.floor) | |
| upper_uc = photo_sheet.utilization_coefficient_for_rcl(@ambient.rcl.ceil) | |
| diff_uc = upper_uc - lower_uc | |
| diff_rcl = (@ambient.rcl.floor - @ambient.rcl) / 100 | |
| lower_uc + diff_rcl * diff_uc | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment