How to make a list of user's reputation ? :)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
?:
3 comentarios
Mark Shore
el 8 de Feb. de 2011
At a glance, it's missing a few well-known significant contributors. And since the MATLAB newsgroup (unlike the FEX) doesn't allow comment rating, it's hard to say how one would go about this process.
Respuesta aceptada
Matt Fig
el 8 de Feb. de 2011
S = urlread('http://www.mathworks.com/matlabcentral/answers/contributors/2710900'); % 2710900 is your user number.
I = findstr(S,'<div class="value">');
regexp(S(I+19:I+22),'\d+','match')
For the name:
I = findstr(S,'<h1 class="fn">');
regexp(S(I:I+40),'(?<=\">)\w+','match')
So you need to get the user numbers and loop through. The only issue is the user numbers don't appear to be consecutive. This would mean try catch on numbers 1 through ??.
EDIT
I used this code, letting it run for about 8 minutes and got only 3 users,
JoshIsCool - number 1, Patrick - number 2, Rhonda - number 385
all have reputation 0. The code was on number 589 when I ctrl+c it. So this method would be an overnight run the first night. Then using the stored numbers would make it easier!
cnt = 1;
for ii = 1:3000000
try
S = urlread(['http://www.mathworks.com/matlabcentral/answers',...
'/contributors/',sprintf('%i',ii)]);
catch
continue
end
I = findstr(S,'<h1 class="fn">');
N = regexp(S(I:I+40),'(?<=\">)\w+','match') % dump to command...
if ~isempty(N)
NM{cnt} = N; % Growing is nothing compared to urlread!
I = findstr(S,'<div class="value">');
R = regexp(S(I+19:I+22),'\d+','match');
N{cnt} = ii; % For making this easier next time!
REP{cnt} = R;
cnt = cnt + 1;
end
end
EDIT2
O.k., so here is what I ended up doing. I went to google and did this search:
"inurl:matlabcentral answers contributors" site:mathworks.com
with 100 results per page, there were only four pages. So I then saved them to disk. From there I ran the below code:
Uold = 'gggggg';
cnt = 1;
for ii = 1:4
% This is the saved file.
s = urlread(['file:///', 'C:\Users\matt fig\Documents\search',sprintf('%i',ii),'.htm']);
% Read the links to the pages.
I = findstr(s,'www.mathworks.com/matlabcentral/answers/contributors/');
for jj = 1:length(I)
% Find the specific jjth page.
U = regexp(s(I(jj):I(jj)+90),'www.+?(?=["|+])','match');
if strcmp(U,Uold)
continue
end
s2 = urlread(['http://',U{1}]);
I2 = findstr(s2,'<h1 class="fn">'); % Looking for the name.
N = regexp(s2(I2:I2+40),'(?<=\">)\w+\s*\w*','match'); % The name
if ~isempty(N)
disp(N) % Display name.
NM{cnt} = N{1}; % Store the name
I2 = findstr(s2,'<div class="value">'); % looking for reput.
R = regexp(s2(I2+19:I2+22),'\d+','match');
REP{cnt} = R{1}; % Store the reputation
cnt = cnt + 1;
end
Uold = U;
end
end
[NM,JJ] = unique(NM);
REP = REP(JJ);
REP = cellfun(@str2double,REP);
[REP,G] = sort(REP,'descend');
NM = NM(G);
fid = fopen('answersnames.txt','w+');
for ii = 1:length(NM)
fprintf(fid,'%s %i\n',NM{ii},REP(ii));
end
fclose(fid)
This printed all to a nice text file in about 5 minutes. Now if anyone knows how to manipulate google programatically, this would work on autopilot.
11 comentarios
Walter Roberson
el 8 de Feb. de 2011
sprintf('http://www.google.com/search?q=site:http://www.mathworks.com/matlabcentral/answers/contributors/&num=100&start=%d',ii)
where ii is 100, 200, 300, etc.
I don't know if this would show the 100th on both the first page (bottom) and the second page (top), but there are only about 6 pages worth to pull out.
Más respuestas (3)
Greg Bacon
el 24 de Feb. de 2011
A new Contributor page was added to MATLAB Answers today. The Contributor page lists user reputation and is sortable along a few different axis.
You can get to the new page by clicking on the new Contributor link in the left nav. The url is http://www.mathworks.com/matlabcentral/answers/contributors
0 comentarios
Kenneth Eaton
el 9 de Feb. de 2011
Here's yet another variation that uses Walter's idea of going through the pages of questions, fetching the question links, then fetching user Reputation data from each question page. It's fully automated and takes about 3 minutes to run on my machine.
NOTE: This code will only find users who have posted at least one question, answer, or comment. Users who have an Answers account but haven't posted anything (like this guy or this guy) will not show up in the ranking list, but they should have 0 Rep anyway so it doesn't really matter. ;)
function [userData,nQuestions] = answers_rankings
% Initializations:
userData = cell(0,2);
nQuestions = 0;
pagesLeft = true;
iPage = 1;
% Loop over question pages:
while pagesLeft
nextPage = ['http://www.mathworks.com/matlabcentral/answers/' ...
'?dir=asc&sort=asked&page=' int2str(iPage)];
[pageText,pageFound] = urlread(nextPage);
questionLinks = regexp(pageText,['href="(/matlabcentral/answers/' ...
'\d+[^"]+)"'],'tokens');
if pageFound && ~isempty(questionLinks)
questionLinks = strcat('http://www.mathworks.com',...
vertcat(questionLinks{:}));
for iQuestion = 1:numel(questionLinks)
[pageText,pageFound] = urlread(questionLinks{iQuestion});
if pageFound
nQuestions = nQuestions+1;
data = regexp(pageText,'title="Reputation: (\d+)">([^<]+)<',...
'tokens');
userData = [userData; vertcat(data{:})]; %#ok<AGROW>
end
end
iPage = iPage+1;
else
pagesLeft = false;
end
end
updateTime = now;
% Format the user data:
userReps = cellfun(@str2double,userData(:,1)); % Convert Rep to integer
[userNames,~,index] = unique(userData(:,2)); % Find unique user names
userReps = accumarray(index,userReps,[],@max); % Take the max Rep found
[userReps,sortIndex] = sort(userReps,'descend'); % Sort by Rep
userNames = userNames(sortIndex);
userData = [userNames num2cell(userReps)].';
% Display the results:
maxLength = max([9; cellfun('prodofsize',userNames)]);
fprintf('\nMATLAB Answers user rankings as of %s:\n\n',...
datestr(updateTime));
fprintf('%*s: %s\n',maxLength,'User name','Reputation');
fprintf('%s\n',repmat('-',1,maxLength+13));
fprintf(['%' int2str(maxLength) 's: %4d\n'],userData{:});
end
0 comentarios
Ver también
Categorías
Más información sobre Historical Contests en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!