def invention(item_id): """ Display the invention page with all price data pre calculated """ item = Item.query.get(item_id) char = current_user.pref.invention_character if item is None or item.max_production_limit is None: abort(404) # global activity activity_copy = item.activities.filter_by( activity=Activity.COPYING).first() invention_skills = item.activity_skills.filter_by( activity=Activity.INVENTION).all() # copy stuff copy_base_cost = 0.0 if activity_copy is not None: # copy base cost, as it's different from the invention materials = item.activity_materials.filter_by( activity=Activity.MANUFACTURING) copy_base_cost = calculate_base_cost(materials) # loop through skills for display as we need to do the difference # between both skills (not the same bonuses in invention probability) encryption_skill = None datacore_skills = [] for s in invention_skills: skill = get_skill_data(s.skill, char) if skill.name.find('Encryption') == -1: datacore_skills.append(skill) else: encryption_skill = skill # other skills # calculate baseCost for invention materials = item.activity_products.filter_by( activity=Activity.INVENTION).first( ).product.activity_materials.filter_by(activity=Activity.MANUFACTURING) invention_base_cost = calculate_base_cost(materials) # base solar system indexes = IndustryIndex.query.filter( IndustryIndex.solarsystem_id == SolarSystem.id, SolarSystem.name == current_user.pref.invention_system, IndustryIndex.activity.in_([ Activity.COPYING, Activity.INVENTION, ])) index_list = {} for index in indexes: index_list[index.activity] = index.cost_index # get decryptor decryptors = Decryptor.query.all() # get regions regions = Region.query.filter(Region.id.in_( config.ESI_REGION_PRICE)).filter_by(wh=False) # display return render_template( 'blueprint/invention.html', **{ 'blueprint': item, 'activity_copy': activity_copy, 'activity_invention': item.activities.filter_by(activity=Activity.INVENTION).one(), 'copy_base_cost': copy_base_cost, 'invention_base_cost': invention_base_cost, 'datacore_skills': datacore_skills, 'decryptors': decryptors, 'encryption_skill': encryption_skill, 'index_list': index_list, 'invention_materials': item.activity_materials.filter_by( activity=Activity.INVENTION).all(), 'invention_products': item.activity_products.filter_by( activity=Activity.INVENTION).all(), 'regions': regions, 'industry_skills': get_common_industry_skill(char), })
def invention(item_id): """ Display the invention page with all price data pre calculated """ item = Item.query.get(item_id) char = current_user.pref.invention_character if item is None: abort(404) # check if the blueprint requested actually has invention available check_invention = ActivityProduct.query.filter_by( item_id=item_id ).filter_by( activity=ActivityEnum.INVENTION.aid ).first() if item.max_production_limit is None or check_invention is None: # the item_id is not a blueprint, so get the blueprint then redirect if item.max_production_limit is None and item.is_from_manufacturing: source_blueprint = item.product_for_activities.filter_by( activity=ActivityEnum.MANUFACTURING.aid ).one_or_none() return redirect( url_for( ".invention", item_id=source_blueprint.item_id ), code=301 ) # the item id is always a blueprint or an non manufactured item here # so we check if it's a blueprint (check_invention is None) and get # the source from invention, or abort. if item.max_production_limit is not None: activity_product = item.product_for_activities.filter_by( activity=ActivityEnum.INVENTION.aid ).one_or_none() if activity_product is not None: return redirect( url_for( ".invention", item_id=activity_product.item_id ), code=301 ) abort(404) # global activity activity_copy = item.activities.filter_by( activity=ActivityEnum.COPYING.aid ).first() invention_skills = item.activity_skills.filter_by( activity=ActivityEnum.INVENTION.aid ).all() # copy stuff copy_base_cost = 0.0 if activity_copy is not None: # copy base cost, as it's different from the invention materials = item.activity_materials.filter_by( activity=ActivityEnum.MANUFACTURING.aid ) copy_base_cost = calculate_base_cost(materials) # loop through skills for display as we need to do the difference # between both skills (not the same bonuses in invention probability) encryption_skill = None datacore_skills = [] for s in invention_skills: skill = get_skill_data(s.skill, char) if skill.name.find('Encryption') == -1: datacore_skills.append(skill) else: encryption_skill = skill # other skills # calculate baseCost for invention materials = item.activity_products.filter_by( activity=ActivityEnum.INVENTION.aid ).first().product.activity_materials.filter_by( activity=ActivityEnum.MANUFACTURING.aid ) invention_base_cost = calculate_base_cost(materials) # base solar system indexes = IndustryIndex.query.filter( IndustryIndex.solarsystem_id == SolarSystem.id, SolarSystem.name == current_user.pref.invention_system, IndustryIndex.activity.in_([ ActivityEnum.COPYING.aid, ActivityEnum.INVENTION.aid, ]) ) index_list = {} for index in indexes: index_list[index.activity] = index.cost_index # get decryptor decryptors = Decryptor.query.all() # display return render_template('blueprint/invention.html', **{ 'blueprint': item, 'activity_copy': activity_copy, 'activity_invention': item.activities.filter_by( activity=ActivityEnum.INVENTION.aid ).one(), 'copy_base_cost': copy_base_cost, 'invention_base_cost': invention_base_cost, 'datacore_skills': datacore_skills, 'decryptors': decryptors, 'encryption_skill': encryption_skill, 'index_list': index_list, 'invention_materials': item.activity_materials.filter_by( activity=ActivityEnum.INVENTION.aid ).all(), 'invention_products': item.activity_products.filter_by( activity=ActivityEnum.INVENTION.aid ).all(), 'regions': get_regions(), 'industry_skills': get_common_industry_skill(char), })
def research(item_id): """ Display the research page with all price data pre calculated """ item = Item.query.get(item_id) char = current_user.pref.research_character if item is None or item.max_production_limit is None: abort(404) activity_material = item.activities.filter_by( activity=Activity.RESEARCH_MATERIAL_EFFICIENCY).one() activity_time = item.activities.filter_by( activity=Activity.RESEARCH_TIME_EFFICIENCY).one() activity_copy = item.activities.filter_by(activity=Activity.COPYING).one() # indexes indexes = IndustryIndex.query.filter( IndustryIndex.solarsystem_id == SolarSystem.id, SolarSystem.name == current_user.pref.research_system, IndustryIndex.activity.in_([ Activity.COPYING, Activity.RESEARCH_MATERIAL_EFFICIENCY, Activity.RESEARCH_TIME_EFFICIENCY, ])) index_list = {} for index in indexes: index_list[index.activity] = index.cost_index # calculate baseCost and build cost per ME materials = item.activity_materials.filter_by( activity=Activity.MANUFACTURING) base_cost = calculate_base_cost(materials) cost = calculate_build_cost(materials, 10000002, xrange(0, 11), item.max_production_limit) cost_prev_me = cost[0]['run'] cost_prev_me_max = cost[0]['max_bpc_run'] for level in xrange(0, 11): # cost current_cost = cost[level]['run'] delta_me0 = cost[0]['run'] - current_cost delta_prev_me = cost_prev_me - current_cost delta_pct_me0 = (1 - current_cost / cost[0]['run']) * 100 delta_pct_prev_me = (1 - current_cost / cost_prev_me) * 100 current_cost = cost[level]['max_bpc_run'] max_delta_me0 = cost[0]['max_bpc_run'] - current_cost max_delta_prev_me = cost_prev_me_max - current_cost max_delta_pct_me0 = (1 - current_cost / cost[0]['max_bpc_run']) * 100 max_delta_pct_prev_me = (1 - current_cost / cost_prev_me_max) * 100 cost[level].update({ 'delta_me0': delta_me0, 'delta_prev_me': delta_prev_me, 'delta_pct_me0': delta_pct_me0, 'delta_pct_prev_me': delta_pct_prev_me, 'max_delta_me0': max_delta_me0, 'max_delta_prev_me': max_delta_prev_me, 'max_delta_pct_me0': max_delta_pct_me0, 'max_delta_pct_prev_me': max_delta_pct_prev_me, }) cost_prev_me = cost[level]['run'] cost_prev_me_max = cost[level]['max_bpc_run'] me_time = {} te_time = {} for level in xrange(1, 11): # time level_modifier = (250 * 2**(1.25 * level - 2.5) / 105) me_duration = activity_material.time * level_modifier te_duration = activity_time.time * level_modifier me_cost = (base_cost * 0.02 * level_modifier * 1.1 * index_list[Activity.RESEARCH_MATERIAL_EFFICIENCY]) te_cost = (base_cost * 0.02 * level_modifier * 1.1 * index_list[Activity.RESEARCH_TIME_EFFICIENCY]) me_time[level] = { 'duration': float("%0.2f" % me_duration), 'cost': me_cost, } te_time[level] = { 'duration': float("%0.2f" % te_duration), 'cost': te_cost, } # display return render_template( 'blueprint/research.html', **{ 'blueprint': item, 'activity_copy': activity_copy, 'activity_material': activity_material, 'activity_time': activity_time, 'base_cost': base_cost, 'index_list': index_list, 'cost_per_me': cost, 'industry_skills': get_common_industry_skill(char), 'me_time': me_time, 'te_time': te_time, })
def invention(item_id): """ Display the invention page with all price data pre calculated """ item = Item.query.get(item_id) char = current_user.pref.invention_character if item is None: abort(404) # check if the blueprint requested actually has invention available check_invention = ActivityProduct.query.filter_by( item_id=item_id ).filter_by( activity=ActivityEnum.INVENTION.id ).first() if item.max_production_limit is None or check_invention is None: # the item_id is not a blueprint, so get the blueprint then redirect if item.max_production_limit is None and item.is_from_manufacturing: source_blueprint = item.product_for_activities.filter_by( activity=ActivityEnum.MANUFACTURING.id ).one_or_none() return redirect( url_for( ".invention", item_id=source_blueprint.item_id ), code=301 ) # the item id is always a blueprint or an non manufactured item here # so we check if it's a blueprint (check_invention is None) and get # the source from invention, or abort. if item.max_production_limit is not None: activity_product = item.product_for_activities.filter_by( activity=ActivityEnum.INVENTION.id ).one_or_none() if activity_product is not None: return redirect( url_for( ".invention", item_id=activity_product.item_id ), code=301 ) abort(404) # global activity activity_copy = item.activities.filter_by( activity=ActivityEnum.COPYING.id ).first() invention_skills = item.activity_skills.filter_by( activity=ActivityEnum.INVENTION.id ).all() # copy stuff copy_base_cost = 0.0 if activity_copy is not None: # copy base cost, as it's different from the invention materials = item.activity_materials.filter_by( activity=ActivityEnum.MANUFACTURING.id ) copy_base_cost = calculate_base_cost(materials) # loop through skills for display as we need to do the difference # between both skills (not the same bonuses in invention probability) encryption_skill = None datacore_skills = [] for s in invention_skills: skill = get_skill_data(s.skill, char) if skill.name.find('Encryption') == -1: datacore_skills.append(skill) else: encryption_skill = skill # other skills # calculate baseCost for invention materials = item.activity_products.filter_by( activity=ActivityEnum.INVENTION.id ).first().product.activity_materials.filter_by( activity=ActivityEnum.MANUFACTURING.id ) invention_base_cost = calculate_base_cost(materials) # base solar system indexes = IndustryIndex.query.filter( IndustryIndex.solarsystem_id == SolarSystem.id, SolarSystem.name == current_user.pref.invention_system, IndustryIndex.activity.in_([ ActivityEnum.COPYING.id, ActivityEnum.INVENTION.id, ]) ) index_list = {} for index in indexes: index_list[index.activity] = index.cost_index # get decryptor decryptors = Decryptor.query.all() # display return render_template('blueprint/invention.html', **{ 'blueprint': item, 'activity_copy': activity_copy, 'activity_invention': item.activities.filter_by( activity=ActivityEnum.INVENTION.id ).one(), 'copy_base_cost': copy_base_cost, 'invention_base_cost': invention_base_cost, 'datacore_skills': datacore_skills, 'decryptors': decryptors, 'encryption_skill': encryption_skill, 'index_list': index_list, 'invention_materials': item.activity_materials.filter_by( activity=ActivityEnum.INVENTION.id ).all(), 'invention_products': item.activity_products.filter_by( activity=ActivityEnum.INVENTION.id ).all(), 'regions': get_regions(), 'industry_skills': get_common_industry_skill(char), })