Пример #1
0
    def get_export_data(cls):
        count_attrs = ['state', 'has_been_read', 'vote']
        edits_attrs = ['state', 'vote', 'note']

        data = {
            'public': {
                'votes': {
                    'counts': export_attr_counts(cls, count_attrs),
                    'edits': export_attr_edits(cls, edits_attrs),
                },
            },
            'tables': ['cfp_vote', 'cfp_vote_version'],
        }
        data['public']['votes']['counts']['created_day'] = export_intervals(cls.query, cls.created, 'day', 'YYYY-MM-DD')

        return data
Пример #2
0
    def get_export_data(cls):
        count_attrs = ['state', 'has_been_read', 'vote']
        edits_attrs = ['state', 'vote', 'note']

        data = {
            'public': {
                'votes': {
                    'counts': export_attr_counts(cls, count_attrs),
                    'edits': export_attr_edits(cls, edits_attrs),
                },
            },
            'tables': ['cfp_vote', 'cfp_vote_version'],
        }
        data['public']['votes']['counts']['created_day'] = export_intervals(
            cls.query, cls.created, 'day', 'YYYY-MM-DD')

        return data
Пример #3
0
    def get_export_data(cls):
        count_attrs = ["state", "has_been_read", "vote"]
        edits_attrs = ["state", "vote", "note"]

        data = {
            "public": {
                "votes": {
                    "counts": export_attr_counts(cls, count_attrs),
                    "edits": export_attr_edits(cls, edits_attrs),
                }
            },
            "tables": ["cfp_vote", "cfp_vote_version"],
        }
        data["public"]["votes"]["counts"]["created_day"] = export_intervals(
            cls.query, cls.created, "day", "YYYY-MM-DD")

        return data
Пример #4
0
    def get_export_data(cls):
        if cls.__name__ == 'Proposal':
            # Export stats for each proposal type separately
            return {}

        count_attrs = [
            'needs_help', 'needs_money', 'needs_laptop', 'one_day',
            'notice_required', 'may_record', 'state'
        ]

        edits_attrs = [
            'published_title', 'published_description', 'requirements',
            'length', 'notice_required', 'needs_help', 'needs_money',
            'one_day', 'has_rejected_email', 'published_names',
            'arrival_period', 'departure_period', 'telephone_number',
            'may_record', 'needs_laptop', 'available_times', 'attendees',
            'cost', 'size', 'funds', 'age_range', 'participant_equipment'
        ]

        # FIXME: include published_title
        proposals = cls.query.with_entities(
            cls.id,
            cls.title,
            cls.description,
            cls.favourite_count,  # don't care about performance here
            cls.length,
            cls.notice_required,
            cls.needs_money,
            cls.available_times,
            cls.allowed_times,
            cls.arrival_period,
            cls.departure_period,
            cls.needs_laptop,
            cls.may_record,
        ).order_by(cls.id)

        if cls.__name__ == 'WorkshopProposal':
            proposals = proposals.add_columns(cls.attendees, cls.cost)
        elif cls.__name__ == 'InstallationProposal':
            proposals = proposals.add_columns(cls.size, cls.funds)
        elif cls.__name__ == 'YouthWorkshopProposal':
            proposals = proposals.add_columns(cls.attendees, cls.cost,
                                              cls.age_range,
                                              cls.participant_equipment)

        # Some unaccepted proposals have scheduling data, but we shouldn't need to keep that
        accepted_columns = (
            User.name,
            User.email,
            cls.published_names,
            cls.scheduled_time,
            cls.scheduled_duration,
            Venue.name,
        )
        accepted_proposals = proposals.filter(cls.state.in_(['accepted', 'finished'])) \
                                      .outerjoin(cls.scheduled_venue) \
                                      .join(cls.user) \
                                      .add_columns(*accepted_columns)

        other_proposals = proposals.filter(
            ~cls.state.in_(['accepted', 'finished']))

        user_favourites = cls.query.filter(cls.state.in_(['accepted', 'finished'])) \
                                   .join(cls.favourites) \
                                   .with_entities(User.id.label('user_id'), cls.id) \
                                   .order_by(User.id)

        anon_favourites = []
        for user_id, proposals in groupby(user_favourites,
                                          lambda r: r.user_id):
            anon_favourites.append([p.id for p in proposals])
        anon_favourites.sort()

        public_columns = (
            cls.published_title,
            cls.published_description,
            cls.published_names.label('names'),
            cls.may_record,
            cls.scheduled_time,
            cls.scheduled_duration,
            Venue.name.label('venue'),
        )
        accepted_public = cls.query.filter(cls.state.in_(['accepted', 'finished'])) \
                                   .outerjoin(cls.scheduled_venue) \
                                   .with_entities(*public_columns)

        favourite_counts = [p.favourite_count for p in proposals]

        data = {
            'private': {
                'proposals': {
                    'accepted_proposals': accepted_proposals,
                    'other_proposals': other_proposals,
                },
                'favourites': anon_favourites,
            },
            'public': {
                'proposals': {
                    'counts': export_attr_counts(cls, count_attrs),
                    'edits': export_attr_edits(cls, edits_attrs),
                    'accepted': accepted_public,
                },
                'favourites': {
                    'counts':
                    bucketise(favourite_counts,
                              [0, 1, 10, 20, 30, 40, 50, 100, 200]),
                },
            },
            'tables': [
                'proposal', 'proposal_version', 'favourite_proposal',
                'favourite_proposal_version'
            ],
        }
        data['public']['proposals']['counts'][
            'created_week'] = export_intervals(cls.query, cls.created, 'week',
                                               'YYYY-MM-DD')

        return data
Пример #5
0
    def get_export_data(cls):
        if cls.__name__ == "Proposal":
            # Export stats for each proposal type separately
            return {}

        count_attrs = [
            "needs_help",
            "needs_money",
            "needs_laptop",
            "one_day",
            "notice_required",
            "may_record",
            "state",
        ]

        edits_attrs = [
            "published_title",
            "published_description",
            "requirements",
            "length",
            "notice_required",
            "needs_help",
            "needs_money",
            "one_day",
            "has_rejected_email",
            "published_names",
            "arrival_period",
            "departure_period",
            "telephone_number",
            "may_record",
            "needs_laptop",
            "available_times",
            "attendees",
            "cost",
            "size",
            "funds",
            "age_range",
            "participant_equipment",
        ]

        # FIXME: include published_title
        proposals = cls.query.with_entities(
            cls.id,
            cls.title,
            cls.description,
            cls.favourite_count,  # don't care about performance here
            cls.length,
            cls.notice_required,
            cls.needs_money,
            cls.available_times,
            cls.allowed_times,
            cls.arrival_period,
            cls.departure_period,
            cls.needs_laptop,
            cls.may_record,
        ).order_by(cls.id)

        if cls.__name__ == "WorkshopProposal":
            proposals = proposals.add_columns(cls.attendees, cls.cost)
        elif cls.__name__ == "InstallationProposal":
            proposals = proposals.add_columns(cls.size, cls.funds)
        elif cls.__name__ == "YouthWorkshopProposal":
            proposals = proposals.add_columns(
                cls.attendees, cls.cost, cls.age_range, cls.participant_equipment
            )

        # Some unaccepted proposals have scheduling data, but we shouldn't need to keep that
        accepted_columns = (
            User.name,
            User.email,
            cls.published_names,
            cls.scheduled_time,
            cls.scheduled_duration,
            Venue.name,
        )
        accepted_proposals = (
            proposals.filter(cls.state.in_(["accepted", "finished"]))
            .outerjoin(cls.scheduled_venue)
            .join(cls.user)
            .add_columns(*accepted_columns)
        )

        other_proposals = proposals.filter(~cls.state.in_(["accepted", "finished"]))

        user_favourites = (
            cls.query.filter(cls.state.in_(["accepted", "finished"]))
            .join(cls.favourites)
            .with_entities(User.id.label("user_id"), cls.id)
            .order_by(User.id)
        )

        anon_favourites = []
        for user_id, proposals in groupby(user_favourites, lambda r: r.user_id):
            anon_favourites.append([p.id for p in proposals])
        anon_favourites.sort()

        public_columns = (
            cls.published_title,
            cls.published_description,
            cls.published_names.label("names"),
            cls.may_record,
            cls.scheduled_time,
            cls.scheduled_duration,
            Venue.name.label("venue"),
        )
        accepted_public = (
            cls.query.filter(cls.state.in_(["accepted", "finished"]))
            .outerjoin(cls.scheduled_venue)
            .with_entities(*public_columns)
        )

        favourite_counts = [p.favourite_count for p in proposals]

        data = {
            "private": {
                "proposals": {
                    "accepted_proposals": accepted_proposals,
                    "other_proposals": other_proposals,
                },
                "favourites": anon_favourites,
            },
            "public": {
                "proposals": {
                    "counts": export_attr_counts(cls, count_attrs),
                    "edits": export_attr_edits(cls, edits_attrs),
                    "accepted": accepted_public,
                },
                "favourites": {
                    "counts": bucketise(
                        favourite_counts, [0, 1, 10, 20, 30, 40, 50, 100, 200]
                    )
                },
            },
            "tables": [
                "proposal",
                "proposal_version",
                "favourite_proposal",
                "favourite_proposal_version",
            ],
        }
        data["public"]["proposals"]["counts"]["created_week"] = export_intervals(
            cls.query, cls.created, "week", "YYYY-MM-DD"
        )

        return data
Пример #6
0
    def get_export_data(cls):
        if cls.__name__ == 'Proposal':
            # Export stats for each proposal type separately
            return {}

        count_attrs = ['needs_help', 'needs_money', 'needs_laptop',
                       'one_day', 'notice_required', 'may_record', 'state']

        edits_attrs = ['published_title', 'published_description', 'requirements', 'length',
                       'notice_required', 'needs_help', 'needs_money', 'one_day',
                       'has_rejected_email', 'published_names', 'arrival_period',
                       'departure_period', 'telephone_number', 'may_record',
                       'needs_laptop', 'available_times',
                       'attendees', 'cost', 'size', 'funds',
                       'age_range', 'participant_equipment']

        # FIXME: include published_title
        proposals = cls.query.with_entities(
            cls.id, cls.title, cls.description,
            cls.favourite_count,  # don't care about performance here
            cls.length, cls.notice_required, cls.needs_money,
            cls.available_times, cls.allowed_times,
            cls.arrival_period, cls.departure_period,
            cls.needs_laptop, cls.may_record,
        ).order_by(cls.id)

        if cls.__name__ == 'WorkshopProposal':
            proposals = proposals.add_columns(cls.attendees, cls.cost)
        elif cls.__name__ == 'InstallationProposal':
            proposals = proposals.add_columns(cls.size, cls.funds)
        elif cls.__name__ == 'YouthWorkshopProposal':
            proposals = proposals.add_columns(cls.attendees, cls.cost, cls.age_range, cls.participant_equipment)

        # Some unaccepted proposals have scheduling data, but we shouldn't need to keep that
        accepted_columns = (
            User.name, User.email, cls.published_names,
            cls.scheduled_time, cls.scheduled_duration, Venue.name,
        )
        accepted_proposals = proposals.filter(cls.state.in_(['accepted', 'finished'])) \
                                      .outerjoin(cls.scheduled_venue) \
                                      .join(cls.user) \
                                      .add_columns(*accepted_columns)

        other_proposals = proposals.filter(~cls.state.in_(['accepted', 'finished']))

        user_favourites = cls.query.filter(cls.state.in_(['accepted', 'finished'])) \
                                   .join(cls.favourites) \
                                   .with_entities(User.id.label('user_id'), cls.id) \
                                   .order_by(User.id)

        anon_favourites = []
        for user_id, proposals in groupby(user_favourites, lambda r: r.user_id):
            anon_favourites.append([p.id for p in proposals])
        anon_favourites.sort()

        public_columns = (
            cls.published_title, cls.published_description,
            cls.published_names.label('names'), cls.may_record,
            cls.scheduled_time, cls.scheduled_duration, Venue.name.label('venue'),
        )
        accepted_public = cls.query.filter(cls.state.in_(['accepted', 'finished'])) \
                                   .outerjoin(cls.scheduled_venue) \
                                   .with_entities(*public_columns)

        favourite_counts = [p.favourite_count for p in proposals]

        data = {
            'private': {
                'proposals': {
                    'accepted_proposals': accepted_proposals,
                    'other_proposals': other_proposals,
                },
                'favourites': anon_favourites,
            },
            'public': {
                'proposals': {
                    'counts': export_attr_counts(cls, count_attrs),
                    'edits': export_attr_edits(cls, edits_attrs),
                    'accepted': accepted_public,
                },
                'favourites': {
                    'counts': bucketise(favourite_counts, [0, 1, 10, 20, 30, 40, 50, 100, 200]),
                },
            },
            'tables': ['proposal', 'proposal_version', 'favourite_proposal', 'favourite_proposal_version'],
        }
        data['public']['proposals']['counts']['created_week'] = export_intervals(cls.query, cls.created, 'week', 'YYYY-MM-DD')

        return data