%       File: VTthesis_template.tex
%     Created: Thu Mar 24 11:00 AM 2016 EDT
%     Last Change: Thursday, December 19, 2019
%     Author: Alan M. Lattimer, VT
%	  With modifications by Carrie Cross, Robert Browder, and LianTze Lim. 
%
% This template is designed to operate with XeLaTeX.
%
% All elements in the Title, Abstract, and Keywords MUST be formatted as text and NOT as math.
%
%Further instructions for using this template are embedded in the document. Additionally, there are comments at the end of the file that give suggestions on writing your thesis.  
%
%In addition to the standard formatting options, the following options are defined for the VTthesis class: proposal, prelim, doublespace, draft. 

\documentclass[doublespace,nopageskip]{VTthesis} % nopageskip - Removes arbitrary blank pages.


% Using the following header instead will create a draft copy of your thesis
%\documentclass[doublespace,draft]{VTthesis}

% The lipsum package is just included to put dummy text in the document in order to demonstrate page headers and table of contents behavior. You should remove it once you begin writing your actual thesis or dissertation.
%\usepackage{lipsum}

% Title of your thesis
\title{Integrated Framework for Dairy Feeding}

% This should be your defense date:
\submitdate{\today} 

\begin{document}
% The following lines set up the front matter of your thesis or dissertation and are required to ensure proper formatting per the VT ETD standards.
  \frontmatter
  \maketitle
  \tableofcontents

% The list of figures and tables are now optional per the official ETD standards.  Unless you have a very good reason for removing them, you should leave these lists in the document. Comment them out to remove them.
	% ====================================================================
    %                       CH: LIST OF FIGURES
    % ====================================================================
	\listoffigures
	
	% ====================================================================
    %                       CH: LIST OF TABLES
    % ====================================================================
	\listoftables


% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

	\mainmatter

	%now go ahead and start writing your thesis
% ====================================================================
%                       CH: EXECUTIVE SUMMARY
% ====================================================================
    \chapter*{Executive Summary}
    \addcontentsline{toc}{chapter}{Executive Summary}
	Cattle farmers today have technology such as total mixed rations trackers that gather feeding data with respect to nutrients and total amount of feed consumed by pens of cattle [11]. An online platform that could help farmers manage nutritional diets for an individual cow and/or pens of cattle based on statistical feedback from milk production would serve as a useful complimentary tool to existing total mixed rations tracking technologies. A potential online platform such as the one described could prevent the use of excess nutrients during feeding, mitigate costs, as well as optimize dairy production and herd health. These aforementioned potential benefits are exactly what the Integrated Dairy Feeding Framework aims to provide.  The web platform created by our team provides farmers with a simplistic and practical interface that allows them to construct new diets for their cattle based on the statistical feedback of their previous milk composition data and health reports with the intention of generating healthier cattle capable of producing higher quantities of milk as well as a higher quality milk product for the consumer.   
	

% ====================================================================
%                       CH: PROJECT DESCRIPTION
% ====================================================================
    \chapter{Project Description} \label{ch:lit_review}
    The goal of this project is to produce a web framework that provides data management and analysis tools for dairy farmers, as well as information and manipulation of data regarding their herds' diets, ingredients, feeding details, and other preliminary and tertiary data aspects such as weather data and particular statistical analyses. The specific target audience/user base is the subset of farmers who are bovine dairy-oriented farmers who currently utilize a sister technology called Select Sires[10] for ``developing and delivering innovative genetic solutions".\\
    Data that is produced from Select Sires by the farmers is used as input to our tool, and is stored in our databases. Additionally, farmers will be able to input data manually regarding their herds' feeding/diet specifics including ingredients, percentages, and mixtures. These are the basic blocks of data that users will interact with and that our website will provide to the interface. Analysis using R will produce statistics designed by dairy scientists working with the development team to provide useful anomaly detection statistics as well as statistical visualizations and analysis of dairy production.

% ====================================================================
%                       CH: REQUIREMENTS
% ====================================================================

% we are required to provide an interface and meet functionality from the farmer's perspective that enable the website to function to its intended purpose. These specifications include allowing the farmer to be able to upload new data as well as view old data, to be able to view the weather in real time, and to not only be able to view statistics about their data in a data-visualized manner, but also to be able to view calculations made on their data (calculations done by dairy scientists in R) that are provided with intended use for the farmer to be able to maximize their dairy profits.

	\chapter{Requirements} \label{ch:results}
    	The main technological deliverables that our clients required included the following: finishing or redesigning the website, automating data acquisition from multiple sources, creating data-driven reports for the farmer, finishing anomaly detection code, and creating an anomaly event report. Outside of the technical specifications of our clients' requirements, we are required to lead weekly meetings with our clients where we will show our current progress in completing the main deliverables. 
	
	\section{Website}
    	Since our clients decided to step away from their initial decision to develop the website with PHP, our team was tasked to develop the website from scratch using Python and the Django Web Framework. The clients required that our website should be implemented with ease of use since farmers are the target users of the website. With this in mind, we were tasked with creating a login and registration system, a page within the website for the farmer to edit or add ingredients from a master ingredients SQL table, a page for farmers to create mixtures from their local ingredients, and a page for farmers to create diets from their mixtures. This will give the farmer the ability to control diet composition and optimization from the website.
	
	\section{Data Acquisition}
    	Our clients originally requested that our web framework server would automatically pull Select Sires[10] data, feeding data, local weather data by farm zip code, TMR Tracker data, and DHIA Milk composition data. However, later our clients decided that the Select Sires data will be collected via template file upload by the user and then stored within the mySQL database. Data collection for weather data is remotely pulled via API calls and should take place every week. Similar to the Select Sires data, the TMR Tracker data will be manually uploaded via template files. Finally, the DHIA Milk composition data will be inserted by the user into the web framework for analysis. 
	
	\section{Data Reports}
    	Once our web framework has all of the appropriate data, our clients specified that the framework needs to give the farmer a report that will summarize the milk production by herd, pen, or farmer defined groups of cows. These data reports should be formatted appropriately for readability and should be easily accessed by the farmer on the website. 
    	
    \section{Anomaly Detection}
    	The web framework is required to support anomaly detection. An anomaly detection report will summarize multiple anomalies that include events like farmer reported health events, environmental stress events, reproductive activity events, nutrition delivery events, and undefined events. We can use the analysis to predict when a dairy animal becomes sick or when a cow is producing less milk. We can then use this data and the history of the dairy animals to figure out what caused this. We can then suggest a change in certain variables like food and eating habits to help the dairy animal. 
	
    \section{What Tools Did We Use?} \label{se:what_tools_did_we_use}
        Following is a list of the tools that our team used to fulfill our clients needs. 
        \begin{itemize}
        \item Python (version 3.7.9) and the Django Web Framework (version 3.1.7)
        \item Bootstrap 4.0 with HTML 5
        \item MySQL which is supported by rlogin.cs.vt.edu
        \item rlogin.cs.vt.edu to host the website 
        \item R package (rpy2 3.4.3) so we can use R in Django Framework.
        \end{itemize}
	
	
% ====================================================================
%                       CH: USER MANUAL
% ====================================================================
	\chapter{User Manual} \label{ch:user_man}
        \section{Overview}  \label{se:overview}
            This web app is designed for farmers to be able to upload, track, and make inferences on their data of both their cattle's performance and output, and their diet ingredients and mixtures they give to the cattle. In this user manual you will find how to sign up and start an account with the application, how to utilize the diet mixtures/ingredients, how to upload your own data, how to edit that data, and what kinds of analysis you can find with the web app's visualization measures.
        \section{Purpose}   \label{se:purpose}
            The purpose of this user manual is to inform future users of how to use the Dairy Feeding Framework so that they can employ the appropriate functionalities listed in the Overview (see above).
        \section{Farmers}   \label{se:farmers}
             \subsection{User Sign Up Process}  \label{ss:fe_user_sign_up}
                \subsubsection{Registration}  \label{ss:fe_registration}
                
                    If you are new to the website, the first thing you will need to do is create an account.  To register, click “Sign Up Now For Free!”
                    \begin{center}
                    \includegraphics[scale=1]{./images/Register.png}
                    \captionof{figure}{Register for an account}
                    \label{fig:register}
                    \end{center}
                    After clicking the ``Sign Up Now For Free!" link shown in Figure 3.1, you will be redirected to our registration page shown in Figure 3.2.  There you will need to create a unique username, providing an email that does not already have an account and a password.  The password cannot be similar to your personal information, must be at least 8 characters long, cannot be a commonly used password (e.g., “Password”) and cannot be completely numeric.  You will also have to confirm the password, for verification.  If there are any errors, you will receive an error message.
                    \begin{center}
                    \includegraphics[scale=1]{./images/Registration_Example.png}
                    \captionof{figure}{Registration example}
                    \label{fig:registration_example}
                    \end{center}
                    After inputting all the required information, click the “Sign Up” button.  If you receive any error messages, you will need to rectify the errors.  If not, your account has been created and you will now need to verify your email address. Figure 3.3 shows a successful attempt at registering an account.
                    \begin{center}
                    \includegraphics[scale=1]{./images/Activation_Page_Example.png}
                    \captionof{figure}{Activation page example}
                    \label{fig:activation_page_example}
                    \end{center}
                
                \subsubsection{Email Verification}  \label{ss:fe_email_verification}
                
                    After successfully registering for an account, you will need to activate it before being able to access the website.  You should have received an email, but if you would like the email to be resent, you can click the “Resend Email” button. To activate your account, you will need to check your email for the activation link. The email a user can expect to see is shown in Figure 3.4.
                    \begin{center}
                    \includegraphics[scale=1]{./images/Activation_Email.png}
                    \captionof{figure}{Activation email}
                    \label{fig:activation_email}
                    \end{center}
                    After accessing the link, your account will be activated and you will be redirected to the login page where you can log in and finally access the website.
                
                \subsubsection{Login}   \label{ss:fe_login}
                
                    Now that you have created and activated your account, you can log in using your username and password.  If either of these two are incorrect, error messages will be displayed and you will need to fix the errors before logging in.  If the username and password are both correct, log in by pressing the “Log in” button.  After logging in, you will be redirected to our home page.
            
            \subsection{Farms}  \label{ss:fe_farms}
                After logging into the website, you will be taken directly to the PFP Dashboard.  Here, you will see your farm(s).  Each farm has a name, the date when data collection began on the farm, the time zone and address of the farm.  To add a farm, simply click the “Add a Farm” button on the dashboard.  You will be redirected to our add farm page shown in Figure 3.5, where you must enter the farm name, date when data collection began, time zone and address of the farm.  After entering the required information, click the “Submit” button and the farm data will be saved on the back end and displayed on the dashboard.
                \begin{center}
                \includegraphics[scale=0.9]{./images/Add_Farm.png}
                \captionof{figure}{Add farm information}
                \label{fig:add_farm}
                \end{center}
                To update an existing farm, click the ``Update Farm” button next to the farm you wish to update.  After clicking the button, you will be redirected to our update farm page where you can modify the name of the farm only.  After modifying the name, click the “Update” button and the modifications will be saved on the back end and displayed on the dashboard.  Figure 3.6 shows the result of an update on ``Sample Farm" after its name was changed to ``Sample Farm - Update."
                \begin{center}
                \includegraphics[scale=1]{./images/Farm_Update.png}
                \captionof{figure}{Updated farm}
                \label{fig:update_farm}
                \end{center}
            
            \subsection{Edit/Update Ingredients}  \label{ss:edit_update_ingredients}
                To edit or update an ingredient, you will need to head over to the ingredients page located under the relevant pages tab.  After navigating to this page, you will see two tables, one called ``My Ingredients" and one called ``Default Ingredients."  The ``Default Ingredients" table contains 283 ingredients which you can copy and edit into your ``My Ingredients" table to make mixes.
                To do this, click the ``Copy \& Edit" button next to the ingredient of your choice, make edits to the ingredient composition (if applicable) and rename the ingredient.  You can see in Figure 3.7 that the alfalfa meal ingredient was copied from the ``Default Ingredients Table," renamed to ``Alfalfa meal - Edited," and moved into the ``My Ingredients" table.
                \begin{center}
                \includegraphics[scale=1]{./images/Copy_and_Edit_Ingr.png}
                \captionof{figure}{Ingredient was copied and moved to the local table}
                \label{fig:copy_edit_ingr}
                \end{center}
                Once you have ingredients in your ``My Ingredients" table, you can still edit and make copies of those ingredients.  There will be an ``Edit" button next to each ingredient so that you can still edit ingredients.  You must edit ingredients within 35 days of the last edit/copy and the admin will be notified via email that you have made changes.  This is important because any changes to an ingredient will change any mixes and diets that ingredient is in.  There is also a ``Copy" button next to each ingredient so that you can create a copy of an ingredient.
            
            \subsection{Edit/Update Mixes}  \label{ss:edit_update_mixes}
                To look at your mixes, you will need to head over to the mixes page located under the relevant pages tab.  After navigating to this page, you can view mixes you've already created or create a new mix.  To create a new mix, click the ``Make a New Mix" button on the top right of the page.  After clicking this button, you will be redirected to the create a mix page.  Here you will see two tables, your ``My Ingredients" table from the ingredients tab shown in Figure 3.8, and your ``Mixture Ingredients" table shown in Figure 3.9.  If you would like to add an ingredient to a mix, click the ``+" button next to that ingredient.  You can add as many ingredients you would like to a mix.
                \begin{center}
                \includegraphics[scale=1]{./images/Add_Ingr_to_Mix.png}
                \captionof{figure}{Adding an ingredient to a mix}
                \label{fig:add_ingr_mix}
                \end{center}
                After adding the ingredient to the mix, you will see it in the ``Mixture Ingredients" table as shown in Figure 3.9.  Here you will have to input the percentage in dry matter of the ingredient.  The total percentage in dry matter of all the ingredients should have a sum of 100\%.  If the total percentage of dry matter doesn't sum up to 100\%, an error message will pop up and instruct you to fix the percentages so that they sum up to 100\% (though there is a slight amount of rounding up allowed if it is not a perfect 100\%).  If you'd like to remove an ingredient from the mix, click the red ``X" button next to that ingredient.  After you have your desired mixture, create a name for the mixture and click the ``Submit" button to create your mix.
                \begin{center}
                \includegraphics[scale=1]{./images/Create_Mix.png}
                \captionof{figure}{Create a mix composed of ingredients}
                \label{fig:create_mix}
                \end{center}
                After you create your mix, you should see it in the mixes page.  Here, you can edit the mix (changing ingredients or the percentage in dry matter composition), or delete the mix altogether as shown in Figure 3.10.
                \begin{center}
                \includegraphics[scale=1]{./images/My_Mixes.png}
                \captionof{figure}{Created mixes in the mixes page}
                \label{fig:my_mixes}
                \end{center}
            
            \subsection{Edit/Update Diets}  \label{ss:edit_update_diets}
                To look at your diets, you will need to head over to the diets page located under the relevant pages tab.  After navigating to this page, you will need to choose the farm where the diet is being used.  After choosing the farm, you can view the diets you have already created, or create a new diet.  To create a diet, click the ``Make a New Diet" button on the top right of the screen.  After clicking this button, you should be redirected to our make a diet page.  Here you will see two tables, your ``My Mixtures" table from the mixes tab shown in Figure 3.11 and your ``Diet Mixtures" table shown in Figure 3.12.  If you would like to add a mix to a diet, click the ``+" button next to that mix.  You can add as many mixes you would like to a diet.
               
               \begin{center} \includegraphics[scale=1]{./images/my_mix_diets.png}
                \captionof{figure}{Adding a mixture to a diet}
                \label{fig:my_mix_diets}
                \end{center}
                
                After adding the mix to the diet, you will see it in the ``Diet Mixtures" table.  Here you will have to input pounds of each mixture in the diet.  If you'd like to remove a mix from the diet, click the red ``X" button next to that mix.  You must also input the diet start date, and animal ID if applicable.  After you have your desired diet, create a name for the diet and click the ``Done" button to create your diet.
                
                \begin{center} \includegraphics[scale=1]{./images/diet_mixtures.png}
                \captionof{figure}{Create a diet composed of mixtures}
                \label{fig:my_mix_diets}
                \end{center}
                
                After you create your diet, you should see it in the diets page.  Here you can edit the mix (changing mixes or the percentage of mixes) or delete the diet altogether.
            
            \subsection{Analysis}  \label{ss:analysis}
                Analysis of the cattle data and the ingredients data will be utilized along with weather data in R. The calculations done on the data are unknown to the development team at the moment, but it can be speculated that the dairy scientists currently formulating the R data analysis will be targeting statistics such as what diets are correlated with the best dairy output from the given farmer's cattle, what weather makes which herds perform differently, and what ingredients to use to respond to conditions in herd performance or weather changes or possibly other dependencies. 
                
            % \subsection{Feedback}  \label{ss:feedback}
                % Start writing here (Maybe not needed)
                
                
        \section{Data Management Team} \label{se:data_management_team}
            The data management team includes the users who handle data flow, data injection, and data modifications. 
            These users have data coming in every day. Not all data needs to be monitored at all times, only at crucial times. This team will have access to run different scripts which will run processes to help with data flow and modifications. This team will also handle any edit commits that farmers may want to make. 
            When farmers need to speak with someone to tackle data errors, this team can be at their service. 
            
                
        \section{Admin(s)}   \label{se:amdins}
            Admin users are privileged users that have permissions within the Dairy Feeding Framework beyond the permissions shared with regular users. Admin users can: add log entries, view log entries, change log entries, delete log entries, etc. (see Figure 3.13).
            
             \begin{center}
                \includegraphics[scale=0.5]{./images/AdminUserPermissions - For admin page.png}
                \captionof{figure}{An image displaying admin user permissions}
                \label{fig:adminpermissions}
            \end{center}
            
            Certain admins also have access to view/add/edit/delete data in the tables this website contains, 
            based on what permissions are given to this admin user by the super user. 
            
	
% ====================================================================
%                       CH: DEVELOPERS MANUAL
% ====================================================================
	\chapter{Developers Manual} \label{ch:dev_man}
        \section{Overview}   \label{se:dev_overview}
            The developers manual will give anyone assigned to start development on the web framework, guidance as to what dependencies are needed to run the web framework locally, front end design choices and implementation, back end design choices and implementation, and methodology for using the application.
        \section{Getting Started}   \label{se:dev_pupose}
            To get started on development for this project, the developer will need to make sure that they have the following languages and dependencies downloaded. 
            \begin{itemize}
              \item Python version 3.7.9
              \item GitHub
              \item R programming language
            \end{itemize}
            After installing the programming languages and dependencies above, the new developer must clone the GitHub repository using the following URL.
            
            https://github.com/dwarakhvt/DairyFeedingFramework/
            
            The developer must make sure they pull from the master branch. Now the developer should have all files for the web framework. Next, the developer will need to install all of the web framework's dependencies by running the `setup.sh -all' bash script that will set up the virtual environment and install the Django framework dependencies from the requirements.txt file. \\
            Another way to install all the dependencies is to run 
            \begin{verbatim}    Python PythonPackageInstaller.py requirements.txt\end{verbatim}
            
        \section{Front End}   \label{se:front_end}
            \subsection{Design}  \label{ss:fe_design}
                Django has the capability to stitch and merge several HTML documents together and send them to the user as a single HTML file. This allows developers to put sections of the HTML code in separate files. One HTML document can be used for several different page requests. For example, if you wanted your website to look the same with different pages having only a few sections modified, you can have an HTML document act as a base template, where other HTML files will use the base template and fill in the missing sections in the body and/or head. 
                Each section of the code, for a different purpose, is in a separate file. 
                This helps organize the different components that go into creating the final page. 
                Django has template merging capabilities which allow for easy inheritance of the contents of other HTML documents.
                \begin{center}
                    \includegraphics[scale=.65]{./images/My_tmr_wf.png}
                    \captionof{figure}{First design of a farmer's local ingredients}
                    \label{fig:tmr_wf}
                \end{center}
                \vspace{-2cm}
                    The team's first design for the farmer to manipulate ingredients was to have two separate pages where the farmer will have one page for adding ingredient, Figure 4.2, and another page for viewing and editing their local ingredients, Figure 4.1. 
                    
                \begin{center}
                    \includegraphics[scale=.65]{./images/tmr_ingr_page.png}
                    \captionof{figure}{First design of the default ingredients that a farmer will choose from}
                    \label{fig:tmr_ingr}
                \end{center}
                \vspace{-2cm}
                    After reviewing the simple solution with our clients, we decided to change the design so that both actions of adding ingredients from the default ingredients table to the farmer's local table and viewing those local ingredients would be in a single page, see Figure 4.3. 
                    
                \begin{center}
                    \includegraphics[scale=.65]{./images/Ingr_page_3.png}
                    \captionof{figure}{Final wire-frame design for viewing user and default ingredients.}
                    \label{fig:ingr_page}
                \end{center}
            \newpage
            \subsection{Ingredients}  \label{ss:fe_ingredients}
            Table 4.1 shows the file structure for the ingredients components in the web framework. 
            \begin{flushleft}
             \begin{tabular}{||p{0.1\textwidth} | p{0.4\textwidth} | p{0.5\textwidth}||} 
             \hline
             \textbf{Files} & \textbf{Description} & \textbf{File Path} \\ [0.5ex] 
             \hline\hline
             Templates & Contain all of the HTML documents & PFP\_WEB/core/templates/core/ingredients \\ 
             \hline
             Models & Classes and tables used for ingredients & PFP\_WEB/core/models.py \\
             \hline
             Views & Implements the functionality for ingredients pages & PFP\_WEB/core/views.py \\
             \hline
             URLs & Contains the URL extensions for the ingredients pages & PFP\_WEB/core/urls.py \\
             \hline
             Forms & Allow storing user input into an existing ingredients model & PFP\_WEB/core/forms.py \\ [1ex] 
             \hline
            \end{tabular}
            \end{flushleft}
            \captionof{table}{Files related to the front-end}
            \label{table:files-front-end}
            \newpage
            \subsection{Mixes}  \label{ss:fe_mixes}
            Table 4.2 shows the file structure for the mixes components in the web framework.
            \label{ss:fe_ingredients}
            \begin{flushleft}
             \begin{tabular}{||p{0.1\textwidth} | p{0.4\textwidth} | p{0.5\textwidth}||} 
             \hline
             \textbf{Files} & \textbf{Description} & \textbf{File Path} \\ [0.5ex] 
             \hline\hline
             Templates & Contain all of the HTML documents & PFP\_WEB/core/templates/core/Mixes \\ 
             \hline
             Models & Classes and tables used for mixes & PFP\_WEB/core/models.py \\
             \hline
             Views & Implements the functionality for mixes pages & PFP\_WEB/core/views.py \\
             \hline
             URLs & Contains the URL extensions for the mixes pages & PFP\_WEB/core/urls.py \\
             \hline
             Forms & Allow storing user input into an existing mixes model & PFP\_WEB/core/forms.py \\ [1ex] 
             \hline
            \end{tabular}
            \end{flushleft}
            \captionof{table}{Files related to the mixes}
            \label{table:files-mixes}
            \newpage
            \subsection{Diets}  \label{ss:fe_diets}
            Table 4.2 shows the file structure for the diets components in the web framework.
            \label{ss:fe_ingredients}
            \begin{flushleft}
             \begin{tabular}{||p{0.1\textwidth} | p{0.4\textwidth} | p{0.5\textwidth}||} 
             \hline
             \textbf{Files} & \textbf{Description} & \textbf{File Path} \\ [0.5ex] 
             \hline\hline
             Templates & Contain all of the HTML documents & PFP\_WEB/core/templates/core/Diets \\ 
             \hline
             Models & Classes and tables used for diets & PFP\_WEB/core/models.py \\
             \hline
             Views & Implements the functionality for diets pages & PFP\_WEB/core/views.py \\
             \hline
             URLs & Contains the URL extensions for the diets pages & PFP\_WEB/core/urls.py \\
             \hline
             Forms & Allow storing user input into an existing diets model & PFP\_WEB/core/forms.py \\ [1ex] 
             \hline
            \end{tabular}
            \end{flushleft}
            \captionof{table}{Files related to the diets}
            \label{table:files-diets}
            \newpage
            \subsection{File Uploads}  \label{ss:fe_file_upload}
                Within the File Upload page, there is a box containing a button that users can click to upload files to the Dairy Feeding Framework. For a more explicit illustration of what this button looks like, please see the Figure 4.4.
                
                \begin{center}
                    \includegraphics[scale=.65]{./images/FileUpload.png}
                    \captionof{figure}{Uploading Files HTML Format.}
                    \label{fig:file_upload}
                \end{center}
               
            \subsection{R Analysis}  \label{ss:fe_analysis}
                We use an artificial R environment that runs with Python [8]. Our website back-end can pass file names and necessary variables to R scripts provided by the dairy scientist admins. This is done to produce statistical analysis output in an HTML format for the dairy science users. Our tool is not only a valuable tool for farmers, but an interactive and useful tool for dairy scientists.\\
                The flow of operations would be that a user navigates to a data analytics page, and a user action/button click takes the user through installing their R script, runs it, and returns the results to their webpage in HTML [9].
                
                
        \section{Back End}   \label{se:back_end}
                
            \subsection{Django Framework}  \label{ss:be_django_framework}
            
                \subsubsection{Overview}  \label{sss:django_overview}
                    This website needs to have high functionality and performance capabilities. Django is an organized Python based web framework platform with many security features and integrations built straight into it. This framework allows us to build apps, templates with special Python/Django capabilities for filling in information, customized URLs, customized forms, and customized functions[1].

                \subsubsection{Security}  \label{sss:django_security}
                    In the main project folder, there is a file called settings.py. This file contains all the security and Django application settings. For security, there is a secret security key which is NOT to be revealed to the public. This key is used for any transfers between the user and the server. There are several middleware security packages added by default. 
    \begin{verbatim} 
    django.middleware.security.SecurityMiddleware
    django.contrib.sessions.middleware.SessionMiddleware
    django.middleware.common.CommonMiddleware
    django.middleware.csrf.CsrfViewMiddleware
    django.contrib.auth.middleware.AuthenticationMiddleware
    django.contrib.messages.middleware.MessageMiddleware
    django.middleware.clickjacking.XFrameOptionsMiddleware
    \end{verbatim}

                \subsubsection{Apps}  \label{sss:django_apps}
                    Django can create apps (a collection of methods, templates, URLs, and forms for a particular sub-project of the whole website). All these apps combined make the whole website. Plus it maintains a certain degree of proper organization. Currently, we have two apps (user and core).
                    
                    \begin{enumerate}
                        \item User App \label{ssss:django_apps_user} 
                      \\
                        The user app contains all of the necessary components and information about the user. 
                        This includes the user’s profile with active status and “send me alerts”. 
                        This user’s templates directory contains a base template which all app’s HTML templates use.
                        There are certain forms in this app for user registration and log-in.
                    
                    \item Core App  \label{ssss:django_apps_core} \\
                        The core app contains all of the components for the dairy feeding framework. 
                        This includes viewing, making, editing farms, ingredients, mixes, and diets, etc. 
                        The templates directory is organized into sub-folders for the different sections such as Diets, Farm, Mixes, etc. 
                        Be sure to add new sub-folders for new tasks to maintain organization. 
                    \end{enumerate}
                \subsubsection{Models}  \label{sss:django_models}
                    Models are another term for tables. These models contain the column names (fields) with their corresponding data storage type and restrictions [3]. 
                    In views.py you can treat these as a query set with class variables (the unique fields), 
                    for example: \begin{verbatim}    User.objects.first().username\end{verbatim}.
                    This will get the username value for this first record.
                    Changes to the model can be pushed to the database by running two commands. 
                    \begin{verbatim}    python manage.py makemigrations\end{verbatim}
                    This will make a staging file with the changes to commit. This also points out any errors that may exist. You must not have any errors to continue. 
                    \begin{verbatim}    python manage.py migrate\end{verbatim}
                    This will push the staging changes to the server’s database. After this you can see the changes in the admin page.
                    
                    % \begin{center}
                    % \includegraphics[scale=0.5]{./images/ERD.png}
                    % \captionof{figure}{A diagram of the model}
                    % \label{fig:diagram_model}
                    % \end{center}

                \subsubsection{Views (Classes and Functions)}  \label{sss:django_classes_functions}
                    The views contains all the classes and functions that would be run for a particular page request [6]. 
                    These page request functions must take in at least one parameter (request); additional parameters can be passed in, but it must be configured in the urls.py to accept those extra parameters.  Along with this, this function should be called from within the urls.py file with the URL path and ID set properly. See the URLs section for more information. 
                    The page request functions must return either a render of an HTML template or a redirect to another page (URL).
                    Other helper functions can exist, but do not require the request parameter. 
                    The request parameter contains all information about the user requesting that page.
                    The render can take in a dictionary of information you want to display on the HTML webpage. This data can be accessed in the HTML using the Python/Django template structures. 

                \subsubsection{Templates}  \label{sss:django_templates}
                    Apps may or may not have templates. Templates only are required for any page requests that app may have. Templates are stored in the <APP>/templates/<APP>/ directory. In the templates, you place your HTML code as well as any Python code with special syntax for any areas where you want to pass data to the HTML page. The views.py render call can pass in a dictionary which holds data that can be used. Django takes the HTML template document, edits it (to add the dictionary data to the document), then sends the rendered HTML file(s) to the user [4]. 
                    You can access the data in the dictionary by using the key in this format {{<KEY>}}.
                    Below you can find an example of using ``if'' conditionals and ``for'' loops.
        \begin{verbatim} 
        {% for farm in farms %}
            {% if farm.visible == True %}
                <h2> {{farm.name}} </h2> <br>
            {% else %}
                <h2> Hidden Farm </h2> <br>
            {% endif %}
        {% empty %}
            <h2> farms is empty! </h2>
        {% endfor %}
        \end{verbatim}
                    
                \subsubsection{URLs}  \label{sss:django_urls}
                    Apps may or may not have a urls.py file. The urls.py file contains any URLs with matching functions the page is associated with. `urlspatterns' holds an array of these paths where the first parameter is for the link, the second parameter is for the method it calls, and the last parameter is for the unique name this link has [5]. 
        \begin{verbatim}
        urlpatterns = [
            path('farms/', views.viewFarms, name="my-farms"),
            ...
        ]\end{verbatim}
                    All page requests are directed to these URL paths. Upon a request, the method or class is called, then renders an HTML document for the user and sends it to the user. 
                    
                \subsubsection{Forms}  \label{sss:django_forms}
                    You may create templates for any forms you may need in the forms.py file. 
                    Forms classes can use an existing model (table), custom entries, or both together [2]. 
                    For the existing model, you can specify which columns of the model you want to display as a form to the user. It will take care of any input types and restrictions that are present in the models.py for that particular model. Here is an example with Address being a model with columns being Street, City, State, Country, ZipCode, Lat, and Long.
        \begin{verbatim}
        class AddFarmAddressForm(forms.ModelForm):
            class Meta:
                model = Address
                fields = ['Street', 'City', 'State', 'Country', 'ZipCode']
        \end{verbatim}
                    For custom entries, every entry is assigned a form field from forms.Form. 
        \begin{verbatim}
        class DocumentForm(forms.Form):
            docfile = forms.FileField(label='Select a file')
        \end{verbatim}
                    In the views.py an instance of this form can be passed into the dictionary for the HTML template to use this. 
                    In the document, all you need is the form tag, csrf token, {{farmForm}} and your submit button. 
                    You can also add crispy (a Django to HTML formatting package) to make use of Bootstrap 4 in the Python form rendering process.
        \begin{verbatim}
        {% load crispy_forms_tags %}
        <form method="POST" enctype="multipart/form-data">
            {% csrf_token %} 
            {{ farmForm|crispy }}
            <div><button type="submit" class="btn btn-primary">Submit</button></div>    
        </form>
        \end{verbatim}
                    This will take the fields in the form and make the HTML form for you. This data can then be read in by the request parameter in views functions. 
                    
            \subsection{Data Parsing}  \label{ss:be_data_parsing}
                The weather data is pulled from weatherbit.io [12] API. A request to fetch data is done once per week and is stored in the database. The \emph{weather.py} script contains all of the parsing logic. During the data fetch, only information needed is gathered and pushed to the weather info model; see Figure 4.5. If no error occurs then the model gets migrated into the database. 
                
                \begin{center}
                    \includegraphics[scale=0.55]{./images/WeatherModel.png}
                    \captionof{figure}{An image of the weather model}
                    \label{fig:weather_model}
                \end{center}
                
                For file uploads, a file type restriction is applied. Currently, only file types .csv and .xlsx are accepted. Changes can be made in the future if the restriction needs to expand. The file is parsed by iterating through each row and storing the column's value to its appropriate variable name. Figure 4.6 shows a small code snippet of ingredient data being stored in each iteration. Once the file has been parsed, the data is pushed to the database and updates the library. The systems does not need to differentiate the type of file beings parsed since each file upload is specific to its tab. If a farmer is uploading ingredients, then they can only do it in the ingredients tab.
                
                \begin{center}
                    \includegraphics[scale=0.55]{./images/FileUploadIngr.png}
                    \captionof{figure}{An image of the weather model}
                    \label{fig:weather_model}
                \end{center}
                
                % TMR: TBD
                
                
            \subsection{Alerts}  \label{ss:be_alerts}
                Users who are given staff status and have the `Send Me Alerts' box checked shown in Figure 4.7 will receive email notifications whenever user(s) make a change to any ingredients after 90 days from when the ingredient was last edited/created.
                
                \begin{center}
                    \includegraphics[scale=0.75]{./images/Profiles.png}
                    \captionof{figure}{An image of some of the user profiles}
                    \label{fig:profiles}
                \end{center}
                
                The email notifications mentioned when a user modifies an ingredient appear in the format shown in Figure 4.8.
                
                \begin{center}
                    \includegraphics[scale=0.75]{./images/INGR_Edit_Email.png}
                    \captionof{figure}{An image of an ingredient edit notification email}
                    \label{fig:profiles}
                \end{center}
                
                The staff/admin can click on the link and it will take them to this page as shown in Figure 4.9.
                
                \begin{center}
                    \includegraphics[scale=0.50]{./images/Staff_Link_Commit.png}
                    \captionof{figure}{Staffs link to commit user edits}
                    \label{fig:profiles}
                \end{center}
                
                The staff/admin can see the edits made in the ingredients. They can view which mixes and storage records need to be edited to use the updated ingredient's data. You can see a sample of the sections in Figures 4.10, 4.11, and 4.12. 
                
                \begin{center}
                    \includegraphics[scale=0.50]{./images/Staff_Link_Compare_Ingredients.png}
                    \captionof{figure}{Staffs view to see a user edits on an ingredient}
                    \label{fig:profiles}
                \end{center}
                \begin{center}
                    \includegraphics[scale=0.50]{./images/Staff_Link_Compare_Mixes.png}
                    \captionof{figure}{Staffs view to see possibly affected mixes on an ingredient edit}
                    \label{fig:profiles}
                \end{center}
                \begin{center}
                    \includegraphics[scale=0.50]{./images/Staff_Link_Compare_Storage.png}
                    \captionof{figure}{Staffs view to see possibly affected storage ingredients on an ingredient edit}
                    \label{fig:profiles}
                \end{center}
                
                The staff can click the Commit Changes button which will update all the mixes and storage records shown to use the new/updated ingredient. 
                
        \section{Docker}   \label{se:docker}
            To host the web framework on Virginia Tech's cloud container cluster, we needed to create a Docker repository to hold a Docker image of the web app. The Docker image is created using the Dockerfile located at `DairyFeedingFramework/Dockerfile' in the project directory. A Docker image declares the state of a Docker container when running the container on a cluster. To get started with Docker, the developer must first install the Docker desktop application from the following link.
            
            https://docs.docker.com/desktop/
            
            \subsection{Dockerfile} \label{ss:dockerfile}
            
            \begin{center}
                \includegraphics[scale=0.75]{./dockerfile.PNG}
                \captionof{figure}{Dockerfile for the dairy\_feeding\_framework Docker image}
                \label{fig:profiles}
            \end{center}
            
            
            The first line of the Dockerfile shown in Figure 4.13 is a `FROM' command that specifies the base Docker image that our Docker image will build from. Next, the `RUN` command will install dependencies in the container once the CentOS8 Docker image is loaded. After the dependencies are installed to our Docker image, the `COPY' command is used to copy files from our local machine to the Docker image so that all of the content needed to run the web framework are present in the Docker image. Once the `COPY' commands are complete, we set the working directory in our Docker image by using the `WORKDIR' command which is set to `var/www/html'. Next, another `RUN' command is used to run the PythonPackageInstaller.py with the requirements.txt file that were previously copied from our local machine to the Docker image. This will install all of the web frameworks dependencies so the Web framework can run properly. Finally, the last command in the Dockerfile is the `ENTRYPOINT' command that will configure the container to run the start.sh file once the container starts [7]. 
            
            When any changes are made to the Dockerfile, the developer will need to push the changes to the Docker Hub repository that stores the Docker image. The following steps will correctly push the Dockerfile changes to the repository. 
            
            On a command line tool, navigate to the project's root directory `DairyFeedingFramework/'
            Run the command `docker build -t ewebb4505/dairy\_feeding\_framework'
            Run the command `docker push ewebb4505/dairy\_feeding\_framework' 
            
            \begin{itemize}
              \item on a command line tool, navigate to the project's root directory `DairyFeedingFramework/'
              \item Run the command `docker build -t ewebb4505/dairy\_feeding\_framework .'
              \item Run the command `docker push ewebb4505/dairy\_feeding\_framework' 
            \end{itemize}
            
            Once the Docker image is successfully pushed to the Docker Hub, the developer will have to redeploy the container on Virginia Tech's cloud container cluster with the following steps. 
            
            \begin{itemize}
              \item Navigate to the following link https://cloud.cs.vt.edu/p/c-l4mcr:p-z6pfk/workloads
              \item Click on the checkbox beside `pfp\_web' on the namespace table. The namespace will also be labeled `pfp\_web'
              \item Next click on the `Redeploy' button. This will take time to restart the container and pull the image from the Docker Hub repository.
            \end{itemize}
            
            \subsection{Apache Configuration} \label{ss:apacheconfiguration}
            
            The Apache Configuration file that is copied from our local working directory to the etc/httpd/conf.d/ directory in the Docker image will configure the Apache web server that our Docker image runs. 
            
            Currently, the api.conf file does not display the web framework but the Apache test page is currently displayed at the host URL. Getting the web framework to be served by the Apache Web Server in the Docker container will be a part of the future work for this project since we had to make a switch from our web framework being host by the Virginia Tech rlogin service to the Virginia Tech Cloud Container Cluster. Figure 4.14 shows the current state of the api.conf file.
            
	        \newpage
            \begin{center}
                \includegraphics[scale=0.80]{./images/apiconf.PNG}
                \captionof{figure}{api.conf file used by Docker image to configure Apache Server}
                \label{fig:profiles}
            \end{center}
% ====================================================================
%                       CH: METHODOLOGY
% ====================================================================
    \chapter{Methodology} \label{ch:methodology}
        \section{Outline}   \label{se:outline}
             For the dairy feeding framework, there will be two types of users: farmers and data management users. Farmers will use the dairy feeding framework to virtually monitor the dairy production at each of their registered farms. Farmers will interact with interfaces that will give them the ability to create diets, download dairy production reports, upload data reports, and view visuals that portray milk production anomalies and other relevant statistics. Data management users will have access to a farmer’s dairy production data to make inferences on the quality of the dairy production. Also, data management users will be notified when farmers make changes to a diet.
             
        \section{Farmer Goals}   \label{se:farmer_goals}
            Farm Management: The farmer will be able to register multiple farms under their user profile. Each farm will have farm-specific information. \\
            Ingredient Retrieval: The farmer will be able to copy ingredients from the default (global) ingredient dataset into their local ingredients table and edit these ingredients if necessary. Farmers will be able to create mixes composed of the ingredients in their local ingredients table. \\
            Create Mixtures: The farmer will be able to create ingredient mixtures composed of ingredients from the farmer’s local ingredients table. The farmer will determine the amount of each ingredient in the mixture by percentage and will be able to edit and delete mixtures after creation. \\
            Create Diets: The farmer will be able to create diets composed of mixtures from their list of mixtures. Farmers can assign a diet to a particular herd of cows or an individual cow. \\
            File Upload and Data Injection: The farmer will be able to upload DHIA (Dairy Herd Improvement Association) data reports which the web framework will analyze and provide useful information to the farmer. \\
            Retrieve Dairy Production Data: The farmer will be able to view and download a dairy production data report that shows milk production statistics over time including anomalies and visual diagrams of farmer-relevant data.
    
            \subsection{Farm Management Tasks} \label{ss:farmer_goals_management_tasks}
                Refer to Figure 5.1 for the Farm Management Tasks work flow diagram. Following are the task to complete the Farm Management user goal.\\
                a) Farmer registers a farm via a form.\\
                b) Update farm information as needed.  This task is reliant on task a.\\
                \begin{center}
                  \includegraphics[scale=0.75]{./images/Capstone_Farmer_Management.JPG}
                    \captionof{figure}{Farm registration and management work flow}
                    \label{fig:farm_reg_and_management}
                \end{center}

            \subsection{Ingredient Retrieval Tasks} \label{ss:farmer_goals_retrieval_tasks}
                Refer to Figure 5.2 for the Ingredient Retrieval Tasks work flow diagram. Following are the task to complete the Ingredient Retrieval farmer goal.\\
                a) Display global library of ingredients: retrieve global ingredients data from database.\\
                b) Display farmer’s local ingredients: retrieve the farmer’s ingredients stored in the database and present it to the farmer.  Reliant on tasks c, d and e.\\
                c)  ingredients from the global library to the local table: the copy functionality is necessary for a farmer to copy an ingredient from the default/global table into their local ingredients table to later create mixes.  This task is reliant on task a.\\
                d) Update/edit ingredient data in the local ingredients table: a farmer will be presented with the tools to edit or update individual ingredient’s data from their local ingredients table. The farmer will be able to edit ingredients data through a form on a separate page when the user indicates that they need to edit an ingredient’s data.  This task is reliant on task b.\\
                e) Clone local ingredients: a farmer will be presented with the tools to clone ingredients that already exist in their local ingredients table. This will be more efficient than cloning from the default/global table, as the farmer will not have to edit the ingredient all over again.  This task is reliant on task b.\\
                
                \begin{center}
                  \includegraphics[scale=0.75]{./images/Capstone_Ingredient_Retrieval.JPG}
                    \captionof{figure}{Ingredient retrieval task work flow}
                    \label{fig:farm_ingr_retrieval}
                \end{center}

            
            \subsection{Create Mixtures Tasks} \label{ss:farmer_goals_mixtures_tasks}
                Refer to Figure 5.3 for the Create Mixtures Tasks work flow diagram. Following are the task to complete the Create Mixtures farmer goal.\\
                a) Display farmer’s local ingredients: retrieve the farmer’s ingredients stored in the database and present it to the farmer.\\
                b) Add an ingredient to a mixture.  This task is reliant on task a.\\
                c) Edit percentage of ingredients in a mixture: the farmer will be given an input field to enter the percentage of an added ingredient in the mixture.  This task is reliant on task b.\\
                d) Notify the farmer when mixture composition percentage is not 100\%: display a message to the farmer that the sum of ingredient percentages do not equal 100\%.  This task is reliant on task c.\\
                e) Edit the mixture name: give the farmer the ability to edit the mixture name when creating the mixture.  This task is reliant on task c.\\
                
                \begin{center}
                  \includegraphics[scale=0.75]{./images/CreateMixturesTasks.png}
                    \captionof{figure}{Create mixture task work flow}
                    \label{fig:CapstoneMixturesTask}
                \end{center}
            
            
            \subsection{Create Diets Tasks} \label{ss:farmer_goals_diets_tasks}
                Refer to Figure 5.4 for the Create Diets Tasks work flow diagram. Following are the task to complete the Create Diets farmer goal.\\
                a) Display the farmer’s mixtures: retrieve the farmer’s mixtures stored in the database.\\
                b) Add a mixture to the diet.  This task is reliant on task a.\\
                c) Adjust the appropriate percentages of each mixture for a given diet.  This task is reliant on task b.\\
                d) Assign a start date for the diet. This task is reliant on task c.\\
                e) Assign diet to a particular pen of cattle or an individual cow.  This task is reliant on task d.\\

                \begin{center}
                  \includegraphics[scale=0.75]{images/makeDietTask.png}
                    \captionof{figure}{Creating the diets task work flow}
                    \label{fig:CreateDietsTasks}
                \end{center}
                
                
            \subsection{File Upload and Data Injection Tasks} \label{ss:farmer_goals_file_upload_tasks}
            
                a) Add a file via file-dialog box.\\
                b) Receive confirmation that file is stored.  This task is reliant on task a.\\

            
            \subsection{Retrieve Dairy Production Data} \label{ss:farmer_goals_retrieve_prod_data_tasks}
                Refer to Figure 5.5 for Retrieve Dairy Production Data work flow diagram. Following are the task to complete the Retrieve Dairy Production Data farmer goal.\\
                a) Pull dairy production data from the database.\\
                b) Perform data analysis on the dairy production data with R.  This task is reliant on task a.\\
                c) Render the results of data analysis to the web interface.  This task is reliant on task b.\\
                d) A Farmer can download results to their local computer.  This task is reliant on task c.\\

                \begin{center}
                  \includegraphics[scale=0.75]{./images/RetrieveDairyProductionData.png}
                    \captionof{figure}{Retrieve dairy production data work flow}
                    \label{fig:RetrieveDairyProductionData}
                \end{center}
            
            
        \section{Data Management User Goals}   \label{se:data_managment_user_goals}
    	    Data Management User Goals: Receive Notifications Upon Dietary Changes: Data managers will receive notifications when diets have been altered if the change has taken place within 35 days of creation or the last edit. The data managers will then review the change to ensure that it is an acceptable change.
            Monitor Farmers Production Data: Data managers will be able to monitor milk production data from farms.  This data includes the amount of milk yielded, contents of the milk and other additional fields related to the quality of the milk (such as spectral DHIA data).
            
            \subsection{Receive Notifications Upon Dietary Changes Tasks} \label{ss:data_managment_user_goals_notifications_tasks}
            Refer to Figure 5.6 for Receive Notifications Upon Dietary Changes work flow diagram. Following are the task to complete the Receive Notifications Upon Dietary Changes data management user goal.\\
                a) Received email that a farmer has changed diet data.\\
                b) View data changes side by side.  This task is reliant on task a.\\
                c) Confirm that the changes to the diet data are accurate.  This task is reliant on task b.\\
                
                \begin{center}
                  \includegraphics[scale=0.75]{./images/ReceiveNotificationsUponDietaryChangesTasks.png}
                    \captionof{figure}{Notifications when editing an ingredient work flow}
                    \label{fig:ReceiveNotificationsUponDietaryChangesTasks}
                \end{center}

            \subsection{Monitor Farmers Production Data} \label{ss:data_managment_user_goals_production_data}
            Refer to Figure 5.7 for Monitor Farmers Production Data work flow diagram. Following are the task to complete the Monitor Farmers Production Data data management user goal.\\
        	    a) Connect to R with Python to run the anomaly detection tool.\\
                b) Calculate diet changes and production statistics (run R script).  This task is reliant on task a.\\
                c) Produce visuals based on past/current data statistics, data anomalies, and recommended future changes/actions.  This task is reliant on task b.\\

                \begin{center}
                  \includegraphics[scale=0.75]{./images/MonitorFarmersProductionData.png}
                    \captionof{figure}{Monitoring data in production work flow}
                    \label{fig:data_managment_user_goals_production_data}
                \end{center}
	
% ====================================================================
%                       CH: TESTING
% ====================================================================
    \chapter{Testing} \label{ch:testing}
        In this chapter, we'll discuss the steps on how to test each function of our website.
        
        \section{Farm}   \label{se:testing_farm}
            To test the creation of the farm, you will need to do the following: \\
            \vspace{-8mm}
            \begin{enumerate}
                \item Run server
                \item Log in (then the website takes you to the home page)
                \item Click the ``Add Farm" button
                \item Enter your farm information
                \item The newly added farm should be displayed once the information is saved.
            \end{enumerate}
            
            
        \section{Ingredients}   \label{se:testing_ingr}
            To test the ``Make Copy" of default ingredients, you will need to do the following.\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Navigate to the Ingredients Tab.
            \item Choose ``Make Copy" from the defaults ingredients. 
            \item Make certain changes and save.
            \item The edited mix should be in My Ingredients. This mix should have a reference ID to the original default mix (you can check on the admin ingredients tab for ``old\_ingr").
            \end{enumerate}
            \\ \\
            To test the ``Edit" of my ingredients, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Navigate to the Ingredients Tab.
            \item Choose ``Edit" from my ingredients. 
            \item Make certain changes and save.
            \item Should create a new record for the edited mix.
            \item Should set old ingredient's, (IngrID prior to edit), visible to false.
            \item Should see the updated ingredient in my ingredients
            \end{enumerate}
            \\ \\
            To test the ``Make Copy" of my ingredients, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Navigate to the Ingredients Tab.
            \item Choose ``Make Copy" from my ingredients. 
            \item Make certain changes and save.
            \item Should create a new record for the edited mix.
            \item Should keep the old ingredient's, (Ingr\_ID prior to edit), visible to true.
            \item Should see both old and updated ingredient in my ingredients
            \end{enumerate}
            
        \section{Mixes}   \label{se:testing_mixes}
            Testing for mixes is similar to testing ingredients. The only difference is that the mixes have a JSON string object to hold the ingredients and its percentages together. 
            They follow the same structure with the ``Edit" button. It creates a new record for every edit and sets the old mix's visible to false. 
            You can also remove a mix if needed. 
            
        \section{Diets}   \label{se:testing_diets}
            Testing for diets is similar to testing mixes. The only difference is that the mixes have a JSON string object to hold the mixes and its amount together. 
        
        \section{Storage}   \label{se:testing_storage}
            To test the creation of a storage ingredient record, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Navigate to the Storage Tab.
            \item Click on the ``Add Storage" button. 
            \item Fill in the information and save.
            \item The newly added storage ingredient should be displayed once the information is saved.
            \end{enumerate}
        
        \section{Data Uploading}   \label{se:testing_data_uploading}
            To test the file uploading, data parsing, and saving, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Log in as admin/staff.
            \item Go to the staff links. 
            \item If you have Select Sires Animal data, then choose Select Sires, then Upload Animal Data. If you have TMR data, then choose Upload TMR Data.  
            \item Choose the farm you are uploading this data for. Then upload the file. 
            \item The process should not take long before it directs you to the files uploaded page.
            \item You should see the newly added file at the bottom of the list. 
            \item If you navigate to the Django Administrator page to the respective table, the data should be uploaded to the farm you chose.
            \end{enumerate}
        
        \section{Staff Notifications and Commit}   \label{se:testing_staff_notifications_commit}
            To test the staff notifications and the commit changes option, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item Change EDIT\_NOTIFY\_DAYS in PFP\_WEB/core/views.py to 0 or a number smaller than the age of the ingredient/mix you wish to edit.
            \item Make sure there is at least one staff who has send\_me\_alerts on.
            \item Make sure the ingredient's age is larger than EDIT\_NOTIFY\_DAYS.
            \item Make sure the ingredient is used in Mixes and Storage tabs. (Not needed)
            \item Edit that ingredient. 
            \item A notification should appear indicating a notification to the staff. 
            \item Every staff with send\_me\_alerts on, will get an email notification. 
            \item The email should contain a link only accessible to Staff/Admin.
            \item The link will display all the changes made in ingredients. It will also show you where the old ingredient was used in Mixes and Storage tabs if step 4 is complete. 
            \item There is a commit button at the bottom. Click it. 
            \item This should commit all the changes. Mixes and Storage records will now use the updated/new ingredient.
            \item The link will refresh and should show you no possible changes to Mixes or Storage records. 
            \end{enumerate}
        \section{R with Python}   \label{se:testing_r_with_python}
            To test the functionality of the R to Python to HTML bridge, you will need to do the following:\\
            \vspace{-8mm}
            \begin{enumerate}
            \item  Login as admin
            \item  Click the analytics page
            \item  Select ``Add R File"
            \item  Upload the R file using provided GUI
            \item  Select ``Submit"
            \item  You should now see a new line of input on the analytics page. Select either ``view" or ``run" -- if you select ``view" you must then select ``run" and in both situations you will be redirected to the output of the R code that was input in an HTML page format.
            \end{enumerate}
        \section{Troubleshooting}
            Django offers its own debugging tool to help developers troubleshoot errors that arise within their websites.  When errors occur, the debugger will output useful information so developers/programmers can find where and why these errors occur.  The website is currently running in production, so the debugger has been turned off.  However, developers can turn the debugger on by navigating to the settings.py folder found at the following path:
            \par
            \quad \quad \quad PFP\_WEB/PFP\_WEB/settings.py
            \par
            After navigating to the file, programmers will need to change the DEBUG and ALLOWED\_HOSTS settings.  DEBUG needs to be changed to true and the ALLOWED\_HOSTS setting needs to be changed to an empty list.
            \par
            \quad \quad \quad DEBUG = True \par
            \quad \quad \quad ALLOWED\_HOSTS = []
            \par
            After changing these settings, the debugger will be on and programmers will be able to troubleshoot any errors within the site.
            \par
            After fixing any errors, it's important for the programmers to change the settings back to what they were before.  The DEBUG and ALLOWED\_HOSTS settings should look like this:
            \par
            \quad \quad \quad DEBUG = False \par
            \quad \quad \quad ALLOWED\_HOSTS = [`*']
        
% ====================================================================
%                       CH: Lessons Learned
% ====================================================================
    \chapter{Lessons Learned} \label{ch:lessons_learned}
        \section{Timeline/Schedule}  \label{se:timeline_schedule}
        \begin{center}
            \includegraphics[scale=0.45]{images/timeline.png}
            \captionof{figure}{An image of our timeline}
            \label{fig:timeline}
        \end{center}
        
        The timeline shown in Figure 7.1 was the schedule we had set for completing this project. We split up the project into six sub-tasks and organized them based on priority or logical order.
     
        \emph{Create Login System and Accounts}:\\
    	We decided to work on the login and accounts functionality first. The reason is so we can build a rough web interface that will act as our foundation. The login system and accounts weren't complicated to implement, but it allowed us to set up some of the basic web functionality into our web page.\\ 
    
        \emph{Upload File for Data Injection}:\\
    	Next, we supported file upload functionality to our web page.  From the front-end perspective, this functionality simply allows users to upload TMRTracker templates and Select Sires files. The file(s) containing the data must be in the range of allowed format. From the back-end perspective, we are making sure that the file is being parsed correctly. This also includes making sure the parsed data are stored in their appropriate table in the database.
            
        \emph{Pushing File Uploads to Database}:\\
    	Next, after properly parsing data from the uploaded file, we pushed the data to our database. Originally, we are using SQLite as our temporary Database Management System but had moved on to MySQL to support client and server architecture.
    
        \emph{User Dashboard}:\\
    	The user dashboard covers the majority of the user interface for the website. We made sure that our website is accessible and simple enough for farmers to use. We've organized different pages into tabs on the side menu so farmers can easily access information. We've also made sure to set a common style/format for all the pages. This is to allow design consistency throughout the website and for any new pages that may get added later on.
    
        \emph{Data Analytics}:\\
    	Admins and staff who need to upload their R scripts can upload their scripts and run said scripts from the website. However, as of current, any data analytics to be gathered from running R scripts would have to be done within the R script itself, as the current functionality of the site does not support otherwise.
	
        \emph{Web Hosting}:\\
        Unfortunately, the web framework could not be hosted by the Virginia Tech rlogin cluster since the rlogin cluster's operating system is CentOS7 which is incompatible with the project's version of Django. We were given the task to containerize the project and run the project container on the Virginia Tech cloud container cluster service. Since the cloud container cluster using Kubernetes for container orchestration and workload management, we started trying to make YAML files that would create the Kubernetes deployment container. Thanks to Chris Arnold in Virginia Tech Tech Staff, we learned that we could manually create the deployment on the cloud container cluster user interface by giving our project Docker image and a couple of other parameters. The deployment container works but the Apache configuration file currently is not set up with our web framework. The lessons learned in this part of the project was getting a high level introduction to containerization with Docker and container orchestration with Kubernetes. 
        % \section{Problems}  \label{se:problems}
        %     \subsection{Problem: Hosting the website on a server} \label{ss:problem1}
        %     At first, the plan was to host the website on Rlogin, VT CS Department server, but there were complications with the backend using Django. The project first used PHP to develop the web interface because Rlogin supports it, but was scrapped after running into errors. The project then moved on to use the Django framework instead. Since Rlogin does not support Django, the next option is to host the web server on a container, such as Docker, on Rlogin.
            
        % \section{Solutions}  \label{se:solution}
        %     \subsection{Solution: Hosting the website on a server} \label{ss:solution1}
        %     Work in progress.
    
% ====================================================================
%                       CH: FUTURE WORK
% ====================================================================
	\chapter{Future Work} \label{ch:summary}
    As of the point in time of producing this document, the requirements given by the clients have been met in accordance to what has been given. However, while the development team has accomplished meeting expectations for herd diets (ingredients/mixes), front end functionality, farmer sign up and log in, R to Python data analysis connection, and personalized data storage, what is left to be completed are the following items:
    \begin{enumerate} 
        \item Interface and data management tool for bovine product progress (this is separate from the completed diet and ingredient data management tool)
        \item R anomaly detection
        \item Statistical data visualization tool
        \item Weather data visualization interface
        \item Full data management interface for cumulative data resources (an interface for the farmer to manage \textbf{all} of their data)
        \item Cumulative interface that links to and incorporates every aspect of the web site (this is a home page that gives a basic interface to each tool the website provides in a convenient manner)
        \item Need to add Pen information to diets. Must retrieve Pen information from Select Sires or through other means. 
        \item Staff notifications for user edits for ingredients and mixes within X number days; you will need to set the value of X (EDIT\_NOTIFY\_DAYS) in PFP\_WEB/core/views.py. 
        \item Staff notifications will need to expand to diets. 
        \item Staff commit user edits may need a backtrack option. Enable the ability to revert committed changes and or see list of all staff commits with detailed information. 
        \item Edit email settings on PFP\_WEB/PFP\_WEB/settings.py to use an account more professional to the Dairy Feeding Project in production.
        \item Create testing scripts to test more efficiently. 
        \item Correct the Apache Configuration file (api.conf) to communicate with Django and display the web framework at the dis.cs.vt.edu
        \item Add commands to install the R programming language on CentOS8 and set R to the path variable in the Dockerfile. 
        \item Set up MySQL container with persistent volume on Virginia Tech's cloud container cluster. 
    \end{enumerate}
	

% ====================================================================
%                       CH: ACKNOWLEDGEMENT
% ====================================================================
	\chapter{Acknowledgement}
	We would like to acknowledge our clients and members of the Dairy Feeding Framework project. 
	
	Mark Hanigan, Dairy Science Professor           \\
    Wu Feng, Computer Science Professor             \\
    Leticia M. Campos, Dairy Science Ph.D. Student  \\
	Sonal Jha, Graduate Research Assistant          \\
    Charles Zawacki, Research Assistant             \\
    Yanlin Du, Research Assistant                   \\
    
    
% ====================================================================
%                       CH: REFERENCES
% ====================================================================
    \chapter{References}
	[1] Django Developers, “Documentation Django 3.2,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/. [Accessed: 04-May-2021].
	
    [2] Django Developers, “Documentation Django Forms,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/topics/forms/. [Accessed: 04-May-2021].
    
    [3] Django Developers, “Documentation Django Models,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/topics/db/models/. [Accessed: 04-May-2021]. 
	
    [4] Django Developers, “Documentation Django Templates,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/topics/templates/. [Accessed: 04-May-2021]. 
    
    [5] Django Developers, “Documentation Django URLs,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/topics/http/urls/. [Accessed: 04-May-2021]. 
    
    [6] Django Developers, “Documentation Django Views,” 2021. [Online]. Available: https://docs.djangoproject.com/en/3.2/topics/http/views/. [Accessed: 04-May-2021]. 

	[7] Docker Developers, “Orientation and setup,” Docker Documentation, 2021. [Online]. Available: https://docs.docker.com/get-started/. [Accessed: 04-May-2021]. 
	
	[8] RPY2 Developers “Introduction to rpy2,” rpy2 3.5.0dev documentation, 2017. [Online]. Available: https://rpy2.github.io/doc/latest/html/introduction.html. [Accessed: 04-May-2021]. 
	
	[9] RStudio Developers, “Introduction R Markdown,” 2020. [Online]. Available: https://rmarkdown.rstudio.com/lesson-1.html. [Accessed: 04-May-2021]. 
	
	[10] Select Sires Development Team, Select Sires, 2021. [Online]. Available: https://www.selectsires.com/ [Accessed: 04-May-2021]. 
	
	[11] Digi-Star TMR Tracker Solution, Digi-Star, 2021. [Online]. Available: https://digi-star.com/solutions/2-2/TMR\_Tracker. [Accessed: 13-may-2021]
	
    [12] WeatherBit Developers, Weatherbit, “Weather API for You,” 2021. [Online]. Available: https://www.weatherbit.io/. [Accessed: 29-Apr-2021]. 
	
    

    
    

% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\end{document}


%****************************************************************************
% 
% Below are some general suggestions for writing your dissertation:
%
% 1. Label everything with a meaningful prefix so that you
%    can refer back to sections, tables, figures, equations, etc.
%    Usage \label{<prefix>:<label_name>} where some suggested
%    prefixes are:
%			ch: Chapter
%     		se: Section
%     		ss: Subsection
%     		sss: Sub-subsection
%			app: Appendix
%     		ase: Appendix section
%     		tab: Tables
%     		fig: Figures
%     		sfig: Sub-figures
%     		eq: Equations
%
% 2. The VTthesis class provides for natbib citations. You should upload
%	 one or more *.bib bibtex files. Suppose you have two bib files: some_refs.bib and 
%    other_refs.bib.  Then your bibliography line to include them
%    will be:
%      \bibliography{some_refs, other_refs}
%    where multiple files are separated by commas. In the body of 
%    your work, you can cite your references using natbib citations.
%    Examples:
%      Citation                     Output
%      -------------------------------------------------------
%      \cite{doe_title_2016}        [18]
%      \citet{doe_title_2016}       Doe et al. [18]
%      \citet*{doe_title_2016}      Doe, Jones, and Smith [18]
%
%    For a complete list of options, see
%      https://www.ctan.org/pkg/natbib?lang=en
%
% 3. Here is a sample table. Notice that the caption is centered at the top. Also
%    notice that we use booktabs formatting. You should not use vertical lines
%    in your tables.
% 
%				\begin{table}[htb]
%					\centering
%					\caption{Approximate computation times in hh:mm:ss for full order 						versus reduced order models.}
%					\begin{tabular}{ccc}
%						\toprule
%						& \multicolumn{2}{c}{Computation Time}\\
%						\cmidrule(r){2-3}
%						$\overline{U}_{in}$ m/s & Full Model & ROM \\
%						\midrule
%						0.90 & 2:00:00 & 2:08:00\\
%						0.88 & 2:00:00 & 0:00:03\\
%						0.92 & 2:00:00 & 0:00:03\\
%						\midrule
%						Total & 6:00:00 & 2:08:06\\
%						\bottomrule
%					\end{tabular}
%					\label{tab:time_rom}
%				\end{table}
% 
% 4. Below are some sample figures. Notice the caption is centered below the
%    figure.
%    a. Single centered figure:
%					\begin{figure}[htb]
%						\centering
%						\includegraphics[scale=0.5]{my_figure.eps}
%						\caption{Average outlet velocity magnitude given an average  
%				        input velocity magnitude of 0.88 m/s.} 
%						\label{fig:output_rom}
%					\end{figure}
%    b. Two by two grid of figures with subcaptions
%					\begin{figure}[htb]
%						\centering
%						\begin{subfigure}[h]{0.45\textwidth}
%							\centering
%							\includegraphics[scale=0.4]{figure_1_1.eps}
%							\caption{Subcaption number one}
%							\label{sfig:first_subfig}
%						\end{subfigure}
%						\begin{subfigure}[h]{0.45\textwidth}
%							\centering
%							\includegraphics[scale=0.4]{figure_1_2.png}
%							\caption{Subcaption number two}
%							\label{sfig:second_subfig}
%						\end{subfigure}
%
%						\begin{subfigure}[h]{0.45\textwidth}
%							\centering
%							\includegraphics[scale=0.4]{figure_2_1.pdf}
%							\caption{Subcaption number three}
%							\label{sfig:third_subfig}
%						\end{subfigure}
%						\begin{subfigure}[h]{0.45\textwidth}
%							\centering
%							\includegraphics[scale=0.4]{figure_2_2.eps}
%							\caption{Subcaption number four}
%							\label{sfig:fourth_subfig}
%						\end{subfigure}
%						\caption{Here is my main caption describing the relationship between the 4 subimages}
%						\label{fig:main_figure}
%					\end{figure}
%
%----------------------------------------------------------------------------
%
% The following is a list of definitions and packages provided by VTthesis:
%
% A. The following packages are provided by the VTthesis class:
%      amsmath, amsthm, amssymb, enumerate, natbib, hyperref, graphicx, 
%      tikz (with shapes and arrows libraries), caption, subcaption,
%      listings, verbatim
%
% B. The following theorem environments are defined by VTthesis:
%      theorem, proposition, lemma, corollary, conjecture
% 
% C. The following definition environments are defined by VTthesis:
%      definition, example, remark, algorithm
%
%----------------------------------------------------------------------------
%
%  I hope this template file and the VTthesis class will keep you from having 
%  to worry about the formatting and allow you to focus on the actual writing.
%  Good luck, and happy writing.
%    Alan Lattimer, VT, 2016
%
%****************************************************************************

% Possible areas to change:
% -Chapter 5.36 (R Analysis stuff, could change bc we added that)               - Oli
% -Chapter 5.5 (Docker stuff is blank atm)                                      - Evan
% -Chapter 6 (Testing is blank atm)                                             - Dwarakh Oli
% -Chapter 7 (Troubleshooting is blank atm)                                     - Mike
% -Chapter 8.1 (the description of the timeline contains a few TBD's)           - Kevin (DONE)
% -Chapter 8.3 (solution talks about us hosting the website which isnt done)   - 
% -Chapter 9 (future work would be subject to change since we added more stuff) - 



