-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscddemo.py
134 lines (111 loc) · 4.74 KB
/
scddemo.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
import PySimpleGUI as sg
import datetime
class DataWareHouse:
DW = {}
def __init__(self,data):
self.DW = data
def check_if_exist_and_active(self,customerkey):
for i in self.DW:
if(self.DW[i]['CustomerKey']==customerkey):
if(self.DW[i]['isActive']==1):
return i
return False
def insert_data(self,data):
dt = datetime.datetime.now()
date = "-".join(str(x) for x in [dt.year,dt.month,dt.day])
if self.check_if_exist_and_active(data['CustomerKey'])==False:
self.DW[len(self.DW)+1] = {
"SurrogateKey":len(self.DW)+1,
"CustomerKey":data['CustomerKey'],
"CustomerAddress":data['CustomerAddress'],
"isActive":1,
"ValidFrom":date,
"ValidTo":"9999-12-31",
}
else:
i = self.check_if_exist_and_active(data['CustomerKey'])
if self.DW[i]['CustomerAddress']!=data["CustomerAddress"]:
self.DW[i]['isActive']=0
self.DW[i]['ValidTo']=date
self.DW[len(self.DW)+1] = {
"SurrogateKey":len(self.DW)+1,
"CustomerKey":data['CustomerKey'],
"CustomerAddress":data['CustomerAddress'],
"isActive":1,
"ValidFrom":date,
"ValidTo":"9999-12-31",
}
def view_records(self):
return self.DW
def get_record_list(self):
records = []
for i in self.DW:
record = list(self.DW[i].values())
records.append(record)
return records
dw = DataWareHouse({
1:{
"SurrogateKey":1,
"CustomerKey":1,
"CustomerAddress":"82 Margate Drive, Sheffield, S4 8FQ",
"isActive":1,
"ValidFrom":"2022-01-19",
"ValidTo":"9999-12-31",
},
2:{
"SurrogateKey":2,
"CustomerKey":2,
"CustomerAddress":"135 High Barns, Ely, CB7 4RH",
"isActive":1,
"ValidFrom":"2022-01-19",
"ValidTo":"9999-12-31",
},
3:{
"SurrogateKey":3,
"CustomerKey":3,
"CustomerAddress":"39 Queen Annes Drive, Bedale, DL8 2EL",
"isActive":1,
"ValidFrom":"2022-01-19",
"ValidTo":"9999-12-31",
}
})
# dw.insert_data({'CustomerKey':1,'CustomerAddress':'82 Margate Drive, Sheffield, S4 8FQ'})
# dw.insert_data({'CustomerKey':2,'CustomerAddress':'135 High Barns, Ely, CB7 4RH, DL8 2EL'})
# dw.insert_data({'CustomerKey':3,'CustomerAddress':'Guyzance Cottage, Guyzance, NE65 9AF'})
# dw.insert_data({'CustomerKey':4,'CustomerAddress':'322 Fernhill, Mountain Ash, CF45 3EN'})
# dw.insert_data({'CustomerKey':5,'CustomerAddress':'381 Southborough Lane, Bromley, BR2 8BQ'})
# dw.view_records()
sg.set_options(font=("Arial Bold", 14))
toprow = "Surrogate Key, Customer Key, Customer Address, isActive, ValidFrom, ValidTo".split(",")
sg.theme('DarkBrown4') # Add a touch of color
rows = dw.get_record_list()
tbl1 = sg.Table(values=rows, headings=toprow,
auto_size_columns=True,
display_row_numbers=False,
justification='center', key='-TABLE-',
selected_row_colors='yellow on blue',
enable_events=True,
expand_x=True,
expand_y=True,
enable_click_events=True)
layout = [ [sg.Text('Add New Record')],
[sg.Text('Enter Customer Key : '), sg.HSeparator(pad=(10,0)),sg.Input(key='-CustKey-')],
[sg.Text('Enter Customer Address : '), sg.HSeparator(pad=(10,0)),sg.Input(key='-CustAdd-')],
[sg.Button('Add')],
[tbl1],
[sg.Button('Exit')]
]
window = sg.Window("Table Test",layout, resizable=True)
while True:
event, values = window.read(timeout=1000)
if event in (None, 'Exit'):
break
if '+CLICKED+' in event:
x = event[2][0]
window['-CustKey-'].update(rows[x][1])
window['-CustAdd-'].update(rows[x][2])
if event == 'Add':
dw.insert_data({'CustomerKey':int(values['-CustKey-']),'CustomerAddress':values['-CustAdd-']})
rows = dw.get_record_list()
window['-TABLE-'].update(rows)
window.close()