-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress toward #6 Assumes existing PoC data for now
- Loading branch information
Showing
8 changed files
with
139 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
up: function(migration, DataTypes, done) { | ||
migration.addColumn( | ||
'Users', | ||
'isPersonOfColour', | ||
DataTypes.BOOLEAN | ||
); | ||
done(); | ||
}, | ||
|
||
down: function(migration, DataTypes, done) { | ||
migration.removeColumn( | ||
'Users', | ||
'isPersonOfColour' | ||
); | ||
done(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// FIXME extract a generalised solution from this and GenderMessageCount | ||
|
||
class RaceMessageCount { | ||
constructor(statistics, userIsPersonOfColour) { | ||
this.statistics = statistics; | ||
this.userIsPersonOfColour = userIsPersonOfColour; | ||
} | ||
|
||
generate() { | ||
var userIDs = Object.keys(this.statistics); | ||
|
||
var counts = userIDs.reduce(function(counts, userID) { | ||
var isPersonOfColour = this.userIsPersonOfColour[userID]; | ||
var count = this.statistics[userID]; | ||
|
||
if (isPersonOfColour) { | ||
counts.peopleOfColour += count; | ||
} else if (isPersonOfColour === false) { | ||
counts.whitePeople += count; | ||
} else { | ||
counts.unknown += count; | ||
} | ||
|
||
return counts; | ||
}.bind(this), {peopleOfColour: 0, whitePeople: 0, unknown: 0}); | ||
|
||
return counts; | ||
} | ||
} | ||
|
||
module.exports = RaceMessageCount; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// TODO also untested except by integration | ||
|
||
var moment = require('moment'); | ||
var values = require('amp-values'); | ||
|
||
var GenderMessageCountStatisticsGenerator = require('../calculators/gender-message-count'); | ||
var RaceMessageCount = require('../calculators/race-message-count'); | ||
|
||
class TerseReportGenerator { | ||
constructor(userMessageCount, userIsMan, userIsPersonOfColour, startTime, statsChannel) { | ||
this.userMessageCount = userMessageCount; | ||
// FIXME should collect attributes into an object? | ||
// also querying the table multiple times, inefficient | ||
this.userIsMan = userIsMan; | ||
this.userIsPersonOfColour = userIsPersonOfColour; | ||
this.startTime = startTime; | ||
this.statsChannel = statsChannel; | ||
} | ||
|
||
generate() { | ||
var genderMessageCountStatistics = new GenderMessageCountStatisticsGenerator(this.userMessageCount, this.userIsMan).generate(); | ||
var raceMessageCount = new RaceMessageCount(this.userMessageCount, this.userIsPersonOfColour).generate(); | ||
|
||
var total = genderMessageCountStatistics.men + genderMessageCountStatistics.notMen + genderMessageCountStatistics.unknown; | ||
|
||
var notMenPercent = (100*genderMessageCountStatistics.notMen/total).toFixed(0); | ||
var peopleOfColourPercent = (100*raceMessageCount.peopleOfColour/total).toFixed(0); | ||
|
||
|
||
|
||
var report = `Since ${moment(this.startTime).fromNow()}, not-men sent ${notMenPercent}% of messages and people of colour sent ${peopleOfColourPercent}% of messages. See #${this.statsChannel} for more details.`; | ||
|
||
return report; | ||
} | ||
} | ||
|
||
module.exports = TerseReportGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env iojs --es_staging --use-strict | ||
|
||
var test = require('tape'); | ||
|
||
var RaceMessageCount = require('../../src/calculators/race-message-count'); | ||
|
||
test('RaceMessageCount groups messages by race', function(t) { | ||
var statistics = { | ||
'White': 4, | ||
'Also-white': 3, | ||
'Person-of-colour': 2, | ||
'Unknown': 1 | ||
}; | ||
|
||
var userIsPersonOfColour = { | ||
'White': false, | ||
'Also-white': false, | ||
'Person-of-colour': true, | ||
'Unknown': undefined | ||
}; | ||
|
||
var generator = new RaceMessageCount(statistics, userIsPersonOfColour); | ||
statistics = generator.generate(); | ||
|
||
t.equal(statistics.whitePeople, 7, 'counts 7 messages from white people'); | ||
t.equal(statistics.peopleOfColour, 2, 'counts 2 messages from people of colour'); | ||
t.equal(statistics.unknown, 1, 'counts 1 message from unknown'); | ||
|
||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters