Пример #1
0
def map(request, *args, **kwargs):
    context = {'page': 'map'}
    drc = Entity.get_root()

    context.update({
        'root': drc,
        'periods': MonthPeriod.all_till_now(),
        'dps_list': drc.get_children()
    })

    return render(request, kwargs.get('template_name', 'map.html'), context)
Пример #2
0
def map(request, *args, **kwargs):
    context = {'page': 'map'}
    drc = Entity.get_root()

    context.update({
        'root': drc,
        'periods': MonthPeriod.all_till_now(),
        'dps_list': drc.get_children()
    })

    return render(request, kwargs.get('template_name', 'map.html'), context)
Пример #3
0
def process_period_filter(request, period_str=None, name='period'):
    if period_str:
        period = MonthPeriod.get_or_none(period_str)
        if period is None:
            raise Http404(request,
                          _("Unable to match period with `{period}`")
                          .format(period=period_str))
    else:
        period = MonthPeriod.current().previous()

    all_periods = MonthPeriod.all_till_now()
    return {
        'periods': sorted([p.to_tuple() for p in all_periods],
                          reverse=True),
        'all_periods': all_periods,
        name: period,
    }
Пример #4
0
    def handle(self, *args, **options):

        # make sure we're at project root
        chdir_dmd()

        logger.info("Updating cache for dashboard completeness...")

        root = Entity.get_root()
        periods = MonthPeriod.all_till_now()
        all_dps = root.get_children()
        all_entities = list(all_dps) + [root]
        indicators = Indicator.objects.all()
        all_indicators = list(indicators) + [None]
        nb_items = len(periods) * len(all_dps) * len(all_indicators)

        nb_ran = 0
        for period in periods:
            # logger.debug("{}".format(period))
            for dps in all_dps:
                # logger.debug("== {}".format(dps))
                for indicator in all_indicators:
                    nb_ran += 1
                    # logger.debug("==== {}".format(indicator))

                    params = {
                        'dps': dps,
                        'period': period,
                        'indicator': indicator
                    }

                    # existing cache 4months+ old are not regenerated
                    if period <= periods[-4]:
                        if cache_exists_for('completeness', **params):
                            # logger.info("***** Skipping existing.")
                            continue

                    update_cached_data('completeness', **params)

                    sys.stdout.write("{}/{} - {}%\r".format(
                        nb_ran, nb_items, int(nb_ran / nb_items * 100)))
                    sys.stdout.flush()

        logger.info("Updating cache for section2/arrivals...")

        nb_items = len(periods) * len(all_dps) * len(indicators)
        nb_ran = 0
        for period in periods:
            for entity in all_entities:
                for indicator in indicators:
                    params = {
                        'entity': entity,
                        'period': period,
                        'indicator': indicator
                    }
                    if period <= periods[-4]:
                        if cache_exists_for('section2-arrivals', **params):
                            continue

                        update_cached_data('section2-arrivals',
                                           entity=entity,
                                           period=period,
                                           indicator=indicator)

                        sys.stdout.write("{}/{} - {}%\r".format(
                            nb_ran, nb_items, int(nb_ran / nb_items * 100)))
                        sys.stdout.flush()

        logger.info("Updating cache for section2/points")

        nb_items = len(periods) * len(all_dps)
        nb_ran = 0
        for period in periods:
            for entity in all_entities:
                if period <= periods[-4]:
                    if cache_exists_for('section2-points', **params):
                        continue

                    update_cached_data('section2-points',
                                       entity=entity,
                                       period=period)

                    sys.stdout.write("{}/{} - {}%\r".format(
                        nb_ran, nb_items, int(nb_ran / nb_items * 100)))
                    sys.stdout.flush()

        logger.info("done.")
Пример #5
0
    def handle(self, *args, **options):

        # make sure we're at project root
        chdir_dmd()

        logger.info("Updating cache for dashboard completeness...")

        root = Entity.get_root()
        periods = MonthPeriod.all_till_now()
        all_dps = root.get_children()
        all_entities = list(all_dps) + [root]
        indicators = Indicator.objects.all()
        all_indicators = list(indicators) + [None]
        nb_items = len(periods) * len(all_dps) * len(all_indicators)

        nb_ran = 0
        for period in periods:
            # logger.debug("{}".format(period))
            for dps in all_dps:
                # logger.debug("== {}".format(dps))
                for indicator in all_indicators:
                    nb_ran += 1
                    # logger.debug("==== {}".format(indicator))

                    params = {
                        'dps': dps,
                        'period': period,
                        'indicator': indicator
                    }

                    # existing cache 4months+ old are not regenerated
                    if period <= periods[-4]:
                        if cache_exists_for('completeness', **params):
                            # logger.info("***** Skipping existing.")
                            continue

                    update_cached_data('completeness', **params)

                    sys.stdout.write("{}/{} - {}%\r"
                                     .format(nb_ran, nb_items,
                                             int(nb_ran / nb_items * 100)))
                    sys.stdout.flush()

        logger.info("Updating cache for section2/arrivals...")

        nb_items = len(periods) * len(all_dps) * len(indicators)
        nb_ran = 0
        for period in periods:
            for entity in all_entities:
                for indicator in indicators:
                    params = {
                        'entity': entity,
                        'period': period,
                        'indicator': indicator
                    }
                    if period <= periods[-4]:
                        if cache_exists_for('section2-arrivals', **params):
                            continue

                        update_cached_data('section2-arrivals',
                                           entity=entity,
                                           period=period,
                                           indicator=indicator)

                        sys.stdout.write("{}/{} - {}%\r"
                                         .format(nb_ran, nb_items,
                                                 int(nb_ran / nb_items * 100)))
                        sys.stdout.flush()

        logger.info("Updating cache for section2/points")

        nb_items = len(periods) * len(all_dps)
        nb_ran = 0
        for period in periods:
            for entity in all_entities:
                if period <= periods[-4]:
                    if cache_exists_for('section2-points', **params):
                        continue

                    update_cached_data('section2-points',
                                       entity=entity,
                                       period=period)

                    sys.stdout.write("{}/{} - {}%\r"
                                     .format(nb_ran, nb_items,
                                             int(nb_ran / nb_items * 100)))
                    sys.stdout.flush()

        logger.info("done.")