Last active
September 15, 2015 19:29
-
-
Save sudipto80/84e5280c4eb1bda427b4 to your computer and use it in GitHub Desktop.
Arranging books in your bookshelves
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table books = DataAcquisition.LoadCSV(@"C:\personal\books.csv"); | |
//genre,author,height-genre*author | |
books.AddColumn("GenreAsNum", books.ValuesOf("Genre")); | |
books.Transform("GenreAsNum", x => x == "fiction" ? "1" : x == "nonfiction" ? | |
"2" : x == "philosophy" ? | |
"3" : x == "science" ? | |
"4" : x == "tech" ? | |
"5" : | |
"-1"); | |
books = books.Transform("Author", x => | |
{ | |
if (x.Contains(',')) return x.Substring(0, x.IndexOf(',')); | |
else if (x.Contains(' ')) return x.Substring(0, x.IndexOf(' ')); else return x; | |
}); | |
books.AddColumn("Shelf", "Floor([Height]/[GenreAsNum])", 0); | |
int max = books.ValuesOf("Shelf").Select(t => Convert.ToInt32(t)).Max(); | |
books.Transform("Shelf", x => Math.Ceiling((6 * Convert.ToDecimal(Convert.ToDouble(x) / Convert.ToDouble(max)))).ToString()); | |
var shelfs = books.SortBy("Height").ThenBy("Author").ThenBy("Genre").SplitOn("Shelf"); | |
shelfs.ToList().ForEach(t => { t.Value.Pick("Title", "Genre", "Height").PrettyDump(); Console.WriteLine("----------"); }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment