Skip to content

Instantly share code, notes, and snippets.

@ParthibanSoundram
Last active December 18, 2018 05:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ParthibanSoundram/f24ef8b3271709dd4c7f95ed50afd074 to your computer and use it in GitHub Desktop.
Save ParthibanSoundram/f24ef8b3271709dd4c7f95ed50afd074 to your computer and use it in GitHub Desktop.
BossyDistantDownload created by ParthibanSoundr - https://repl.it/@ParthibanSoundr/BossyDistantDownload
def f():
# print(s)
s = 'HAI...'
print(s)
s = "I love Paris in the summer!"
f()
print(s)
print(":::::::::::::::::::::::::::::::::::::::::::::::::")
def f():
global s
# print(s)
s = "Only in spring, but London is great as well!"
print(s)
# s = "I am looking for a course in Paris!"
f()
s='gggggggg'
print(s)
print(":::::::::::::::::::::::::::::::::::::::::::::::::")
# nonlocal
def f():
x = 42
# global x
def g():
nonlocal x
x = 43
print("Before calling g: " + str(x))
print("Calling g now:")
g()
print("After calling g: " + str(x))
x = 3
f()
print("x in main: " + str(x))
print(":::::::::::::::::::::::::::::::::::::::::::::::::")
import numpy as np
x1 = np.linspace(65.4400, 101.6280, num=12, endpoint=False)
print(x1)
print("*******************")
x2 = np.linspace(0,1,num=4)
print(x2)
x2 = np.linspace(0,1,num=4,endpoint=False)
print(x2)
import pendulum
date = '2018-12-17 16:18:00'
print('America/Los_Angeles:',pendulum.parse(date, tz='America/Los_Angeles').strftime('%Y-%m-%d %H:%M:%S %Z%z'))
print('America/New_York:',pendulum.parse(date, tz='America/New_York').strftime('%Y-%m-%d %H:%M:%S %Z%z'))
print('Pacific/Honolulu:',pendulum.parse(date, tz='Pacific/Honolulu').strftime('%Y-%m-%d %H:%M:%S %Z%z'))
print('Asia/Kolkata:',pendulum.parse(date, tz='Asia/Kolkata').strftime('%Y-%m-%d %H:%M:%S %Z%z'))
import random
import numpy as np
# Generate Random Float numbers given range
def Rand(start, end, num):
pressure = []
for j in range(num):
pressure.append(random.uniform(start, end))
return pressure
# Driver Code
num = 100
start = 984.01
end = 990.99
pressure = Rand(start, end, num)
temp = Rand(61.97, 73.36, 100)
x = []
for j in range(num):
x.append([pressure[j],temp[j]])
# print('x:',x)
# print('xx:',np.array(x))
x = np.array(x)
tempratureReadings = x[:len(x), 1]
# temperature_conversion = list(map(float,tempratureReadings))
# print('maxxxxxxx',np.amax(tempratureReadings))
# print('temperature_conversion',temperature_conversion[:10])
pressureReadings = [np.float(row) for row in tempratureReadings]
print('pressureReadings',pressureReadings)
x = np.around(x, decimals=3)
print(x[:5])
modified_Reading = np.around(pressure, decimals=3)
# print(modified_Reading[:10])
modified_Reading = np.reshape(modified_Reading,(-1, 1))
# print(modified_Reading[:10])
# Class Sample For Understanding Methods
class Sample:
def __init__(self):
print('dunder called')
self.var1 = 10
self.var2 = 20
# Methods calling inside the class init method
print('static INIT--->> add',self.add(self.var1,self.var2))
print('class INIT--->> sub',self.sub(self.var1,self.var2))
print('instance INIT--->> multi',self.multi(self.var1,self.var2))
print('static INIT--->> add',Sample.add(self.var1,self.var2))
print('class INIT--->> sub',Sample.sub(self.var1,self.var2))
# print('instance INIT--->> multi',Sample.multi(self.var1,self.var2)) #Error Throws
# Instance method should be use self to call the method
@staticmethod
def add(var1,var2):
return var1 + var2
@classmethod
def sub(cls,val1,val2):
return val1 - val2
def multi(self,x,y):
return x * y
# return self.var1 * self.var2 working
object1 = Sample()
# Correct WAY
# static method calling
outer1 = Sample.add(object1.var1,object1.var2)
outer1 = object1.add(object1.var1,object1.var2)
outer1 = object1.add(5,5)
print('Static method OUTSIDE CALL::>>>>',outer1)
# class method calling
outer3 = Sample.sub(object1.var1,object1.var2)
outer3 = object1.sub(object1.var1,object1.var2)
outer3 = object1.sub(5,4)
print('Class method OUTSIDE CALL::>>>>',outer3)
# instancemethod calling
outer2 = object1.multi(object1.var1,object1.var2)
# outer2 = object1.multi()# Error bacoz should pass parameter
outer2 = object1.multi(1,2)
print('Instance method OUTSIDE CALL::>>>>',outer2)
# Wrong Way
# static method calling
# outer1 = Sample.add(Sample().var1,Sample().var2)
# or
# outer1 = Sample.add(Sample.var1,Sample.var2)
# class method calling
# outer3 = Sample.sub(Sample.var1,Sample.var2)
# outer3 = Sample.sub(Sample().var1,Sample().var2)
class Test:
# class variables / static variables
aa = 20
bb = 10
def __init__(self):
# instance variables
self.a = 1
self.b = 2
def sample(self):
print('instance method ::', self.aa + self.bb)
print('instance method access __init__ ::', self.a + self.b)
@staticmethod
def static_method():
print('static_method ::', Test.aa + Test.bb)
# print('static_method access __init__ ::', Test.a + Test.b) Can't access directly so create object
obj = Test()
print('static_method access __init__ ::', obj.a + obj.b)
@classmethod
def class_method(cls):
print('class_method ::', cls.aa + cls.bb)
# print('class_method access __init__ ::', cls.a + cls.b) Can't access directly so create object
cls.a = 100
# obj = Test()
# print('class_method access __init__ ::', obj.a + obj.b)
print('class_method access __init__ ::', cls.a + obj.b)
print('class_method access __init__ ::', cls.aa + obj.bb)
def testing(self):
print('instance method test access __init__ ::', self.aa + self.bb)
obj = Test()
obj.sample()
obj.static_method()
obj.class_method()
obj.testing()
# If use class name to change class variable then the value was changed here after for whole program
Test.aa = 100
Test.bb = 200
print("After Changing class variable")
obj.sample()
obj.static_method()
obj.class_method()
obj.testing()
# import numpy as np
# import matplotlib
# matplotlib.use("agg")
# import matplotlib.pyplot as plt
# import matplotlib.font_manager
# from sklearn import svm
# # Train _data
# temp = [65.44,68.45566667,71.47133333,74.487,77.50266667,80.51833333,83.534,86.54966667,89.56533333,92.581]
# outside_temp = [67,70,73,74.487,73.50,78.518,80.534,81.5496,89,92.581]
# pressure = [987.9200,987.9300,987.9300,987.9200,987.9400,987.9400,987.9400,987.9500,987.9500,987.9400,987.9400]
# humidity = [31.7000,31.3800,31.3800,31.4000,31.3900,31.3400,31.4100,31.4200,31.4200,31.4200,31.4000]
# train_data = []
# for i in range(0,len(temp)):
# train_data.append([temp[i],outside_temp[i],pressure[i],humidity[i]])
# train_data = np.array(train_data)
# print("Train_data::::::::::::::::")
# # train_data = np.delete(train_data,[2],axis=1)
# print(train_data)
# # Test _data
# test_temp = [61.47133333,67.487,71.50266667,72.51833333,78.534,82.54966667]
# test_outside_temp = [61,65.487,74.50,75.51833333,80.534,85.54966667]
# test_pressure = [977.9200,967.9400,989.9500,988.9400,986.9500,987.9500]
# test_humidity = [31.6000,31.1800,31.2800,31.3400,31.5100,31.5200,31.6000]
# test_data = []
# for i in range(0,len(test_temp)):
# test_data.append([test_temp[i],test_outside_temp[i],test_pressure[i],test_humidity[i]])
# test_data = np.array(test_data)
# print("Test test_data::::::::::::::::")
# # test_data = np.delete(test_data,[2],axis=1)
# print(test_data)
# clf = svm.OneClassSVM(nu=0.2, kernel="rbf", gamma='auto')
# clf.fit(train_data)
# # y_pred_train = clf.predict(train_data)
# # print(":::::: y_pred_train ::::")
# # print(y_pred_train)
# y_pred_test = clf.predict(test_data)
# print(":::::: y_pred_test ::::")
# print(y_pred_test)
# test_decision = clf.decision_function(test_data)
# print('decision function is:::::')
# print(test_decision)
# test_score=clf.score_samples(test_data)
# print('score samples is:::::::::')
# print(test_score)
from datetime import datetime
# from pytz import timezone
from pendulum import timezone
print(timezone)
date_str = "2014-05-28 22:28:15"
datetime_obj_naive = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
# Wrong way!
datetime_obj_pacific = datetime_obj_naive.replace(tzinfo=timezone('US/Pacific'))
print(datetime_obj_pacific.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
# Right way!
datetime_obj_pacific = timezone('US/Pacific').localize(datetime_obj_naive)
print(datetime_obj_pacific.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
# UTC time now
print('_______________UTC__________________')
time_zone = 'America/Los_Angeles' #'US/Pacific'
utc_now = datetime.utcnow()
# print(utc_now)
# utc_now = datetime.strptime(str(utc_now),"%Y-%m-%d %H:%M:%S.%f").strftime("%Y-%m-%d %H:%M:%S")
# dateTimeobj = datetime.strptime(utc_now, "%Y-%m-%d %H:%M:%S")
# local_time = timezone(time_zone).localize(dateTimeobj)
# print('dateTimeobj::',local_time.strftime("%Y-%m-%d %H:%M:%S %Z%z"))
from datetime import datetime
from pytz import timezone
format = "%Y-%m-%d %H:%M:%S %Z%z"
print("----------------DateTime to timezone Local time---------------")
date_str = "2018-12-17 17:04:10"
datetime_obj_naive = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
now_asia = datetime_obj_naive.astimezone(timezone('Asia/Kolkata'))
print('India now:',now_asia.strftime(format))
seattle = datetime_obj_naive.astimezone(timezone('America/Los_Angeles'))
print('seattle::',seattle.strftime(format))
virginia = datetime_obj_naive.astimezone(timezone('America/New_York'))
print('virginia::',virginia.strftime(format))
print("----------------TImestamp to timezone Local time---------------")
utc_ts = 1545110450
utc_dateTime = datetime.fromtimestamp(int(utc_ts))
readable_dateTime = utc_dateTime
print('Readable Datetime:',readable_dateTime)
now_asia = readable_dateTime.astimezone(timezone('Asia/Kolkata'))
print('Indian Time:',now_asia.strftime(format))
seattle = readable_dateTime.astimezone(timezone('America/Los_Angeles'))
print('seattle::',seattle.strftime(format))
virginia = readable_dateTime.astimezone(timezone('America/New_York'))
print('virginia::',virginia.strftime(format))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment