Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Fixes Bug 1036026, counts for country, city, mentor, coorganizer
Browse files Browse the repository at this point in the history
+ add mentors, coorganizers and cities to per country stats
  • Loading branch information
adamlofting committed Jul 18, 2014
1 parent 2f3d657 commit 4f962f5
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions bin/getEventStats
Expand Up @@ -17,12 +17,19 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S
// arrays to dedupe things w/
var event_hosts = [];
var countries = [];
var cities = [];
var mentors = [];
var coorganizers = [];

// init stats object
var event_stats = {
hosts: 0,
attendees: 0,
events: 0,
countries:0,
cities:0,
mentors: 0,
coorganizers: 0,
byCountry: {}
};

Expand All @@ -31,7 +38,11 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S

// make access to other stats easier to figure
events.forEach( function( event, idx ) {
var new_host = 0; // little trick to count hosts per country
// little trick to count hosts/mentors/coorganizers per country
var new_host = 0;
var new_mentors = 0;
var new_coorganizers = 0;
var new_city = 0;

/*
get people stats
Expand All @@ -47,12 +58,49 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S
new_host = 1; // this is a new host, add to country host count ;)
}

// get mentor stats
if ( event.mentors && (event.mentors.length > 0) ) {
event.mentors.forEach( function( mentor, idx ) {
if ( mentor.userId ) {
if( mentors.indexOf( mentor.userId ) === -1){
mentors.push( mentor.userId );

new_mentors += 1; // this is a new mentor, add to country mentor count
}
}
});
}

// get coorganizers stats
if ( event.coorganizers && (event.coorganizers.length > 0) ) {
event.coorganizers.forEach( function( coorganizer, idx ) {
if ( coorganizer.userId ) {
if( coorganizers.indexOf( coorganizer.userId ) === -1){
coorganizers.push( coorganizer.userId );

new_coorganizers += 1; // this is a new mentor, add to country mentor count
}
}
});
}

/*
Get city stats
*/
if( event.city ) {
if(cities.indexOf( event.city ) === -1){
cities.push( event.city );

new_city = 1;
}
}

/*
get country level stats
*/
var origCountry = event.country;
// if null make unknown (we still want any other info we can extract)
if( event.country === null ) {
if( event.country === null || event.country === '') {
event.country = 'UNKNOWN';
}
// else force country code not name
Expand All @@ -78,7 +126,10 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S
country: origCountry,
events: 0,
hosts: 0,
attendees: 0
mentors: 0,
coorganizers: 0,
attendees: 0,
cities: 0
};
countries.push( event.country );
}
Expand All @@ -91,7 +142,10 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S
country: origCountry,
events: country.events + 1,
hosts: country.hosts + new_host,
attendees: country.attendees + event.attendees
mentors: country.mentors + new_mentors,
coorganizers: country.coorganizers + new_coorganizers,
attendees: country.attendees + event.attendees,
cities: country.cities + new_city
};

// not sure this line is even needed.
Expand All @@ -114,6 +168,12 @@ request.get( env.get( 'EVENTS_SERVICE' ) + '/events?after=' + env.get( 'EVENTS_S

event_stats.byCountry = new_byCountry;

// include theses counts for quick reading by humans
event_stats.countries = countries.length;
event_stats.cities = cities.length;
event_stats.mentors = mentors.length;
event_stats.coorganizers = coorganizers.length;

// save the results in a cache file
fs.writeFileSync( './event-stats.json', JSON.stringify( event_stats ) );

Expand Down

0 comments on commit 4f962f5

Please sign in to comment.