forked from codehouseindia/Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathQuery Processing For Distributed Database.py
More file actions
64 lines (49 loc) · 1.78 KB
/
Query Processing For Distributed Database.py
File metadata and controls
64 lines (49 loc) · 1.78 KB
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
no = int(input("Enter the total no of sites"))
result_site = int(input("Enter the result site"))
A = [None] * (no+1)
B = []
strategies = []
strategy = 0
# Accept data information for each site(check for availability)
for i in range(1, no+1):
available = input("Is data for this site available ? Enter y or n")
if(available == "y"):
nooftuples = int(input("Enter no of tuples"))
size = int(input("Enter size of each tuple"))
data_size = nooftuples*size
A[i] = data_size
else:
A[i] = 0
# Accept result relation data
print("** Enter Result Site Data ***")
nooftuples = int(input("Enter no of tuples"))
size = int(input("Enter size of each tuple"))
result_data = nooftuples * size
# Find total strategies and calculate data transfer for each strategy
print("** PROCESSING ***")
for i in range(1, no+1):
(total_data, total_data_transfer) = (0, 0)
if(i == result_site):
for j in range(1, no+1):
if(j != result_site):
print("Transfer data from site ",j," to site ",result_site)
total_data += A[j]
strategy += 1
print("Strategy Id:", strategy)
print("Total Data Transfer:", total_data)
B.append(total_data)
strategies.append(strategy)
else:
for k in range(1, no+1):
if(k != i):
print("Transfer data from site ",k," to site ",i)
total_data += A[k]
total_data_transfer = total_data + result_data
strategy += 1
B.append(total_data_transfer)
strategies.append(strategy)
print("Strategy Id:", strategy)
print("Total Data Transfer:", total_data_transfer)
print("** ENDED ***")
print("Min data transfer", min(B))
print("Best strategy", strategies[B.index(min(B))])