{"id":15567241,"url":"https://github.com/iml1111/simple-atm-controller","last_synced_at":"2025-03-29T05:35:01.054Z","repository":{"id":45116866,"uuid":"358882570","full_name":"iml1111/simple-atm-controller","owner":"iml1111","description":"Simple ATM Controller for Bear Robotics","archived":false,"fork":false,"pushed_at":"2022-01-07T04:02:03.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T15:55:47.752Z","etag":null,"topics":["code-structure","python"],"latest_commit_sha":null,"homepage":"","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/iml1111.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}},"created_at":"2021-04-17T13:13:04.000Z","updated_at":"2022-08-04T13:14:40.000Z","dependencies_parsed_at":"2022-09-17T14:10:39.788Z","dependency_job_id":null,"html_url":"https://github.com/iml1111/simple-atm-controller","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/iml1111%2Fsimple-atm-controller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml1111%2Fsimple-atm-controller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml1111%2Fsimple-atm-controller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iml1111%2Fsimple-atm-controller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iml1111","download_url":"https://codeload.github.com/iml1111/simple-atm-controller/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145014,"owners_count":20730494,"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":["code-structure","python"],"created_at":"2024-10-02T17:10:27.929Z","updated_at":"2025-03-29T05:35:01.018Z","avatar_url":"https://github.com/iml1111.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-atm-controller\nThis Repo is a simple ATM Controller implemented by using Python3.\n\nThe Simple ATM Controller provides the following features .\n\n- PIN Number Validation\n- Account Id Validation\n- Return all Accounts that PIN Number hasconfirm the balance of the Account \n- Deposit the money to the Account \n- Withdraw money from the Account\n\n\n\n# Dependency\n\n- **Python 3.7.1+**\n\n\n\n# Test \u0026 Sample Code\n\n```bash\n$ git clone https://github.com/iml1111/simple-atm-controller\n$ cd ~/simple-atm-controller\n\n# Sample Code\n$ python3 example.py\n\n# Test Code\n$ python3 test.py\n```\n\n\n\n# Get Started\n\nTo use an ATM controller, you need a connection process with the Data Model you are using in your system. For example, I implemented a simple `Database` Class.\n\n(All the codes below can be found at **/tests/data_model.py** and **example.py**)\n\n\n```python\nclass DataBase:\n    \"\"\"\n    Virtual data model class to run the Test Code\n    \"\"\"\n\n    def __init__(self):\n        self.records = [\n            # PIN, AccountId, Valance\n            [\"00-00\", \"shin10256\", 0],\n            [\"00-01\", \"shino1025\", 73],\n            [\"00-01\", \"shino102566\", 23],\n            [\"00-02\", \"iml1111\", 100_000],\n            [\"00-03\", \"imiml\", 2312],\n        ]\n\n    def find_accounts(self, pin_number):\n        \"\"\"Returns the list of account IDs with the received Pin Number\"\"\"\n        result =  filter(lambda x: x[0] == pin_number, self.records)\n        return [record[1] for record in result]\n\n    def get_valance(self, pin_number, account_id):\n        \"\"\"Return the balance of the account\"\"\"\n        result = list(filter(\n            lambda x: (x[0], x[1]) == (pin_number, account_id),\n            self.records\n        ))\n        return result[0][2] if result else None\n\n    def update_valance(self, pin_number, account_id, dollar):\n        \"\"\"Modify the balance of the account\"\"\"\n        for record in self.records:\n            if (record[0], record[1]) == (pin_number, account_id):\n                record[2] += dollar\n                return\n\n    def print_all_records(self):\n        \"\"\"Print all information of current CASH BIN\"\"\"\n        print(\"\u003c CASH BIN TOTAL \u003e\")\n        for item in self.records:\n            print(\"Record(pin=%s, account=%s, valance=%s)\" % tuple(item))\n\n```\n\nATM controller must specify the following approaches for the corresponding Data Model.\n\n- Query that returns the Account ID List that belongs to the entered PIN\n- Query that checks the balance of the entered Account\n- Query that increases or decreases the balance of the entered Account\n\nIf the query is ready, inherit ATM Controller as below and implement the below method by overriding. \n\n```python\nfrom collections.abc import Iterable\nfrom simple_atm_controller.atm_controller import AtmController\n\n\nclass MyAtmController(AtmController):\n    \"\"\"\n    Overridden ATM Controller\n    - You must specify the access method of the data model to the controller\n    \"\"\"\n\n    def find_accounts_query(self, pin_number) -\u003e Iterable:\n        return self.model.find_accounts(pin_number)\n\n    def get_valance_query(self, pin_number, account_id) -\u003e int:\n        return self.model.get_valance(pin_number, account_id)\n\n    def update_valance_query(self, pin_number, account_id, dollar):\n        self.model.update_valance(pin_number, account_id, dollar)\n\n```\n\n`self.model` is a variable that holds the entered `data model` when the Controller Class assigns an Instance.\n\nIn the method(`find_accounts_query`, `get_valance_query`, `update_valance_query`) ,\nyou can implement queries in the same way that you used previously to meet each requirement\n\n\n\n### Use Controller\n\nIf all of the above settings are ready, you can use `Controller`.\n\nFirst of all, declare `Data Model` and connect it with `Controller` to assign Instance.\n\n```python\nCASH_BIN = DataBase()\natm_controller = MyAtmController(CASH_BIN)\n```\n\nAssuming that you received the user's card PIN number, create the PIN object as shown below.\n\n```python\nfrom simple_atm_controller.pin import Pin\n\ninput_pin = \"00-01\"\npin = Pin(input_pin)\n# Pin(00-01)\n```\n\nIf you want to define the logic for verifying the PIN number, \ninherit the `PinValidationRule` class, define the Custom Rule, and then hand it over as a argument when creating the `Pin` object.\n\n```python\nfrom simple_atm_controller.pin import PinValidationRule\n\nclass CustomPinNumberRule(PinValidationRule):\n    \"\"\"\n    PinNumber Validation Rule\n    - Write a rule to verify the pin number\n    \"\"\"\n    def validate(self, pin_number) -\u003e bool:\n        return bool(re.search(r\"\\d{2}-\\d{2}\", pin_number))\n\npin = Pin(input_pin, rule=CustomPinNumberRule())\n```\n\nPass the `Pin` object to `atm_controller`, check the account list that belongs to it, and select the desired account.\n\n```python\naccounts = atm_controller.find_accounts(pin)\nselected_account = accounts[0]\n# [Account(pin_number=00-01, account_id=shino1025), \n#  Account(pin_number=00-01, account_id=shino102566)]\n```\n\nBy passing the account back as an argument to `atm_controller`, you can use the following functions.\n\n```python\n# Get current valance method \n# - If the account cannot be found, it returns None.\nvalance = atm_controller.get_valance(selected_account)\n\n# Withdraw method\n# - Status is the withdrawal success or not, msg is returned the reason for failure.\nstatus, msg = resuatm_controller.withdraw(selected_account, 30)\n\n# Deposit method \n# - Since there is no number of cases where a deposit fails within a given requirement, we do not track success or failure separately.\natm_controller.deposit(selected_account, 30)\n```\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiml1111%2Fsimple-atm-controller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiml1111%2Fsimple-atm-controller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiml1111%2Fsimple-atm-controller/lists"}