Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intermediate - migrate beyond tutorials google sheet to v3 format #20855

Merged
merged 8 commits into from Feb 26, 2018
2 changes: 2 additions & 0 deletions pegasus/data/beyond_tutorials.gsheet
@@ -0,0 +1,2 @@
TestSuresh/beyond_tutorials
exclude_columns: ['notes_t']
3 changes: 2 additions & 1 deletion pegasus/data/cdo-glossary-csf.csv
Expand Up @@ -28,7 +28,8 @@ call,call (a function),This is the piece of code that you add to a program to in
click,click,Press the mouse button.,,,,,,,,,,,,
code,code,The language that programmers create and use to tell a computer what to do.,Course 1: Stage 2,Course 1: Stage 2,,,,,,,,,,
command,command,An instruction for the computer. Many commands put together make up algorithms and computer programs.,Course 1: Stage 2,Course 1: Stage 2,,,,,,,,,,
computational thinking,computational thinking,"Mental processes and strategies that include: decomposition, pattern matching, abstraction, algorithms (decomposing problems into smaller, more manageable problems, finding repeating patterns, abstracting specific differences to make one solution work for multiple problems, and creating step-by-step algorithms).",Course 3: Stage 1,Course 3: Stage 1,,,,,,,,,,
computational thinking,computational thinking,"Modifying a problem in such a way that it can be modeled or solved using a computer or machine.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't have changes to these csv's in PR, they'll get overwritten by gsheet changes once merged. Let's not add them to commits.

Strategies include: decomposition, pattern matching, abstraction, algorithms.",Course 3: Stage 1,Course 3: Stage 1,,,,,,,,,,
computer science,computer science,Using the power of computers to solve problems.,Course 1: Stage 2,Course 1: Stage 2,,,,,,,,,,
conditionals,conditionals,Statements that only run under certain conditions.,"Course 2: Stages 12, 13<br/>
Course 3: Stages 7, 8","Course 2: Stages 12, 13 |
Expand Down
2 changes: 1 addition & 1 deletion pegasus/data/cdo-team.csv
Expand Up @@ -136,7 +136,7 @@ Kate Brunette,,https://www.linkedin.com/in/brunettekate,Partnerships and Campaig
Katie Apone,,https://www.linkedin.com/in/katieapone/,Program Manager ,extended_inactive
Katie Kurtz,,http://www.linkedin.com/in/misskatiek,Grant Writer,extended_inactive
Kevin Scannell,,https://www.linkedin.com/in/kscanne,Irish Translator,translator
Koichi Ito,,https://j-code.org ,Japanese Translator,translator
Koichi Ito,,https://j-code.org,Japanese Translator,translator
Laura Kline,,http://www.linkedin.com/in/lkline/,Marketing & Product Manager,extended_inactive
Lauren Selig,,http://www.imdb.com/name/nm0783147/,Producer,extended_inactive
Lesley Chilcott,,http://www.imdb.com/name/nm2026261/,Filmmaker,extended_inactive
Expand Down
40 changes: 22 additions & 18 deletions pegasus/rake/seed.rake
Expand Up @@ -7,6 +7,7 @@ class CsvToSqlTable
@db = params[:db] || DB
@path = path
@table = File.basename(@path, File.extname(@path)).tr('-', '_').to_sym
@remove_type_suffix = (@table == :beyond_tutorials) ? true : false
end

def up_to_date?
Expand All @@ -29,9 +30,10 @@ class CsvToSqlTable
at = 1

CSV.open(@path, 'rb') do |csv|
table, columns = create_table(csv.shift)
csv_column_names = csv.shift
table, db_column_names = create_table(csv_column_names)
while values = csv.shift
table.insert(hash_from_keys_and_values(columns, values).merge({id: at += 1}))
table.insert(hash_from_column_names_and_values(db_column_names, csv_column_names, values).merge({id: at += 1}))
end
end

Expand All @@ -44,12 +46,13 @@ class CsvToSqlTable

private

def hash_from_keys_and_values(keys, values)
def hash_from_column_names_and_values(db_column_names, csv_column_names, values)
h = {}
(0..keys.count - 1).each do |i|
key_name = keys[i].to_s
(0..db_column_names.count - 1).each do |i|
csv_column_name = csv_column_names[i].to_s
type_suffix = csv_column_name[csv_column_name.rindex('_')..-1]
value =
case key_name[key_name.rindex('_')..-1]
case type_suffix
when '_b'
values[i].to_bool
when '_f'
Expand All @@ -60,13 +63,13 @@ class CsvToSqlTable
values[i]
end

h[keys[i]] = value
h[db_column_names[i]] = value
end
h
end

def create_table(columns)
schema = columns.map {|column| column_name_to_schema(column)}
def create_table(csv_column_names)
schema = csv_column_names.map {|csv_column_name| column_name_to_schema(csv_column_name)}

DB.create_table!(@table, charset: 'utf8') do
primary_key :id
Expand All @@ -81,20 +84,20 @@ class CsvToSqlTable
[DB[@table], schema.map {|i| i[:name]}]
end

def column_name_to_schema(name)
i = name.rindex('_')
def column_name_to_schema(csv_column_name)
i = csv_column_name.rindex('_')

if i.nil?
ChatClient.log "Bad column name (#{name}) for table (#{@table}), see this " \
ChatClient.log "Bad column name (#{csv_column_name}) for table (#{@table}), see this " \
"<a href='https://drive.google.com/drive/folders/0B0OFfWqnAHxhM0prRGd0UWczMUU'>Google Drive</a> folder."
end

if name.ends_with?('!') || name.ends_with?('*')
type_flag = name[-1..-1]
name = name[0..-2]
if csv_column_name.ends_with?('!') || csv_column_name.ends_with?('*')
type_flag = csv_column_name[-1..-1]
csv_column_name = csv_column_name[0..-2]
end

type_info = name[i..-1]
type_info = csv_column_name[i..-1]

type = {
'_b' => {type: 'boolean'},
Expand All @@ -110,7 +113,9 @@ class CsvToSqlTable
type = type.merge(unique: true) if type_flag == '!'
type = type.merge(index: true) if type_flag == '*'

type.merge({name: name.to_sym})
db_column_name = @remove_type_suffix ? csv_column_name.rpartition('_')[0] : csv_column_name

type.merge({name: db_column_name.to_sym})
end

def set_table_mtime(mtime)
Expand Down Expand Up @@ -238,7 +243,6 @@ namespace :seed do
sync_tasks = []

imports = {
beyond_tutorials: 'Data/HocBeyondTutorials.gsheet',
tutorials: 'Data/HocTutorials.gsheet'
}

Expand Down