• Save
Super spike
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Super spike

on

  • 384 views

An investigation into using F# and MongoDB for a line of business application.

An investigation into using F# and MongoDB for a line of business application.

Statistics

Views

Total Views
384
Views on SlideShare
384
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Principles: 1) software is a means to an end; 2) the customer is the architect
  • Principles: 1) software is a means to an end; 2) the customer is the architect
  • INVESTIGATION of a solutionNarrow: focused on particular objectivesDrives deep: feasibility and “how it works”
  • Not unique…
  • SOLUTION EXPLORER- Models, Lib, Web- Show References- Order of files in F# project
  • Schema: wastexform: ripe for error, low bus numberload: complex, business rules data driven during load, can only be changed by reloading, “further from the data”Show C# code – fields we need versus “things that are interesting”How much effort did we just eliminate?
  • So What? Can do this with RDBMSMapping to database tables and columns vs. mapping to properties of an object
  • Field names: Parent, Salesman, Industry
  • Map-ReduceSELECT … GROUP BY!!!!Within a single toolUnit testing
  • So many ways to compose functions. Make DSLs

Super spike Presentation Transcript

  • 1. Super SpikeYep. It’s Super
  • 2. Who am I? Who I am?
  • 3. Indoctrination Reduction in fear Super awesome MongoDB non-relational database tipsAn introduction on how to use the MongoDB C# Driver Super awesome F# functional programming tips How to integrate F# into your apps today Looks at some functional techniques BONUS: (I hope) some inspiration
  • 4. 1. Analyze transactional data 2. Create models for setting prices3. Work with sales team to raise prices 4. Measure results
  • 5. Narrow Deep
  • 6. • Mongo – Unstructured data – Flexible query language…using JavaScript! – Feels…”light”• F# – Reasoning • Less code • No side effects – Productivity • fsi • Focus on what, not where
  • 7. • Data Access – Mostly read-only – Data processing heavy – Non-standard formats from client to client• Data Processing – Calculate metrics on different slices of data – Different formulas for various metrics
  • 8. View (razor) Controller (C#)Model Data Processing (F#) (C#) Data Access (F#) MongoDB
  • 9. • Current Situation – Unknown schema – Complex transformation scripts – Complex loading scripts
  • 10. static member Initialize() = BsonClassMap.RegisterClassMap<Customer>(fun cm -> cm.AutoMap() cm.SetIdMember(cm.GetMemberMap("Number")) ) |> ignore BsonClassMap.RegisterClassMap<Product>(fun cm -> cm.AutoMap() cm.SetIdMember(cm.GetMemberMap("SKU")) ) |> ignore
  • 11. private static void ImportFromFile<T>( string filename, Dictionary<string, int> fieldMappings)where T: CoreObject { var datafile = DataFile.FindOneById(filename); var record = datafile.ReadLine(); while (record != null) { var o = Activator.CreateInstance<T>(); o.Load(record, fieldMappings); o.Save(); record = datafile.ReadLine(); }}
  • 12. { "_id": "1234567", "_t": "Customer", "Attributes": { "Parent": "Mikes Chocolates", "Salesman": "Willy Wonka", "Industry": "Candy" }, "Name": "Choc a lot"} • Invoice • Date • Quantity • Amount • Customer • Product
  • 13. • Current Situation – Hard to find – Hard to test – Calculations are often performed “on top of” other calculations – Technical team needs to explain how formulas work
  • 14. let GetCollection<T>() = (new MongoRepository()) .GetDatabase() .GetCollection<T> typeof<T>.Namelet Invoices = GetCollection<Invoice>let GetInvoices (fromDate:DateTime) (toDate:DateTime) includeFields = let query = Query .GTE("Date", BsonDateTime.Create(fromDate)) .LTE(BsonDateTime.Create(toDate)) let fields = Fields.Exclude("_id").Include(includeFields) Invoices().Find(query).SetFields(fields) :> seq<Invoice>
  • 15. static member GetRevenueByYear (fromDate:DateTime) (toDate:DateTime) = GetInvoices fromDate toDate [|"Date"; "Amount"|] |> Seq.groupBy (fun i -> i.Date.Year) |> Seq.map (fun (year, invoices) -> (year, (sumRevenue invoices))) |> Seq.sortBy (fun (year, _) -> year) let sumRevenue (invoices:seq<Invoice>) = invoices |> Seq.sumBy (fun i -> i.Amount)
  • 16. let IndexByCustomer fromDate toDate operation attribute = Index “Customer” (fun i -> i.Customer.Attributes.[attribute]) fromDate toDate operationlet IndexByProduct fromDate toDate operation attribute = Index “Product” (fun i -> i.Product.Attributes.[attribute]) fromDate toDate operation let Index type groupF fromDate toDate indexF string -> (Invoice -> string) -> DateTime -> DateTime -> (seq<Invoice> -> float) -> seq<string * float * float>
  • 17. string -> (Invoice -> string) -> DateTime -> DateTime -> (seq<Invoice> -> float) -> seq<string * float * float>let IndexCustomers attribute = Index "Customer" (fun (i:Invoice) -> i.Customer.Attributes.[attribute])let IndexProducts attribute = Index "Product" (fun (i:Invoice) -> i.Product.Attributes.[attribute])string -> (DateTime -> DateTime -> (seq<Invoice> -> float) -> seq<string * float * float>)let IndexByCustomer fromDate toDate operation attribute = IndexCustomers attribute fromDate toDate operationlet IndexByProduct fromDate toDate operation attribute = IndexProducts attribute fromDate toDate operation
  • 18. type Entity =| Customer| Productlet IndexEntity t attribute fromDate toDate indexOp = let f = match t with | Customer -> IndexCustomers | Product -> IndexProducts f attribute fromDate toDate indexOp
  • 19. OPERATIONAL DEVELOPMENT USER PERCEIVEDFrom days to minutes Reasoning about code “OK” Closer to the data
  • 20. mongodb.orghttps://github.com/mongodb/mongo-csharp-driverhttp://www.tryfsharp.orgFsUnit (via NuGet)http://www.jqplot.com/
  • 21. www: michaelfalanga.comE-mail: me@michaelfalanga.comTwitter: @mfalanga