Created
September 15, 2015 19:44
-
-
Save sudipto80/342a8f69c93f044fe4b7 to your computer and use it in GitHub Desktop.
Squirrel to organize books
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"); | |
string html = shelfs.Select( t => t.Value.Pick("Title", "Author", "Genre", "Height") | |
.ToHTMLTable()) | |
.Aggregate((a,b)=> a + " <h2>New Book Shelf</h2>" + b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment