-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateModStats.m
More file actions
93 lines (86 loc) · 3.18 KB
/
generateModStats.m
File metadata and controls
93 lines (86 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function [modStats] = generateModStats(chatFile)
% Moderation Statistics Generator
% This function takes a .txt file of a Pokémon Showdown chat log as
% input, then generates a list of usernames ranked by number of
% moderative actions taken in the chat room.
modLines = 0;
totalLines = 0;
fid = fopen(['logs/' chatFile]);
while feof(fid) == 0
line = fgetl(fid);
verticalBars = strfind(line, '|');
if length(verticalBars) >= 3
if length(line) >= verticalBars(3) + 4
if strcmp(line((verticalBars(3) + 1):(verticalBars(3) + 4)), '/log')
modLines = modLines + 1;
end
end
end
totalLines = totalLines + 1;
end
fclose(fid);
fprintf('The chat log has been scanned.\n');
fprintf('There are %d lines containing moderative actions and %d total lines.\n', modLines, totalLines);
if modLines > 0
usernames = java_array('java.lang.String', modLines);
currentChatLine = 1;
fid = fopen(['logs/' chatFile]);
while feof(fid) == 0
line = fgetl(fid);
verticalBars = strfind(line, '|');
if length(verticalBars) >= 3
if length(line) >= verticalBars(3) + 4
if strcmp(line((verticalBars(3) + 1):(verticalBars(3) + 4)), '/log')
fullUsername = line((verticalBars(2) + 2):(verticalBars(3) - 1));
alphanumericUsername = lower(regexprep(fullUsername, '[^a-zA-Z0-9]', ''));
usernames(currentChatLine) = java.lang.String(alphanumericUsername);
currentChatLine = currentChatLine + 1;
end
end
end
end
fclose(fid);
fprintf('The username database has been generated.\n');
uniqueUsernames = java_array('java.lang.String', 1);
modCount = double.empty(0, modLines);
fprintf('Scanning the username database...\n');
reverse = '';
for i = 1:modLines
for j = 1:length(uniqueUsernames)
if usernames(i) == uniqueUsernames(j)
modCount(j) = modCount(j) + 1;
unique = false;
break
else
unique = true;
end
end
if unique
uniqueUsernames(length(uniqueUsernames)+1) = usernames(i);
modCount(length(uniqueUsernames)) = 1;
end
progress = sprintf('%d/%d lines scanned\n', i, modLines);
fprintf([reverse, progress]);
reverse = repmat(sprintf('\b'), 1, length(progress));
end
modPercent = double.empty(0, modLines);
for i = 1:length(modCount)
modPercent(i) = 100 * (modCount(i) / modLines);
end
c1 = cell(uniqueUsernames);
c2 = num2cell(transpose(modCount));
c3 = num2cell(transpose(modPercent));
dataArray = [c1 c2 c3];
sortedData = sortrows(dataArray, -2);
sortedData(size(sortedData, 1),:) = [];
rank = cell(size(sortedData, 1), 1);
for i = 1:size(sortedData, 1)
rank(i) = num2cell(i);
end
header = {'Rank' 'Username' 'Mod Actions' 'Percent Total'};
modStats = [header; [rank sortedData]];
else
fprintf('There were no moderative actions taken during this period.\n');
modStats = {'Rank' 'Username' 'Mod Actions' 'Percent Total'};
end
end