-
Notifications
You must be signed in to change notification settings - Fork 9
/
CSPplotParticipationStatistics.m
86 lines (74 loc) · 3.09 KB
/
CSPplotParticipationStatistics.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function CSPplotParticipationStatistics(site,startdate,enddate)
%Find path of DB file
CSPloadPaths
dbfile = fullfile([DB_path filesep 'CoastSnapDB.xlsx']);
[data,txt] = xlsread(dbfile,'database');
siteDB = CSPreadSiteDB(site); %Read metadata
%Read image times - make sure Excel format is as below
if isempty(strfind(txt{2,3},'PM'))||isempty(strfind(txt{2,3},'AM')) %if using AM/PM
imtimes = datenum(char(txt{2:end,3}),'dd/mm/yyyy HH:MM:SS AM');
else
imtimes = datenum(char(txt{2:end,3}),'dd/mm/yyyy HH:MM:SS'); %if using 24 hour clock
end
%Convert to GMT time
imtimesGMT = imtimes;
Idefault= find(strcmp(txt(2:end,4),siteDB.timezone.name)); %e.g. AEDT = Australian Eastern Daylight Time
imtimesGMT(Idefault) = imtimesGMT(Idefault)-siteDB.timezone.gmt_offset/24; %Subtract the offset in hours to convert to gmt time
Ialternative = find(strcmp(txt(2:end,4),siteDB.timezone.alternative.name)); %e.g. AEDT = Australian Eastern Daylight Time
imtimesGMT(Ialternative) = imtimesGMT(Ialternative)-siteDB.timezone.alternative.gmt_offset/24; %Subtract the offset in hours to convert to default
imtimesLocal = imtimesGMT+siteDB.timezone.gmt_offset/24;
dd = startdate:enddate;
for i = 1:length(dd)
J = find(floor(imtimesLocal)==dd(i)&strcmp(txt(2:end,1),site));
N(i) = length(J);
end
cN = cumsum(N);
%cN(cN==0) = NaN;
%cN(1) = 0;
%Get submission types
subtypes = {'Email','Facebook','Twitter','Instagram'};
subtypes_count = NaN(length(subtypes),1);
for i = 1:length(subtypes)
J = find(strcmp(txt(2:end,6),subtypes{i})&strcmp(txt(2:end,1),site));
subtypes_count(i) = length(J);
end
width = 30;
height = 9;
piesize = 8;
geomplot(1,1,1,1,width,height,[1.4 piesize],[0.4 1.2],[0 0])
plot(dd,cN,'b','linewidth',1)
hold on
datetick('x')
set(gca,'fontsize',10)
xlabel('Month','fontsize',12)
ylabel('Cumulative images','fontsize',12)
set(gca,'ygrid','on')
set(gcf,'color','w')
xlim([startdate enddate])
%title(['Cumulative number of images:' datestr(startdate,'dd/mm/yyyy') ' - ' datestr(enddate,'dd/mm/yyyy')],'Fontsize',10)
%print 'Cumulative_Posts.jpg' -r600 -djpeg
XL = xlim;
YL = ylim;
text_title1 = ['Cumulative number of images:'];
text_title2 = [datestr(startdate,'dd/mm/yyyy') ' - ' datestr(enddate,'dd/mm/yyyy')];
text(XL(1)+0.1*diff(XL),YL(1)+0.8*diff(YL),text_title1,'fontsize',14,'fontweight','bold')
text(XL(1)+0.1*diff(XL),YL(1)+0.71*diff(YL),text_title2,'fontsize',14,'fontweight','bold')
geomplot(1,1,1,1,width,height,[width-piesize 0],[0.4 1],[0 0])
h1=pie(subtypes_count);
h1(2).FontSize = 10;
h1(4).FontSize = 10;
h1(6).FontSize = 10;
if length(h1)>=8
h1(8).FontSize = 10;
end
h = legend(subtypes,'Location','southoutside')%,'Orientation','horizontal');
h.FontSize = 10;
title(h,'Submission type');
%title('Image submission type')
%Get most popular time of day
J = find(strcmp(txt(2:end,1),site));
M = datevec(imtimesLocal(J));
disp(['Most popular day of week is ' num2str(mode(weekday(imtimesLocal(J))))])
disp(['Most popular time of day is ' num2str(mode(M(:,4)))])
disp(['Total number of submissions is ' num2str(cN(end))])
disp(['Average number of submissions per week is ' num2str(7*cN(end)/((1+(enddate-startdate))),'%0.1f')])