Difference between revisions of "Spreadsheet To Dictionaries Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
=Code To Use=
 
=Code To Use=
==[[Spreadsheet_Assignment|Spreadsheet]] Exercise==
+
*[[Spreadsheet_Assignment|Spreadsheet]] Exercise
==[[Chained_Dictionary_Assignment|SingleChainedDictionary]] Exercise==
+
*[[Chained_Dictionary_Assignment|SingleChainedDictionary]] Exercise
==[https://smlfamily.github.io/Basis/list.html List] structure==
+
*[https://smlfamily.github.io/Basis/list.html List] structure
==[https://smlfamily.github.io/Basis/list-pair.html ListPair] structure==
+
*[https://smlfamily.github.io/Basis/list-pair.html ListPair] structure
  
 
=Code To Implement=
 
=Code To Implement=
==structure SpreadsheetToDictionaries==
+
{{SMLToImplement|spreadsheet_to_dictionaries|to_dictionaries_using_headers_as_keys|spreadsheet_to_dictionaries}}
===to_dictionaries_using_headers_as_keys===
+
 
 +
<syntaxhighlight lang="sml">
 
  fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list =
 
  fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list =
 
         raise NotYetImplemented
 
         raise NotYetImplemented
 +
</syntaxhighlight>
  
 
Given this spreadsheet:
 
Given this spreadsheet:

Latest revision as of 19:40, 14 July 2023

Inspiration

The spectacuarly helpful Ruby libraries which support CSV parsing to hashes with headers as keys.

Code To Use

Code To Implement

file: src/main/sml/spreadsheet_to_dictionaries/spreadsheet_to_dictionaries.sml Smlnj-logo.png
functions: to_dictionaries_using_headers_as_keys
 fun to_dictionaries_using_headers_as_keys(s : sheet) : (cell,cell) SingleListDictionary.dictionary list =
        raise NotYetImplemented

Given this spreadsheet:

Name Uniform Number Birth Year Games Played Goals Assists
Bobby Orr 4 1948 657 270 645
Wayne Gretzky 99 1961 1487 894 1963
Mario Lemieux 66 1965 915 690 1033

to_dictionaries_using_headers_as_keys should return a list with 3 single list dictionaries, one for each non-header row. The dictionaries would be filled with entries for each column, using the cell in the header of the column as the key and the cell in the particular row of the column as the value.

[ { TEXT("Name") => TEXT("Bobby Orr"),     TEXT("Uniform Number") => INTEGER(4),  TEXT("Birth Year") => INTEGER(1948), TEXT("Games Played") => INTEGER(657),  TEXT("Goals") => INTEGER(270), TEXT("Assists") => INTEGER(645)  }, 
  { TEXT("Name") => TEXT("Wayne Gretzky"), TEXT("Uniform Number") => INTEGER(99), TEXT("Birth Year") => INTEGER(1961), INTEGER("Games Played") => INTEGER(1487), TEXT("Goals") => INTEGER(894), TEXT("Assists") => INTEGER(1963) }, 
  { TEXT("Name") => TEXT("Mario Lemieux"), TEXT("Uniform Number") => INTEGER(66), TEXT("Birth Year") => INTEGER(1965), INTEGER("Games Played") => INTEGER(915),  TEXT("Goals") => INTEGER(690), TEXT("Assists") => INTEGER(1033) } ]

NOTE: you can assume that you will not be passed the empty list. If you want to handle this case anyway, raising Empty seems like a reasonable thing to do.

Testing

source folder: src/test/sml/spreadsheet_to_dictionaries
how to run with CM.make verbosity off: sml -Ccm.verbose=false run_spreadsheet_to_dictionaries_testing.sml
how to run with CM.make verbosity on: sml run_spreadsheet_to_dictionaries_testing.sml

note: ensure that you have removed all printing to receive credit for any assignment.

SML Error Messages