Movie Ticketing Project - project

these is my movie ticketing Code
x = 10
Booked_seat = 0
prize_of_ticket = 0
Total_Income = 0
Row = int(input('Enter number of Row - \n'))
Seats = int(input('Enter number of seats in a Row - \n'))
Total_seat = Row*Seats
Booked_ticket_Person = [[None for j in range(Seats)] for i in range(Row)]
class chart:
#staticmethod
def chart_maker():
seats_chart = {}
for i in range(Row):
seats_in_row = {}
for j in range(Seats):
seats_in_row[str(j+1)] = 'S'
seats_chart[str(i)] = seats_in_row
return seats_chart
#staticmethod
def find_percentage():
percentage = (Booked_seat/Total_seat)*100
return percentage
class_call = chart
table_of_chart = class_call.chart_maker()
while x != 0:
print('1 for Show the seats \n2 for Buy a Ticket \n3 for Statistics ',
'\n4 for Show booked Tickets User Info \n0 for Exit')
x = int(input('Select Option - '))
if x == 1:
if Seats < 10:
for seat in range(Seats):
print(seat, end=' ')
print(Seats)
else:
for seat in range(10):
print(seat, end=' ')
for seat in range(10, Seats):
print(seat, end=' ')
print(Seats)
if Seats < 10:
for num in table_of_chart.keys():
print(int(num)+1, end=' ')
for no in table_of_chart[num].values():
print(no, end=' ')
print()
else:
count_num = 0
for num in table_of_chart.keys():
if int(list(table_of_chart.keys())[count_num]) < 9:
print(int(num)+1, end=' ')
else:
print(int(num)+1, end=' ')
count_key = 0
for no in table_of_chart[num].values():
if int(list(table_of_chart[num].keys())[count_key]) <= 10:
print(no, end=' ')
else:
print(no, end=' ')
count_key += 1
count_num += 1
print()
print('Vacant Seats = ', Total_seat - Booked_seat)
print()
elif x == 2:
Row_number = int(input('Enter Row Number - \n'))
Column_number = int(input('Enter Column Number - \n'))
if Row_number in range(1, Row+1) and Column_number in range(1, Seats+1):
if table_of_chart[str(Row_number-1)][str(Column_number)] == 'S':
if Row*Seats <= 60:
prize_of_ticket = 10
elif Row_number <= int(Row/2):
prize_of_ticket = 10
else:
prize_of_ticket = 8
print('prize_of_ticket - ', '$', prize_of_ticket)
conform = input('yes for booking and no for Stop booking - ')
person_detail = {}
if conform == 'yes':
person_detail['Name'] = input('Enter Name - ')
person_detail['Gender'] = input('Enter Gender - ')
person_detail['Age'] = input('Enter Age - ')
person_detail['Phone_No'] = input('Enter Phone number - ')
person_detail['Ticket_prize'] = prize_of_ticket
table_of_chart[str(Row_number-1)][str(Column_number)] = 'B'
Booked_seat += 1
Total_Income += prize_of_ticket
else:
continue
Booked_ticket_Person[Row_number-1][Column_number-1] = person_detail
print('Booked Successfully')
else:
print('This seat already booked by some one')
else:
print()
print('*** Invalid Input ***')
print()
elif x == 3:
print('Number of purchased Ticket - ', Booked_seat)
print('Percentage - ', class_call.find_percentage())
print('Current Income - ', '$', prize_of_ticket)
print('Total Income - ', '$', Total_Income)
print()
elif x == 4:
Enter_row = int(input('Enter Row number - \n'))
Enter_column = int(input('Enter Column number - \n'))
if Enter_row in range(1, Row+1) and Enter_column in range(1, Seats+1):
if table_of_chart[str(Enter_row-1)][str(Enter_column)] == 'B':
person = Booked_ticket_Person[Enter_row - 1][Enter_column - 1]
print('Name - ', person['Name'])
print('Gender - ', person['Gender'])
print('Age - ', person['Age'])
print('Phone number - ', person['Phone_No'])
print('Ticket Prize - ', '$', person['Ticket_prize'])
else:
print()
print('---**--- Vacant seat ---**---')
else:
print()
print('*** Invalid Input ***')
print()
else:
print()
print('*** Invalid Input ***')
print()
(i want To add Admin login panal and Customer login panel. How to do it??. also i want seperate things in Admin panal and customer panal, to Add first the 4 options into admin panal and Add First 2 options in Customer panal .. Thanks little help would be Very Helpfull <3

Related

SQL syntax query order by

SELECT TCID, START_TIME, RESULT,
cast(START_TIME as date) as m_date,
max(cast(START_TIME as time)) as max_time
FROM jenkins_result.JENKINS_RESULT
WHERE TCID = 'A330506'
GROUP BY TCID, m_date;
This is my data:
ID TCID START_DATE RESULT
1545240 A435727 2020-11-08 03:11:43 PASS
1545334 A435727 2020-11-08 03:19:53 PASS
1547439 A435727 2020-11-09 03:11:52 PASS
1547621 A435727 2020-11-09 03:20:05 PASS
1548388 A435727 2020-11-09 07:51:29 PASS
1558801 A435727 2020-11-12 00:11:10 PASS
1561899 A435727 2020-11-12 08:48:59 PASS
I want to get result of each TCID follow date like this
ID TCID START_DATE RESULT
1545334 A435727 2020-11-08 03:19:53 PASS
1548388 A435727 2020-11-09 07:51:29 PASS
1561899 A435727 2020-11-12 08:48:59 PASS
But the result current like that:
1545240 A435727 2020-11-08 03:11:43 PASS 2020-11-08 03:19:53
1547439 A435727 2020-11-09 03:11:52 PASS 2020-11-09 07:51:29
1558801 A435727 2020-11-12 00:11:10 PASS 2020-11-12 08:48:59
def connect_cli_server(self):
connect_success = 0
if self.ssh_client is None:
self.ssh_client = paramiko.SSHClient()
self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
for cnt in range(self.retry_cnt):
try:
self.ssh_client.connect(self.ip, 22, self.id, self.pw, timeout=self.time_out,
banner_timeout=self.banner)
connect_success = 1
break
except:
if cnt < 10:
time.sleep(random.uniform(0.1, 0.3))
if 10 <= cnt < 20:
time.sleep(random.uniform(0.1, 1))
else:
time.sleep(random.uniform(0.5, 1.5))
continue
if not connect_success:
try:
self.connect_cli_server_thru_remote_server()
except Exception as error:
print(error)
return False
return True
def send_command(self, ssh_client, command):
chan = ssh_client.get_transport().open_session()
chan.get_pty()
fileobject = chan.makefile()
chan.exec_command(command)
byteoutput = fileobject.read()
convetedstring = byteoutput.decode("UTF-8")
return convetedstring
I created some sample input by sql command
create table tbl_mock (
id int,
tc int,
startdate datetime,
result varchar(20)
);
insert into tbl_mock(id, tc, startdate, result) values (1, 1, '2020/11/12 09:00:00', 'pass');
insert into tbl_mock(id, tc, startdate, result) values (2, 1, '2020/11/12 10:00:00', 'fail');
insert into tbl_mock(id, tc, startdate, result) values (3, 1, '2020/11/12 11:00:00', 'pass');
insert into tbl_mock(id, tc, startdate, result) values (4, 1, '2020/11/13 09:00:00', 'pass');
insert into tbl_mock(id, tc, startdate, result) values (5, 1, '2020/11/13 10:00:00', 'fail');
insert into tbl_mock(id, tc, startdate, result) values (6, 1, '2020/11/13 11:00:00', 'fail');
You can try the below sql command to get your result
select tbl_a.*
from tbl_mock as tbl_a,
(select tc,
cast(startdate as date) as m_date,
max(cast(startdate as time)) as m_time
from tbl_mock
group by tc, m_date) as tbl_b
where tbl_a.tc = tbl_b.tc
and timestamp(tbl_b.m_date, tbl_b.m_time) = tbl_a.startdate
You can try this:
SELECT TCID
,START_TIME
,RESULT
,cast(START_TIME as date) as m_date
,max(cast(START_TIME as time)) as max_time
FROM jenkins_result.JENKINS_RESULT
WHERE TCID='A330506'
GROUP BY TCID
,START_TIME
,RESULT
,cast(START_TIME as date)
ORDER BY TCID
,m_date;
which should be the same as this:
SELECT DISTINCT TCID
,START_TIME
,RESULT
,cast(START_TIME as date) as m_date
,max(cast(START_TIME as time)) OVER() as max_time
FROM jenkins_result.JENKINS_RESULT
WHERE TCID='A330506'
ORDER BY TCID
,m_date;
or if you need to get the MAX value per TCID:
SELECT DISTINCT TCID
,START_TIME
,RESULT
,cast(START_TIME as date) as m_date
,max(cast(START_TIME as time)) OVER(PARTITION BY TCID) as max_time
FROM jenkins_result.JENKINS_RESULT
WHERE TCID='A330506'
ORDER BY TCID
,m_date;
import pygame
import os
import numpy as np
import queue
pygame.init()
q = 8
w = 70
def normalize_image(img):
return pygame.transform.scale(img, (w - 10, w - 10))
agent = pygame.image.load(os.path.join('EmptyAgent.png'))
wumpus = pygame.image.load(os.path.join('Wumpus.png'))
gold = pygame.image.load(os.path.join('Gold.png'))
pit = pygame.image.load(os.path.join('Pit.png'))
agent = normalize_image(agent)
wumpus = normalize_image(wumpus)
gold = normalize_image(gold)
pit = normalize_image(pit)
gr_empty = 0
gr_agent = 4
gr_wumpus = 1
gr_gold = 3
gr_pit = 2
clock = pygame.time.Clock()
screen = pygame.display.set_mode((q * w, q * w))
xh, yh = q - 1, 0
grid = [[gr_empty] * q for _ in range(q)]
grid[xh][yh] = gr_agent
bg_color = (255, 255, 255)
border_color = (0, 0, 0)
dx = [0,1,0,-1]
dy = [1,0,-1,0]
def bfs():
vs = np.zeros((q,q,8))
tracex = np.zeros((q,q,8))
tracey = np.zeros((q,q,8))
traced = np.zeros((q,q,8))
tracex[0][0][0] = 2
que = queue.Queue()
que.put((q-1,0,0,0))
vs[q-1][0][0]=1
gx, gy, gd, gt = 0, 0, 0, 1000
while not que.empty():
(x,y,dir,t) = que.get()
d=0
if grid[x][y]==3 and dir<4:
if gt>t:
gx, gy, gd, gt = x,y,dir,t
if vs[x][y][dir+4]==0:
que.put((x,y,dir+4,t+1))
vs[x][y][dir+4]=1
tracex[x][y][dir+4],tracey[x][y][dir+4],traced[x][y][dir+4] = x,y,dir
continue
if x==q-1 and y==0 and dir>3:
return 1000-(t+1)*10, gx, gy, gd, tracex, tracey, traced
if x<0 or y<0 or x>=q or y>=q:
continue
if grid[x][y]==gr_wumpus or grid[x][y]==gr_pit:
continue
if dir>3:
d+=4
dir-=4
if vs[x][y][(dir + 1 + 4) % 4 + d] == 0:
que.put((x, y, (dir + 1 + 4) % 4 + d, t + 1))
vs[x][y][(dir + 1 + 4) % 4 + d] = 1
tracex[x][y][(dir + 1 + 4) % 4 + d], tracey[x][y][(dir + 1 + 4) % 4 + d], traced[x][y][(dir + 1 + 4) % 4 + d] = x, y, dir
if vs[x][y][(dir - 1 + 4) % 4 + d] == 0:
que.put((x, y, (dir - 1 + 4) % 4 + d, t + 1))
vs[x][y][(dir - 1 + 4) % 4 + d] = 1
tracex[x][y][(dir - 1 + 4) % 4 + d], tracey[x][y][(dir - 1 + 4) % 4 + d], traced[x][y][(dir - 1 + 4) % 4 + d] = x, y, dir
if x+dx[dir]<0 or x+dx[dir]>=q or y+dy[dir]<0 or y+dy[dir]>=q:
continue
if vs[x + dx[dir]][y + dy[dir]][dir + d] == 0:
que.put((x + dx[dir], y + dy[dir], dir + d, t + 1))
vs[x + dx[dir]][y + dy[dir]][dir + d] = 1
tracex[x + dx[dir]][y + dy[dir]][dir + d], tracey[x + dx[dir]][y + dy[dir]][dir + d], traced[x + dx[dir]][y + dy[dir]][dir + d] = x, y, dir
return -1, gx, gy, gd, tracex, tracey, traced
def test():
grid[q-2][1] = gr_wumpus
grid[q-3][2] = gr_gold
grid[q-3][0] = gr_pit
ans, gx, gy, gd, tracex, tracey, traced = bfs()
if ans<0:
ans=-1
print(ans)
tx, ty, td = gx, gy, gd
if ans>=0:
while 1:
print(tx, ty, td)
if tx==q-1 and ty==0:
break
xn, yn, dn = int(tracex[tx][ty][td]), int(tracey[tx][ty][td]), int(traced[tx][ty][td])
tx, ty, td = xn,yn,dn
# print(tracex[0][0][0])
def draw_img(img, x, y):
screen.blit(img, (x + 5, y + 5))
def draw():
x, y = 0, 0
screen.fill(bg_color)
for i in range(q):
for j in range(q):
if grid[i][j] == gr_agent:
draw_img(agent, x, y)
elif grid[i][j] == gr_wumpus:
draw_img(wumpus, x, y)
elif grid[i][j] == gr_gold:
draw_img(gold, x, y)
elif grid[i][j] == gr_pit:
draw_img(pit, x, y)
for k in range(4):
pygame.draw.rect(screen, border_color, (x - k, y - k, w, w), 1)
x = x + w
x = 0
y = y + w
def main():
test()
while True:
events = pygame.event.get()
keys = pygame.key.get_pressed()
for event in events:
if event.type == pygame.QUIT:
return
elif event.type == pygame.MOUSEBUTTONDOWN:
mx, my = event.pos
gy = mx // w
gx = my // w
if not grid[gx][gy] == gr_empty:
continue
elif event.button == 1:
# Left click
grid[gx][gy] = gr_wumpus
elif event.button == 3:
# Scroll slick
grid[gx][gy] = gr_gold
elif event.button == 2:
# Middle click
grid[gx][gy] = gr_pit
draw()
pygame.display.flip()
clock.tick(600)
main()
import pygame
import os
import numpy as np
import queue
pygame.init()
q = 3
w = 70
def normalize_image(img):
return pygame.transform.scale(img, (w - 10, w - 10))
agent = pygame.image.load(os.path.join('EmptyAgent.png'))
wumpus = pygame.image.load(os.path.join('Wumpus.png'))
gold = pygame.image.load(os.path.join('Gold.png'))
pit = pygame.image.load(os.path.join('Pit.png'))
agent = normalize_image(agent)
wumpus = normalize_image(wumpus)
gold = normalize_image(gold)
pit = normalize_image(pit)
gr_empty = 0
gr_agent = 4
gr_wumpus = 1
gr_gold = 3
gr_pit = 2
clock = pygame.time.Clock()
screen = pygame.display.set_mode((q * w, q * w))
xh, yh = q - 1, 0
grid = [[gr_empty] * q for _ in range(q)]
grid[xh][yh] = gr_agent
bg_color = (255, 255, 255)
border_color = (0, 0, 0)
dx = [0,1,0,-1]
dy = [1,0,-1,0]
def bfs():
vs = np.zeros((q,q,8))
tracex = np.zeros((q,q,8))
tracey = np.zeros((q,q,8))
traced = np.zeros((q,q,8))
tracex[0][0][0] = 2
que = queue.Queue()
que.put((q-1,0,0,0))
vs[q-1][0][0]=1
gx, gy, gd, gt = 0, 0, 0, 1000
while not que.empty():
(x,y,dir,t) = que.get()
d=0
if grid[x][y]==3 and dir<4:
if gt>t:
gx, gy, gd, gt = x,y,dir,t
if vs[x][y][dir+4]==0:
que.put((x,y,dir+4,t+1))
vs[x][y][dir+4]=1
tracex[x][y][dir+4],tracey[x][y][dir+4],traced[x][y][dir+4] = x,y,dir
continue
if x==q-1 and y==0 and dir>3:
gx, gy, gd, gt = x, y, dir, t
return 1000-(t+1)*10, gx, gy, gd, tracex, tracey, traced
if x<0 or y<0 or x>=q or y>=q:
continue
if grid[x][y]==gr_wumpus or grid[x][y]==gr_pit:
continue
if dir>3:
d+=4
dir-=4
if vs[x][y][(dir + 1 + 4) % 4 + d] == 0:
que.put((x, y, (dir + 1 + 4) % 4 + d, t + 1))
vs[x][y][(dir + 1 + 4) % 4 + d] = 1
tracex[x][y][(dir + 1 + 4) % 4 + d], tracey[x][y][(dir + 1 + 4) % 4 + d], traced[x][y][(dir + 1 + 4) % 4 + d] = x, y, dir + d
if vs[x][y][(dir - 1 + 4) % 4 + d] == 0:
que.put((x, y, (dir - 1 + 4) % 4 + d, t + 1))
vs[x][y][(dir - 1 + 4) % 4 + d] = 1
tracex[x][y][(dir - 1 + 4) % 4 + d], tracey[x][y][(dir - 1 + 4) % 4 + d], traced[x][y][(dir - 1 + 4) % 4 + d] = x, y, dir + d
if x+dx[dir]<0 or x+dx[dir]>=q or y+dy[dir]<0 or y+dy[dir]>=q:
continue
if vs[x + dx[dir]][y + dy[dir]][dir + d] == 0:
que.put((x + dx[dir], y + dy[dir], dir + d, t + 1))
vs[x + dx[dir]][y + dy[dir]][dir + d] = 1
tracex[x + dx[dir]][y + dy[dir]][dir + d], tracey[x + dx[dir]][y + dy[dir]][dir + d], traced[x + dx[dir]][y + dy[dir]][dir + d] = x, y, dir + d
return -1, gx, gy, gd, tracex, tracey, traced
def test():
grid[q-2][1] = gr_wumpus
grid[q-3][2] = gr_gold
grid[q-3][0] = gr_pit
ans, gx, gy, gd, tracex, tracey, traced = bfs()
if ans<0:
ans=-1
print(ans)
tx, ty, td = gx, gy, gd
if ans>=0:
while 1:
print(tx, ty, td)
if tx==q-1 and ty==0 and td==0:
break
xn, yn, dn = int(tracex[tx][ty][td]), int(tracey[tx][ty][td]), int(traced[tx][ty][td])
tx, ty, td = xn,yn,dn
# print(tracex[0][0][0])
def draw_img(img, x, y):
screen.blit(img, (x + 5, y + 5))
def draw():
x, y = 0, 0
screen.fill(bg_color)
for i in range(q):
for j in range(q):
if grid[i][j] == gr_agent:
draw_img(agent, x, y)
elif grid[i][j] == gr_wumpus:
draw_img(wumpus, x, y)
elif grid[i][j] == gr_gold:
draw_img(gold, x, y)
elif grid[i][j] == gr_pit:
draw_img(pit, x, y)
for k in range(4):
pygame.draw.rect(screen, border_color, (x - k, y - k, w, w), 1)
x = x + w
x = 0
y = y + w
def main():
test()
while True:
events = pygame.event.get()
keys = pygame.key.get_pressed()
for event in events:
if event.type == pygame.QUIT:
return
elif event.type == pygame.MOUSEBUTTONDOWN:
mx, my = event.pos
gy = mx // w
gx = my // w
if not grid[gx][gy] == gr_empty:
continue
elif event.button == 1:
# Left click
grid[gx][gy] = gr_wumpus
elif event.button == 3:
# Scroll slick
grid[gx][gy] = gr_gold
elif event.button == 2:
# Middle click
grid[gx][gy] = gr_pit
draw()
pygame.display.flip()
clock.tick(600)
main()

Need to print Five sequence number for one sale.order other than ir.sequence

I have writen code to print five sequence number for 1 sale order
but it affect last sale order number , it was jumping 5 order numbers
I have to print 5 sequence number for 1 sale order without ir sequence
ticket = fields.Char(string="Ticket", readonly=True, required=True, copy=False, default='New')
#api.multi
def action_confirm(self):
result = super(SaleOrder, self).action_confirm()
len_count = []
ticket_list = []
tickets = ""
count = 5
for i in range(count):
x = self.env['ir.sequence'].next_by_code('sale.order')
if not len(len_count) == 5:
if not tickets:
tickets = x
else:
tickets = tickets + ',' + x
print tickets
print 'abc'
ticket_list.append(str(tickets))
self.ticket = ticket_list
print ticket_list
ctx = dict(self.env.context or {})
ctx.update({
'sale_action_new': ticket_list,
})
print ctx
template = self.env.ref('sale_order.email_template_ticket')
template.with_context(ctx).send_mail(self.id)
Let me try to help.
start = self.id //sales-order id
limit = start + 5
for x in range(start, limit):
if not tickets:
tickets = x
else:
tickets = tickets + ',' + x

Probabilistic Record Linkage in Pandas

I have two dataframes (X & Y). I would like to link them together and to predict the probability that each potential match is correct.
X = pd.DataFrame({'A': ["One", "Two", "Three"]})
Y = pd.DataFrame({'A': ["One", "To", "Free"]})
Method A
I have not yet fully understood the theory but there is an approach presented in:
Sayers, A., Ben-Shlomo, Y., Blom, A.W. and Steele, F., 2015. Probabilistic record linkage. International journal of epidemiology, 45(3), pp.954-964.
Here is my attempt to implementat it in Pandas:
# Probability that Matches are True Matches
m = 0.95
# Probability that non-Matches are True non-Matches
u = min(len(X), len(Y)) / (len(X) * len(Y))
# Priors
M_Pr = u
U_Pr = 1 - M_Pr
O_Pr = M_Pr / U_Pr # Prior odds of a match
# Combine the dataframes
X['key'] = 1
Y['key'] = 1
Z = pd.merge(X, Y, on='key')
Z = Z.drop('key',axis=1)
X = X.drop('key',axis=1)
Y = Y.drop('key',axis=1)
# Levenshtein distance
def Levenshtein_distance(s1, s2):
if len(s1) > len(s2):
s1, s2 = s2, s1
distances = range(len(s1) + 1)
for i2, c2 in enumerate(s2):
distances_ = [i2+1]
for i1, c1 in enumerate(s1):
if c1 == c2:
distances_.append(distances[i1])
else:
distances_.append(1 + min((distances[i1], distances[i1 + 1], distances_[-1])))
distances = distances_
return distances[-1]
L_D = np.vectorize(Levenshtein_distance, otypes=[float])
Z["D"] = L_D(Z['A_x'], Z['A_y'])
# Max string length
def Max_string_length(X, Y):
return max(len(X), len(Y))
M_L = np.vectorize(Max_string_length, otypes=[float])
Z["L"] = M_L(Z['A_x'], Z['A_y'])
# Agreement weight
def Agreement_weight(D, L):
return 1 - ( D / L )
A_W = np.vectorize(Agreement_weight, otypes=[float])
Z["C"] = A_W(Z['D'], Z['L'])
# Likelihood ratio
def Likelihood_ratio(C):
return (m/u) - ((m/u) - ((1-m) / (1-u))) * (1-C)
L_R = np.vectorize(Likelihood_ratio, otypes=[float])
Z["G"] = L_R(Z['C'])
# Match weight
def Match_weight(G):
return math.log(G) * math.log(2)
M_W = np.vectorize(Match_weight, otypes=[float])
Z["R"] = M_W(Z['G'])
# Posterior odds
def Posterior_odds(R):
return math.exp( R / math.log(2)) * O_Pr
P_O = np.vectorize(Posterior_odds, otypes=[float])
Z["O"] = P_O(Z['R'])
# Probability
def Probability(O):
return O / (1 + O)
Pro = np.vectorize(Probability, otypes=[float])
Z["P"] = Pro(Z['O'])
I have verified that this gives the same results as in the paper. Here is a sensitivity check on m, showing that it doesn't make a lot of difference:
Method B
These assumptions won't apply to all applications but in some cases each row of X should match a row of Y. In that case:
The probabilities should sum to 1
If there are many credible candidates to match to then that should reduce the probability of getting the right one
then:
X["I"] = X.index
# Combine the dataframes
X['key'] = 1
Y['key'] = 1
Z = pd.merge(X, Y, on='key')
Z = Z.drop('key',axis=1)
X = X.drop('key',axis=1)
Y = Y.drop('key',axis=1)
# Levenshtein distance
def Levenshtein_distance(s1, s2):
if len(s1) > len(s2):
s1, s2 = s2, s1
distances = range(len(s1) + 1)
for i2, c2 in enumerate(s2):
distances_ = [i2+1]
for i1, c1 in enumerate(s1):
if c1 == c2:
distances_.append(distances[i1])
else:
distances_.append(1 + min((distances[i1], distances[i1 + 1], distances_[-1])))
distances = distances_
return distances[-1]
L_D = np.vectorize(Levenshtein_distance, otypes=[float])
Z["D"] = L_D(Z['A_x'], Z['A_y'])
# Max string length
def Max_string_length(X, Y):
return max(len(X), len(Y))
M_L = np.vectorize(Max_string_length, otypes=[float])
Z["L"] = M_L(Z['A_x'], Z['A_y'])
# Agreement weight
def Agreement_weight(D, L):
return 1 - ( D / L )
A_W = np.vectorize(Agreement_weight, otypes=[float])
Z["C"] = A_W(Z['D'], Z['L'])
# Normalised Agreement Weight
T = Z .groupby('I') .agg({'C' : sum})
D = pd.DataFrame(T)
D.columns = ['T']
J = Z.set_index('I').join(D)
J['P1'] = J['C'] / J['T']
Comparing it against Method A:
Method C
This combines method A with method B:
# Normalised Probability
U = Z .groupby('I') .agg({'P' : sum})
E = pd.DataFrame(U)
E.columns = ['U']
K = Z.set_index('I').join(E)
K['P1'] = J['P1']
K['P2'] = K['P'] / K['U']
We can see that method B (P1) doesn't take account of uncertainty whereas method C (P2) does.

How do I use values to create a stacked bargraph?

so I created three dataframes in R using the count function
scan_count_AB <- count(Hive_AB$Has_been_scanned == 1)
scan_count_C <- count(Hive_C$Has_been_scanned == 1)
scan_count_D <- count(Hive_D$Has_been_scanned == 1)
> scan_count_AB
x freq
1 FALSE 1403
2 TRUE 627
> scan_count_C
x freq
1 FALSE 167
2 TRUE 846
> scan_count_D
x freq
1 FALSE 135
2 TRUE 880
Now I want to create three bargraphs that look like this
Can anyone help me how to do this?
You can try a ggplot2/tidyverse
library(tidyverse)
# your data
scan_count_AB <- data.frame(x= c(T, F), freq = c(1403, 627))
scan_count_C <- data.frame(x= c(T, F), freq = c(167, 846))
scan_count_D <- data.frame(x= c(T, F), freq = c(135, 880))
# and the plot
list(AB=scan_count_AB, C=scan_count_C, D=scan_count_D) %>%
bind_rows(.id = "id") %>%
group_by(id) %>%
mutate(perc = freq/(sum(freq))) %>%
mutate(x = factor(x, levels = c(T,F), labels=c("HNBS", "HBS"))) %>%
ggplot(aes(id, perc, fill = factor(x))) +
geom_col() +
scale_y_continuous(labels = scales::percent) +
scale_fill_discrete("") +
theme_bw() +
theme(legend.position = "bottom")

when i try to run the program, at the end its gives an error saying 'unexpected eof while parsing' how can i fix?

def main():
randOperation = Randomchoice(operation)
while True:
try:
randOperation()
randOperation = choice(operation)
userAns=int(input("Answer: "))
if userAns == answers:
print("Correct!" + "\n")
score = score + 1
NumOfTries =NumOfTries + 1
else:
print("Incorrect!" + "\n")
NumOfTries = NumOfTries + 1 #here is where the issue is