Difference between revisions of "W2653 CSV File Processing"
From Coder Merlin
Line 9: | Line 9: | ||
* Read [https://www.aviationweather.gov/info Aviation Weather Center Mission] (US Government) | * Read [https://www.aviationweather.gov/info Aviation Weather Center Mission] (US Government) | ||
* Read [https://en.wikipedia.org/wiki/METAR Metar Overview] (Wikipedia) | * Read [https://en.wikipedia.org/wiki/METAR Metar Overview] (Wikipedia) | ||
* Read [https://docs.swift.org/swift-book/LanguageGuide/Initialization.html#ID231 Initialization] (Swift Documentation) - Read only the section on convenience initializers | |||
== Experiment == | == Experiment == | ||
Line 24: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Carefully | Carefully observe the file. Remember that the "\" character as the ''last'' character in a line in emacs is a '''line-continuation''' character. (For reference, you may read [https://www.gnu.org/software/emacs/manual/html_node/emacs/Continuation-Lines.html Continuation-Lines].) You'll probably find it much easier to read most lines if you maximize the width of your window. | ||
== | Questions: | ||
# On which line does the actual data begin? | |||
# How could you programmatically make this determination? | |||
# What is the purpose of the immediately preceding line? | |||
# How are '''records''' delimited? | |||
# How are '''fields''' delimited? | |||
Create a new file in the current directory, "main.swift". Perform all exercises in this lab in that file. | |||
== Exercises == | |||
# Design a class that will contain each field in a metar as a separate property. Pay close attention to the type of each field. (Hint: In some cases you may opt to use more than one property for a single field in the file.) | |||
# Create an initializer that accepts a series of ''fields'' of the expected type | |||
# Create a convenience initializer that accepts a series of strings, one for each field | |||
# Create a convenience initializer that accepts a single string, in a format identical to that in the sample file | |||
# Support the CustomStringConvertible protocol, providing a ''reasonable'' description of the data encapsulated in the class. | |||
== Key Concepts == | == Key Concepts == |
Revision as of 20:43, 26 March 2019
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
CSV File Processing[edit]
This tutorial will provide an introduction about processing CSV files.
Research[edit]
- Read CSV Files (Creativyst)
- Read ICAO Airport Codes (Wikipedia)
- Read Aviation Weather Center Mission (US Government)
- Read Metar Overview (Wikipedia)
- Read Initialization (Swift Documentation) - Read only the section on convenience initializers
Experiment[edit]
Create a new directory in your ~/projects folder, named project-2651. Then, download this file Example-metars.csv to that directory.
cd ~/projects
mkdir project-2651
cd project-2651
wget https://wiki.codermerlin.com/mediawiki/images/1/15/Example-metars.csv
View the file in emacs:
emacs Example-metars.csv
Carefully observe the file. Remember that the "\" character as the last character in a line in emacs is a line-continuation character. (For reference, you may read Continuation-Lines.) You'll probably find it much easier to read most lines if you maximize the width of your window.
Questions:
- On which line does the actual data begin?
- How could you programmatically make this determination?
- What is the purpose of the immediately preceding line?
- How are records delimited?
- How are fields delimited?
Create a new file in the current directory, "main.swift". Perform all exercises in this lab in that file.
Exercises[edit]
- Design a class that will contain each field in a metar as a separate property. Pay close attention to the type of each field. (Hint: In some cases you may opt to use more than one property for a single field in the file.)
- Create an initializer that accepts a series of fields of the expected type
- Create a convenience initializer that accepts a series of strings, one for each field
- Create a convenience initializer that accepts a single string, in a format identical to that in the sample file
- Support the CustomStringConvertible protocol, providing a reasonable description of the data encapsulated in the class.