Esempio n. 1
0
    def handle(self, *args, **options):
        from usermanagement.utils import member_statistic

        # statistic = member_statistic(year=options['year'])
        statistic = member_statistic()

        statistic = [stat._replace(date=stat.date.isoformat()) for stat in statistic]

        print(';'.join(['date', 'members', 'joined', 'left', 'full', 'reduced']))
        for stat in statistic:
            # stat = stat._asdict()
            print(";".join([stat.date,
                            str(stat.members),
                            str(stat.joined),
                            str(stat.left),
                            str(stat.full),
                            str(stat.reduced),
                            str(stat.sum),
                            ]))
        import json
        import decimal

        def decimal_default(obj):
            if isinstance(obj, decimal.Decimal):
                return float(obj)
            raise TypeError

        statistic_json = []
        for stat in statistic:
            fees = dict((str(key), value) for (key, value) in stat.fees.items())
            stat_dict = stat._asdict()
            stat_dict["fees"] = fees
            statistic_json.append(stat_dict)
        print(json.dumps(statistic_json, indent=2, sort_keys=True, skipkeys=True, default=decimal_default))
Esempio n. 2
0
 def test_member_statistic(self, member_fixture_transfer, join_date_fixture, membership_fixture):
     from usermanagement.utils import member_statistic
     from decimal import Decimal
     statistic = member_statistic()
     assert len(statistic) > 0
     join_date = join_date_fixture.replace(day=1)
     for stat in statistic:
         if stat.date == join_date:
             assert stat.members > 0
             assert stat.fees[Decimal(membership_fixture.membership_fee_monthly)] > 0
     assert join_date in [stat.date for stat in statistic]
Esempio n. 3
0
    def handle(self, *args, **options):
        from usermanagement.utils import member_statistic

        # statistic = member_statistic(year=options['year'])
        statistic = member_statistic()

        statistic = [
            stat._replace(date=stat.date.isoformat()) for stat in statistic
        ]

        print(';'.join(
            ['date', 'members', 'joined', 'left', 'full', 'reduced']))
        for stat in statistic:
            # stat = stat._asdict()
            print(";".join([
                stat.date,
                str(stat.members),
                str(stat.joined),
                str(stat.left),
                str(stat.full),
                str(stat.reduced),
                str(stat.sum),
            ]))
        import json
        import decimal

        def decimal_default(obj):
            if isinstance(obj, decimal.Decimal):
                return float(obj)
            raise TypeError

        statistic_json = []
        for stat in statistic:
            fees = dict(
                (str(key), value) for (key, value) in stat.fees.items())
            stat_dict = stat._asdict()
            stat_dict["fees"] = fees
            statistic_json.append(stat_dict)
        print(
            json.dumps(statistic_json,
                       indent=2,
                       sort_keys=True,
                       skipkeys=True,
                       default=decimal_default))