• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python Periods.MonthPeriod类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中snisi_core.models.Periods.MonthPeriod的典型用法代码示例。如果您正苦于以下问题:Python MonthPeriod类的具体用法?Python MonthPeriod怎么用?Python MonthPeriod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MonthPeriod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: dashboard

def dashboard(request, **kwargs):

    now = timezone.now()
    last_period = MonthPeriod.current().previous() if now.day < 26 else None
    periods = MonthPeriod.all_from(
        MonthPeriod.from_url_str("11-2014"), last_period)
    entity = request.user.location.casted()

    context = {
        'periods': periods,
        'entity': entity,
    }

    if entity.has_ureni or entity.has_urenas:
        context.update({
            'sam_performance': SAMPerformanceTable(entity=entity,
                                                   periods=periods)
        })
    if entity.has_urenam:
        context.update({
            'mam_performance': MAMPerformanceTable(entity=entity,
                                                   periods=periods)
        })

    return render(request, kwargs.get('template_name',
                  'nutrition/dashboard.html'), context)
开发者ID:yeleman,项目名称:snisi,代码行数:26,代码来源:indicators.py


示例2: handle

    def handle(self, *args, **options):

        logger.info("Issue #67. Removing expecteds for djenne entities.")

        january = MonthPeriod.from_url_str("12-2014")
        periods = MonthPeriod.all_from(january)
        entity_slugs = ['ANT9', 'M894', 'C332']

        for exp in ExpectedReporting.objects.filter(
                period__in=periods, entity__slug__in=entity_slugs):
            logger.debug(exp)
            exp.delete()

        logger.info("Disable health area if not already")
        for slug in entity_slugs:
            area_slug = "Z{}".format(slug)
            e = Entity.objects.get(slug=area_slug)
            if e and e.active:
                logger.info(e)
                e.active = False
                e.save()

        logger.info("Remove from clusters")
        Participation.objects.filter(entity__slug__in=entity_slugs).delete()

        logger.info("Update cluster cache")
        call_command("update-cluster-caches")

        logger.info("done.")
开发者ID:yeleman,项目名称:snisi,代码行数:29,代码来源:fix_67_rm_expecteds.py


示例3: handle

    def handle(self, *args, **options):

        october = MonthPeriod.from_url_str("10-2014")
        november = MonthPeriod.from_url_str("11-2014")
        mopti_csref = Entity.get_or_none("J5C6")

        logger.info("Remove Expected and data for {}".format(october))

        rc_slugs = ['nutrition_monthly_routine',
                    'nutrition_monthly_routine_aggregated',
                    'nut_urenam_monthly_routine',
                    'nut_urenam_monthly_routine_aggregated',
                    'nut_urenas_monthly_routine',
                    'nut_urenas_monthly_routine_aggregated',
                    'nut_ureni_monthly_routine',
                    'nut_ureni_monthly_routine_aggregated',
                    'nut_stocks_monthly_routine',
                    'nut_stocks_monthly_routine_aggregated',
                    'nutrition_weekly_routine',
                    'nutrition_weekly_routine_aggregated']

        for rc_slug in rc_slugs:
            rc = ReportClass.get_or_none(rc_slug)

            logger.info("Deleting expecteds")
            ExpectedReporting.objects.filter(
                report_class=rc,
                period__end_on__lte=october.end_on).delete()

            logger.info("Deleting reports and expected validations")
            rqs = rc.report_class.objects.filter(
                period__end_on__lte=october.end_on)
            for r in rqs:
                logger.info("\treport: {}".format(r))
                if r.expected_reportings.count():
                    logger.info("\tfound exp")
                    r.expected_reportings.all().delete()
                if r.expected_validation:
                    logger.info("\tfound expval")
                    r.expected_validation.delete()
                logger.info("\tdeleting report.")
                r.delete()

        logger.info("Updating Mopti CSRef")
        mopti_csref.has_urenam = False
        mopti_csref.has_urenas = False
        mopti_csref.save()

        logger.info("Removing Mopti CSRef Expected")
        ExpectedReporting.objects.filter(
            entity__slug=mopti_csref.slug,
            report_class__slug__in=['nut_urenam_monthly_routine',
                                    'nut_urenam_monthly_routine_aggregated',
                                    'nut_urenas_monthly_routine',
                                    'nut_urenas_monthly_routine_aggregated'],
            period=november).delete()

        logger.info("done.")
开发者ID:yeleman,项目名称:snisi,代码行数:58,代码来源:fix_mopti_ureni_and_october.py


示例4: handle

    def handle(self, *args, **options):

        start = MonthPeriod.from_url_str('12-2014').start_on
        end = MonthPeriod.from_url_str('01-2015').end_on

        bads = ExpectedReporting.objects.filter(
            period__start_on__gte=start,
            period__end_on__lte=end,
            completion_status='')
        logger.info("DELETING {} bads".format(bads.count()))
        bads.delete()

        for exp in ExpectedReporting.objects.filter(
                period__start_on__gte=start,
                period__end_on__lte=end,
                completion_status=ExpectedReporting.COMPLETION_MISSING):

            # logger.info(exp)

            params = {
                'report_class': exp.report_class,
                'reporting_role': exp.reporting_role,

                'period': exp.period,
                'within_period': exp.within_period,

                'entity': exp.entity,
                'within_entity': exp.within_entity,

                'reporting_period': exp.reporting_period,
                'extended_reporting_period': exp.extended_reporting_period,

                'amount_expected': exp.amount_expected,

                'completion_status__in': (
                    ExpectedReporting.COMPLETION_COMPLETE,
                    ExpectedReporting.COMPLETION_MATCHING),
            }

            filter = ExpectedReporting.objects.filter(**params)

            if not filter.count():
                # no duplicates on this one.
                logger.info("... No duplicate")
                continue

            good = filter.get()

            if not exp.satisfied and not exp.arrived_reports.count():
                logger.info(". DELETING exp: {}".format(exp))
                exp.delete()
            else:
                logger.info("CAN'T DELETE EXP as satisfied: {}".format(exp))
                logger.info(good)
开发者ID:yeleman,项目名称:snisi,代码行数:54,代码来源:fix_double_expected.py


示例5: handle

    def handle(self, *args, **options):

        logger.info("snisi_cataract daily-checkups")

        day = timezone.now().day
        period = MonthPeriod.current().previous()

        category_matrix = {
            'end_of_cataract_mission_period': generate_aggregated_reports,
        }

        def handle_category(category):
            slug = "{domain}_{period}_{category}".format(
                domain=DOMAIN_SLUG, period=period.strid(), category=category)
            task, created = PeriodicTask.get_or_create(slug, category)

            if task.can_trigger():
                try:
                    category_matrix.get(category)(period)
                except Exception as e:
                    logger.exception(e)
                else:
                    task.trigger()

        if day >= ROUTINE_REGION_AGG_DAY:
            # validate all district reports
            # create aggregated for region
            # create aggregated for country
            # send notification to central/national
            handle_category("end_of_cataract_mission_period")
开发者ID:yeleman,项目名称:snisi,代码行数:30,代码来源:snisi_cataract_daily.py


示例6: handle

    def handle(self, *args, **options):

        period = MonthPeriod.current().previous()
        cluster = Cluster.get_or_none("nutrition_routine")

        districts = [e.casted() for e in cluster.members()
                     if e.type.slug == 'health_district']

        print("DISTRICT,ATTENDUS,ARRIVÉS,COMPLÉTUDE")
        tot_nb_exp = 0
        tot_nb_arr = 0

        for district in districts:
            exps = ExpectedReporting.objects.filter(
                period=period, entity__parent__parent=district,
                report_class__slug='nutrition_monthly_routine')
            nb_exp = exps.count()
            nb_arr = exps.filter(
                completion_status=ExpectedReporting.COMPLETION_COMPLETE) \
                .count()

            tot_nb_exp += nb_exp
            tot_nb_arr += nb_arr

            pc = nb_arr / float(nb_exp)

            print("{ds},{exp},{arr},{pc}".format(
                ds=district.name, exp=nb_exp, arr=nb_arr, pc=pc))

        tot_pc = tot_nb_arr / float(tot_nb_exp)
        print("TOTAL,{exp},{arr},{pc}".format(exp=tot_nb_exp,
                                              arr=tot_nb_arr, pc=tot_pc))
开发者ID:yeleman,项目名称:snisi,代码行数:32,代码来源:nut_collect_report.py


示例7: handle

    def handle(self, *args, **options):

        epidemio_cluster = Cluster.objects.get(slug="epidemiology_routine")
        DEBUG_change_system_date(
            MonthPeriod.from_url_str("07-2012").end_on
            - datetime.timedelta(days=5), True)

        mali = Entity.get_or_none("mali")

        regions = ['2732']

        health_units = [mali]
        for region_slug in regions:
            region = Entity.get_or_none(region_slug)
            health_units += [region] + region.get_health_districts() \
                                     + region.get_health_centers()

        for health_unit in health_units:
            logger.info(health_unit)

            p, created = Participation.objects.get_or_create(
                cluster=epidemio_cluster,
                entity=health_unit,
                modified_on=timezone.now())

        DEBUG_change_system_date(None, True)
开发者ID:yeleman,项目名称:snisi,代码行数:26,代码来源:epidemiology_create_cluster.py


示例8: get_indicator_data

def get_indicator_data(request, domain_slug='malaria'):

    try:
        json_request = json.loads(request.body)
    except Exception as e:
        return HttpResponse(json.dumps({"error": e}))

    domain = Domain.get_or_none(domain_slug)

    indicator_slug = json_request.get('indicator_slug')
    year = json_request.get('year')
    month = json_request.get('month')
    period = MonthPeriod.find_create_from(year=int(year), month=int(month))
    indicator = import_path('{}.indicators.{}'
                            .format(domain.module_path, indicator_slug))
    parent = Entity.get_or_none(json_request.get('entity_slug'))
    targets = parent.get_health_centers() \
        if parent.type.slug == 'health_district' \
        else parent.get_health_districts()
    computed_values = {}
    for entity in targets:
        ind = indicator(period=period, entity=entity)
        computed_values.update({entity.slug: {
            'slug': entity.slug,
            'data': ind.data,
            'hdata': ind.human,
            'is_not_expected': not ind.is_expected,
            'is_missing': ind.is_missing,
            'is_yesno': ind.is_yesno}})

    return withCORS(HttpResponse(json.dumps(computed_values),
                                 content_type='application/json'))
开发者ID:yeleman,项目名称:snisi,代码行数:32,代码来源:mapping.py


示例9: _notified_cases_from_db

    def _notified_cases_from_db(entity, year, month):
        period = MonthPeriod.find_create_from(year, month, dont_create=True)
        try:
            report = MalariaR.objects.get(entity=entity, period=period)
        except MalariaR.DoesNotExist:
            return None

        return getattr(report, 'total_confirmed_malaria_cases')
开发者ID:yeleman,项目名称:snisi,代码行数:8,代码来源:epidemio_utils.py


示例10: boundaries

 def boundaries(cls, date_obj):
     date_obj = normalize_date(date_obj, as_aware=True)
     start = date_obj.replace(day=29, hour=0, minute=0,
                              second=0, microsecond=0)
     end = MonthPeriod.find_create_by_date(date_obj,
                                           dont_create=True).following() \
                      .start_on - ONE_MICROSECOND_DELTA
     return (start, end)
开发者ID:yeleman,项目名称:snisi,代码行数:8,代码来源:FixedWeekPeriods.py


示例11: periods_for_quarter

 def periods_for_quarter(year, quarter_num):
     start_period = MonthPeriod.find_create_from(
         year=int(year),
         month={'1': 1, '2': 4, '3': 7, '4': 10}.get(quarter_num),
         dont_create=True)
     periods = [start_period]
     for _ in range(1, 3):
         periods.append(periods[-1].following())
     return periods
开发者ID:yeleman,项目名称:snisi,代码行数:9,代码来源:quarter_reports.py


示例12: periods_from_url

def periods_from_url(perioda_str, periodb_str,
                     period_cls, assume_previous, report_cls,
                     backlog_periods=12, allow_coming_year=False):

    def period_from_strid(period_str, report_cls=None):
        period = None
        base_cls = period_cls or Period
        if period_str:
            try:
                period = base_cls.from_url_str(period_str).casted()
            except:
                pass
        return period
    perioda = period_from_strid(perioda_str)
    periodb = period_from_strid(periodb_str)

    if periodb is None:
        periodb = period_cls.current()

    if perioda is None:
        perioda = periodb
        for __ in range(backlog_periods):
            perioda = perioda.previous()

    if perioda is None or periodb is None:
        raise Http404("Période incorrecte.")

    if perioda > periodb:
        t = perioda
        perioda = periodb
        periodb = t
        del(t)

    current_period = period_cls.current()

    if assume_previous:
        current_period = current_period.previous()

    first_period = current_period
    if report_cls is not None:
        try:
            first_period = period_cls.find_create_by_date(
                report_cls.objects.all().order_by('period__start_on')[0]
                                        .period.middle())
        except IndexError:
            pass

    if allow_coming_year:
        last_period = MonthPeriod.find_create_from(
            current_period.middle().year, 12)
    else:
        last_period = current_period

    all_periods = period_cls.all_from(first_period, last_period)
    periods = period_cls.all_from(perioda, periodb)

    return periods, all_periods, perioda, periodb
开发者ID:yeleman,项目名称:snisi,代码行数:57,代码来源:utils.py


示例13: following_week

 def following_week(cls, reference):
     idx = cls.week_classes.index(reference.__class__)
     if idx == len(cls.week_classes) - 1:
         ncls = cls.week_classes[0]
         nmonth = MonthPeriod.find_create_by_date(reference.middle())
         at = nmonth.next().middle()
     else:
         ncls = cls.week_classes[idx + 1]
         at = reference.middle()
     return ncls.find_create_by_date(at)
开发者ID:yeleman,项目名称:snisi,代码行数:10,代码来源:FixedWeekPeriods.py


示例14: previous_week

 def previous_week(cls, reference):
     idx = cls.week_classes.index(reference.__class__)
     if idx == 0:
         ncls = cls.week_classes[-1]
         nmonth = MonthPeriod.find_create_by_date(reference.middle())
         at = nmonth.previous().middle()
     else:
         ncls = cls.week_classes[idx - 1]
         at = reference.middle()
     return ncls.find_create_by_date(at)
开发者ID:yeleman,项目名称:snisi,代码行数:10,代码来源:FixedWeekPeriods.py


示例15: handle

    def handle(self, *args, **options):

        period = MonthPeriod.from_url_str("11-2014")

        for report in AggMalariaR.objects.filter(period=period):
            logger.info(report)
            report.update_expected_reportings_number()
            report.save()

        logger.info("All done.")
开发者ID:yeleman,项目名称:snisi,代码行数:10,代码来源:fix_malaria_nb_exp_nov14.py


示例16: chk_period_is_not_future

    def chk_period_is_not_future(self, **options):
        # default period is MonthPeriod from year/month
        if not self.has('period') or not self.get('period'):
            period = MonthPeriod.find_create_from(year=self.get('year'),
                                                  month=self.get('month'))
            self.set('period', period)

        # check period
        if self.get('period').is_ahead():
            self.add_error("La période indiquée ({period}) est dans "
                           "le futur".format(period=self.get('period')),
                           blocking=True, field='month')
开发者ID:yeleman,项目名称:snisi,代码行数:12,代码来源:integrity.py


示例17: handle

    def handle(self, *args, **options):

        period = MonthPeriod.current().previous()
        category = 'end_of_district_period'

        for pt in PeriodicTask.objects.filter(category=category):
            regexp = r'_{p}_{cat}'.format(p=period.strid(), cat=category)
            if not pt.slug.endswith(regexp):
                continue

            logger.info("Untriggering {}".format(pt))
            pt.untrigger()
开发者ID:yeleman,项目名称:snisi,代码行数:12,代码来源:remove_end_of_district_pt.py


示例18: routine_month_period_complete

def routine_month_period_complete(period, domain, entity):
    region_eord = domain.import_from('ROUTINE_REGION_AGG_DAY')
    district_eord = domain.import_from('ROUTINE_DISTRICT_AGG_DAY')
    current = MonthPeriod.current()
    if period >= current:
        return False
    if period < current.previous():
        return True
    if entity.type.slug in ('country', 'region', 'health_district'):
        eord = region_eord
    else:
        eord = district_eord
    return timezone.now().day >= eord
开发者ID:yeleman,项目名称:snisi,代码行数:13,代码来源:reporting.py


示例19: handle

    def handle(self, *args, **options):

        period = MonthPeriod.current()
        now = timezone.now()
        if not period.end_on < now:
            logger.error("Can not close mission before end of period")
            return

        for mission in CATMissionR.objects.filter(strategy=FIXED,
                                                  period=period):
            logger.info("Closing {}".format(mission))
            mission.close(period.end_on.date())

        logger.info("All Done")
开发者ID:yeleman,项目名称:snisi,代码行数:14,代码来源:close_fixed_missions.py


示例20: handle

    def handle(self, *args, **options):

        logger.info("Issue #74. Wrong counts in Agg meta (reg #61)")

        november = MonthPeriod.from_url_str("11-2014")

        for report in SNISIReport.objects.filter(period=november):
            report = report.casted()
            if not hasattr(report, 'update_expected_reportings_number'):
                continue

            logger.info(".{}".format(report))
            report.update_expected_reportings_number()

        logger.info("done.")
开发者ID:yeleman,项目名称:snisi,代码行数:15,代码来源:fix_74_meta_numbers.py



注:本文中的snisi_core.models.Periods.MonthPeriod类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python snmp_helper.snmp_extract函数代码示例发布时间:2022-05-27
下一篇:
Python Entities.Entity类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap