Ejemplo n.º 1
0
def get_ordinal_from_period(date_str, freq=None):
    from dlstats.cache import cache
    from dlstats import constants
    from pandas import Period
    
    if not cache or not freq in constants.CACHE_FREQUENCY:
        return Period(date_str, freq=freq).ordinal
    
    key = "%s.%s" % (date_str, freq)
    period_from_cache = cache.get(key)
    if period_from_cache:
        return period_from_cache
    
    period_ordinal = Period(date_str, freq=freq).ordinal
    cache.set(key, period_ordinal)
    
    return period_ordinal
Ejemplo n.º 2
0
def slugify(text, **kwargs):

    from dlstats.cache import cache

    key = "slugify.%s" % text

    if cache:
        slug_from_cache = cache.get(key)
        if slug_from_cache:
            return slug_from_cache

    slug = original_slugify(text, **kwargs)

    if cache:
        cache.set(key, slug)

    return slug
Ejemplo n.º 3
0
def slugify(text, **kwargs):
    
    from dlstats.cache import cache

    key = "slugify.%s" % text

    if cache:
        slug_from_cache = cache.get(key)
        if slug_from_cache:
            return slug_from_cache
    
    slug = original_slugify(text, **kwargs)

    if cache:
        cache.set(key, slug)
        
    return slug
Ejemplo n.º 4
0
def get_ordinal_from_period(date_str, freq=None):
    """
    Frequency stats - 2016-03-30
    { "_id" : "A", "count" : 36858826 }
    { "_id" : "Q", "count" : 3318158 }
    { "_id" : "M", "count" : 507243 }
    { "_id" : "W-WED", "count" : 1713 }
    { "_id" : "D", "count" : 845 }
    { "_id" : "W-MON", "count" : 77 }
    { "_id" : "W-FRI", "count" : 60 }
    { "_id" : "W-THU", "count" : 2 }    
    """
    
    from dlstats.cache import cache
    from dlstats import constants
    from pandas import Period
        
    if not cache or not freq in constants.CACHE_FREQUENCY:
        return Period(date_str, freq=freq).ordinal
    
    key = "%s.%s" % (date_str, freq)
    period_from_cache = cache.get(key)
    if not period_from_cache is None:
        return period_from_cache
    
    period_ordinal = None
    if freq == "A":
        year = int(get_year(date_str))
        period_ordinal = year - 1970
        return period_ordinal

    if not period_ordinal:
        period_ordinal = Period(date_str, freq=freq).ordinal
    cache.set(key, period_ordinal)
    
    return period_ordinal
Ejemplo n.º 5
0
def get_ordinal_from_period(date_str, freq=None):
    """
    Frequency stats - 2016-03-30
    { "_id" : "A", "count" : 36858826 }
    { "_id" : "Q", "count" : 3318158 }
x    { "_id" : "M", "count" : 507243 }
    { "_id" : "W-WED", "count" : 1713 }
    { "_id" : "D", "count" : 845 }
    { "_id" : "W-MON", "count" : 77 }
    { "_id" : "W-FRI", "count" : 60 }
    { "_id" : "W-THU", "count" : 2 }
    """

    from dlstats.cache import cache
    from dlstats import constants
    from pandas import Period

    key = "ordinal.%s.%s" % (date_str, freq)

    if cache and freq in constants.CACHE_FREQUENCY:
        period_from_cache = cache.get(key)
        if not period_from_cache is None:
            return period_from_cache

    period_ordinal = None
    if freq == "A":
        year = int(get_year(date_str))
        period_ordinal = year - 1970
    elif freq == "S":
        year = int(get_year(date_str))
        if date_str.endswith("S1"):
            date_str = '%s-01' % year
        elif date_str.endswith("S2"):
            date_str = '%s-07' % year
        else:
            raise NotImplementedError(
                "freq not implemented freq[%s] date[%s]" % (freq, date_str))
    """
    elif freq == "M":
        year = int(get_year(date_str))
        month = int(get_month(date_str))
        period_ordinal = ((year - 1970) * 12) * month
    """
    """
     ("1970", "A", 0),
     ("1969", "A", -1),
     ("1971", "A", 1),

     ("1970-01", "M", 0),
     ("197001", "M", 0),
     ("1970-02", "M", 1),
     ("1969-12", "M", -1),
     ("1969-01", "M", -12),
     ("1971-01", "M", 12),
     ("1970-07", "M", 6),
     ("1971-07", "M", 18),
     ("1969-07", "M", -6),

    """

    if not period_ordinal:
        period_ordinal = Period(date_str, freq=freq).ordinal

    if cache and freq in constants.CACHE_FREQUENCY:
        cache.set(key, period_ordinal)

    return period_ordinal
Ejemplo n.º 6
0
def get_ordinal_from_period(date_str, freq=None):
    """
    Frequency stats - 2016-03-30
    { "_id" : "A", "count" : 36858826 }
    { "_id" : "Q", "count" : 3318158 }
    { "_id" : "M", "count" : 507243 }
    { "_id" : "W-WED", "count" : 1713 }
    { "_id" : "D", "count" : 845 }
    { "_id" : "W-MON", "count" : 77 }
    { "_id" : "W-FRI", "count" : 60 }
    { "_id" : "W-THU", "count" : 2 }    
    """
    
    from dlstats.cache import cache
    from dlstats import constants
    from pandas import Period
        
    key = "ordinal.%s.%s" % (date_str, freq)

    if cache and freq in constants.CACHE_FREQUENCY:
        period_from_cache = cache.get(key)
        if not period_from_cache is None:
            return period_from_cache
    
    period_ordinal = None
    if freq == "A":
        year = int(get_year(date_str))
        period_ordinal = year - 1970
    elif freq == "S":
        year = int(get_year(date_str))
        if date_str.endswith("S1"):
            date_str = '%s-01' % year
        elif date_str.endswith("S2"):
            date_str = '%s-07' % year
        else:
            raise NotImplementedError("freq not implemented freq[%s] date[%s]" % (freq, date_str))
    """
    elif freq == "M":
        year = int(get_year(date_str))
        month = int(get_month(date_str))
        period_ordinal = ((year - 1970) * 12) * month
    """
    """
     ("1970", "A", 0),
     ("1969", "A", -1),
     ("1971", "A", 1),

     ("1970-01", "M", 0),
     ("197001", "M", 0),
     ("1970-02", "M", 1),
     ("1969-12", "M", -1),
     ("1969-01", "M", -12),
     ("1971-01", "M", 12),
     ("1970-07", "M", 6),
     ("1971-07", "M", 18),
     ("1969-07", "M", -6),
     
    """

    if not period_ordinal:
        period_ordinal = Period(date_str, freq=freq).ordinal
    
    if cache and freq in constants.CACHE_FREQUENCY:
        cache.set(key, period_ordinal)
    
    return period_ordinal