-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
142 lines (119 loc) · 4.24 KB
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
import pickle
import heapq
import psycopg2
import datetime
from twilio.rest import Client
# initializing sms api-twilio
with open('resources/auth.txt', 'r') as file:
account_sid = file.readline()
auth_token = file.readline()
print(auth_token)
client = Client(account_sid, auth_token)
# initializing postgresql db
conn = psycopg2.connect("dbname=syndicatebank user=postgres password='postgres'")
cur = conn.cursor()
def sql_query(mobile_number):
# RAMANSH PSYCOPG2 IS SQL INJECTION PROOF!!!!!
cur.execute("SELECT * FROM customerdetails WHERE mobilenumber=%s;", (mobile_number,))
customers = cur.fetchall()
if len(customers)>1:
print("Multiple customers with same mobile numbers!")
return None
elif len(customers)==0:
print("No entry found!")
return -1
else:
return (customers[0])
try:
with open("resources/weights.bat","rb") as file:
weights = pickle.load(file)
except FileNotFoundError:
weights = {'time':1,
'D_score':1,
'is_specially_abled':1,
'POV':1
}
def get_POV():
try:
with open("resources/POV.dat","rb") as file:
POV = pickle.load(file)
return POV
except FileNotFoundError:
POV={'1':4}
class customer():
instances = 0
def __init__(self, mobile_number, POV, weights):
# details to be entered by user
self.mobile_number = str(mobile_number)
self.POV_code = str(POV)
# details to get from sql using mobile_number
details = sql_query(self.mobile_number)
self.D_score = details[2]
self.name = details[1]
self.is_specially_abled = details[3]
# details generated
self.ID = str(datetime.datetime.now().microsecond)+mobile_number[6:]
self.in_time = datetime.datetime.now()
self.score = self.calculate_score(weights)
# increasing instances
customer.instances += 1
# variables for internal use
self.re_entries = 0
self.waiting_time = 0
self.service_start = datetime.datetime.now()
self.on_counter_time = 0
def __del__(self):
customer.instances -= 1
def __lt__(self, other):
return self.score > other.score
def __eq__(self, other):
return self.ID == other.ID
def calculate_score(self, weights):
POV = get_POV()
score = 0
print(weights)
score += weights["time"]*(datetime.datetime.now()-self.in_time).total_seconds()
score += weights["D_score"]*self.D_score
score += weights["is_specially_abled"]*self.is_specially_abled
score += weights["POV"]*POV[self.POV_code]
return score
def end_waiting_time(self):
self.waiting_time = (datetime.datetime.now() - self.in_time).total_seconds()
def start_counter_time(self):
self.service_start = datetime.datetime.now()
def end_service(self):
self.on_counter_time = (datetime.datetime.now() - self.service_start).total_seconds()
def update_digital_score(self, value):
# TODO: update_digital_score
pass
def alert_customer(self, text):
to_number = "+91"+self.mobile_number
print(to_number)
message = client.messages.create(body=text, from_="+12015089104", to=to_number)
print(message.sid)
def update_details(self):
# TODO: update_details
pass
class line():
def __init__(self):
self.queue = []
def __push(self, customer):
heapq.heappush(self.queue, customer)
heapq._heapify_max(self.queue)
def add_customer(self, customer):
self.__push(customer)
for i in range(len(self.queue)):
if self.queue[i] == customer:
l = self.queue[i+1:]
self.queue = self.queue[:i+1]
break
heapq._heapify_max(self.queue)
for i in l:
self.__push(i)
for i in range(len(l)):
l[i].calculate_score(weights)
self.__push(l[i])
def get_next_customer(self):
print(type(self.queue))
return heapq._heappop_max(self.queue)