Hussain Kara Fallah
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Scripts ## `settings.py` `settings.py`: This script contains addresses of databases and collections. * **MONGO_URL_SOURCE**: host address of mongodb containing the resources * **MONGO_URL_SINK**: host address of mongodb where we write results (they should be the same usually) * **MONGO_DB_SINK**: the database where we want to write the merged collection * **MONGO_COLL_SINK**: the name of the target collection **THERE IS A PARAMETER NO_URL_VALIDATION MAKE SURE TO SET IT TO FALSE WHEN NOT EXPERIMENTING** ### IMPORTANT: There are 2 parameters `MONGO_DB_SOURCE` and `MONGO_DB_LATEST` `MONGO_DB_LATEST` refers to the sprint and ideally contains all collections which get updated `MONGO_DB_SOURCE` is basically `zippia_pipeline` and contains the one which are not updated periodically Check the sources pairs (db,collection) before running. ## `source_info.py` `source_info.py`: This script basically contains a dictionary. The keys of the dictionary are the resources we are fetching information from. Each document contains the database and the collection name corresponding to the resource. ``` "CompanyCulturalImage": { "db": MONGO_COLL_COMPANY_CULTURAL_IMAGES[0], "collection": MONGO_COLL_COMPANY_CULTURAL_IMAGES[1], "field_path": "", "kwargs" : {}, 'projection' : { 'companyID' : 1, 'pictures.keep' : 1, 'pictures.original' : 1 } }, "mission_statements": { "field_path": "cleanMissionStatement", "db": MONGO_COLL_MISSION_STATEMENTS[0], "collection": MONGO_COLL_MISSION_STATEMENTS[1], "kwargs" : {} } ``` * **db**: database name * **collection**: collection name * **field_path**: if we are only interested in a subdocument of the full document (extract only that SUBDOCUMENT/field) * **kwargs**: filter arguments for find query of mongodb * **projection**: projection arguments for find query of mongodb ### IMPORTANT: you should verify the flags for each collection. Also this script checks that every collection exists and contains at least one document ## `merge.py` This script is unlikely to change because it basically composes all other logic parts and run a very trivial logic for merging. ### General steps: * Given a batch of company ids * Download all their data from all resources * Merge each company individually ### Individual Merge 1. Take the data of a single company from all resources 2. First do extra fields generation * Gathering all name fields from all resources into aliases * Creating a compound field like (state_city) so that we vote on it using majority to get a consistent location instead of writing the logic specifically for it separately 3. Take each field separately and apply a premerge processing if necessary * Filtering bad descriptions * Checking urls 4. Apply merging function * Raw priority * Majority * Interpolation window * Concatenation 5. Postmerge processing.. Examples are (but not limited to): * Converting numerical values to discrete (revenue...) * Splitting merged (city,state) tuple into separate fields * Capping images links into maximum threshold ## `download_filters.py` This script contains logic functions for filtering documents from certain resources. It has a dictionary which looks like: ``` SOURCES_DOWNLOAD_FN = { 'CompanyCulturalImage': pictures_filter, 'CompanyLogos' : logos_filter, 'mission_statements' : statements_filter } ``` Write new functions and add new resources to this dictionary per demand. ## `augmentation.py` This script contains logic for adding synthetic fields to documents before merging and to add extra fields after merging. ### Before merging The only instance where we need this is constructing the `state_city` field across all resources. This is because when selecting the best value we should do it in a way that the city and the state are consistent to avoid getting a result where the city is in a different state. ### After merging Several functionalities: * Splitting `city_state` into individual fields * Populating all fields corresponding to names as aliases * Adding detailed address while making sure it's consistent with city/state * Extracting company domain * Adding the initial category based on industry (note that this is a temporary field) and the actual generation is in update_industries.py * Making `primary_sic` and `secondary_sic` fields after populating siccodes * Adding discrete size/revenue fields * Adding company display website * Capping urls in company images ## `premerge.py` Now as mentioned above, for each field we construct a dictionary {resource -> value} for all resources and then obtain the merged value. This script contains preprocessing functions for each field. ``` PREMERGE_FN_MAP = { COMPANY_DESCRIPTION_FIELD : filter_bad_descriptions, COMPANY_IMAGES_FIELD : partial(check_urls , data_type = "Image" , set_rv_to_v = True), COMPANY_LOGO_FIELD : partial(check_urls , data_type = "Image" , set_rv_to_v = True) , COMPANY_URLS : partial(check_urls , data_type = "Text" , set_rv_to_v = False) , URL_FIELD : partial(check_urls , data_type = "Text" , set_rv_to_v = False) , DOMAIN_ALIASES : partial(check_urls , data_type = "Text" , set_rv_to_v = False) , COMPANY_DOMAIN_FIELD : partial(check_urls , data_type = "Text" , set_rv_to_v = False) , POPULATED_INDUSTRY : remove_unmappable_industries } ``` Write new functions and add new resources to this dictionary per demand. ## `merging_functional.py` This script contains all logic functions for merging values from different resources to a final value. Example of functions are: * raw_priority (**THIS IS THE DEFAULT**) * majority (city state) * concatenation (urls for example) * selection of url based on type flags * window interpolation of numerical values * definite fixed source ``` FIELD_MERGING_FN = { URL_FIELD : partial(url_selective , fn = raw_priority), COMPANY_DOMAIN_FIELD : partial(url_selective , fn = raw_priority), COMPANY_FOUNDED_DATE_FIELD : partial(majority , map_fn = int), ACTUAL_REVENUE : partial(window_interpolate , window_size=3 , pick = 'priority'), ACTUAL_EMPLOYEE_COUNT : raw_priority, COMPANY_STATE_CITY_FIELD : majority, COMPANY_CITY_FIELD : "AVOID", COMPANY_STATE_FIELD : "AVOID", COMPANY_ALIASES : concat, SICCODES : concat, POPULATED_INDUSTRY : raw_priority, MAPPED_CATEGORY : "AVOID", COMPANY_TYPE: majority, COMPANY_LOCATION: "AVOID", COMPANY_STOCK_TICKER_FIELD : majority, } ``` **PLEASE NOTE THAT THE DEFAULT IS RAW PRIORITY, ANYTHIING ELSE RELATED TO ANY FIELD SHOULD BE ADDED TO THIS DICTIONARY** You can pretty much write any function you want. Use `functools` library for easier way of adding custom logic. **USE "AVOID" for fields where you don't want any merge happening (fields with special separate derivation/merging)** ## # Running Instructions: Read the information regarding `settings.py`, `source_info.py` Ideally for running you only need to modify the database and collection names in `settings.py` and it should be fine. `source_info.py` contains no addresses but it's rather better for clarifying explicitly which resources we need. For modifying filters and projections change in `source_info.py`. The only thing you need is running `python merge.py` **IMPORTANT NOTE :: update_industries.py should be run before running `suppliment.py` because all the industry/category fields setting is moved exclusively to that script. Suppliment should only add the startup and fortune flags** # Additional scripts ### `create_test_set.csv` For downloading a batch of companies and generating sheets per field for analysis ### `gridsearch.py` For testing different logic functions on a field and comparing against verification sheet and outputing metrics ### `compare_sheets.py` comparison utilities and metrics

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully