Skip to content
Snippets Groups Projects
Commit a0479788 authored by keleher's avatar keleher
Browse files

Merge branch 'master' of gitlab.cs.umd.edu:keleher/424f19

parents a32dcc01 a4b62d34
No related branches found
No related tags found
No related merge requests found
Showing
with 268 additions and 297 deletions
setenv LANG "en_US.utf-8"
setenv PATH "${PATH}:${HOME}/bin"
setenv PATH "${PATH}:${HOME}/.cargo/bin"
setenv PATH "${PATH}:/usr/local/bin:/usr/games/bin:/usr/sbin:/usr/local/mysql/bin:/sbin:/usr/local/texlive/2014/bin/x86_64-darwin:."
setenv PATH "/opt/local/bin:/opt/local/sbin:$PATH"
setenv PATH "/usr/local/graphviz-2.14/bin:$PATH"
setenv PATH "/Users/keleher/bin:$PATH"
setenv BLOCKSIZE 1024
if ( $OSTYPE == "linux" ) then
setenv GOPATH "/home/keleher/go:/home/keleher/space/go"
setenv PATH "/usr/local/go/bin:/home/keleher/go/bin:/home/keleher/space/go/bin:$PATH"
else
setenv GOPATH "/Users/keleher/go:/Users/keleher/space/go"
setenv PATH "/usr/local/go/bin:/Users/keleher/go/bin:/Users/keleher/space/go/bin:$PATH"
endif
setenv PERL5LIB "/opt/local/lib/perl5/site_perl/5.12.3"
if ( ! $?prompt ) exit
# move rosana's pics to another directory
# exiftool -if '$model eq "iPhone 6"' -directory=../../group_rosana_and_pete_trip/ *png
setenv S3_ACCESS_KEY_ID AKIAJTQWQCMTADVH5JRQ
setenv S3_SECRET_ACCESS_KEY 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
#setenv TERM_PGRM none
set hostname=`/bin/hostname | sed "s/\..*//"`
#stty crt erase 
#set notify mail=/usr/spool/mail/$user
setenv TTY `tty`
setenv EDITOR emacs
setenv PAGER 'less -i -M -e -c'
setenv DISP "${HOST}:0"
setenv PS ps4
# Add an architecture-specific directory to your path. This way you can
# put your own SPARCstation binaries in ~/bin/sun4, DECstation binaries in
# ~/bin/mips, etc.
set history=100 noclobber
umask 022
#bindkey "^[delete" delete-word
bindkey "^[h" backward-delete-word
bindkey "^[H" backward-delete-word
bindkey "\310" backward-delete-word
bindkey "\350" backward-delete-word
bindkey "^R" i-search-back
bindkey "^S" i-search-fwd
# Pete's local modifications
if ( $TERM == "network" ) then
setenv TERM vt220
endif
limit coredumpsize 0
unset ignoreeof
unset noclobber
alias a alias
# encode jpgs to a time-lapse, must be run from bash
a timeLapse 'mencoder mf://*.JPG -mf w=1920:h=1080:fps=25:type=jpg -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=16000:keyint=15:mbd=2:trell -oac copy -o output.avi'
a tog "ssh -p 1022 pi@keleher.duckdns.org 'gpio write 7 0;sleep 1;gpio write 7 1'"
a rvm 'rvm.tcsh'
a topc 'top -o cpu'
a getsite 'wget --recursive --no-clobber --page-requisites --html-extension --convert-links "\!*"'
# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
# git init --bare
# git clone triffid.cs.umd.edu:/home/archive/git/dss
a gitauto 'git commit -a -m auto'
#a gitpush 'git push origin master'
a gpull 'git pull origin master'
a greset 'git reset --hard FETCH_HEAD'
a gall '(cd ~/ios/cmsc436spring2019-student; echo; echo "cmsc436spring2019-student"; gpull; cd ../ios436; echo; echo "ios436"; gpull; cd ../ios436demos; echo; echo "ios436demos"; gpull; cd ../ios436tas; echo; echo "ios436tas"; gpull)'
a push '(cd ~/ios/cmsc436spring2019-student; echo; echo "cmsc436spring2019-student"; gush; cd ../ios436; echo; echo "ios436"; gush; cd ../ios436demos; echo; echo "ios436demos"; gush; cd ../ios436tas; echo; echo "ios436tas"; gush)'
a gush 'git commit -a -m auto; git push origin master'
a gushm 'git commit -a -m \!*; git push origin master'
a gitRestage 'git reset HEAD; git checkout -- .'
a clonetriffid 'git clone triffid.cs.umd.edu:/home/archive/git/dss'
a flowclone 'git clone git@bitbucket.org:keleher/flow.git'
a dssclone 'git clone git@gitlab.cs.umd.edu:keleher/dss.git'
a bfsclone 'git clone git@github.com:keleher/bfs.git'
a libraryshow 'chflags nohidden ~/Library/'
a libraryhide 'chflags hidden ~/Library/'
a rmtilde 'rm `find . -name "*~" -print`'
a f 'find . -name \!* -print'
#a f "sh -c 'find . -name \\!* -print 2> /dev/null'"
a timeread 'time dd if=tstfile bs=1024k of=/dev/null count=1024'
a timewrite 'time dd if=/dev/zero bs=1024k of=tstfile count=1024'
a mojo eftp mojo 'umd-csd-nt\\keleher'
a pdf_remove_crypto 'gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=\!:1:r_nopasswd.pdf -c .setpdfwrite -f \!:1'
a zp 'lpr -Pps4 \!*'
a q 'lpq -Pps4'
a qrm 'lprm -Pps4 \!*'
a putflow 'rsync -avz ~/.flow \!*\:'
a getflow 'rsync -avz \!*\:.flow ~/'
a getshortcuts 'scp hub.local:Library/Preferences/com.nulana.shortcuts.plist Library/Preferences'
a putshortcuts 'scp Library/Preferences/com.nulana.shortcuts.plist hub.local:Library/Preferences'
a getcshrc 'scp hub.local:.{emacs,cshrc} ~/'
a putcshrc 'scp ~/.{emacs,cshrc} hub.local:'
a vnc 'vncserver -geometry 1280x1024'
a zdvi 'pstex -q ps4 \!*'
a zv 'pstex -q ps4 \!*'
a zd 'pstex -q ps4 \!*'
a zq 'rqstat ps4'
a qrmjob 'rqmod -k \!*'
a ctan 'ftp pip.shsu.edu'
a lth 'ls -lt \!* | head'
a color_slides lpr -Ppolaroid
a color_paper lpr -Ppolapaper
a recipes 'ftp CADADMIN.CADLAB.VT.EDU'
a ta 'tail -2000 \!* | most'
a tim 'awk -f ~/Bach/awk/awkTimers \!* | most'
a uu 'awk -f ~/bin/sun4/awkuu \!* | uudecode >& /dev/null'
a backupsecondinterval 'sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int \!*'
a p 'lpr -p -o sides=two-sided-long-edge \!*'
a babel "gpsbabel -i nmea -f \!:1 -x discard,hdop=10,vdop=10,hdopandvdop,sat=4 -o gpx -F \!:2"
a dpdf 'pdflatex \!*; bibtex \!*; pdflatex \!*; pdflatex \!*; open \!*.pdf'
a doh 'latex \!*; bibtex \!*; latex \!*; latex \!*; dvips -Ppdf -G0 \!*; dvips -Ppdf -G0 \!*; ps2pdf \!*.ps; open \!*.pdf'
a proposal "gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=1 -dLastPage=15 -sOutputFile=desc.pdf \!*.pdf; gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=16 -sOutputFile=refs.pdf \!*.pdf"
a doh 'latex \!*; bibtex \!*; latex \!*; latex \!*; dvips -Ppdf -G0 \!*; ps2pdf \!*.ps; open \!*.pdf'
a proposalold "pdftk \!*.pdf cat 1-15 output desc.pdf;pdftk \!*.pdf cat 16-end output refs.pdf"
a mttriffid 'sshfs -p 22 keleher@triffid.cs.umd.edu: ~/triffid -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mthyperion 'sshfs -p 22 keleher@hyperion.cs.umd.edu: ~/hyperion -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mtsedna 'sshfs -p 22 keleher@sedna.cs.umd.edu: ~/sedna -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mthiring 'sshfs -p 22 keleher@hiring: ~/hiring -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mthyperion 'sshfs -p 22 keleher@hyperion: ~/hyperion -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mtlagoon 'sshfs -p 22 keleher@lagoon: ~/lagoon -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
a mtsp1 'sshfs -p 22 keleher@spore1: ~/spore1 -oauto_cache,reconnect,defer_permissions,noappledouble,negative_vncache,volname=myVolName,follow_symlinks'
#a zcat 'gunzip -c'
a setmachostname 'sudo scutil --set HostName \!*'
a indexon 'sudo mdutil -a -i on'
a indexoff 'sudo mdutil -a -i off'
a startupvolume - 'sudo bless -mount \!* -setBoot'
a backupsoff 'defaults write com.apple.iTunes DeviceBackupsDisabled -bool true'
a backupson 'defaults write com.apple.iTunes DeviceBackupsDisabled -bool false'
a convertplist 'plutil -convert xml1 \!*'
a hiddenfileson 'defaults write com.apple.Finder AppleShowAllFiles YES'
a hiddenfilesoff 'defaults write com.apple.Finder AppleShowAllFiles NO'
a cpan "sudo /usr/bin/perl -MCPAN -e 'install \!*'"
a nman 'nroff -man \!* | m'
a ae "open -a /Applications/Aquamacs\ Emacs.app/ "
a dist 'rdist -f ~/src/distfile \!*'
set host=`hostname`
a apropos 'man -k' #simulates the apropos command
set nobeep
set history = 150
set savehist = 150
a pd pushd
a pps "ps uax | grep keleher"
a psm "ps uax | m"
a pws "ps uaxw | grep keleher"
a hcp 'scp -P 10022 -r \!* keleher.duckdns.org:Desktop'
a lk "grep \!* [^,]*.{cc,md,c,go,pl,html,h,py,s,H,U,tex,java}"
a lki "grep -i \!* [^,]*.{cc,md,c,go,pl,html,h,py,s,H,U,tex,java}"
a lkw "grep -w \!* [^,]*.{cc,md,c,go,pl,html,h,py,s,H,U,tex,java}"
a pv 'ps vax | grep '
a k kill -9
a ka killall -KILL
a l ls -CF
a ll "ls -alh \!*"
a llm "ls -alh \!* | m"
a lsd "ls -alhd \!*"
a m 'less -i -M -e -c'
set prompt_info = "%m:%~> "
if ($?RUBY_VERSION) then
set prompt_info = "[$RUBY_VERSION] $prompt_info"
endif
set prompt = "$prompt_info"
a tem '/usr/bin/stty rows 51 cols 93 ; emacs19'
a e 'emacs -nw '
a up uptime
a prot "protoc \!* --go_out=plugins=grpc:. "
a airport "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
a no_sleep_one_hour "caffeinate -u -t 3600"
a clear_dns_cache "sudo killall -HUP mDNSResponder"
a om 'ssh keleher@omega'
a omr 'ssh root@omega'
a ki 'ssh kino'
a jup 'jupyter notebook --port=8888 --no-browser --ip=0.0.0.0'
a junk 'ssh junkfood.cs.umd.edu'
a la 'ssh lagoon.cs.umd.edu'
a lar 'ssh root@lagoon.cs.umd.edu'
a se 'ssh sedna.cs.umd.edu'
a ser 'ssh root@sedna.cs.umd.edu'
a hub 'ssh hub.local'
a hu 'ssh hub.local'
a hubr 'ssh root@hub.local'
a pi 'ssh pi@pi'
a err 'ssh root@eris.cs.umd.edu'
a er 'ssh eris.cs.umd.edu'
a hyr 'ssh root@hyperion.cs.umd.edu'
a hy 'ssh hyperion.cs.umd.edu'
a ti 'ssh titan.cs.umd.edu'
a hi 'ssh hiring.cs.umd.edu'
a hir 'ssh root@hiring.cs.umd.edu'
a tir 'ssh root@titan.cs.umd.edu'
a tr 'ssh triffid.cs.umd.edu'
a trr 'ssh root@triffid.cs.umd.edu'
a gr "sshpass -p 'Ntier15;' ssh keleher@grace.umd.edu"
a keleher 'ssh keleher.duckdns.org'
a keleherhub 'ssh -p 10022 keleher.duckdns.org'
a keleherpi 'ssh -p 1022 keleher.duckdns.org'
a ph 'ssh root@10.0.1.21'
a netrestore 'sudo cp -r /Users/keleher/wizsave/* /opt/local/share/nethackdir/save/'
a netsave 'cp -r /opt/local/share/nethackdir/save/* /Users/keleher/wizsave/'
a homeup "launchctl unload ~/Library/LaunchAgents/com.homebridge.server.plist; launchctl load ~/Library/LaunchAgents/com.homebridge.server.plist"
a hibernateon 'sudo pmset -a hibernatemode 1'
a hibernateoff 'sudo pmset -a hibernatemode 0'
a backPhotos "rsync -avz --exclude=half --exclude=thumbs --exclude='*#*' --exclude='*.rb' --exclude='*.html' --exclude='*.HTML' --exclude='*.MOV' --exclude ='*.MP4' --exclude=movies --exclude='*.yaml' --exclude='*.YAML' --exclude='*.mp4' --exclude='*.MP4' --exclude='*.mp4' --exclude='*.mov' --exclude='preface' --exclude='*~' -del --delete-excluded /media/duo1/pictures /media/duo2 -del --delete-excluded \!*"
setenv CVSROOT :ext:keleher@junkfood.cs.umd.edu:/fs/cvs/motefs
a vcvs 'setenv CVSROOT :ext:keleher@junkfood.cs.umd.edu:/fs/cvs/TerraDir'
a acvs 'setenv CVSROOT :ext:keleher@junkfood.cs.umd.edu:/fs/cvs/als'
setenv PKG_CONFIG_PATH "/usr/local/lib/pkgconfig/"
setenv PATH /Users/keleher/.rvm/gems/ruby-1.9.3-p448@global/bin:$PATH
setenv PATH /usr/local/bin:$PATH
setenv PATH /usr/local/texlive/2015/bin:$PATH
File moved
File moved
# Project 1: Computing Environment, and SQL
# Project 0: Computing Environment
Over the course of the semester, you will work with a variety of software packages, including PostgreSQL, Apache Spark, Python Django, and others. Installing those packages and getting started can often be a hassle, because of software dependencies. You have three choices.
......@@ -17,9 +17,9 @@ collaboration for your class project, or for other classes.
#### Cloning the Class Repository
We will be using the department `gitlab` for downloading project materials,
and Elms for uploading. Clone `Project1` by installing `git`, and then:
and Elms for uploading. Clone `Project0` by installing `git`, and then:
`git clone https://gitlab.cs.umd.edu/keleher/424-f19/project1.git`
`git clone https://gitlab.cs.umd.edu/keleher/424f19`
*NOTE*: If you are having trouble installing `git`, you can just download the files instead (as a zipfile), although updating may become tedious.
......@@ -29,9 +29,9 @@ and Elms for uploading. Clone `Project1` by installing `git`, and then:
- In order to use this option, you have to first install Vagrant and VirtualBox on your machine (called `Host` henceforth). See the instructions on the two websites above to do that.
- Vagrant makes things **super-easy**. We will provide you with appropriate setup files -- all you need to do is `vagrant up` to start the virtual machine.
- More specifically: in the git sub-directory `project1`, run `vagrant up`. This will start the virtual machine in the background. You may be prompted to run `vagrant box update`. Do so.
- More specifically: in the git sub-directory `project0`, run `vagrant up`. This will start the virtual machine in the background. You may be prompted to run `vagrant box update`. Do so.
- By default, vagrant only provides **ssh** access into the virtual machine (called `Guest VM` henceforth), using `vagrant ssh`. This will work as if you are doing `ssh` into a remote machine.
- The Guest VM will have access to the files in the current directory *on the host machine* (i.e., the files in the `project1` directory and its subdirectories). These are mounted in the guest VM at `/vagrant`. It would be best if you only make edits to that directory -- since those edits will survive a `vagrant destroy`. In fact, you can continue using your favorite text editor (in the host machine) to edit files, and only use the VM for running specific programs (like `postgres`, `psql`, or `ipython notebook` below).
- The Guest VM will have access to the files in the current directory *on the host machine* (i.e., the files in the `project0` directory and its subdirectories). These are mounted in the guest VM at `/vagrant`. It would be best if you only make edits to that directory -- since those edits will survive a `vagrant destroy`. In fact, you can continue using your favorite text editor (in the host machine) to edit files, and only use the VM for running specific programs (like `postgres`, `psql`, or `ipython notebook` below).
- If the Guest VM has a program (e.g., a Web Server) running and listening on a specific port (e.g., 80), you can access those ports from the host machine by adding them to the `VagrantFile`. The provided VagrantFile has two such mappings: for port 8888, used by iPython (mapped to port 8888 on the host machine), and for port 80, used by a Web server (mapped to port 8080 on the host machine).
- If you just exit the `ssh` the VM continues running in the background.
- Some other vagrant commands that you would need to be familiar with:
......@@ -117,75 +117,10 @@ IPython is an enhanced command shell for Python, that offers enhanced introspect
```
This will start a server on the VM, listening on port 8888. We will access it from the **host** (as discussed above, the VagrantFile maps the 8888 port on the guest VM to the 8888 port on the host VM). To do that, simply start the browser, and point it to: http://127.0.0.1:8888
* You should see the Notebooks in the `project1/` directory. Click to open the "IPython Getting Started" Notebook, and follow the instruction therein.
* You should see the Notebooks in the `project0/` directory. Click to open the "IPython Getting Started" Notebook, and follow the instruction therein.
* The second Notebook ("Basics of SQL") covers basics of SQL, by connecting to your local PostgreSQL instance. The Notebook also serves as an alternative mechanism to run queries. However, in order to use that, you must set up a password in `psql` using `\password` (set the password to be `ubuntu`).
# The Actual Assignment
*This assignment is to be done by **yourself**.*
You should have the following present in your vagrant directory (`/vagrant` in the VM):
1. README.md: This file.
1. small.sql: The SQL script for creating the data.
1. queries.py: The file where to enter your answer; this is the file to be submitted
1. answers.py: The answers to the queries on the small dataset.
1. SQLTesting.py: File to be used for testing your submission -- see below.
1. Vagrantfile: A Vagrantfile that creates the 'flights' database and populates it using `small.sql` file.
*Our testing will be done on the different, large dataset*.
### Schema
The dataset contains synthetic air flight data. Specifically it contains the following tables:
1. airports: airportid, city, name, total2011, total2012
1. customers: customerid, name, birthdate, frequentflieron
1. airlines: airlineid, name, hub
1. flights: flightid, source, dest, airlineid, local_departing_time, local_arrival_time
1. flewon: flightid, customerid, flightdate
See the provided SQL file for the table definitions.
The dataset was generated synthetically: the airport ids and the cities were chosen from the biggest airports in the US, but the rest of the data is populated randomly. The data will not make sense. For example, two different flights between the same cities may have very different flight durations. The flight times between the cities may not correspond to geographical distances that you know. Some other information about the data:
- **The dates in the *large* database might be different than in the *small*.**
- Each customer may at most take one flight every day.
- The flight times were chosen between 30 minutes to 5 hours randomly.
- All flights are daily (start and end on a single day), and none are overnight.
- For every flight from city A to city B, there is corresponding return flight from B to A.
- The "flewon" table only contains the flight date -- the flight times must be extracted from the flights table.
In many cases (especially for complex queries or queries involving
`max` or `min`), you will find it easier to create temporary tables
using the `with` construct. This also allows you to break down the full
query and makes it easier to debug.
You don't have to use the "hints" if you don't want to; there might
be simpler ways to solve the questions.
### Testing and submitting using SQLTesting.py
Your answers (i.e., SQL queries) should be added to the `queries.py` file. A simple query is provided for the first answer to show you how it works.
You are also provided with a Python file `SQLTesting.py` for testing your answers.
- We recommend that you use `psql` to design your queries, and then paste the queries to the `queries.py` file, and confirm it works.
- SQLTesting takes quite a few options: use `python3 SQLTesting.py -h` to see the options.
- To get started with SQLTesting, do: `python3 SQLTesting.py -v -i` -- that will run each of the queries and show you your answer and correct answer.
- If you want to test your answer to Question 1, use: `python3 SQLTesting.py -q 1`. The program compares the result of running your query against the provided answer (in the `answers.py` file).
- The `-v` flag will print out more information, including the correct and submitted answers etc.
- If you want to test your answers to all questions (this is what we will do), use: `python3 SQLTesting.py` and look at the final total score.
- `-i` flag to SQLTesting will run all the queries, one at a time (waiting for you to press Enter after each query).
- **Note that**: We will basically run this same program on your submitted `queries.py` file, but with the larger dataset; your score on the assignment will
be score output by the program. The program tries to do partial credits (as you can see in the code). It is very unlikely that your score on the larger, hidden
dataset will be higher than your score on the provided dataset.
### Submission Instructions
Submit the `queries.py` file using ELMS [here](https://umd.instructure.com/courses/1267269/assignments/4946597). **Due September 6.**
This project is ungraded and does not need to be submitted, but you should try to finish **before September 1.**
### Assignment Questions
See `queries.py` file.
File moved
File moved
File moved
File moved
import psycopg2
import os
import sys
import datetime
from collections import Counter
from types import *
import argparse
from queries import *
from answers import *
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', help="Print out the query results and more details", required=False, action="store_true")
parser.add_argument('-i', '--interactive', help="Run queries one at a time, and wait for user to proceed", required=False, action="store_true")
parser.add_argument('-q', '--query', type = int, help="Only run and check the given query number", required=False)
args = parser.parse_args()
verbose = args.verbose
interactive = args.interactive
# Check if x and y are almost near match
def match(x, y):
if type(x) != type(y):
return False
if type(x) is int or type(x) is bool:
return x == y
if type(x) is float:
return (abs(x - y) < 0.01)
# Conver to string and compare
# print "Found type: {}".format(type(x))
return str(x).strip() == str(y).strip()
def compareAnswers(ans, correct):
# Special case empty answer
if len(ans) == 0:
if len(correct) == 0:
return ("Score = 4: Both answers empty", 4)
else:
return ("Score = 0: Empty answer", 0)
if len(correct) == 0:
return ("Score = 0: The answer should have been empty", 0)
# If the number of columns is not correct, no score
if len(ans[0]) != len(correct[0]):
return ("Score = 0: Incorrect Number of Columns", 0)
# If the number of rows in the answer is the same, check for near-exact match
if len(ans) == len(correct):
c = Counter()
for (t1, t2) in zip(ans, correct):
for (t1x, t2x) in zip(t1, t2):
c[match(t1x, t2x)] += 1
if c[False] == 0:
return ("Score = 4: Exact or Near-exact Match", 4)
# Let's try to do an approximate match
flattened_ans = Counter([str(x).strip() for y in ans for x in y])
flattened_correct = Counter([str(x).strip() for y in correct for x in y])
jaccard = sum((flattened_correct & flattened_ans).values()) * 1.0/sum((flattened_correct | flattened_ans).values())
if verbose:
print("------ Creating word counts and comparing answers ---------")
print(flattened_correct )
print(flattened_ans)
print("Jaccard Coefficient: {}".format(jaccard) )
if jaccard > 0.9:
if len(ans) == len(correct):
return ("Score = 3: Very similar, but not an exact match (possibly wrong sort order)", 3)
else:
return ("Score = 2: Very similar, but incorrect number of rows", 2)
if jaccard > 0.5:
return ("Score = 1: Somewhat similar answers", 1)
return ("Score = 0: Answers too different", 0)
conn = psycopg2.connect("dbname=flights user=ubuntu")
cur = conn.cursor()
totalscore = 0
for i in range(1, 11):
# If a query is specified by -q option, only do that one
if args.query is None or args.query == i:
try:
print("========== Executing Query {}".format(i))
print(queries[i])
cur.execute(queries[i])
ans = cur.fetchall()
if verbose:
print("--------- Your Query Answer ---------")
for t in ans:
print(t)
print("--------- Correct Answer ---------")
for t in correctanswers[i]:
print(t)
# Compare with correctanswers[i]
cmp_res = compareAnswers(ans, correctanswers[i])
print("-----> " + cmp_res[0])
totalscore += cmp_res[1]
if interactive:
input('Press enter to proceed')
os.system('clear')
except:
print(sys.exc_info())
raise
print("-----------------> Total Score = {}".format(totalscore))
This diff is collapsed.
queries = ["" for i in range(0, 11)]
### 0. List all airport codes and their cities. Order by the city name in the increasing order.
### Output column order: airportid, city
queries[0] = """
select airportid, city
from airports
order by city;
"""
### 1. Write a query to find the names of the customers whose names are at least 15 characters long, and the second letter in the name is "l".
### Order by name.
queries[1] = """
select 0;
"""
### 2. Write a query to find any customers who flew on their birthday. Hint: Use "extract" function that operates on the dates.
### Order output by Customer Name.
### Output columns: all columns from customers
queries[2] = """
select 0;
"""
### 3. Write a query to generate a list: (source_city, source_airport_code, dest_city, dest_airport_code, number_of_flights) for all source-dest pairs with at least 3 flights.
### Order first by number_of_flights in decreasing order, then source_city in the increasing order, and then dest_city in the increasing order.
### Note: You must generate the source and destination cities along with the airport codes.
queries[3] = """
select 0;
"""
### 4. Find the name of the airline with the maximum number of customers registered as frequent fliers.
### Output only the name of the airline. If multiple answers, order by name.
queries[4] = """
select 0;
"""
### 5. For all flights from OAK to IAD, list the flight id, airline name, and the
### duration in hours and minutes. So the output will have 4 fields: flightid, airline name,
### hours, minutes. Order by flightid.
queries[5] = """
select 0;
"""
### 6. Write a query to find empty flights (flight, flight date) on any date
### which someone flew. Assume that if anyone flew on a given date, all
### flights took off as scheduled, with or without passengers. Order by flight
### id in increasing order, and then by date in increasing order.
queries[6] = """
select 0;
"""
### 7. Write a query to generate a list of customers who don't list Southwest as their frequent flier airline, but
### actually flew the most (by number of flights) on that airline.
### Output columns: customerid, customer_name
### Order by: customerid
queries[7] = """
select 0;
"""
# fall17
### 8. Write a query to generate a list of customers where the interval between first and last flight is 5 days.
### Order by the customer name.
queries[8] = """
select 0;
"""
# fall17
### 9. Name of customer whose max interval between any two consecutive flights is 4 days.
### The output should be simply a list of names
### Order by the customer name.
queries[9] = """
select 0;
"""
### 10. Write a query that outputs a list: (AirportID, Airport-rank), where we rank the airports
### by the total number of flights that depart that airport. So the airport with the maximum number
### of flights departing gets rank 1, and so on. If two airports tie, then they should
### both get the same rank, and the next rank should be skipped.
### Order the output in increasing order by rank, and then airport ID.
queries[10] = """
select 0;
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment