Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # --------------------------------------------------------------------------------------------
  4. # Machine Learning Project Directory and Environment Setup
  5. # --------------------------------------------------------------------------------------------
  6. # Automatically generates a basic scaffold for machine learning projects. Sets up
  7. # the directory structure along with both a nodejs and python environment as well.
  8. # Environment can be modified as needed with additional packages installed for both
  9. # python and nodejs as well as additional directories being created.
  10. #
  11. # --------------------------------------------------------------------------------------------
  12. # Author Info
  13. # --------------------------------------------------------------------------------------------
  14. # Name :: Tim Kennell Jr. ~ tikenn
  15. #
  16. # --------------------------------------------------------------------------------------------
  17. # Config
  18. # --------------------------------------------------------------------------------------------
  19. # LICENSE_FILE :: the location of the license file to attach to the project
  20. #
  21. # --------------------------------------------------------------------------------------------
  22. # Setting up crontab
  23. # --------------------------------------------------------------------------------------------
  24. # - Create a file in /etc/cron.d/
  25. # - Suggested to run the file once a week
  26. # - Example line (runs at midnight): "0 0 * * 1 /path/to/le-renew-haproxy"
  27. #
  28. # ~ tikenn
  29.  
  30. LICENSE_FILE='licenses/MIT.txt'
  31.  
  32.  
  33. # Detects "y", "n", "yes", and "no" user response in a case-insensitive manner
  34. # param String $1
  35. ## Ex: yes_response "y" --> returns 0
  36. ## Ex: yes_response "yes" --> returns 0
  37. ## Ex: yes_response "n" --> returns 0
  38. ## Ex: yes_response "no" --> returns 0
  39. ## Ex: yes_response "" --> returns 1
  40. ## Ex: yes_response "gobble de guk" --> returns 1
  41. yes_no_response() {
  42. if [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = y ]] \
  43. || [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = yes ]] \
  44. || [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = n ]] \
  45. || [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = no ]] ; then
  46.  
  47. return 0
  48. else
  49. return 1
  50. fi
  51. }
  52.  
  53. # Detect "y" or "yes" response as affirmative answer in case-insensitive manner
  54. # param String $1
  55. ## Ex: yes_response "yes" --> returns 0
  56. ## Ex: yes_response "no" --> returns 1
  57. ## Ex: yes_response "gobble de guk" --> returns 1
  58. yes_response() {
  59. if [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = y ]] \
  60. || [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = yes ]] ; then
  61.  
  62. return 0
  63. else
  64. return 1
  65. fi
  66. }
  67.  
  68. # Detect "n" or "no" response as affirmative answer in case-insensitive manner
  69. # param String $1
  70. ## Ex: no_response "no" --> returns 0
  71. ## Ex: no_response "yes" --> returns 1
  72. ## Ex: no_response "gobble de guk" --> returns 1
  73. no_response() {
  74. if [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = n ]] \
  75. || [[ $(echo "$1" | tr -s '[:upper:]' '[:lower:]') = no ]] ; then
  76.  
  77. return 0
  78. else
  79. return 1
  80. fi
  81. }
  82.  
  83. # Asks for the name of the project
  84. get_project_name() {
  85. local project_name
  86. while [[ -z ${project_name} ]] ; do
  87. read -p "Project name: " project_name
  88. [[ -z "${project_name}" ]] && echo "A project name must be supplied"
  89. done
  90.  
  91. # return value
  92. echo "$project_name"
  93. }
  94.  
  95. # Asks a user for the location to create the project in
  96. # @return {String} The folder location to create the project
  97. ml_project_creation_folder() {
  98. local folder
  99. local current_folder_creation
  100. while ! yes_no_response "$current_folder_creation" ; do
  101. read -p "Create project in the current folder [Y/n]: " current_folder_creation
  102. if [[ -z "$current_folder_creation" ]] || yes_response ${current_folder_creation} ; then
  103. current_folder_creation='y'
  104. folder='.'
  105.  
  106. elif no_response ${current_folder_creation} ; then
  107. while [[ -z ${folder} ]] ; do
  108. read -p "Project folder location (abs path): " folder
  109. [[ -z ${folder} ]] && echo "Must provide a folder!"
  110. done
  111.  
  112. else
  113. echo "This program speaks english, please try again..."
  114. fi
  115. done
  116.  
  117. # return value
  118. echo "$folder"
  119. }
  120.  
  121.  
  122. # --------------------------------
  123. # Get Project Name
  124. # --------------------------------
  125. PROJECT_NAME=''
  126. while [[ -z ${PROJECT_NAME} ]] ; do
  127. read -p "Project name: " PROJECT_NAME
  128. [[ -z "${PROJECT_NAME}" ]] && echo "A project name must be supplied"
  129. done
  130.  
  131. echo "$PROJECT_NAME"
  132.  
  133. # --------------------------------
  134. # Get Project Folder Location
  135. # --------------------------------
  136. PROJECT_PARENT_FOLDER=''
  137. current_folder_creation=''
  138. while ! yes_no_response "$current_folder_creation" ; do
  139. read -p "Create project in the current folder [Y/n]: " current_folder_creation
  140. if [[ -z "$current_folder_creation" ]] || yes_response ${current_folder_creation} ; then
  141. current_folder_creation='y'
  142. PROJECT_PARENT_FOLDER='.'
  143.  
  144. elif no_response ${current_folder_creation} ; then
  145. while [[ -z ${PROJECT_PARENT_FOLDER} ]] ; do
  146. read -p "Project folder location (abs path): " PROJECT_PARENT_FOLDER
  147. [[ -z ${PROJECT_PARENT_FOLDER} ]] && echo "Must provide a folder!"
  148. done
  149.  
  150. else
  151. echo "This program speaks english, please try again..."
  152. fi
  153. done
  154.  
  155. echo "$PROJECT_PARENT_FOLDER"
  156.  
  157. # --------------------------------
  158. # Create project folders
  159. # --------------------------------
  160.  
  161. # Project directory
  162. if [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME" ]] ; then
  163. echo "Error: project ($PROJECT_PARENT_FOLDER/$PROJECT_NAME) already exists; terminating..."
  164. exit 1
  165. fi
  166.  
  167. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME" ]] || mkdir "$PROJECT_PARENT_FOLDER/$PROJECT_NAME"
  168.  
  169. # High level directories for managing configurations and data
  170. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/config" ]] || mkdir "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/config"
  171. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/databases" ]] || mkdir "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/databases"
  172.  
  173. # Lib directories for universal functions and objects
  174. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/data" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/data"
  175. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/features" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/features"
  176. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/models" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/models"
  177. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/visualizations" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/visualizations"
  178. [[ -f "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/__init__.py" ]] || touch "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/lib/__init__.py"
  179.  
  180. # Training directories for iterating through machine learning process
  181. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/feature_exploration" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/feature_exploration"
  182. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/log" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/log"
  183. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/results" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/results"
  184. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/visualizations" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/visualizations"
  185. [[ -d "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/model" ]] || mkdir -p "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/train/iteration 1/model"
  186.  
  187. # --------------------------------
  188. # License and Readme
  189. # --------------------------------
  190. cat "$LICENSE_FILE" | sed -r \
  191. -e 's/\[year\]/'$(date +"%Y")'/i' \
  192. -e 's/\[fullname\]/Timothy Kennell Jr\./i' \
  193. > "$PROJECT_PARENT_FOLDER/$PROJECT_NAME/LICENSE"
  194.  
  195. # --------------------------------
  196. # Setup NodeJS environment
  197. # --------------------------------
  198. CWD=$(pwd)
  199. cd "$PROJECT_PARENT_FOLDER/$PROJECT_NAME"
  200. npm init
  201. npm install mysql
  202.  
  203. # --------------------------------
  204. # Setup Python environment
  205. # --------------------------------
  206. conda_environment_name=$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | sed -re 's/ /_/g')
  207. conda create -n "$conda_environment_name"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement