<commit_before>module.exports = class EventRepository {
    constructor({
        MemberSubscribeEvent,
        MemberPaymentEvent,
        MemberStatusEvent,
        MemberLoginEvent,
        MemberPaidSubscriptionEvent,
        logger
    }) {
        this._MemberSubscribeEvent = MemberSubscribeEvent;
        this._MemberPaidSubscriptionEvent = MemberPaidSubscriptionEvent;
        this._MemberPaymentEvent = MemberPaymentEvent;
        this._MemberStatusEvent = MemberStatusEvent;
        this._MemberLoginEvent = MemberLoginEvent;
        this._logging = logger;
    }

    async registerPayment(data) {
        await this._MemberPaymentEvent.add({
            ...data,
            source: 'stripe'
        });
    }

    async getNewsletterSubscriptionEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberSubscribeEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'newsletter_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getSubscriptionEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberPaidSubscriptionEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'subscription_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getPaymentEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberPaymentEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'payment_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getLoginEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberLoginEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'login_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getEventTimeline(options = {}) {
        if (!options.limit) {
            options.limit = 10;
        }

        options.order = 'created_at desc';

        const allEventPages = await Promise.all([
            this.getNewsletterSubscriptionEvents(options),
            this.getSubscriptionEvents(options),
            this.getLoginEvents(options)
        ]);

        const allEvents = allEventPages.reduce((allEvents, page) => allEvents.concat(page.data), []);

        return allEvents.sort((a, b) => {
            return new Date(b.data.created_at) - new Date(a.data.created_at);
        }).slice(0, options.limit);
    }

    async getSubscriptions() {
        const results = await this._MemberSubscribeEvent.findAll({
            aggregateSubscriptionDeltas: true
        });

        const resultsJSON = results.toJSON();

        const cumulativeResults = resultsJSON.reduce((cumulativeResults, result, index) => {
            if (index === 0) {
                return [{
                    date: result.date,
                    subscribed: result.subscribed_delta
                }];
            }
            return cumulativeResults.concat([{
                date: result.date,
                subscribed: result.subscribed_delta + cumulativeResults[index - 1].subscribed
            }]);
        }, []);

        return cumulativeResults;
    }<commit_msg>Added signup_events to the event timeline<commit_after>module.exports = class EventRepository {
    constructor({
        MemberSubscribeEvent,
        MemberPaymentEvent,
        MemberStatusEvent,
        MemberLoginEvent,
        MemberPaidSubscriptionEvent,
        logger
    }) {
        this._MemberSubscribeEvent = MemberSubscribeEvent;
        this._MemberPaidSubscriptionEvent = MemberPaidSubscriptionEvent;
        this._MemberPaymentEvent = MemberPaymentEvent;
        this._MemberStatusEvent = MemberStatusEvent;
        this._MemberLoginEvent = MemberLoginEvent;
        this._logging = logger;
    }

    async registerPayment(data) {
        await this._MemberPaymentEvent.add({
            ...data,
            source: 'stripe'
        });
    }

    async getNewsletterSubscriptionEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberSubscribeEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'newsletter_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getSubscriptionEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberPaidSubscriptionEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'subscription_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getPaymentEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberPaymentEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'payment_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getLoginEvents(options = {}) {
        options.withRelated = ['member'];
        const {data: models, meta} = await this._MemberLoginEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'login_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getSignupEvents(options = {}) {
        options.withRelated = ['member'];
        options.filter = 'from_status:null';
        const {data: models, meta} = await this._MemberStatusEvent.findPage(options);

        const data = models.map((data) => {
            return {
                type: 'signup_event',
                data: data.toJSON(options)
            };
        });

        return {
            data,
            meta
        };
    }

    async getEventTimeline(options = {}) {
        if (!options.limit) {
            options.limit = 10;
        }

        options.order = 'created_at desc';

        const allEventPages = await Promise.all([
            this.getNewsletterSubscriptionEvents(options),
            this.getSubscriptionEvents(options),
            this.getLoginEvents(options),
            this.getSignupEvents(options)
        ]);

        const allEvents = allEventPages.reduce((allEvents, page) => allEvents.concat(page.data), []);

        return allEvents.sort((a, b) => {
            return new Date(b.data.created_at) - new Date(a.data.created_at);
        }).slice(0, options.limit);
    }

    async getSubscriptions() {
        const results = await this._MemberSubscribeEvent.findAll({
            aggregateSubscriptionDeltas: true
        });

        const resultsJSON = results.toJSON();

        const cumulativeResults = resultsJSON.reduce((cumulativeResults, result, index) => {
            if (index === 0) {
                return [{
                    date: result.date,
                    subscribed: result.subscribed_delta
                }];
            }
            return cumulativeResults.concat([{
                date: result.date,
                subscribed: result.subscribed_delta + cumulativeResults[index - 1].subscribed
            }]);
        }, []);

        return cumulativeResults;
    }
{'fraction_non_alphanumeric': 0.10670918680240403, 'fraction_numerical': 0.0012265423770391267, 'mean_word_length': 1.679592507394019, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6338902', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2032, 'n_words': 385}