PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/doc/doc.tex

https://gitlab.com/z80lives/btvis
LaTeX | 324 lines | 266 code | 56 blank | 2 comment | 0 complexity | 72138f36cafdf204903865655ae232bc MD5 | raw file
  1. % Created 2016-10-03 Mon 16:12
  2. \documentclass[11pt]{article}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage[T1]{fontenc}
  5. \usepackage{fixltx2e}
  6. \usepackage{graphicx}
  7. \usepackage{longtable}
  8. \usepackage{float}
  9. \usepackage{wrapfig}
  10. \usepackage{rotating}
  11. \usepackage[normalem]{ulem}
  12. \usepackage{amsmath}
  13. \usepackage{textcomp}
  14. \usepackage{marvosym}
  15. \usepackage{wasysym}
  16. \usepackage{amssymb}
  17. \usepackage{hyperref}
  18. \tolerance=1000
  19. \usepackage{minted}
  20. \usepackage{geometry} \geometry{ a4paper, total={6.7in,8in}}
  21. \usepackage{indentfirst}
  22. \usepackage{xcolor}
  23. \author{Ibrahim Mohamed Shaatha}
  24. \date{\today}
  25. \title{Programmer's Documentation for Binary Tree Subsystem}
  26. \hypersetup{
  27. pdfkeywords={},
  28. pdfsubject={Documentation for the SBC Project's Binary Tree Subsystem.},
  29. pdfcreator={Emacs 24.4.1 (Org mode 8.2.10)}}
  30. \begin{document}
  31. \maketitle
  32. \setcounter{tocdepth}{3}
  33. \tableofcontents
  34. \section{Design notes}
  35. \label{sec-1}
  36. \begin{itemize}
  37. \item Module requires you to enable mysql specific PDO drivers (php\_\_pdo\_\_mysql.so) installed in the server. (uncomment the line from php ini). Note: This maybe already enabled in Windows based stacks such as WAMP.
  38. \item This module uses MySQL PDO to to interact with the database.
  39. \item The visualizer uses a layer called, 'Repository interface' to access the database. This repository feature can be used individually by the programmer to easily read from the database.
  40. \item Repository works using 'generic database' php interface, which can be passed to it's constructor. Any database system of your choice can be implemented using this interface. By default it uses MySQL PDO driver.
  41. \item System needs a function to update the mapping table ("personally\_\_enrolled"), occasionally.
  42. \item The system does not really enforce a binary tree structure.
  43. \end{itemize}
  44. \subsection{Information}
  45. \label{sec-1-1}
  46. \begin{itemize}
  47. \item Binary Tree nodes can contain any type of data you prefer.
  48. \item If a \emph{TreeGenerator} class is used to create a binary tree it will create a tree by reading data from the database; and the resulting tree node's data will be \emph{UserModel} objects.
  49. \end{itemize}
  50. \subsection{Conflicts}
  51. \label{sec-1-2}
  52. Repetition in binary node label in the database may cause unexpected behaviour. We need to either fix this issue, or focus on avoiding entry of invalid data.
  53. \section{How to Use}
  54. \label{sec-2}
  55. \subsection{Download and Update}
  56. \label{sec-2-1}
  57. \subsubsection{By Dropbox or e-mail.}
  58. \label{sec-2-1-1}
  59. Download and extract the files to the project directory. Give the directory a name you prefer.
  60. \subsubsection{Get the latest version from git.}
  61. \label{sec-2-1-2}
  62. If you have git installed on your computer, you can easily download and install the latest version to the project. Latest version of, Git can be downloaded from \url{https://git-scm.com/}. If you have a linux, OSX or a unix family operating system, you can get the latest version using your package manager software.
  63. Once inside the project directory, to download the script:
  64. \begin{verbatim}
  65. git clone https://gitlab.com/z80lives/btvis.git
  66. \end{verbatim}
  67. To update the script, simply execute:
  68. \begin{verbatim}
  69. git pull
  70. \end{verbatim}
  71. \subsection{Checklist}
  72. \label{sec-2-2}
  73. \begin{itemize}
  74. \item To run the examples here, make sure you have pdo\_\_mysql drivers enabled. The current version uses PDO objects, on lower level to access the database. On a linux based system, run the following command and check whether it returns an output:
  75. \end{itemize}
  76. \begin{verbatim}
  77. php -i | grep 'pdo_mysql'
  78. \end{verbatim}
  79. \begin{itemize}
  80. \item Make sure the database is setup and configured.
  81. \item Make sure data exists in the tables. Test data queries can be found in the "test" folder.
  82. \end{itemize}
  83. \subsection{Installing}
  84. \label{sec-2-3}
  85. \begin{enumerate}
  86. \item Copy the contents to the web folder.
  87. \item Insert test data to the database (Optional).
  88. \item During the final production phase, you can remove the test and doc folder, just to be safe. You can also remove .git folder.
  89. \end{enumerate}
  90. If there exists a file with the name 'config.php', add the configuration class under the \emph{BinaryTreeVisualizer} namespace of that file.
  91. \subsection{Quick setup: Displaying the Binary Tree}
  92. \label{sec-2-4}
  93. Make sure the tables have data, before using the module. Most of the objects in this package are not configured to display user any error message or a fallback item. Therefore it is possible to get an empty '<div>' container as an output if the visualizer cannot read anything from the database.
  94. This module has a quick layer, for the programmer to access and generate the code if they need require it.
  95. \subsubsection{Create a config.php file}
  96. \label{sec-2-4-1}
  97. Config file can be placed directly outside the package folder, or inside the package folder.
  98. \begin{minted}[frame=leftline,framesep=2mm,linenos]{php}
  99. <?php
  100. namespace BinaryTreeVisualizer;
  101. class Config{
  102. public static $db_config = array(
  103. 'host' => "localhost",
  104. 'pass' => "123",
  105. 'name' => 'mlm_database',
  106. 'user' => 'root'
  107. );
  108. }
  109. ?>
  110. \end{minted}
  111. \subsubsection{Display the entire tree, The most basic use.}
  112. \label{sec-2-4-2}
  113. Assume 'btviz' is the name of the module folder, the following script will generate the entire html content, which includes <head> and <body> for you.
  114. Simple example to Display the entire tree.
  115. \begin{minted}[frame=leftline,framesep=2mm,linenos]{php}
  116. <?php
  117. include "btvis/src/BTVisualizer.php";
  118. use BinaryTreeVisualizer\QuickVisualizer as QuickVis;
  119. $qvis = new QuickVis();
  120. //The root node will be 'SBC0' here, since we didn't set anything.
  121. echo $qvis->getVis()->getHTML();
  122. ?>
  123. \end{minted}
  124. In practice, we can fetch the necessary code for <script>, <head> and <div> in form of string using the visualizer object.
  125. Note, in the example:
  126. \begin{minted}[frame=leftline,framesep=2mm,linenos]{perl}
  127. $qvis = new QuickVis(); //Abstraction layer
  128. $vis = $qvis->getVis(); //The actual visualizer object.
  129. \end{minted}
  130. QuickVisualizer class is an abstraction layer, which configures a default visualizer. The actual visualizer object is retrieved using the \emph{getVis()} method. More information about \emph{VisualizerInterface} can be found in the API documentation.
  131. \subsection{Recommended Setup}
  132. \label{sec-2-5}
  133. \subsubsection{Basic API Access}
  134. \label{sec-2-5-1}
  135. \subsubsection{Using an existing PDO to connect to the database}
  136. \label{sec-2-5-2}
  137. \subsection{Tree Walking methods}
  138. \label{sec-2-6}
  139. Using the binary tree walker methods you can walk around the tree and execute your own code on specified nodes.
  140. The walker itself has 5 states:
  141. \includegraphics[width=.9\linewidth]{images/walker_states.png}
  142. For the programmer's purposes, the above diagram provides sufficient information on how the walker works.
  143. \subsection{Tree Display Functions}
  144. \label{sec-2-7}
  145. The system by default, reads from the database and maps the data to a UserModel class (src/UserModel.class.php).
  146. \subsubsection{Change the label for the node.}
  147. \label{sec-2-7-1}
  148. \subsubsection{Change the colour and shape of the node.}
  149. \label{sec-2-7-2}
  150. \subsubsection{Use HTML View Helpers to customize what is being displayed.}
  151. \label{sec-2-7-3}
  152. \subsubsection{Use Views to customize what is bieng showed when hovered.}
  153. \label{sec-2-7-4}
  154. \subsubsection{Write actions to perform when clicked}
  155. \label{sec-2-7-5}
  156. \subsubsection{Styling and using fallback contents}
  157. \label{sec-2-7-6}
  158. \subsection{The User Repository Functions}
  159. \label{sec-2-8}
  160. \subsubsection{Getting the subtree for a specific user.}
  161. \label{sec-2-8-1}
  162. \begin{minted}[frame=leftline,framesep=2mm,linenos]{php}
  163. <?php
  164. //include files
  165. //...
  166. $userId = $_SESSION['id']; //Assume that userId is stored in the session.
  167. $repository = new UserRepository();
  168. $repository->getUser('')
  169. ?>
  170. \end{minted}
  171. Note: Storing the actual userId in the session, might not be the best idea. An unexpected change in the database (removal of the record, and insertion of a new record) may result in a user of a different access level gaining access to the session.
  172. \subsection{Database Functions}
  173. \label{sec-2-9}
  174. \subsubsection{Configuring database: Using non-default configurations}
  175. \label{sec-2-9-1}
  176. \subsection{Testing the Modules}
  177. \label{sec-2-10}
  178. On a Unix based system, open the test directory.
  179. \begin{verbatim}
  180. ./runtests
  181. \end{verbatim}
  182. \subsection{Updating}
  183. \label{sec-2-11}
  184. \subsection{Error resolving.}
  185. \label{sec-2-12}
  186. \subsubsection{Produce the log files and e-mail it back to me.}
  187. \label{sec-2-12-1}
  188. \section{How the system works}
  189. \label{sec-3}
  190. The sub system was designed according to the requirements given.
  191. Pre-req:
  192. \begin{itemize}
  193. \item The system requires following two tables to be present.
  194. \item User table must be configured.
  195. \end{itemize}
  196. Early version:
  197. The system does the following, once connected to the database.
  198. \begin{enumerate}
  199. \item All user records are read from the user table.
  200. \item Binary tree mappings are created by reading the "person\_enrolled" table.
  201. \item Binary tree nodes are created only for records present in the user table.
  202. \item Binary tree is parsed into a readable markup format.
  203. \item Readable markup format is read and processed by the Visualizer Code.
  204. \item Visualizer Code uses a plugin to generate the vector image file.
  205. \item Visualizer add meta data to be processed by the java script.
  206. \end{enumerate}
  207. V2.0:
  208. The system does the following, once given database connection.
  209. \begin{enumerate}
  210. \item Pick an existing current user for the system to center at.
  211. \item Find the tree and position id of that user.
  212. \item Retrieve all user\_keys belonging to the tree.
  213. \item Map the tree into the memory from the database. Store all the necessary datafields, to avoid multiple database queries.
  214. \item Programmer can use the tree data structure, convert it into a markup language or into graph format. Any changes made cannot be committed.
  215. \begin{enumerate}
  216. \item Use the Tree data structure to visualize the tree.
  217. \end{enumerate}
  218. \end{enumerate}
  219. System consists of two major parts.
  220. \begin{enumerate}
  221. \item Data handling system (The database layer and Repository Layer )
  222. \item Visualization System
  223. \end{enumerate}
  224. The visualization part of the code is responsible for generating required code and data to display the tree.
  225. The Database layer code is consists of classes which wraps around PHP's existing database system. It is used by the repository classes. The base Repository class uses database to manipulate database objects. It's subclasses should contain the table layout defined, to let the developer easily access specific Data Objects.
  226. Finally, nodejs can be used in client side to either create a fully interactive html canvas using the graph or just display a static image.
  227. \subsection{Create the Binary tree by reading the database}
  228. \label{sec-3-1}
  229. There are two possible ways to do this:
  230. \subsubsection{Reading the user table recursively.}
  231. \label{sec-3-1-1}
  232. \includegraphics[width=.9\linewidth]{images/user_table.png}
  233. Each user have an enroller\_id and enrolled id, which gives each record a single reference to it's parent. (The enroller)
  234. Therefore it is possible to generate the index table (\emph{personally\_enrolled}), using the data from this table.
  235. \subsubsection{Reading the personally enrolled table.}
  236. \label{sec-3-1-2}
  237. \subsection{Create an error logging system}
  238. \label{sec-3-2}
  239. Right now we are throwing out error message to the user view. We have to devise an error logging mechanism, and show user appropriate fallback content.
  240. \subsubsection{Must have different levels of error.}
  241. \label{sec-3-2-1}
  242. \subsection{Helper HTML/String.}
  243. \label{sec-3-3}
  244. \subsubsection{Let the user insert data from the model into a string.}
  245. \label{sec-3-3-1}
  246. \subsection{Implement for callable/callback interface, for the user to process all graphs.}
  247. \label{sec-3-4}
  248. \section{Features to implement}
  249. \label{sec-4}
  250. \begin{itemize}
  251. \item $\boxtimes$ Add an independent config file, and allow programmer to read config from that file.
  252. \item $\square$ Allow programmer to configure database settings.
  253. \item $\square$ Allow programmer to configure table layouts.
  254. \item $\square$ Allow the programmer to select graphics engine.
  255. \item $\square$ Allow designer to modify style and color.
  256. \item $\square$ Add thumbnail to side.
  257. \end{itemize}
  258. \section{Note to the programmers}
  259. \label{sec-5}
  260. \begin{itemize}
  261. \item Make sure the database is consistent; such that the information in the database is sufficient enough for this module to generate a valid binary tree.
  262. \item To run the tests, its necessary to setup database configurations. Tests were done using a remote database, during the development.
  263. \item You are not really locked down to use a specific graphics renderer. Infact, you can use any java script renderer to display the graph, on client side. All javascript writer will need is an accessible copy of the binary tree.
  264. \item For better performance use this API to retrieve the Binary tree only, and use a third party library to display the tree on the client's browser. (ie, avoid graphics processing on server side.). Most JavaScript libraries are optimized to perform effectively in limited hardware.
  265. \item It is also possible to scale, zoom, and view the tree, using some renderers.
  266. \end{itemize}
  267. % Emacs 24.4.1 (Org mode 8.2.10)
  268. \end{document}