% Template for theses recommended at Czech Technical University, Faculty of Information Technology
% inspired by lipics-v2019 documentclass
% Questions and help: <ondrej.guth@fit.cvut.cz>
% 2021: work in progress

\documentclass[a4paper,czech,unicode,twoside]{book}[2019/12/20]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FILL IN THIS INFORMATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\thesistitle}{Trackman}
\newcommand{\thesistype}{Bakalářská práce}
\newcommand{\thesisauthor}{Dominik Kadera}
\newcommand{\supervisor}{Ing. Michal Valenta, Ph.D.}
\newcommand{\department}{Katedra softwarového inženýrství}
\newcommand{\yearofdefence}{2021}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END FILL IN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TEMPLATE SETTINGS
% no need to modify anything within this section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{\thesistitle}
\author{\thesisauthor}
\RequirePackage{babel}[2020/07/13] %localization
\RequirePackage{iftex}[2020/03/06]
\iftutex
    \RequirePackage{ellipsis}[2020/05/22] %ellipsis workaround for XeLaTeX
\else
    \RequirePackage[utf8]{inputenc}[2018/08/11] %this file encoding
    \RequirePackage{lmodern}[2009/10/30]
\fi
\RequirePackage[bottom=4cm,footskip=4em]{geometry}[2020/01/02] %page layout
\RequirePackage{setspace}[2011/12/19] %line spacing in title page
\RequirePackage{listings}[2020/03/24]
\RequirePackage{xcolor}[2016/05/11]
\RequirePackage{multicol}[2019/12/09]
\RequirePackage{titlesec}[2019/10/16]
\RequirePackage{mathtools}[2020/03/24]
\RequirePackage{amssymb}[2013/01/14]
\RequirePackage[pdfpagelayout=TwoPageRight]{hyperref}[2020-05-15] % optional package
\RequirePackage{pdfpages}[2020/01/28]
\RequirePackage{fancyhdr}[2019/01/31]
\RequirePackage[labelsep=space,singlelinecheck=false,font={up,small},labelfont={sf,bf}]{caption}[2020/05/30]
\RequirePackage{amsthm}[2020/05/29]
\RequirePackage{emptypage}[2010/05/30]
\RequirePackage{polyglossia}[2021/03/16]
\setdefaultlanguage{czech}
\RequirePackage[style=iso-numeric,sorting=nty]{biblatex}[2021/04/01]

%%% modra
 \definecolor{decoration}{RGB}{0, 122, 195} %CTU blue
 \definecolor{heading}{RGB}{0, 122, 195}
 \definecolor{headbackgroundgray}{RGB}{199, 219, 241} %light blue
 \definecolor{backgroundgray}{RGB}{199, 219, 241} %CTU light blue
 \definecolor{headgray}{rgb}{0.50,0.50,0.51}
 \definecolor{enumgray}{RGB}{0, 122, 195} %CTU blue

\addbibresource{bib-database.bib}

\graphicspath{ {images/} }

\setcounter{secnumdepth}{4}% numbering sections; 4: subsubsection

% code listing settings
\usepackage{minted}
\renewcommand{\listingscaption}{Výpis kódu}
\renewcommand{\listoflistingscaption}{Seznam výpisů kódu}
\renewcommand\lstlistingname{Výpis kódu}
\renewcommand\lstlistlistingname{Seznam výpisů kódu}
\lstset{basicstyle=\small\ttfamily,keywordstyle=\bfseries,%
         backgroundcolor=\color{backgroundgray},%
         frame=single,framerule=0pt,xleftmargin=\fboxsep,xrightmargin=\fboxsep}
% code listing setting end

% captions settings
\makeatletter
\@ifpackagelater{hyperref}{2009/12/09}
  {\captionsetup{compatibility=false}}%cf. http://groups.google.de/group/comp.text.tex/browse_thread/thread/db9310eb540fbbd8/42e30f3b7b3aa17a?lnk=raot
  {}
\makeatother
\DeclareCaptionLabelFormat{boxed}{%0.61,0.61,0.61
  \kern0.05em{\color{decoration}\rule{0.73em}{0.73em}}%
  \hspace*{0.67em}\bothIfFirst{#1}{~}#2}
\captionsetup{labelformat=boxed}
\captionsetup[table]{position=top}
% captions settings end

% lists settings
\setlength\leftmargini  \parindent
\setlength\leftmarginii {1.2em}
\setlength\leftmarginiii{1.2em}
\setlength\leftmarginiv {1.2em}
\setlength\leftmarginv  {1.2em}
\setlength\leftmarginvi {1.2em}
\renewcommand\labelenumi{%
  \textcolor{enumgray}{\headfont\bfseries\upshape\mathversion{bold}\theenumi.}}
\renewcommand\labelenumii{%
  \textcolor{enumgray}{\headfont\bfseries\upshape\mathversion{bold}\theenumii.}}
\renewcommand\labelenumiii{%
  \textcolor{enumgray}{\headfont\bfseries\upshape\mathversion{bold}\theenumiii.}}
\renewcommand\labelenumiv{%
  \textcolor{enumgray}{\headfont\bfseries\upshape\mathversion{bold}\theenumiv.}}
\makeatletter
\renewcommand\labelitemi{%
  \textcolor{enumgray}{\ifnum\@listdepth=\@ne
                                  \rule{0.67em}{0.33em}%
                                \else
                                  \rule{0.45em}{0.225em}%
                                \fi}}
\makeatother
\renewcommand\labelitemii{%
  \textcolor{enumgray}{\rule{0.45em}{0.225em}}}
\renewcommand\labelitemiii{%
  \textcolor{enumgray}{\headfont\bfseries\textasteriskcentered}}
\renewcommand\labelitemiv{%
  \textcolor{enumgray}{\headfont\bfseries\textperiodcentered}}
\renewcommand*\descriptionlabel[1]{%
  \hspace\labelsep\textcolor{enumgray}{\headfont\bfseries\mathversion{bold}#1}}
% lists settings end

\def\headfont{\rmfamily} %font for headings (chapter, section, etc.)

% frontmatter headings
\def\frontchapterfont{\Large \bfseries}
\def\frontsectionfont{\large\bfseries}
\def\frontsubsectionfont{\large}
\def\frontsubsubsectionfont{\bfseries}
% frontmatter headings end

% frontmatter pseudochapters: named part without printing actual chapter heading
\makeatletter
\newcommand{\frontchapternotprinted}[1]{%
  \begingroup
  \let\@makechapterhead\@gobble % make \@makechapterhead do nothing
  \let\cleardoublepage\clearpage
  \chapter{#1}
  \endgroup
}
\makeatother
% frontmatter pseudochapters end

% theorems, proofs, definitions, etc. end
\makeatletter
\thm@headfont{%
  \textcolor{decoration}{$\blacktriangleright$}\nobreakspace\headfont\bfseries}
\def\th@remark{%
  \thm@headfont{%
    \textcolor{decoration}{$\blacktriangleright$}\nobreakspace\headfont}%
  \normalfont % body font
  \thm@preskip\topsep \divide\thm@preskip\tw@
  \thm@postskip\thm@preskip
}
\def\@endtheorem{\endtrivlist}%\@endpefalse
\renewcommand\qedsymbol{\textcolor{decoration}{\ensuremath{\blacktriangleleft}}}
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
        \color{black}\headfont\bfseries
    #1\@addpunct{.}]\ignorespaces
}{%
  \popQED\endtrivlist%\@endpefalse
}
\makeatother
\theoremstyle{plain}
\newtheorem{theorem}{Věta}
\newtheorem{lemma}[theorem]{Pomocné tvrzení}
\newtheorem{corollary}[theorem]{Důsledek}
\newtheorem{proposition}[theorem]{Návrh}
\newtheorem{definition}[theorem]{Definice}
\theoremstyle{definition}
\newtheorem{example}[theorem]{Příklad}
\theoremstyle{remark}
\newtheorem{note}[theorem]{Poznámka}
\newtheorem*{note*}{Poznámka}
\newtheorem{remark}[theorem]{Pozorování}
\newtheorem*{remark*}{Pozorování}
\numberwithin{theorem}{chapter}
% theorems, proofs, definitions, etc. end

% table of contents colored chapters
\makeatletter
\let\stdl@chapter\l@chapter
\renewcommand*{\l@chapter}[2]{%
  \stdl@chapter{\textcolor{heading}{#1}}{\textcolor{heading}{#2}}}
\makeatother
% table of contents colored chapters end

% headers and footers
\makeatletter
\def\ps@plain{%chapter beginning
    \let\@evenhead\@empty%
    \let\@oddhead\@empty%
    \def\@evenfoot{\bfseries\color{headgray}\hfill\thepage\hfill}%
    \def\@oddfoot{\bfseries\color{headgray}\hfill\thepage\hfill}}
\makeatother
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE]{\leavevmode\smash{\llap{\color{headgray} \bfseries \thepage \hspace*{4em}}}}
\fancyhead[RE]{\color{headgray}\bfseries\nouppercase{\leftmark}}
\fancyhead[RO]{\leavevmode\smash{\rlap{\hspace*{4em}\color{headgray}\bfseries\thepage}}}
\fancyhead[LO]{\color{headgray}\bfseries\nouppercase{\rightmark}}
\renewcommand{\headrulewidth}{0pt}
% headers and footers end

% title page
\renewcommand{\maketitle}{\begin{titlepage}%
\newgeometry{left=67mm,top=80mm,right=40mm}%\thispagestyle{empty}%
\noindent{\large\headfont\noindent\thesistype}
\vskip 3mm
\noindent{\noindent\huge\headfont\bfseries\color{black}\begin{flushleft}\begin{onehalfspace}\MakeUppercase{\thesistitle}\end{onehalfspace}\end{flushleft}}
\vskip 35mm
\noindent{\large \headfont \bfseries \thesisauthor}

\vfill

\noindent{\headfont Fakulta informačních technologií ČVUT v Praze\\
\department\\
Vedoucí: \supervisor\\
\today}\end{titlepage}
\restoregeometry
}
%title page end

\newenvironment{abstrakt}{%
  \vspace*{18mm}
  \noindent
  {{\frontchapterfont\begin{flushleft}{\color{heading}Abstrakt}\end{flushleft}}}%
  \bigskip
  \noindent\ignorespaces}

\newenvironment{abstract}{%
  \vskip\bigskipamount
  \noindent
  {{\frontchapterfont\begin{flushleft}{\color{heading}Abstract}\end{flushleft}}}%
  \bigskip
  \noindent\ignorespaces}
  
\newenvironment{prohlaseni}{
  {{\frontchapterfont\begin{flushright}{\color{heading}Prohlášení}\end{flushright}}}%
  \bigskip
  \noindent\ignorespaces}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TEMPLATE SETTINGS END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%
% DEMO CONTENTS SETTINGS
% You may choose to modify this part.
%%%%%%%%%%%%%%%%%%%%%%
\usepackage{dirtree}
\usepackage{lipsum,tikz}
\usepackage{lscape}
%%%%%%%%%%%%%%%%%%%%%%
% DEMO CONTENTS SETTINGS END
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\frontmatter
%%%%%%%%%%%%%%
% FRONTMATTER SETTINGS
% no need to modify this part
%%%%%%%%%%%%%%
\titleformat
{\chapter} % command
% [display] % shape
{} % format
{} % label
{} % sep
{\color{heading}\frontchapterfont \raggedleft} % before-code
[\vskip -2em] % after-code

\titleformat
{\section}
{\frontsectionfont\color{heading}}
{}
{}
{}
  
% \titleformat{\subsection}
%   {\frontsubsectionfont\color{heading}}{{{\color{black}\thesubsection}}}{1em}{}[\vskip -1em]
  
% \titleformat{\subsubsection}
%   {\frontsubsubsectionfont\color{heading}}{{{\color{black}\thesubsubsection}}}{1em}{}[\vskip -1em]

\makeatletter
\@openrightfalse
\makeatother
%%%%%%%%%%%%%%
% FRONTMATTER SETTINGS END
%%%%%%%%%%%%%%


\includepdf{assignment-include.pdf}

\thispagestyle{empty}
\cleardoublepage

\maketitle
% \clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREPRINT
% no need to modify
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	\clearpage
	\thispagestyle{empty}
	

		~
	\vfill
	
	{\small
			\noindent České vysoké učení technické v Praze \\
		\noindent Fakulta informačních technologií \\
	\noindent \textcopyright{} \yearofdefence{} \thesisauthor. Všechna práva vyhrazena.\\
		\noindent \textit{Tato práce vznikla jako školní dílo na Českém vysokém učení technickém v Praze, Fakultě informačních technologií. Práce je chráněna právními předpisy a mezinárodními úmluvami o právu autorském a právech souvisejících s právem autorským. K jejímu užití, s výjimkou bez uplatněných zákonných licencí nad rámec oprávnění uvedených v Prohlášení, je nezbytný souhlas autora.}
	
	\vspace{1em}
	
	\noindent Odkaz na tuto práci: \thesisauthor. \textit{\thesistitle}. \thesistype. České vysoké učení technické v Praze, Fakulta informačních technologií, \yearofdefence.
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREPRINT END
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\tableofcontents
\listoffigures
\begingroup
\let\clearpage\relax
\listoftables
\listoflistings
\endgroup

%%%%%%%%%%%%%%%%%%%
% ACKNOWLEDGMENT
% FILL IN / MODIFY
%%%%%%%%%%%%%%%%%%%
\frontchapternotprinted{Poděkování}
~
\vfill
\hskip 0cm \begin{minipage}{0.7\textwidth}
\textit{
	V prvé řadě bych chtěl poděkovat panu doktoru Michalu Valentovi za to, že se ujal vedení mé bakalářské práce, byl mi nápomocen ve věcech technických i formálních a příjemně se mi pod jeho vedením pracovalo.
	Také bych chtěl poděkovat CTO Integromatu, panu Patriku Šimkovi, za možnost použít Trackmana jako bakalářkou práci a za nespočet konzultací, inspirativních rozhovorů a rad, které mi dával v průběhu vývoje.
	Děkuji také všem kolegům z Integromatu za nesmírně přátelské prostředí, které ve firmě tvoří, neb i díky nim jsem si tvorbu Trackmana, stejně jako dalších projektů v Integromatu, velice užil.
	Závěrem děkuji celé mé rodině za jejich nehynoucí podporu v průběhu celého studia a za jejich soudržnost a náklonnost i v těžkých obdobích.
}
\end{minipage}

\vfill

\vfill
%%%%%%%%%%%%%%%%%%%
% ACKNOWLEDGMENT END
%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%
% ACKNOWLEDGMENT
% FILL IN / MODIFY
%%%%%%%%%%%%%%%%%%%
\frontchapternotprinted{Prohlášení}
~
\vfill
% INSTRUCTIONS
% ENG: choose one of approved texts of the declaration. DO NOT CREATE YOUR OWN. Find the approved texts at https://courses.fit.cvut.cz/SFE/download/index.html#_documents (document Declaration for FT in English)
% CZE/SLO: Vyberte jedno z fakultou schvalenych prohlaseni. NEVKLADEJTE VLASTNI TEXT. Schvalena prohlaseni najdete zde: https://courses.fit.cvut.cz/SZZ/dokumenty/index.html#_dokumenty (prohlášení do ZP)
\begin{prohlaseni}
Prohla\v suji, \v ze jsem p\v redlo\v zenou pr\'aci vypracoval samostatn\v e a \v ze jsem uvedl ve\v sker\'e
pou\v zit\'e informa\v cn\'\i{} zdroje v~souladu s~Metodick\'ym pokynem o~do\-dr\v zo\-v\'an\'\i{} etick\'ych
principů p\v ri p\v r\'\i{}prav\v e vysoko\v skolsk\'ych z\'av\v ere\v cn\'ych prac\'\i{}.

Beru na v\v edom\'\i{}, \v ze se na moji pr\'aci vztahuj\'\i{} pr\'ava a povinnosti vy\-pl\'y\-va\-j\'\i{}c\'\i{} ze z\'akona
\v c.\,121/2000~Sb., autorsk\'eho z\'akona, ve zn\v en\'\i{} pozd\v ej\-\v s\'\i{}ch p\v red\-pisů. D\'ale prohla\v suji, \v ze
jsem s~\v Cesk\'ym vysok\'ym u\v cen\'\i{}m tech\-nic\-k\'ym v~Praze uzav\v rel dohodu, na jej\'\i{}m\v z 
z\'aklad\v e se \v CVUT vzdalo pr\'ava na uzav\-\v ren\'\i{} licen\-\v cn\'\i{} smlouvy o~u\v zit\'\i{} t\'eto pr\'ace jako
\v skoln\'\i{}ho d\'\i{}la podle \S{}\,60 odst.\,1 autorsk\'eho z\'akona. Tato skute\v cnost nem\'a vliv na ustanoven\'\i{} \S{}\,47b z\'a\-kona \v c.\,111/1998~Sb., o~vysok\'ych \v skol\'ach, ve zn\v en\'\i{} pozd\v ej\v s\'\i{}ch p\v redpisů.

\vskip 1cm
\noindent
V Praze dne 11.\;května 2021 \hspace{.3\textwidth} \dotfill
\end{prohlaseni}
%%%%%%%%%%%%%%%%%%%
% DECLARATION END
%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%
% ABSTRACT
% FILL IN / MODIFY
%%%%%%%%%%%%%%%%%%%
\frontchapternotprinted{Abstrakt}
\begin{abstrakt}

Tato práce se zabývá návrhem a realizací služby Trackman, která je klíčovou komponentou v rámci interního monitoringu platformy Integromat a následné distribuce nashromážděných dat k další analýze.

Cílem bylo za prvé navrhnout architekturu celé aplikace, což zahrnovalo především databázový model a architekturu aplikační vrstvy v jazyce JavaScript, ovšem také návrh samotné komunikace se třetími stranami
a to s důrazem na využití již existujících integrací, které platforma Integromat nabízí, a za druhé pak navržené řešení implementovat.

Databázová vrstva je založena na databázovém stroji PostgreSQL a využívá přístupu uložených procedur na straně databázového serveru.
Aplikační vrstva je napsána v jazyce JavaScript a díky využití interních knihoven Integromatu nabízí vysokou abstrakci pohledu na data a široké možnosti jejich transformace.

Trackman je v době dokončování práce nasazen v produkčním prostředí platformy a průměrně zpracuje zhruba půl milionu požadavků denně.

\end{abstrakt}

\vskip 0.5cm

{\noindent\color{heading}\bfseries\headfont Klíčová slova\hspace{1em}}{Konfigurovatelná monitorovací služba, Sběr a distribuce událostí, Integromat, NodeJS, PostgreSQL}

\vskip 1cm

\begin{abstract}

This thesis covers the software design and realization of the Trackman service in the integration platform, Integromat.
Trackman is a key component of the internal monitoring system of Integromat, and also plays a major role in the further distribution of collected data on the platform.

The goal was to design the whole architecture of the service, mainly the database model and architecture of the application layer in JavaScript, as well as designing the communication between Trackman and third-party services while leveraging the existing integrations that are already offered by Integromat, and finally implementing the whole solution.

The database layer is built on top of the PostgreSQL database management system and uses the Stored Procedures pattern.
The application layer is then coded in JavaScript and thanks to the internal libraries of Integromat, it offers a high level of data abstraction and a wide range of possibilities for data transformation.

At the time of finishing this thesis, Trackman is already running in the production environment, serving roughly half a million requests a day.
	
\end{abstract}

\vskip 0.5cm

{\noindent\color{heading}\bfseries\headfont Keywords\hspace{1em}}{Configurable monitoring service, Collection and distribution of events, Integromat, NodeJS, PostgreSQL}
%%%%%%%%%%%%%%%%%%%
% ABSTRACT END
%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%
% SUMMARY
% FILL IN / MODIFY
% OR REMOVE ENTIRELY (upon agreement with your supervisor)
% (apropriate to remove in most theses)
%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
% SUMMARY END
%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%
% ABBREVIATIONS
% FILL IN / MODIFY
% OR REMOVE ENTIRELY
%%%%%%%%%%%%%%%%%%%
\include{abbr}

\include{terms}
%%%%%%%%%%%%%%%%%%%
% ABBREVIATIONS END
%%%%%%%%%%%%%%%%%%%

\mainmatter

%%%%%%%%%%%%%%%%%%%%
% MAINMATTER SETTINGS
% no need to modify this part
%%%%%%%%%%%%%%%%%%%%
\makeatletter
\@openrighttrue
\makeatother

\titleformat
{\chapter} % command
[display] % shape
{\headfont \LARGE \bfseries \raggedleft} % format
{ \textcolor{headbackgroundgray}{{\titlerule*[1pc]{\rule{0.25em}{0.25em}}}} \hspace{0.5ex} \color{black} Kapitola \thechapter } % label
{-0.3cm} % sep
{\color{heading} \Huge \vskip 0.5cm} % before-code
[\vskip 1cm] % after-code

%vzhled nadpisů sekcí
\titleformat{\section}
  {\headfont\Large\bfseries\color{heading}}{\colorbox{headbackgroundgray}{{\color{black}\thesection}}}{1em}{}%[\vskip -1em]
  
\titleformat{\subsection}
  {\headfont\Large\bfseries\color{heading}}{{{\color{black}\thesubsection}}}{1em}{}%[\vskip -1em]
  
\titleformat{\subsubsection}
  {\headfont\large\bfseries\color{heading}}{{{\color{black}\thesubsubsection}}}{1em}{}%[\vskip -1em]

%%%%%%%%%%%%%%%%%%%%
% MAINMATTER SETTINGS END
%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%
% THE THESIS
% MODIFY ANYTHING BELOW THIS LINE
%%%%%%%%%%%%%%%%%%%
\include{text}

\appendix

%%%%%%%%%%%%%%%%%%%%
% APPENDIX SETTINGS
% no need to modify this part
%%%%%%%%%%%%%%%%%%%%
\titleformat
{\chapter} % command
[display] % shape
{\headfont \LARGE \bfseries \raggedleft} % format
{ \textcolor{headbackgroundgray}{{\titlerule*[1pc]{\rule{0.25em}{0.25em}}}} \hspace{0.5ex} \color{black} Příloha \thechapter } % label
{-0.3cm} % sep
{\color{heading} \Huge \vskip 0.5cm} % before-code
[\vskip 1cm] % after-code

%%%%%%%%%%%%%%%%%%%%
% MAINMATTER SETTINGS END
%%%%%%%%%%%%%%%%%%%%

\include{appendix}

\backmatter

{
	\setlength{\emergencystretch}{0.8em} 
	\printbibliography
}

\include{medium}


\end{document}
