-
Notifications
You must be signed in to change notification settings - Fork 2
/
m3_sort_doulists_separate.m
66 lines (53 loc) · 1.87 KB
/
m3_sort_doulists_separate.m
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
% 2017-1-10 16:25:54
clear;
fprintf('Sort books for each doulist......\n\n');
% create a folder the save the sorted results
dirname='Doulists_sort';
if ~exist(dirname,'dir')
mkdir(dirname);
end
% record the number of books in each Doulist
fileID_info=fopen('Doulists_info','w');
fprintf(fileID_info,sprintf('%s\n\n',datestr(datetime,'yyyy-mm-dd HH:MM:SS')));
load Doulists_name.mat;
nDoulist=length(sDoulist);
fprintf(fileID_info,sprintf('The number of Doulists: %d\n\n',nDoulist));
fprintf(fileID_info,'doulist ID, number of books, doulist name\n');
tic;
for iDoulist=1:nDoulist
% import books from each Doulists
cDoulist=sDoulist(iDoulist,1);
load(sprintf('Doulists_mat/%s.mat',cDoulist));
load(sprintf('Doulists_info_mat/%s.mat',cDoulist));
% remove duplicates
[ID,ix,~]=unique(ID);
rating=rating(ix);
votes=votes(ix);
title=title(ix);
nBook=length(ID);
fprintf(fileID_info,sprintf('%08d, %04d, %s\n',doulist_ID,number_of_books,doulist_title));
% score
delta=2.5;
score=(rating-delta).*log(votes);
score(isinf(score))=0;
% sort by score
[~,ix]=sort(score,'descend');
ID=ID(ix);
rating=rating(ix);
votes=votes(ix);
title=title(ix);
% export sorted books for each Doulist
exportfilename=sprintf('%s/%s',dirname,cDoulist);
fileID=fopen(exportfilename,'w');
fprintf(fileID,sprintf('%s\n\n',datestr(datetime,'yyyy-mm-dd HH:MM:SS')));
fprintf(fileID,'doulist ID, number of books, doulist name\n');
fprintf(fileID,sprintf('%08d, %04d, %s\n\n',doulist_ID,number_of_books,doulist_title));
fprintf(fileID,'ID, rating, votes, title\n');
for iBook=1:nBook
fprintf(fileID,'%08d, %0.1f, %d, %s\n', ID(iBook), rating(iBook), votes(iBook), title{iBook,1});
end
fclose(fileID);
perct(toc,iDoulist,nDoulist,30);
end
fclose(fileID_info);
fprintf('\n');