{"id":19163305,"url":"https://github.com/programmer-ke/loan-aggregator-sample","last_synced_at":"2025-02-22T22:42:44.264Z","repository":{"id":142051340,"uuid":"142271836","full_name":"programmer-ke/loan-aggregator-sample","owner":"programmer-ke","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-29T14:50:03.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-03T21:43:32.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/programmer-ke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-25T08:37:00.000Z","updated_at":"2018-07-29T14:50:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"e1c3766d-aa2c-4759-8911-3d68791f5c32","html_url":"https://github.com/programmer-ke/loan-aggregator-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/programmer-ke%2Floan-aggregator-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/programmer-ke%2Floan-aggregator-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/programmer-ke%2Floan-aggregator-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/programmer-ke%2Floan-aggregator-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/programmer-ke","download_url":"https://codeload.github.com/programmer-ke/loan-aggregator-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240245887,"owners_count":19771029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T09:14:46.714Z","updated_at":"2025-02-22T22:42:44.251Z","avatar_url":"https://github.com/programmer-ke.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loan-aggregator\n\nA command that aggregates loans by network, product and month\n\n## Usage\n\nThis script requires does not require any third party packages. It only\nexpects python 3 to be installed (tested in python 3.6)\n\nTo test, run the following in the project root:\n\n`python3 loan_aggregator.py Loans.csv Output.csv`\n\nA file named `Output.csv` will be created with the aggregated results.\n\nSample input:\n\n```\nMSISDN,Network,Date,Product,Amount\n27729554427,'Network 1','12-Mar-2016','Loan Product 1',1000\n27722342551,'Network 2','16-Mar-2016','Loan Product 1',1122\n27725544272,'Network 3','17-Mar-2016','Loan Product 2',2084\n27725326345,'Network 1','18-Mar-2016','Loan Product 2',3098\n27729234533,'Network 2','01-Apr-2016','Loan Product 1',5671\n27723453455,'Network 3','12-Apr-2016','Loan Product 3',1928\n27725678534,'Network 2','15-Apr-2016','Loan Product 3',1747\n27729554427,'Network 1','16-Apr-2016','Loan Product 2',1801\n27729234533,'Network 2','01-Apr-2016','Loan Product 1',5671\n27723453455,'Network 3','12-Apr-2016','Loan Product 3',1928\n27725678534,'Network 2','15-Apr-2016','Loan Product 3',1747\n27729554427,'Network 1','16-Apr-2016','Loan Product 2',1801\n27723453455,'Network 3','12-Apr-2016','Loan Product 3',1928\n27725678534,'Network 2','15-Apr-2016','Loan Product 3',1747\n```\n\nSample output:\n\n```\nNetwork,Product,Month,Amount,Count\nNetwork 1,Loan Product 1,Mar-2016,1000.00,1\nNetwork 2,Loan Product 1,Mar-2016,1122.00,1\nNetwork 3,Loan Product 2,Mar-2016,2084.00,1\nNetwork 1,Loan Product 2,Mar-2016,3098.00,1\nNetwork 2,Loan Product 1,Apr-2016,11342.00,2\nNetwork 3,Loan Product 3,Apr-2016,5784.00,3\nNetwork 2,Loan Product 3,Apr-2016,5241.00,3\nNetwork 1,Loan Product 2,Apr-2016,3602.00,2\n```\n\n## Running tests\n\nRun the following command in the project root:\n\n`python3 tests.py`\n\n\n## Some assumptions made\n\n- All dates are in a uniform format\n- The msisdn column is not required in the aggregated output\n- The format `\u003cmonth\u003e-\u003cyear\u003e` is sufficient to uniquely identify a month\n- The output amount is standardized to two decimal places\n\nThis task is implemented in Python, as it's a high-level dynamic language with\na large standard library that enables rapid prototyping and development.\nNo third party packages are required to execute this script.\n\nAt the core is an ordered dictionary (hashtable) that is used to aggregate\nvalues. \n\nA hashtable is suitable because the required tuple of network, product and\nmonth can be used as a unique key over with the input data rows are aggregated,\nand access to each key in the dictionary is O(1)\n\nPerformance by time will therefore grow by O(n) with `n` being the number of rows\nin the input file. Memory requirements will grow according the to pattern of\ndata, the total possible combinations of network by product by month\n(Frequency of validation is two months) as only this amount of state\nis retained in the ordered dictionary\n\nThe Ordered dictionary is used in case it is desirable to preserve the\norder in which each (network, product, month) tuple is encountered in the\ninput file.\n\nAutomated tests have been included to test the correctness of the functionality.\nCode is auto-formatted using [black](https://github.com/ambv/black)\n\nIn case it is not desirable to run this directly as a commandline application,\nthe class `CommandLineAggregator` is provided, which can be imported and only\nrequires that the input and output file handles are supplied.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammer-ke%2Floan-aggregator-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprogrammer-ke%2Floan-aggregator-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprogrammer-ke%2Floan-aggregator-sample/lists"}