Saturday, July 27, 2019

Getting your Hands Dirty with Python

This is an endeavor from my side to demonstrate how easy to grasp language Python is. Targeted for developers with some knowledge of programming.

Real Time Use Case - Food Order & Billing
Check booking data for availability of tables in a restaurant, takes the customer order and generates the bill to the customer and finally gets the rating of the service from the customer


Key Features covered in the program
§  Classes / Objects
§  Docstrings
§  File Handling
§  Error and Exception Handling
§  Data Structures – Dictionaries
§  lambda Function
§  String Manipulation

Imports from Standard Library



Classes & Objects



Docstrings



Read File



Exception Handling



Dictionaries



lambda Function


String Manipulation



Source Code
# Imports from standard library
import datetime
import time
import sys

print("WELCOME TO QUICKCONNECT HUB")

class Restaurant:

    order = {}
    total = 0.0
    tax = 0.04

    def __init__(self):
        """ Read / Display restaurant table booking information stored in a file """

        print("\n" "Displaying Table Booking Data ...." "\n")
        time.sleep(2)
               
        try:

           with open("table.txt","r") as tabfile:

               for line in tabfile:
                  print(line)
               time.sleep(2)

               print("\n" "Please occupy empty table")
               time.sleep(2)

        except FileNotFoundError:
           print("The data file is missing")
           sys.exit()

    def menuDisplay(self):
        """ Display the items in the menu for selection """
       
        print("\n" "Select the items from menu")
        print("\n" "********** MENU CARD **********")
        print("ITEM \t\t PRICE")

        self.menu = {"Burger":120, "Pizza":200, "Hotdog":150,
                "Parata":50, "Donut":80, "Nugget":50,
                "Paneer":120, "Pakora":80, "Coffee":25}

        for k,v in self.menu.items():
              print(k,":", "\t",  "Rs",v)

    def orderConfirm(self):
        """ Take the order and display the items for confirmation """

        print("\n" "Please let us know the order")
        time.sleep(2)

        for i in range(len(self.menu)):
           
            self.select_item = input("\n" "Select an Item: ")
            if self.select_item not in self.menu:
                print("Selected item is not available in the menu")
                self.select_item = input("Please re-enter an item: ")
               
            try:
                self.quantity = int(input("Enter the Quantity: "))
                self.order[self.select_item] = self.quantity

            except Exception:
                print("Quantity to be entered as Numeric")
                self.quantity = int(input("Please re-enter the Quantity:"))
                self.order[self.select_item] = self.quantity

            self.item_flag = input("\n" "Do you wish to continue?(Y/N)")
            if self.item_flag == "N":
                break
           
        print("\n" "Please confirm the order given:")
        print(self.order)
        print("\n" "THANK YOU! Please wait while we get your items")
        time.sleep(2)
        print("\n" "Here you go, Please have your order")
        time.sleep(2)

    def billGeneration(self):
        """ Generates bill for the ordered items """
       
        print("\n" "Generating Bill....")
        time.sleep(2)
        print("------------------------------------------")
        current_time = datetime.datetime.now()
        print("Invoice Generated On:", current_time.strftime("%Y-%m-%d %H:%M:%S"))
        print("------------------------------------------")

        for key in self.menu.keys():

           if key in self.order:
              print(key, "\t", "Qty", self.order[key], "\t", "Rs", self.menu[key] * self.order[key])
              self.cost_item = self.menu[key] * self.order[key]
              self.total += self.cost_item

        self.taxamt = lambda amt, tax : amt * tax
        print("------------------------------------------")
        print("TOTAL:", "\t", "\t", "Rs", self.total)
        print("GST 4%", "\t", "\t", "Rs", self.taxamt(self.total, self.tax))
        print("------------------------------------------")
        self.total += self.taxamt(self.total, self.tax)
        print("GRAND TOTAL:", "\t", "Rs", self.total)
        print("------------------------------------------")
       

    def rateService(self):
        """ Display customer ratings of the services provided """
       
        print("\n" "Dear customer, Please Rate our Service * * * * * ")
        rating = input("\n" "Please key-in the Stars : ")
        rating = rating.replace(" ","")
       
        if rating == "*":
            print("Service Rated is:", rating, " TERRIBLE")
        elif rating == "**":
            print("Service Rated is:", rating, " BAD")
        elif rating == "***":
            print("Service Rated is:", rating, " OK")
        elif rating == "****":
            print("Service Rated is:", rating, " GOOD")
        elif rating == "*****":
            print("Service Rated is:", rating, " EXCELLENT")

       
        print("\n" "THANK YOU! PLEASE VISIT AGAIN....")
       
       
#Main Program 
res = Restaurant()

res.menuDisplay()
res.orderConfirm()
res.billGeneration()
res.rateService()

Table Data File



Output




I really hope the above walk-through help in getting view of python programming.

Thursday, July 25, 2019

Cloud Transformation - Run Better

Whilst we are experiencing a profound transformation in the computational model and role of IT, I thought it would be a good idea to give a walk-through of basic concepts of Cloud Computing and various end to end service cloud offerings in the digital world.

 

Pre-Cloud Era - On-Premise On-Prem Software or App is installed and runs on computers on the premises of the person or organization rather than at a remote facility based on client-server architecture. The cost of building software was so high right from procurement of hardware, software to environment setup along with incurring the delays of service / product delivery to the market.

 

Cloud Computing often referred to as "the cloud", is the delivery of on-demand computing services everything from application to data centers over the internet on a subscription-based service where network storage space and computer resources are provisioned. Cloud provider can both own and house the hardware and software necessary to run business applications. The cloud makes it possible to access the information from anywhere at any time.

 

Why the name Cloud, inspired by the cloud symbol that's been in use to represent internet in the flow charts and network diagrams.

 

Comparison - On-Premise Vs Cloud

On-Premise

Cloud

Time consuming, requires additional hardware / software purchases to set up a new environment

Relatively faster to implement as it leverages a ready-made platform by the vendor

Responsible for maintaining the application, ensuring high availability and disaster recovery

Minimal IT dependence - Cloud Provider takes care of infrastructure risks and disaster recovery

Ownership on the responsibility for upgrades, which are often expensive and time-consuming

Iterative with limited involvement - Informed about impending system upgrades

Long term planning and commitment of resources for scaling

Easily scalable with little effort / time - Solutions can be scaled down without wasting resources

Additional effort / time and software for the required security

Highly secure with expert supervision of network and server security

High entry and operations costs

Low entry cost & flexible pricing

 

Types of Cloud Computing Services The three primary types of Cloud Computing Services are Infrastructure, Platform and Software. These services are made possible by virtualization and high speed networks.

 

Infrastructure as a Service (IaaS) deals primarily with providing access to infrastructure – storage, networking, servers, etc., in the form of virtualization. Only pay for the data transfer, storage, processing power and RAM that is required. IaaS is beneficial to businesses of all sizes, as it allows complete control over the infrastructure, and operates on a pay-as-per-use model.

 

Web hosting, online portals with heavy traffic where on-prem data center can be extended for temporary workloads. Network Architects are primarily involved in this service model to facilitate virtual machines, storage, firewalls, load balancers, virtual local area networks.

 

Platform as a Service (PaaS) provides a platform allowing customers to develop, run and manage applications without the complexity of building and maintaining the infrastructure. Additionally it also provisions middleware, development & deployment tools, Business Intelligence / Analytics services, Database Management System and more.

 

PaaS is primarily used by Application Developers who are building unique software / application.

Example would be web application development where developer to focus on the creative side of app development, as opposed to menial tasks such as managing software updates or security patches.

 

Software as a Service (SaaS) is software licensing and delivery model in which software / applications are hosted by a third party / cloud provider and are made accessible to customer over the internet via a subscription. Physical copy of software is not required to be installed on individual devices.

 

Primary focus of this service would be for End Users. Users connect to the application over the internet via a web browser. SaaS platforms are ideal when an application can run smoothly and reliably with minimal input.

Web-based email / Microsoft Office 365 and Google Apps (Documents) are some of the real-time examples.

 

Potential Risks & Dependencies in Cloud while each of the above models give users choice, flexibility and options that on-premise hosting cannot provide, there certain cons to be aware of :

Vulnerability Attacks - Security Breach for confidential data

Network Connectivity - Reliable and consistent internet service with a good connection speed and bandwidth

Customization & Integration - Enhancement to Legacy systems is required before migrating to Cloud as to seamlessly integrate with cloud provisioned infrastructure and services.

 

Why Migrate to Cloud?

Control growing operational cost

Business is dynamic in nature resulting in dynamic capacity requirements

Attain optimal return on investment

Leverage best of breed processes and continuous functionality upgrades

Go To Market lead time is reducing business potential

On demand model based on environment scaling need

Stay current on application releases without recurring upgrade cost

 

Leading Cloud Computing Service Providers

Microsoft Azure

Amazon Web Services

Google Cloud Platform

VMware

IBM Cloud

Salesforce

Oracle Cloud

Red Hat

Rackspace

Cisco

 

Before you step foot into Cloud Computing Industry, you need to pick up below skills to Run Better

Operating Systems Windows & Linux

Networking VLAN, IP Addressing, VNET, Subnet, DNS Systems

Database SQL, MySQL, MongoDB

Programming Skills Python, Perl, Java, .NET, Powershell

Virtualisation VMware, EC2, Lambda

Basic Concepts of Servers, Cyber Security & DevOps