Sunday 18 October 2020

IOT and COVID 19

 





COVID 19 and Blockchain

 

MAJOR CHALLENGES OF COVID-19

·        One major issue is how prepared the world’s health systems are to respond to this outbreak.

·        Tracking a huge population of infectious patients to stop epidemics

·        Another is the immediate requirement for developing better diagnostics, vaccines, and targeted therapeutics.

·        Misinformation and conspiracy theories spread through social media platforms.

·        Various limitations while accessing the tools when required. 

·        No adequate measures to adopt in a crisis situation. 

CAN BLOCKCHAIN HELP IN PREVENTING PANDEMICS?

With Blockchain we can share any transaction / information, real time, between relevant parties present as nodes in the chain, in a secure and immutable fashion. In this case, had there been a blockchain where WHO, Health Ministry of each country and may be even relevant nodal hospitals of each country, were connected, sharing real time information, about any new communicable disease, then the world might have woken up much earlier. We might have seen travel restrictions given sooner, quarantining policies set sooner and social distancing implemented faster. And may be fewer countries would have got impacted.

What every country is doing now fighting this pandemic, would have been restricted to fewer countries and in a much smaller scale. The usage of a Blockchain to share the information early on, might have saved the world a lot of pain.

The world had not seen anything like COVID-19 pandemic before in the recent history. Today we need to take a hard look at the reporting infrastructure available for communicable diseases, both technology and regulations and improve upon that, such that we do not need to face another pandemic like this in the future. 

 

Source : https://www.bbvaopenmind.com/en/technology/digital-world/blockchain-technology-and-covid-19/

Sunday 15 March 2020

Tkinter Game

import tkinter
#...and for creating random numbers.
import random
 
#the list of possible colour.
colours = ['Red','Blue','Green','Pink','Black','Yellow','Orange','White','Purple','Brown']
#the player's score, initially 0.
score=0
#the game time left, initially 30 seconds.
timeleft=30
 
#a function that will start the game.
def startGame(event):
 
    #if there's still time left...
    if timeleft == 30:
        #start the countdown timer.
        countdown()
        
    #run the function to choose the next colour.
    nextColour()
 
#function to choose and display the next colour.
def nextColour():
 
    #use the globally declared 'score' and 'play' variables above.
    global score
    global timeleft
 
    #if a game is currently in play...
    if timeleft > 0:
 
        #...make the text entry box active.
        e.focus_set()
 
        #if the colour typed is equal to the colour of the text...
        if e.get().lower() == colours[1].lower():
            #...add one to the score.
            score += 1
 
        #clear the text entry box.
        e.delete(0, tkinter.END)
        #shuffle the list of colours.
        random.shuffle(colours)
        #change the colour to type, by changing the text _and_ the colour to a random colour value
        label.config(fg=str(colours[1]), text=str(colours[0]))
        #update the score.
        scoreLabel.config(text="Score: " + str(score))
 
#a countdown timer function. 
def countdown():
 
    #use the globally declared 'play' variable above.
    global timeleft
 
    #if a game is in play...
    if timeleft > 0:
 
        #decrement the timer.
        timeleft -= 1
        #update the time left label.
        timeLabel.config(text="Time left: " + str(timeleft))
        #run the function again after 1 second.
        timeLabel.after(1000, countdown)
    
#create a GUI window.
root = tkinter.Tk()
#set the title.
root.title("TTCANTW")
#set the size.
root.geometry("375x200")
 
#add an instructions label.
instructions = tkinter.Label(root, text="Type in the colour of the words, and not the word text!", font=('Helvetica', 12))
instructions.pack()
 
#add a score label.
scoreLabel = tkinter.Label(root, text="Press enter to start", font=('Helvetica', 12))
scoreLabel.pack()
 
#add a time left label.
timeLabel = tkinter.Label(root, text="Time left: " + str(timeleft), font=('Helvetica', 12))
timeLabel.pack()
 
#add a label for displaying the colours.
label = tkinter.Label(root, font=('Helvetica', 60))
label.pack()
 
#add a text entry box for typing in colours.
e = tkinter.Entry(root)
#run the 'startGame' function when the enter key is pressed.
root.bind('<Return>', startGame)
e.pack()
#set focus on the entry box.
e.focus_set()
 
#start the GUI
root.mainloop()

MR Python

from pandas import DataFrame
from sklearn import linear_model
import statsmodels.api as sm

#statsmodels is a Python module that provides classes and functions
#for the estimation of many different statistical models,
#as well as for conducting statistical tests, and statistical
#data exploration.

Stock_Market = {'Year': [2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2017,2016,2016,2016,2016,2016,2016,2016,2016,2016,2016,2016,2016],
                'Month': [12, 11,10,9,8,7,6,5,4,3,2,1,12,11,10,9,8,7,6,5,4,3,2,1],
                'Interest_Rate': [2.75,2.5,2.5,2.5,2.5,2.5,2.5,2.25,2.25,2.25,2,2,2,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75,1.75],
                'Unemployment_Rate': [5.3,5.3,5.3,5.3,5.4,5.6,5.5,5.5,5.5,5.6,5.7,5.9,6,5.9,5.8,6.1,6.2,6.1,6.1,6.1,5.9,6.2,6.2,6.1],
                'Stock_Index_Price': [1464,1394,1357,1293,1256,1254,1234,1195,1159,1167,1130,1075,1047,965,943,958,971,949,884,866,876,822,704,719]       
                }

df = DataFrame(Stock_Market,columns=['Year','Month','Interest_Rate',
                                     'Unemployment_Rate','Stock_Index_Price'])

X = df[['Interest_Rate','Unemployment_Rate']] # here we have 2 variables for multiple regression. If you just want to use one variable for simple linear regression, then use X = df['Interest_Rate'] for example.Alternatively, you may add additional variables within the brackets
Y = df['Stock_Index_Price']

# with sklearn
regr = linear_model.LinearRegression()
regr.fit(X, Y)

print('Intercept: \n', regr.intercept_)
print('Coefficients: \n', regr.coef_)

# prediction with sklearn
New_Interest_Rate = 2.75
New_Unemployment_Rate = 5.3
print ('Predicted Stock Index Price: \n',
       regr.predict([[New_Interest_Rate ,New_Unemployment_Rate]]))

# with statsmodels
X = sm.add_constant(X) # adding a constant

#OLS stands for ordinary least squares
#As we know, the simplest linear regression algorithm assumes
#that the relationship between an independent variable (x)
#and dependent variable (y) is of the following form: y = mx + c,
#which is the equation of a line.
#In line with that, OLS is an estimator in which the values of m and
#c (from the above equation) are chosen in such a
#way as to minimize the sum of the squares of the differences between the
#observed dependent variable and predicted dependent variable.
#That’s why it’s named ordinary
#least squares.Also, it should be noted that when the sum of
#the squares of the differences is minimum,
#the loss is also minimum—hence the prediction is better.

model = sm.OLS(Y, X).fit()
predictions = model.predict(X)

print_model = model.summary()
print(print_model)


#Stock_Index_Price = (Intercept) + (Interest_Rate coef)*X1 + (Unemployment_Rate coef)*X2
#Stock_Index_Price = (1798.4040) + (345.5401)*X1 + (-250.1466)*X2
Interest Rate = 2.75 (i.e., X1= 2.75)
Unemployment Rate = 5.3 (i.e., X2= 5.3)

#Stock_Index_Price = (1798.4040) + (345.5401)*(2.75) + (-250.1466)*(5.3) = 1422.86

Saturday 14 March 2020

Tkinter2

from openpyxl.workbook import Workbook
import tkinter as tk
import pandas as pd

def saveinfo():
    valor1 = entry1.get()
    valor2 = entry2.get()
    valor3 = entry3.get()

    data.append([valor1, valor2, valor3])
    print(data)

def export():
    df = pd.DataFrame(data)
    df.to_excel("DataBase.xlsx")

def opennewwindow():
    global entry1
    global entry2
    global entry3

    window.destroy()

    newwindow = tk.Tk()

    tk.Label(newwindow, text="Please, enter data: ").grid(column=0, row=0, columnspan=3)

    tk.Label(newwindow, text="Number").grid(column=0, row=1)
    entry1 = tk.Entry(newwindow)
    entry1.grid(column=1, row=1)

    tk.Label(newwindow, text="Description", ).grid(column=0, row=2)
    entry2 = tk.Entry(newwindow)
    entry2.grid(column=1, row=2)

    tk.Label(newwindow, text="Brand").grid(column=0, row=3)
    entry3 = tk.Entry(newwindow)
    entry3.grid(column=1, row=3)

    tk.Button(newwindow, text="Save", command=saveinfo).grid(column=2, row=2, sticky='we')
    tk.Button(newwindow, text="Export", command=export).grid(column=2, row=3, sticky='we')

    newwindow.mainloop()

# --- main ---

df = pd.DataFrame
data = []

window = tk.Tk()
tk.Label(window, text="Platform").grid(column=0, row=0)
tk.Button(window, text="Choose an element: ", command=opennewwindow).grid(column=0, row=1)

window.mainloop()

Tkinter1

import tkinter as tk

root= tk.Tk()

canvas1 = tk.Canvas(root, width = 400, height = 300,  relief = 'raised')
canvas1.pack()

label1 = tk.Label(root, text='Calculate the Square Root')
label1.config(font=('helvetica', 14))
canvas1.create_window(200, 25, window=label1)

label2 = tk.Label(root, text='Type your Number:')
label2.config(font=('helvetica', 10))
canvas1.create_window(200, 100, window=label2)

entry1 = tk.Entry (root)
canvas1.create_window(200, 140, window=entry1)

def getSquareRoot ():
 
    x1 = entry1.get()
 
    label3 = tk.Label(root, text= 'The Square Root of ' + x1 + ' is:',font=('helvetica', 10))
    canvas1.create_window(200, 210, window=label3)
 
    label4 = tk.Label(root, text= float(x1)**0.5,font=('helvetica', 10, 'bold'))
    canvas1.create_window(200, 230, window=label4)
 
button1 = tk.Button(text='Get the Square Root', command=getSquareRoot, bg='brown', fg='white', font=('helvetica', 9, 'bold'))
canvas1.create_window(200, 180, window=button1)

root.mainloop()