πŸ§ͺ DSCI 554 lab 1

Tooling, Web dev, line and pie charts with Google Sheets and Google Charts.

Dr. Luciano Nocera

🧰 Tooling: Chrome, node, VS Code

Install Google Chrome


Download and install from https://www.google.com/chrome
🚨 Make Chrome the default browser for assignments & labs

Install Node


Download and install node LTS from https://nodejs.org

Install Visual Studio Code


Download and install from https://code.visualstudio.com
Install code:
View > Command Palette... > Shell command: Install 'code' command in PATH
πŸ’‘ Learn most used keyboard shortcuts: Windows, macOS, Linux

🧰 Tooling: git

Create a GitHub account with your USC username!


🚨 Assignments from non USC accounts will not be graded!

Install Git


  • Mac (in terminal install xcode dev): xcode-select --install
  • Windows: download and install from https://git-scm.com

Install GitHub Desktop


Download and install from https://desktop.github.com
πŸ’‘ In Windows use GitBash to run shell commands or the terminal in VS Code

Getting started with assignments

  1. Accept the assignment from the course home-page or Blackboard under Content > Week 1
  2. Get assignment GitHub link:
  3. Clone repository:
    1. GitHub Desktop (preferred): File → Clone Repository
    2. VS Code: Git Clone command
    3. Command line (create a personal access token first):
      
      										$ mkdir hw
      										$ cd hw 
      										$ git clone https://github.com/DSCI554/a1-lnocera-1.git
      									
  4. Open the folder in VS Code:
    
    								$ cd a1-lnocera-1
    								$ code -n .
    							

🎒 starter code tour


						ASSIGNMENT.md  #assignment rubric in markdown
						README.md  #repository README in markdown
						index.html
						lab/  #lab files
						  ex1.html   #lab exercise file
						  ex2.html
						  simple-exe/
						    faithful.csv
						    node_modules
						    package-lock.json
						    package.json
						    simple-exe
						  simple-html/
						    index.html
						    node_modules
						    package-lock.json
						    package.json
						  simple-vue/
						    README.md
						    babel.config.js
						    node_modules
						    package-lock.json
						    package.json
						    public
						    src
						    vue.config.js							
						  style.css									
						node_modules  #node modules created when running npm install
						package-lock.json
						package.json  #package.json file
					

πŸ”¨ simple-exe: node command line interface (CLI)

Node.js (JavaScript runtime environment)

						$ node
						> console.log('hello JavaScript')
						> a = [1, 'b', 'c', 2]
						> a.concat(a)
					
This is how to generate files for a CLI executable using npm (JavaScript package manager):
🚨 If you cut-and-paste the commands below do not copy the comments starting with #
$ npm init
$ npm install commander csv-parse #fetch libs in node_modules and adds references in package.json
$ cat > mycli  #create mycli executable
#!/usr/bin/env node
console.log('hello mycli');
$ chmod +x mycli
$ ./mycli
$ code -n .  #open current folder in VS Code
					
πŸ’‘ Debug with console.log() and VS Code debugger (launch.json file)

					{
					 "type": "pwa-node",
					 "request": "launch",
					 "name": "exe args",
					 "skipFiles": [
					  "/**"
					 ],
					 "program": "${workspaceFolder}/bin/exe",
					 "args": ["arg1", "arg2"]
					}
					

πŸ”¨ simple-html: Web page

πŸ’‘ Debug in Chrome with DevTools
πŸ’‘ In Windows use GitBash to execute or VS Code terminal
To debug in Chrome:
  1. Open index.html in Chrome
  2. Open DevTools: View β†’ Developer β†’ Javascript Console
DevTools shortcuts:
Action Mac Windows / Linux
Open whatever panel you used last Command+Option+I F12 or Control+Shift+I
Open the Console panel Command+Option+J Control+Shift+J
Open the Elements panel Command+Shift+C or Command+Option+C Control+Shift+C

πŸ”¨ simple-vue: Vue.js Web app

Run the Vue.js (JavaScript framework) app in VS Code:

						$ cd simple-vue
						$ code -n .  #open simple-vue project
						$ npm install #only when updating package.json with new packages
						$ npm run serve #use vue cli (see in package.json)
					
πŸ’‘ Debug with console.log() or Vue DevTools extension and Chrome
To create a new Vue.js app:

						$ npm install -g @vue/cli  #install vue CLI globally
						$ vue --version
						$ vue create my-app  #choose default vue 2!
					
To debug in Chrome update the devtool property inside vue.config.js:

						$ cat > vue.config.js
						module.exports = {
						  configureWebpack: {
						    devtool: 'source-map'
						  }
						}
					

Graphing with Google Sheets

  1. Read the documentation:
  2. Format the data
  3. Generate the graph

Lab exercises

πŸ‹πŸ½β€β™‚οΈ ex1: line chart in Google Sheets using CCSE COVID-19 dataset

  • Follow the instructions in ex1.html

πŸ‹πŸ½β€β™‚οΈ ex2: Implement a Google Charts pie chart

  • Follow the instructions in ex2.html
πŸ’‘ Implemented and test one step at the time then commit & push!
🚨 Make sure to commit & push by the deadline (15% of grade)

Reference Slides

Git basics

πŸ’‘ You will use git to store and version your code
πŸ’‘ git snapshots are tracked using a SHA-1 hash
πŸ’‘ The git repository is located in .git/

Example SHA-1 hash

ca412e3a7968b81b247fa7ae40c2fd5bf7fb3308

Commands to know


  • clone: fetch copy of remote
  • checkout: create working copy
  • add/rm: mark files to add
  • commit: save changes
  • pull: fetch changes from remote
  • push: upload changes to remote

Markdown basics

πŸ’‘ Use Markdown to document your work
πŸ’‘ Markdown files have .md extension, e.g., README.md
πŸ’‘ Visual Studio Code let's you preview the Markdown
πŸ’‘ README.md is rendered as HTML by GitHub

Markdown



							# Title
							## Subtitle
							__HTML__ `inline` code:

							```html
							<h1 style="color: red">Header 1</h1>
							<h2>Header 2</h2>
							<h3>Header 3</h3>
							```

							A list:

							- [hyperlink text](https://guides.github.com/)
							- list item
							- list item
						

Rendering of Markdown


HTML basics

πŸ’‘ Only the contents of the body tag are visible!
πŸ’‘ Spaces, tabs and newlines outside of html elements are not rendered!

Body



							<h1>Header</h1>

							<h2>Sub-header</h2>
							
							<p>paragraph with text</p>     and some more text
							directly in the body
							<p>
							  Some text with a 
							  <a href="some_url">hyperlink</a>
							</p>
						

Rendering of Body


Header

Sub-header

paragraph with text

and some more text directly in the body

Some text with a hyperlink

UN Data for the assignment

A1 is modeled after Cairo’s example from this week reading so it might help if you read that first.

The goal is to create a toy dataset we can use for the rest of the class.

Find a UNData dataset to use from the Datamarts page: