Exemplo n.º 1
0
def add_extra_seasonreport_context(context):
    context = dict(context)  # copy

    people = context['people']

    context['n_health_people'] = len(
        [person.name for person in people if person.health < 50])

    state = context['state']

    (context['village_goodnews_block'],
     context['has_subsidy']) = village_goodnews_block(state)
    context['village_badnews_block'] = village_badnews_block(state)

    context['water_used'] = water_used(state)

    coeffs = context['coeffs']

    wood_sold_energy = state.wood_income / coeffs.wood_price
    wood_sold_tons = wood_sold_energy / fuel.Wood.coefficient(coeffs)
    wood_used_tons = state.amount_wood - wood_sold_tons

    context['wood_sold_tons'] = wood_sold_tons
    context['wood_used_tons'] = wood_used_tons

    items_bought = []
    items_sold = []
    money_spent = 0
    money_earned = 0

    for item in state.purchase_items:
        if "|" not in item:
            continue
        (name, amount) = item.split("|")
        price = coeffs.market_purchase_prices[coeffs.market_items.index(name)]
        if state.road:
            price = int(0.8 * price)
        label = coeffs.market_items_labels[coeffs.market_items.index(name)]
        money_spent += float(price) * float(amount)
        items_bought.append("%s (%s)" % (label, amount))

    for item in state.sell_items:
        if "|" not in item:
            continue
        (name, amount) = item.split("|")
        price = coeffs.market_purchase_prices[coeffs.market_items.index(name)]
        if state.road:
            price = int(0.8 * price)
        label = coeffs.market_items_labels[coeffs.market_items.index(name)]
        money_earned += float(price) * float(amount)
        items_sold.append("%s (%s)" % (label, amount))

    context['money_earned'] = money_earned
    context['money_spent'] = money_spent

    context['doctor_visit_cost'] = doctor_visit_cost(coeffs, state)
    context['items_bought'] = items_bought
    context['items_sold'] = items_sold

    context['village_improvements'] = list(village_improvements(
        coeffs.available_improvements,
        coeffs.improvement_labels,
        state.improvements))

    context['percent_infected'] = percent_infected(state)

    if 'child born' in state.user_messages:
        context['new_baby'] = new_child_name(state.births, coeffs.child_names)

    context['foreststock'] = simple_controller.get_interval_class(
        state.wood_stock, coeffs.visual_intervals_forest)
    context['fishstock'] = simple_controller.get_interval_class(
        state.fish_stock, coeffs.visual_intervals_fish)

    context['money_report'] = simple_controller.money_report

    context['notifications'] = []

    return context
Exemplo n.º 2
0
def add_extra_seasonreport_context(context):
    context = dict(context) # copy

    people = context['people']

    context['n_health_people'] = len([person.name for person in people if person.health < 50])

    state = context['state']

    ngo_bednets_report = 'NGO bednets' in state.user_messages
    road_subs_report = 'road subsidy' in state.user_messages
    clinic_subs_report = 'clinic subsidy' in state.user_messages
    irrigation_subs_report ='irrigation subsidy' in state.user_messages
    sanitation_subs_report = 'sanitation subsidy' in state.user_messages
    water_pump_report = 'water pump subsidy' in state.user_messages
    meals_subs_report = 'meals subsidy' in state.user_messages
    electric_subs_report = 'electricity subsidy' in state.user_messages
    good_rain_report = 'good rains' in state.user_messages

    has_subsidy = False
    if ngo_bednets_report or road_subs_report or clinic_subs_report or \
            irrigation_subs_report or sanitation_subs_report or \
            water_pump_report or meals_subs_report or electric_subs_report:
        has_subsidy = True
        
    village_goodnews_block = False
    if has_subsidy or good_rain_report:
        village_goodnews_block = True

    fish_depletion_report = 'fish stock depletion' in state.user_messages
    wood_depletion_report = 'wood stock depletion' in state.user_messages

    village_badnews_block = False
    if state.drought or state.epidemic or fish_depletion_report or wood_depletion_report:
        village_badnews_block = True

    context['village_goodnews_block'] = village_goodnews_block
    context['village_badnews_block'] = village_badnews_block
    context['has_subsidy'] = has_subsidy
    
    water_used = state.family_water_needs
    if water_used > state.amount_water:
        water_used = state.amount_water
    if state.water_pump:
        water_used = 0

    context['water_used'] = water_used

    coeffs = context['coeffs']

    wood_sold_energy = state.wood_income / coeffs.wood_price
    wood_sold_tons = wood_sold_energy / fuel.Wood.coefficient(coeffs)
    wood_used_tons = state.amount_wood - wood_sold_tons

    context['wood_sold_tons'] = wood_sold_tons
    context['wood_used_tons'] = wood_used_tons

    items_bought = []
    items_sold = []
    money_spent = 0
    money_earned = 0

    for item in state.purchase_items:
	if "|" not in item:
            continue
	(name,amount) = item.split("|")
	price = coeffs.market_purchase_prices[coeffs.market_items.index(name)]
	if state.road:
	     price = int(0.8 * price)
	label = coeffs.market_items_labels[coeffs.market_items.index(name)]
	money_spent += float(price) * float(amount)
        items_bought.append("%s (%s)" % (label, amount))

    for item in state.sell_items:
	if "|" not in item:
            continue
	(name,amount) = item.split("|")
	price = coeffs.market_purchase_prices[coeffs.market_items.index(name)]
	if state.road:
	     price = int(0.8 * price)
	label = coeffs.market_items_labels[coeffs.market_items.index(name)]
	money_earned += float(price) * float(amount)
        items_sold.append("%s (%s)" % (label, amount))

    context['money_earned'] = money_earned
    context['money_spent'] = money_spent

    # doctor visits are 20% if there's a clinic
    doctor_visit_cost = coeffs.doctor_visit_cost
    if state.clinic:
        doctor_visit_cost *= .2

    context['doctor_visit_cost'] = doctor_visit_cost
    context['items_bought'] = items_bought
    context['items_sold'] = items_sold

    village_improvements = []
    for item,label in zip(coeffs.available_improvements,coeffs.improvement_labels):
        if item in state.improvements:
            village_improvements.append(label)

    context['village_improvements'] = village_improvements

    percent_infected = 0
    if state.village_population != 0:
        percent_infected = state.village_infected_pop / float(state.village_population) * 100

    context['percent_infected'] = percent_infected

    if 'child born' in state.user_messages:
        context['new_baby'] = coeffs.child_names[int(state.births)-1]

    context['foreststock'] = simple_controller.get_interval_class(
        state.wood_stock, coeffs.visual_intervals_forest)
    context['fishstock'] = simple_controller.get_interval_class(
        state.fish_stock, coeffs.visual_intervals_fish)

    context['money_report'] = simple_controller.money_report

    context['notifications'] = []

    return context