Coder Social home page Coder Social logo

hierarchydata's Introduction

HierarchyData

This Python script implements logic in order to get office info using employee id related to this office from PostgresDB. You can also import json data from file to the PostgesDB for your convenience.

Explanation

We should assume hierarchy depth is unlimited so it's needed to use recursive expressions.

In our case we have 2:

  1. Subexpression that is used to get office id.
  2. Main expression is used to get employees based on office id.

Usage

You can run the script with 2 commands availibale:

  • json-to-db - import data from json file tpo PostgreSQL

  • office-by-employee-id - get office info using employee id related to this office

    Please ensure json file has valid format. Example: [{ "id": 1, "ParentId": null, "Name": "St. Petersburg office", "Type": 1 }, { "id": 2, "ParentId": 1, "Name": "Development department", "Type": 2

    }, { "id": 3, "ParentId": 2, "Name": "Иванов", "Type": 3 }]

Dependencies

I use SQLAlchemy Core + Psycopg2 to execute raw SQL expressions in the script. So please install them: pip install SQLAlchemy psycopg2

Example

Input:

python main.py office-by-employee-id 17

Output:

Офис в Москве: Винтиков, Шпунтиков, Морозов, Белова, Крылова, Петрова, Иванова.

hierarchydata's People

Watchers

 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.