Skip to content

Commit

Permalink
Add verbose report of PoC participation
Browse files Browse the repository at this point in the history
Can check a box in #6 now!
  • Loading branch information
backspace committed Feb 12, 2015
1 parent 84bf5cb commit 65c4f47
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/calculators/race-participant-count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var trinaryCounter = require('./trinary-counter');

class RaceParticipantCountReportGenerator {
constructor(userMessages, userIsPersonOfColour) {
this.userMessages = userMessages;
this.userIsPersonOfColour = userIsPersonOfColour;
}

generate() {
return trinaryCounter(
this.userMessages,
this.userIsPersonOfColour,
{
'true': 'peopleOfColour',
'false': 'whitePeople',
'else': 'unknown'
}
);
}
}

module.exports = RaceParticipantCountReportGenerator;
37 changes: 37 additions & 0 deletions src/reports/verbose-race.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// TODO there’s little difference between this and the gender report;
// the calculators are simple wrappers for trinaryCounter and trinaryGrouper

var messageAndParticipantTable = require('./message-and-participant-table');

var RaceMessageCountStatisticsGenerator = require('../calculators/race-message-count');

var RaceParticipantCountStatisticsGenerator = require('../calculators/race-participant-count');

class VerboseRaceReportGenerator {
constructor(userMessageCount, userIsPersonOfColour) {
this.userMessageCount = userMessageCount;
this.userIsPersonOfColour = userIsPersonOfColour;
}

generate() {
var messageCountStatistics = new RaceMessageCountStatisticsGenerator(this.userMessageCount, this.userIsPersonOfColour).generate();

var participantCountStatistics = new RaceParticipantCountStatisticsGenerator(this.userMessageCount, this.userIsPersonOfColour).generate();

var table = messageAndParticipantTable(
messageCountStatistics,
participantCountStatistics,
{
'peopleOfColour': 'PoC',
'whitePeople': 'not-PoC',
'unknown': 'unknown'
}
);

var report = '```\n' + table.toString() + '\n```';

return report;
}
}

module.exports = VerboseRaceReportGenerator;
8 changes: 6 additions & 2 deletions src/statsbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var MessageLog = require('./message-log');
var RepositoryAttributeExtractor = require('./persistence/repository-attribute-extractor');

var VerboseGenderReportGenerator = require('./reports/verbose-gender');
var VerboseRaceReportGenerator = require('./reports/verbose-race');

var TerseReportGenerator = require('./reports/terse');

var DirectMessageHandler = require('./direct-message-handler');
Expand Down Expand Up @@ -105,8 +107,10 @@ class StatsBot {

isPersonOfColourExtractor.extract().then(function(userIsPersonOfColour) {
var preamble = `#${channel.name} since ${moment(metadata.startTime).fromNow()}`;
var fullReport = new VerboseGenderReportGenerator(statistics, userIsMan).generate();
botChannel.send(`${preamble}:\n${fullReport}`);
var genderReport = new VerboseGenderReportGenerator(statistics, userIsMan).generate();
var raceReport = new VerboseRaceReportGenerator(statistics, userIsPersonOfColour).generate();

botChannel.send(`${preamble}:\n${genderReport}\n${raceReport}`);

var terseReport = new TerseReportGenerator(statistics, userIsMan, userIsPersonOfColour, metadata.startTime, botChannel.name).generate();
channel.send(terseReport);
Expand Down
2 changes: 2 additions & 0 deletions test/statsbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ test('StatsBot reports a channel\'s message counts when requested', function(t)
t.ok(botChannel.send.calledWithMatch(/#Ytterbium/), 'reports #Ytterbium statistics in the bot channel');
t.ok(botChannel.send.calledWithMatch(/^.*counts.*2.*$/m), 'reports a message count of 2');
t.ok(botChannel.send.calledWithMatch(/^.*men.*100%.*$/m), 'reports that only men spoke in one channel');
t.ok(botChannel.send.calledWithMatch(/^.*PoC.*0%.*$/m), 'reports that no people of colour spoke in one channel');
t.ok(botChannel.send.calledWithMatch(/^.*not-PoC.*100%.*$/m), 'reports that only non-PoC spoke in one channel');

t.ok(ytterbium.send.calledWithMatch(/not-men sent 0% of messages/), 'reports in the channel that not-men sent no messages');
t.ok(ytterbium.send.calledWithMatch(/people of colour sent 0% of messages/), 'reports in the channel that people of colour sent no messages');
Expand Down

0 comments on commit 65c4f47

Please sign in to comment.