Example #1
0
    def country_count(cls):
        cache_key = "country_count"
        def get_from_database():
           session = DBSession()
           q = session.query(cls.country, func.count('*').label('count')).group_by(cls.country).all()
           return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #2
0
    def count_nonkang(cls):
        cache_key = "count_nonkang"
        def get_from_database():
            session = DBSession()
            q = session.query(func.count(cls.id)).filter(cls.kang == False).one()[0]
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #3
0
    def count_last_day(cls):
        cache_key = "count_last_day"
        def get_from_database():
            timestamp = datetime.datetime.now() - datetime.timedelta(hours=24)
            session = DBSession()
            q = session.query(cls).filter(cls.date_added > timestamp).count()
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #4
0
    def count_nonkang(cls):
        cache_key = "count_nonkang"

        def get_from_database():
            session = DBSession()
            q = session.query(func.count(
                cls.id)).filter(cls.kang == False).one()[0]
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #5
0
    def count_last_day(cls):
        cache_key = "count_last_day"

        def get_from_database():
            timestamp = datetime.datetime.now() - datetime.timedelta(hours=24)
            session = DBSession()
            q = session.query(cls).filter(cls.date_added > timestamp).count()
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #6
0
    def country_count(cls):
        cache_key = "country_count"

        def get_from_database():
            session = DBSession()
            q = session.query(cls.country,
                              func.count('*').label('count')).group_by(
                                  cls.country).all()
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #7
0
    def device_count(cls):
        cache_key = "device_count"
        def get_from_database():
            session = DBSession()
    
            q = session.query(func.count(cls.name), cls.name) \
                .group_by(cls.name).all()
    
            q = sorted(q, key=lambda x: x[0], reverse=True)
    
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #8
0
    def version_count(cls):
        cache_key = "version_count"
        def get_from_database():
            session = DBSession()
    
            q = session.query(func.count(cls.version), cls.version) \
                .filter(cls.kang == False) \
                .group_by(cls.version).all()
    
            q = sorted(q, key=lambda x: x[0], reverse=True)
    
            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #9
0
    def device_count(cls):
        cache_key = "device_count"

        def get_from_database():
            session = DBSession()

            q = session.query(func.count(cls.name), cls.name) \
                .group_by(cls.name).all()

            q = sorted(q, key=lambda x: x[0], reverse=True)

            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result
Example #10
0
    def version_count(cls):
        cache_key = "version_count"

        def get_from_database():
            session = DBSession()

            q = session.query(func.count(cls.version), cls.version) \
                .filter(cls.kang == False) \
                .group_by(cls.version).all()

            q = sorted(q, key=lambda x: x[0], reverse=True)

            return q

        result = cache.get(cache_key)
        if result is None:
            result = cache.set(cache_key, get_from_database())

        return result