Giter Club home page Giter Club logo

landingtech's Introduction

Running the app

You will need minimum node js v 10.15.0 installed

  1. Run npm install
  2. Run npm start
  3. Prompt will appear to enter company id

Initial thoughts

Clear we are looking at a flat list of items that we want to create into a tree structure (unflatten)

Points I need to be consious of:

Files could be quite large, so algorithm needs to take this into account . A recursive method would go in O(n^2) and we should aim to get this in O(n) if possible. My first thoughts are using a dictionary, utilising javascripts useful variable reference

My steps would be in the following order, will plan to take a TDD approach to this:

  • My focus would be on the algorithm itself to convert a flat list into a tree

  • Putting in the functionality to see children for root up to certain levels

  • My next step would be to add some functionality to read files

  • Finally, wrap the whole thing into a packaged solution

  • Gone a bit crazy with dictionaries here, it is my favourite data structure!

Resources

was getting stuck post 3-4 hours with my O(n) dictionary approach and this provided great inspiration

Some help with writing cli:

Solution (see unFlatten.ts and main.ts)

Assumptions:

There are no orphaned companies

Pseudo code:

  1. First build our data, so iterate through every item in the company relation file and create an array of company objects
  2. Also go through the land parcels file and use yet another dictionary to map company to no of parcels
  3. Create a dictionary lookup to reference the array position of company ids, for quick lookups
  4. Our company class has a children of companies property to help generate our tree of nested arrays
  5. As we go through our list update the children arrays as we go along, since we are referencing objects (use our lookup). At the same time keep an eye on the total land parcels and update the root node
  6. Our final root will have children referencing all the lookup items with their respective child arrays, add this root to a root array
  7. For a given node we need to know which is the root parent, for each route recursively go through and map each item to it's root node (another lookup). I believe there is a O(n) solution to this but over an hour on it I settled for this approach.
  8. We can use our route lookup to find which root tree to print out.

Scaling considerations

  • some level of pre-processing that could be done overnight (e.g. land parcels). This would work well if the data is not changing that frequently.
  • or we could create cached outputs (e.g. store in redis) of trees.
  • You could 'listen' to updates to company data, parcels, sub company created etc. and have a CQRS setup that updates the data structure specific for ui in an async manner (giving the feel of real time updates). We would 'eventually' update the source data.

landingtech's People

Contributors

ns6482 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.