""" Helper methods

"""
from __future__ import absolute_import

import calendar
import math

import datetime


def normalize(dictionary, x, y):
    """
    Normalize values in dictinoary to be in range [x, y]

    :param dictionary:
    :param x: range min
    :param y: range max
    :return: dict with values changed accordingly
    """
    #  normalize to [0, 1]
    min_value = min(dictionary.values())
    max_value = max(dictionary.values())
    range1 = max_value - min_value
    for key in dictionary:
        dictionary[key] = (dictionary[key] - min_value) / range1

    # then scale [x,y] and take ceiling
    range2 = y - x
    for key in dictionary:
        dictionary[key] = math.ceil((dictionary[key] * range2) + x)

    return dictionary


def get_months(start_date, months, include_year=False):
    """
    Returns a list of months abbreviations starting from start_date
    :param include_year:
    :param start_date:
    :param months: number of previous months to return
    :return: list of months abbr if not include_year, else list of list [year, month]
    """
    result = []
    for i in range(months):
        start_date -= datetime.timedelta(days=calendar.monthrange(start_date.year,
                                                                  start_date.month)[1])
        if include_year:
            result.append([start_date.year, calendar.month_abbr[start_date.month]])
        else:
            result.append(calendar.month_abbr[start_date.month])
    return result


def get_months_with_last_same_as_first(start_date, months, include_year=False):
    """
    Returns a list of months abbreviations starting from start_date, and last month
    is the same is first month (i.e. extra month)
    :param include_year:
    :param start_date:
    :param months: number of previous months to return
    :return: list of months abbr if not include_year, else list of tuple [year, month]
    """
    if include_year:
        months = get_months(datetime.date.today(), 12, include_year=True)
        #  update last month to have current year
        months = [[start_date.year, calendar.month_abbr[start_date.month]]] + months
    else:
        months = get_months(datetime.date.today(), 12)
        #  append current month to front of list
        months = [months[-1]] + months

    return months
@@ -102,16 +102,48 @@
 atetime%0A
+from operator import itemgetter%0A
 %0A%0Adef no
@@ -149,16 +149,21 @@
 ormalize
+_dict
 (diction
@@ -373,35 +373,8 @@
 %22%22%22%0A
-    #  normalize to %5B0, 1%5D%0A
     
@@ -459,38 +459,172 @@
     
-range1 = max_value - min_value
+if max_value %3C= y and min_value %3E= x:%0A        return dictionary%0A%0A    #  normalize to %5B0, 1%5D%0A    range1 = max_value - min_value%0A    if not range1:%0A        range1 = 1
 %0A   
@@ -673,16 +673,22 @@
 %5Bkey%5D = 
+(float
 (diction
@@ -695,16 +695,17 @@
 ary%5Bkey%5D
+)
  - min_v
@@ -843,16 +843,22 @@
 h.ceil((
+float(
 dictiona
@@ -864,16 +864,17 @@
 ary%5Bkey%5D
+)
  * range
@@ -906,16 +906,954 @@
 onary%0A%0A%0A
+def normalize_tuple_list(tuple_list, x, y):%0A    %22%22%22%0A    Normalize values in a list of tuples to be in range %5Bx, y%5D%0A%0A    :param tuple_list:%0A    :param x: range min%0A    :param y: range max%0A    :return: list of tuples with values changed accordingly%0A    %22%22%22%0A    min_value = min(tuple_list, key=itemgetter(1))%5B1%5D%0A    max_value = max(tuple_list, key=itemgetter(1))%5B1%5D%0A    if max_value %3C= y and min_value %3E= x:%0A        return tuple_list%0A%0A    #  normalize to %5B0, 1%5D%0A    range1 = max_value - min_value%0A    if not range1:%0A        range1 = 1%0A    for idx, pair in enumerate(tuple_list):%0A        key = pair%5B0%5D%0A        value = (float(pair%5B1%5D) - min_value) / range1%0A        tuple_list%5Bidx%5D = (key, value)%0A%0A    # then scale %5Bx,y%5D and take ceiling%0A    range2 = y - x%0A    for idx, pair in enumerate(tuple_list):%0A        key = pair%5B0%5D%0A        value = math.ceil((float(pair%5B1%5D) * range2) + x)%0A        tuple_list%5Bidx%5D = (key, value)%0A%0A    return tuple_list%0A%0A%0A
 def get_

Add method to normalize list of tuples