def calc_new_count(min_value, value, max_value, trigger, target):
try:<EOL><INDENT>new_value = float(value) / float(trigger) * target<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>return value * <NUM_LIT:2><EOL><DEDENT>if new_value > max_value:<EOL><INDENT>return max_value<EOL><DEDENT>new_value = int((value + new_value) / <NUM_LIT:2>)<EOL>if new_value < min_value:<EOL><INDENT>return min_value<EOL><DEDENT>return new_value<EOL>
change 'value' between 'min_value' and 'max_value'
so that 'trigger' will be match 'target'

>>> calc_new_count(min_value=0, value=100, max_value=200, trigger=30, target=30)
100

>>> calc_new_count(min_value=0, value=100, max_value=200, trigger=50, target=5)
55
>>> calc_new_count(min_value=60, value=100, max_value=200, trigger=50, target=5)
60

>>> calc_new_count(min_value=0, value=100, max_value=200, trigger=20, target=40)
150
>>> calc_new_count(min_value=0, value=100, max_value=125, trigger=20, target=40)
125