clc, clear, close all;

windowsize = 2;

times = 2006.5:1/12:(2025 + 1/3);
rating = zeros(1,size(times,2));
rating(1:37) = 0;
rating(38:43) = 0:1/5:1;
rating(44:55) = 1;
rating(56:59) = -1;
rating(60:78) = 1;
rating(79:81) = 0.75;
rating(82:87) = 1.5;
rating(88:91) = -1;
rating(92:95) = 1;
rating(95:100) = 1.5;
rating(101:134) = 2;
rating(135:140) = 2.5;
rating(141:144) = 2;
rating(145:151) = -1.5;
rating(152:165) = -1:4/13:3;
rating(166:175) = 2.5:-2.5/9:0;
rating(176:178) = -1.5;
rating(179:183) = -2;
rating(184:190) = -2.5:-1/6:-3.5;
rating(191:196) = -3.5:1/5:-2.5;
rating(197:199) = -1;
rating(200:209) = -0.5;
rating(210:212) = 1;
rating(213) = 1.5;
rating(214) = 1.75;
rating(215:216) = 2;
rating(217:219) = -3;
rating(220) = -1;
rating(221) = 0;
rating(222) = 1;
rating(223) = 1.5;
rating(224) = 2;
rating(225) = 2;
rating(226) = 3;
rating(227) = 4;

z = zeros(size(times));

rating = rating + (rand(1,227) * 0.2 - 0.1);

rating = movmean(rating, windowsize);

col = rating;

f = figure(1);
hold on;

surface([times;times],[rating;rating],[z;z],[col;col],...
        'facecol','no',...
        'edgecol','interp',...
        'linew',3);

xshift = 0.05;
yshift = -0.05;
rot=-45;
fize = 8;

text(times(1)+xshift, rating(1)+yshift, '\leftarrow 07/06', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(37)+xshift, rating(37)+yshift, '\leftarrow 07/09', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(55)+xshift, rating(55)+yshift, '\leftarrow 01/11', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(59)+xshift, rating(59)+yshift, '\leftarrow 05/11', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(81)+xshift, rating(81)+yshift, '\leftarrow 03/13', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(87)+xshift, rating(87)+yshift, '\leftarrow 09/13', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(91)+xshift, rating(91)+yshift, '\leftarrow 01/14', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(134)+xshift, rating(134)+yshift, '\leftarrow 08/17', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(140)+xshift, rating(140)+yshift, '\leftarrow 02/18', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(144)+xshift, rating(144)+yshift, '\leftarrow 06/18', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(151)+xshift, rating(151)+yshift, '\leftarrow 01/19', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(156)+xshift, rating(156)+yshift, '\leftarrow 06/19', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(165)+xshift, rating(165)+yshift, '\leftarrow 03/20', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(174)+xshift, rating(174)+yshift, '\leftarrow 12/20', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(178)+xshift, rating(178)+yshift, '\leftarrow 04/21', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(183)+xshift, rating(183)+yshift, '\leftarrow 09/21', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(190)+xshift, rating(190)+yshift, '\leftarrow 04/22', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(196)+xshift, rating(196)+yshift, '\leftarrow 10/22', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(199)+xshift, rating(199)+yshift, '\leftarrow 01/23', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(209)+xshift, rating(209)+yshift, '\leftarrow 11/23', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(212)+xshift, rating(212)+yshift, '\leftarrow 02/24', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(216)+xshift, rating(216)+yshift, '\leftarrow 06/24', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(219)+xshift, rating(219)+yshift, '\leftarrow 09/24', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(222)+xshift, rating(222)+yshift, '\leftarrow 01/25', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')
text(times(227)+xshift, rating(227)+yshift, '\leftarrow 05/25', 'Rotation', rot, 'FontSize', fize, 'FontWeight','bold')

xticks(2006:2026)
xlabel('Time')
ylabel('Arbitrary Rating')
grid on;

axis([2006 2026 -5 5])
hold off
exportgraphics(f,'fep1.png',Resolution=300,Units="pixels", ...
     Width=3860,Height=2160, Padding = 10)


integral = trapz(times, rating);

disp(integral)

disp(integral/((2025+1/3)-2006.5))
