Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Update Statistics To Realtime w/ Caching #194

Open
wants to merge 27 commits into
base: staging
Choose a base branch
from
Open

Conversation

ASankaran
Copy link
Contributor

@ASankaran ASankaran commented Jan 29, 2018

  • Write registration, rsvp, and live stats to database and cache in realtime
  • Read stats back from cache when possible
  • Read stats from db and write to cache when needed
  • Remove outdated stats (ie. tracks)
  • Update docs

@ASankaran ASankaran changed the base branch from master to staging January 29, 2018 04:28
@ASankaran
Copy link
Contributor Author

Slightly updated response format:

{
    "meta": null,
    "data": {
        "registration": {
            "school": {
                "University of Illinois at Urbana-Champaign": 4
            },
            "transportation": {
                "BUS_REQUESTED": 0,
                "INTERNATIONAL": 0,
                "IN_STATE": 0,
                "NOT_NEEDED": 9,
                "OUT_OF_STATE": 0
            },
            "diet": {
                "GLUTEN_FREE": 0,
                "NONE": 9,
                "VEGAN": 0,
                "VEGETARIAN": 0
            },
            "shirtSize": {
                "L": 0,
                "M": 8,
                "S": 0,
                "XL": 0
            },
            "gender": {
                "FEMALE": 0,
                "MALE": 9,
                "NON_BINARY": 0,
                "OTHER": 0
            },
            "graduationYear": {
                "2019": 3
            },
            "isNovice": {
                "0": 0,
                "1": 9
            },
            "status": {
                "ACCEPTED": 0,
                "PENDING": 0,
                "REJECTED": 0,
                "WAITLISTED": 0
            },
            "major": {
                "Computer Science": 4
            },
            "attendees": {
                "count": 9
            }
        },
        "rsvp": {
            "school": {
                "University of Illinois at Urbana-Champaign": 1
            },
            "transportation": {
                "BUS_REQUESTED": 0,
                "INTERNATIONAL": 0,
                "IN_STATE": 0,
                "NOT_NEEDED": 1,
                "OUT_OF_STATE": 0
            },
            "diet": {
                "GLUTEN_FREE": 0,
                "NONE": 1,
                "VEGAN": 0,
                "VEGETARIAN": 0
            },
            "shirtSize": {
                "L": 0,
                "M": 1,
                "S": 0,
                "XL": 0
            },
            "gender": {
                "FEMALE": 0,
                "MALE": 1,
                "NON_BINARY": 0,
                "OTHER": 0
            },
            "graduationYear": {
                "2019": 1
            },
            "isNovice": {
                "0": 0,
                "1": 1
            },
            "major": {
                "Computer Science": 1
            },
            "attendees": {
                "count": 0
            }
        },
        "liveevent": {
            "attendees": {
                "count": 17
            },
            "events": {
                "Example Event": 1
            }
        }
    }
}

@redsn0w422
Copy link
Member

What's the status on this?

Copy link
Member

@YashoSharma YashoSharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also are there no changes to the stats controller/service?

@@ -4,7 +4,7 @@ const services = require('../services');
const middleware = require('../middleware');
const requests = require('../requests');
const roles = require('../utils/roles');
const mail = require('../utils/mail');
const config = require('../../config');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctx

const Model = require('./Model');
const validators = require('../utils/validators');

const CATEGORIES = ['registration', 'rsvp', 'liveevent'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

live_event

category: category,
stat: stat,
field: field
}).query().count().then((count) => _Promise.resolve(count[0]['count(*)'] > 0));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do .where().count()

amount = 1;
}

const s = Stat.query((qb) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Stat.where().fetch().increment()

@@ -17,4 +17,10 @@ TrackingEvent.findByName = function(searchName) {
.fetch();
};

TrackingEvent.findAll = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stats Service needs it to query all the tracked events and report the number of people who checked in.

@@ -61,6 +62,8 @@ module.exports.createCheckIn = (attributes) => {
const credentialsRequested = attributes.credentialsRequested;
delete attributes.credentialsRequested;

StatsService.incrementStat('liveevent', 'attendees', 'count');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

live_event

@@ -22,6 +25,18 @@ module.exports.getRSVPById = (id) => RSVP.findById(id);
* @throws {InvalidParameterError} thrown when an attendee already has an rsvp
*/
module.exports.createRSVP = (attendee, user, attributes) => {

StatsService.incrementStat('rsvp', 'school', attendee.get('school'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferably the controller has a const array which designates which fields to increment and then you can call the stat update function for-each element of the array

@@ -66,6 +69,8 @@ module.exports.addEventParticipant = (participantId) => {

currentEvent = result;

StatsService.incrementStat('liveevent', 'events', currentEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

live_event


INSERT INTO `stats` (`category`, `stat`, `field`) VALUES ('liveevent', 'attendees', 'count');

#INSERT INTO `stats` (`category`, `stat`, `field`) VALUES ('liveevent', `status`, `ACCEPTED`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning up this sql table would be nice

@ASankaran ASankaran changed the title Update Statistics To Realtime w/ Caching WIP: Update Statistics To Realtime w/ Caching Feb 19, 2018
@ASankaran ASankaran changed the title WIP: Update Statistics To Realtime w/ Caching Update Statistics To Realtime w/ Caching Feb 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants