-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.py
More file actions
2534 lines (2236 loc) · 157 KB
/
Copy pathtable.py
File metadata and controls
2534 lines (2236 loc) · 157 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from os import sep, stat
from altair import Order
import streamlit as st
import numpy as np
import pandas as pd
import config
import yaml
import utils
from datetime import datetime, timedelta
import itertools
import string
st.set_page_config(layout="wide", initial_sidebar_state="auto")
database_config = st.session_state.map
left_column, right_column = st.columns(spec=config.page_split, gap="small", vertical_alignment="top")
# avoid overall scrolling
left_column = left_column.container(height=config.page_height, border=config.show_all_edge)
right_column = right_column.container(height=config.page_height, border=config.show_all_edge)
right_column.write("Table")
# confirm or rollback
sql_change = left_column.container(border=True)
sql_change_left, sql_change_right = sql_change.columns(([1,1]))
change_confirm = sql_change_left.button(label="Confirm", use_container_width=True)
cannot_rollback = False if len(st.session_state.stack) != 0 else True
change_rollback = sql_change_right.button(label="Rollback", use_container_width=True, disabled=cannot_rollback)
# table list and data change
table_and_change = left_column.container(border=True)
table_change = table_and_change.container(border=True)
area_add, area_delete, area_update = table_change.columns(3)
buttom_table_add = area_add.button(label="Add", use_container_width=True)
buttom_table_delete = area_delete.button(label="Delete", use_container_width=True)
buttom_table_update = area_update.button(label="Update", use_container_width=True)
table_list = table_and_change.container(border=True)
table_list_checkbox=[]
for name in database_config['table_name']:
is_default = False
if name == config.default_table:
is_default = True
tmp = table_list.checkbox(label=name, value = is_default)
table_list_checkbox.append(tmp)
# filters
filter_area = left_column.form("filters", border=True, enter_to_submit=False, clear_on_submit=False)
filter_area.write("Filters")
# if no selected table, no submission
has_selected_table = False
for status in table_list_checkbox:
if status:
has_selected_table = True
filter_area_buttom = filter_area.form_submit_button(label="Submit", disabled=not(has_selected_table))
# Store expanders/containers for the page
filters = {
"geolocation": None,
"sellers": None,
"customers": None,
"orders": None,
"order_payments": None,
"products": None,
"order_items": None,
"order_reviews": None
}
filters_geolocation = None
filters_sellers = None
filters_customers = None
filters_orders = None
filters_order_payments = None
filters_products = None
filters_order_items = None
filters_order_reviews = None
if has_selected_table:
# Store input widgets results
filters_geolocation = {
"geolocation_zip_code_prefix": None,
"geolocation_lat": None,
"geolocation_lng": None,
"geolocation_city": None,
"geolocation_state": None
}
filters_sellers = {
"seller_id": None,
"seller_zip_code_prefix": None,
"seller_city": None,
"seller_state": None
}
filters_customers = {
"customer_id": None,
"customer_unique_id": None,
"customer_zip_code_prefix": None,
"customer_city": None,
"customer_state": None}
filters_orders = {
"order_id": None,
"customer_id": None,
"order_status": None,
"order_purchase_timestamp": None,
"order_approved_at": None,
"order_delivered_carrier_date": None,
"order_delivered_customer_date": None,
"order_estimated_delivery_date": None
}
filters_order_payments = {
"order_id": None,
"payment_sequential": None,
"payment_type": None,
"payment_installments": None,
"payment_value": None
}
filters_products = {
"product_id": None,
"product_category_name": None,
"product_name_length": None,
"product_description_length": None,
"product_photos_qty": None,
"product_weight_g": None,
"product_length_cm": None,
"product_height_cm": None,
"product_width_cm": None
}
filters_order_items = {
"order_id": None,
"order_item_id": None,
"product_id": None,
"seller_id": None,
"shipping_limit_date": None,
"price": None,
"freight_value": None
}
filters_order_reviews = {
"review_id": None,
"order_id": None,
"review_score": None,
"review_creation_date": None
}
for name, status in zip(database_config['table_name'], table_list_checkbox):
if name == 'geolocation' and status:
geolocation_zip_code_prefix_list = st.session_state.connector.get_single_unique(name, "geolocation_zip_code_prefix").astype(str).tolist()
geolocation_latitude_min, geolocation_latitude_max = st.session_state.connector.get_single_min_max(name, "geolocation_lat")
geolocation_latitude_min = float(geolocation_latitude_min.iloc[0])
geolocation_latitude_max = float(geolocation_latitude_max.iloc[0])
geolocation_longtitude_min, geolocation_longtitude_max = st.session_state.connector.get_single_min_max(name, "geolocation_lng")
geolocation_longtitude_min = float(geolocation_longtitude_min.iloc[0])
geolocation_longtitude_max = float(geolocation_longtitude_max.iloc[0])
geolocation_city_list = st.session_state.connector.get_single_unique(name, 'geolocation_city').astype(str).tolist()
geolocation_state_list = st.session_state.connector.get_single_unique(name, 'geolocation_state').astype(str).tolist()
filters[name] = filter_area.expander(label = name)
filters_geolocation['geolocation_zip_code_prefix'] = filters[name].selectbox(label="zip_code", options = geolocation_zip_code_prefix_list, index=None)
filters_geolocation['geolocation_lat'] = filters[name].slider(label="Latitude", min_value=geolocation_latitude_min, max_value=geolocation_latitude_max, value=(geolocation_latitude_min, geolocation_latitude_max), step=config.accuracy)
filters_geolocation['geolocation_lng'] = filters[name].slider(label="Longtitude", min_value=geolocation_longtitude_min, max_value=geolocation_longtitude_max, value=(geolocation_longtitude_min, geolocation_longtitude_max), step=config.accuracy)
filters_geolocation['geolocation_city'] = filters[name].selectbox(label="City", options = geolocation_city_list, index=None)
filters_geolocation['geolocation_state'] = filters[name].selectbox(label="State", options = geolocation_state_list, index=None)
elif name == 'sellers' and status:
seller_id_list = st.session_state.connector.get_single_unique(name, "seller_id").astype(str).tolist()
seller_zip_code_prefix_list = st.session_state.connector.get_single_unique(name, "seller_zip_code_prefix").astype(str).tolist()
seller_city_list = st.session_state.connector.get_single_unique(name, 'seller_city').astype(str).tolist()
seller_state_list = st.session_state.connector.get_single_unique(name, 'seller_state').astype(str).tolist()
filters[name] = filter_area.expander(label = name)
filters_sellers['seller_id'] = filters[name].selectbox(label="ID", options=seller_id_list, index = None)
filters_sellers['seller_zip_code_prefix'] = filters[name].selectbox(label="zip_code", options=seller_zip_code_prefix_list, index = None)
filters_sellers['seller_city'] = filters[name].selectbox(label="City", options=seller_city_list, index = None)
filters_sellers['seller_state'] = filters[name].selectbox(label="State", options=seller_state_list, index = None)
elif name == 'customers' and status:
customer_id_list = st.session_state.connector.get_single_unique(name, "customer_id").astype(str).tolist()
customer_unique_id_list = st.session_state.connector.get_single_unique(name, "customer_unique_id").astype(str).tolist()
customer_zip_code_prefix_list = st.session_state.connector.get_single_unique(name, "customer_zip_code_prefix").astype(str).tolist()
customer_city_list = st.session_state.connector.get_single_unique(name, "customer_city").astype(str).tolist()
customer_state_list = st.session_state.connector.get_single_unique(name, "customer_state").astype(str).tolist()
filters[name] = filter_area.expander(label = name)
filters_customers["customer_id"] = filters[name].selectbox(label="ID", options=customer_id_list, index = None)
filters_customers["customer_unique_id"] = filters[name].selectbox(label="Unique_ID", options=customer_unique_id_list, index = None)
filters_customers["customer_zip_code_prefix"] = filters[name].selectbox(label="zip_code", options=customer_zip_code_prefix_list, index = None)
filters_customers["customer_city"] = filters[name].selectbox(label="City", options=customer_city_list, index = None)
filters_customers["customer_state"] = filters[name].selectbox(label="State", options=customer_state_list, index = None)
elif name == 'orders' and status:
order_id_list = st.session_state.connector.get_single_unique(name, "order_id").astype(str).tolist()
customer_id_list = st.session_state.connector.get_single_unique(name, "customer_id").astype(str).tolist()
order_status_list = st.session_state.connector.get_single_unique(name, 'order_status').astype(str).tolist()
order_purchase_timestamp_min, order_purchase_timestamp_max = st.session_state.connector.get_single_min_max(name, 'order_purchase_timestamp')
order_purchase_timestamp_min = pd.to_datetime(order_purchase_timestamp_min.loc[0]).to_pydatetime()
order_purchase_timestamp_max= pd.to_datetime(order_purchase_timestamp_max.loc[0]).to_pydatetime()
order_approved_at_min, order_approved_at_max = st.session_state.connector.get_single_min_max(name, 'order_approved_at')
order_approved_at_min = pd.to_datetime(order_approved_at_min.loc[0]).to_pydatetime()
order_approved_at_max = pd.to_datetime(order_approved_at_max.loc[0]).to_pydatetime()
order_delivered_carrier_date_min, order_delivered_carrier_date_max = st.session_state.connector.get_single_min_max(name, "order_delivered_carrier_date")
order_delivered_carrier_date_min = pd.to_datetime(order_delivered_carrier_date_min.loc[0]).to_pydatetime()
order_delivered_carrier_date_max = pd.to_datetime(order_delivered_carrier_date_max.loc[0]).to_pydatetime()
order_delivered_customer_date_min, order_delivered_customer_date_max = st.session_state.connector.get_single_min_max(name, "order_delivered_customer_date")
order_delivered_customer_date_min = pd.to_datetime(order_delivered_customer_date_min.loc[0]).to_pydatetime()
order_delivered_customer_date_max = pd.to_datetime(order_delivered_customer_date_max.loc[0]).to_pydatetime()
order_estimated_delivery_date_min, order_estimated_delivery_date_max = st.session_state.connector.get_single_min_max(name, "order_estimated_delivery_date")
order_estimated_delivery_date_min = pd.to_datetime(order_estimated_delivery_date_min.loc[0]).to_pydatetime()
order_estimated_delivery_date_max = pd.to_datetime(order_estimated_delivery_date_max.loc[0]).to_pydatetime()
filters[name] = filter_area.expander(label = name)
filters_orders['order_id'] = filters[name].selectbox(label="Order ID", options=order_id_list, index=None)
filters_orders['customer_id'] = filters[name].selectbox(label="Customer ID", options=customer_id_list, index=None)
filters_orders['order_status'] = filters[name].selectbox(label="Status", options=order_status_list, index=None)
filters_orders['order_purchase_timestamp'] = filters[name].slider("Purchase time", min_value=order_purchase_timestamp_min, max_value=order_purchase_timestamp_max, value=(order_purchase_timestamp_min, order_purchase_timestamp_max), step=config.time['step']['second'], format=config.time['format']['long'])
filters_orders['order_approved_at'] = filters[name].slider("Approved time", min_value=order_approved_at_min, max_value=order_approved_at_max, value=(order_approved_at_min, order_approved_at_max), step=config.time['step']['second'], format=config.time['format']['long'])
filters_orders['order_delivered_carrier_date'] = filters[name].slider("Delivered Carrier Date", min_value=order_delivered_carrier_date_min, max_value=order_delivered_carrier_date_max, value=(order_delivered_carrier_date_min, order_delivered_carrier_date_max), step=config.time['step']['day'], format=config.time['format']['short'])
filters_orders['order_delivered_customer_date'] = filters[name].slider("Delivered Customer Date", min_value=order_delivered_customer_date_min, max_value=order_delivered_customer_date_max, value=(order_delivered_customer_date_min, order_delivered_customer_date_max), step=config.time['step']['day'], format=config.time['format']['short'])
filters_orders['order_estimated_delivery_date'] = filters[name].slider("Estimated Delivery Date", min_value=order_estimated_delivery_date_min, max_value=order_estimated_delivery_date_max, value=(order_estimated_delivery_date_min, order_estimated_delivery_date_max), step=config.time['step']['day'], format=config.time['format']['short'])
elif name == 'order_payments' and status:
order_id_list = st.session_state.connector.get_single_unique(name, 'order_id').astype(str).tolist()
payment_sequential_list = st.session_state.connector.get_single_unique(name, 'payment_sequential').astype(str).tolist()
payment_type_list = st.session_state.connector.get_single_unique(name, 'payment_type').astype(str).tolist()
payment_installments_list = st.session_state.connector.get_single_unique(name, 'payment_installments').astype(str).tolist()
payment_value_min, payment_value_max = st.session_state.connector.get_single_min_max(name, 'payment_value')
payment_value_min = float(payment_value_min.iloc[0])
payment_value_max = float(payment_value_max.iloc[0])
filters[name] = filter_area.expander(label = name)
filters_order_payments['order_id'] = filters[name].selectbox(label = "Order ID", options = order_id_list, index = None)
filters_order_payments['payment_sequential'] = filters[name].selectbox(label = "Payment Sequential", options=payment_sequential_list, index=None)
filters_order_payments['payment_type'] = filters[name].selectbox(label="Payment Type", options=payment_type_list, index = None)
filters_order_payments['payment_installments'] = filters[name].selectbox(label="Payment Installments", options=payment_installments_list, index = None)
filters_order_payments['payment_value'] = filters[name].slider("Payment Value", min_value=payment_value_min, max_value=payment_value_max, value=(payment_value_min, payment_value_max), step=config.concurrency)
elif name == 'products' and status:
product_id_list = st.session_state.connector.get_single_unique(name, "product_id").astype(str).tolist()
product_category_name_list = st.session_state.connector.get_single_unique(name, "product_category_name").astype(str).tolist()
product_name_length_min, product_name_length_max = st.session_state.connector.get_single_min_max(name, "product_name_length")
product_name_length_min = int(product_name_length_min.loc[0])
product_name_length_max= int(product_name_length_max.loc[0])
product_description_length_min, product_description_length_max = st.session_state.connector.get_single_min_max(name, "product_description_length")
product_description_length_min = int(product_description_length_min.loc[0])
product_description_length_max = int(product_description_length_max.loc[0])
product_photos_qty_min, product_photos_qty_max = st.session_state.connector.get_single_min_max(name,"product_photos_qty")
product_photos_qty_min = int(product_photos_qty_min.loc[0])
product_photos_qty_max = int(product_photos_qty_max.loc[0])
product_weight_g_min, product_weight_g_max = st.session_state.connector.get_single_min_max(name,"product_weight_g")
product_weight_g_min = int(product_weight_g_min.loc[0])
product_weight_g_max = int(product_weight_g_max.loc[0])
product_length_cm_min, product_length_cm_max = st.session_state.connector.get_single_min_max(name, "product_length_cm")
product_length_cm_min = int(product_length_cm_min.loc[0])
product_length_cm_max = int(product_length_cm_max.loc[0])
product_height_cm_min, product_height_cm_max = st.session_state.connector.get_single_min_max(name, "product_height_cm")
product_height_cm_min = int(product_height_cm_min.loc[0])
product_height_cm_max = int(product_height_cm_max .loc[0])
product_width_cm_min, product_width_cm_max = st.session_state.connector.get_single_min_max(name, "product_width_cm")
product_width_cm_min = int(product_width_cm_min.loc[0])
product_width_cm_max = int(product_width_cm_max.loc[0])
filters[name] = filter_area.expander(label = name)
filters_products['product_id'] = filters[name].selectbox(label="Product ID", options = product_id_list, index=None)
filters_products['product_category_name'] = filters[name].selectbox(label="Product Category", options=product_category_name_list, index = None)
filters_products['product_name_length'] = filters[name].slider(label="Name Length", min_value=product_name_length_min, max_value=product_name_length_max, value=(product_name_length_min, product_name_length_max), step=config.integer)
filters_products['product_description_length'] = filters[name].slider(label="Description Length", min_value=product_description_length_min, max_value=product_description_length_max, value=(product_description_length_min, product_description_length_max), step=config.integer)
filters_products['product_photos_qty'] = filters[name].slider(label="Photo Quantity", min_value=product_photos_qty_min, max_value=product_photos_qty_max, value=(product_photos_qty_min,product_photos_qty_max), step=config.integer)
filters_products['product_weight_g'] = filters[name].slider(label="Weight in gram", min_value=product_weight_g_min, max_value=product_weight_g_max, value=(product_weight_g_min,product_weight_g_max), step=config.integer)
filters_products['product_length_cm'] = filters[name].slider(label="Length in cm", min_value=product_length_cm_min, max_value=product_length_cm_max, value=(product_length_cm_min,product_length_cm_max), step=config.integer)
filters_products['product_height_cm'] = filters[name].slider(label="Height in cm", min_value=product_height_cm_min, max_value=product_height_cm_max, value=(product_height_cm_min,product_height_cm_max), step=config.integer)
filters_products['product_width_cm'] = filters[name].slider(label="Width in cm", min_value=product_width_cm_min, max_value=product_width_cm_max, value=(product_width_cm_min,product_width_cm_max), step=config.integer)
elif name == 'order_items' and status:
order_id_list = st.session_state.connector.get_single_unique(name, "order_id").astype(str).tolist()
order_item_id_list = st.session_state.connector.get_single_unique(name, "order_item_id").astype(str).tolist()
product_id_list = st.session_state.connector.get_single_unique(name, "product_id").astype(str).tolist()
seller_id_list = st.session_state.connector.get_single_unique(name, "seller_id").astype(str).tolist()
shipping_limit_date_min, shipping_limit_date_max = st.session_state.connector.get_single_min_max(name, "shipping_limit_date")
shipping_limit_date_min = pd.to_datetime(shipping_limit_date_min.loc[0]).to_pydatetime()
shipping_limit_date_max = pd.to_datetime(shipping_limit_date_max.loc[0]).to_pydatetime()
price_min, price_max = st.session_state.connector.get_single_min_max(name, "price")
price_min = float(price_min.loc[0])
price_max = float(price_max.loc[0])
freight_value_min, freight_value_max = st.session_state.connector.get_single_min_max(name, "freight_value")
freight_value_min = float(freight_value_min.loc[0])
freight_value_max = float(freight_value_max.loc[0])
filters[name] = filter_area.expander(label = name)
filters_order_items['order_id'] = filters[name].selectbox(label="Order ID", options = order_id_list, index=None)
filters_order_items['order_item_id'] = filters[name].selectbox(label="Order Item ID", options=order_item_id_list, index=None)
filters_order_items['product_id'] = filters[name].selectbox(label="Product ID", options=product_id_list, index=None, key="order_items-product_id")
filters_order_items['seller_id'] = filters[name].selectbox(label="Seller ID", options =seller_id_list, index=None)
filters_order_items['shipping_limit_date'] = filters[name].slider("Shipping Limit Date", min_value=shipping_limit_date_min, max_value=shipping_limit_date_max, value=(shipping_limit_date_min, shipping_limit_date_max), step=config.time['step']['day'], format=config.time['format']['short'])
filters_order_items['price'] = filters[name].slider("Price", min_value=price_min, max_value=price_max, value=(price_min, price_max), step=config.concurrency)
filters_order_items['freight_value'] = filters[name].slider("Freight Value", min_value=freight_value_min, max_value=freight_value_max, value=(freight_value_min, freight_value_max), step=config.concurrency)
elif name == 'order_reviews' and status:
review_id_list = st.session_state.connector.get_single_unique(name, "review_id").astype(str).tolist()
order_id_list = st.session_state.connector.get_single_unique(name, "order_id").astype(str).tolist()
review_score_min, review_score_max = st.session_state.connector.get_single_min_max(name, "review_score")
review_score_min = int(review_score_min.loc[0])
review_score_max = int(review_score_max.loc[0])
review_creation_date_min, review_creation_date_max = st.session_state.connector.get_single_min_max(name, "review_creation_date")
review_creation_date_min = pd.to_datetime(review_creation_date_min.loc[0]).to_pydatetime()
review_creation_date_max = pd.to_datetime(review_creation_date_max.loc[0]).to_pydatetime()
filters[name] = filter_area.expander(label = name)
filters_order_reviews['review_id'] = filters[name].selectbox("Review ID", options=review_id_list, index=None)
filters_order_reviews['order_id'] = filters[name].selectbox("order_id", options=order_id_list, index=None)
filters_order_reviews['review_score'] = filters[name].slider("Review Score", min_value=review_score_min, max_value=review_score_max, value = (review_score_min, review_score_max), step=config.integer)
filters_order_reviews['review_creation_date'] = filters[name].slider("Review Creation Date", min_value=review_creation_date_min, max_value=review_creation_date_max, value=(review_creation_date_min, review_creation_date_max), step=config.time['step']['day'], format=config.time['format']['short'])
used_table = []
used_filters = {}
for name, status in zip(database_config['table_name'], table_list_checkbox):
if status:
used_table.append(name)
if name == "geolocation":
used_filters[name] = filters_geolocation
elif name == "sellers":
used_filters[name] = filters_sellers
elif name == "customers":
used_filters[name] = filters_customers
elif name == "orders":
used_filters[name] = filters_orders
elif name == "order_payments":
used_filters[name] = filters_order_payments
elif name == "products":
used_filters[name] = filters_products
elif name == "order_items":
used_filters[name] = filters_order_items
elif name == "order_reviews":
used_filters[name] = filters_order_reviews
if len(used_table) == 0:
right_column.write("You haven't select any table yet.")
else:
query = {}
query['body'] = ""
query['value'] = tuple()
# SELECT
# IF geolocation in used_table, create new table customer_geolocation and sellers_geolocation
# for replacing the city and state in the customer or sellers with the city and state in geolcoation
query['body'] += "SELECT "
if 'geolocation' in used_table:
if len(used_table) == 1:
query['body'] += "geolocation.geolocation_zip_code_prefix AS geolocation_zip_code_prefix, "
query['body'] += "geolocation.geolocation_lat AS geolocation_lat, "
query['body'] += "geolocation.geolocation_city AS geolocation_city, "
query['body'] += "geolocation.geolocation_state AS geolocation_state, "
if 'customers' in used_table:
query['body'] += "customer.customer_id AS customer_id, "
query['body'] += "customer.customer_unique_id AS customer_unique_id, "
query['body'] += "customer.customer_zip_code_prefix AS customer_zip_code_prefix, "
if 'geolocation' not in used_table:
query['body'] += "customer.customer_city AS customer_city, "
query['body'] += "customer.customer_state AS customer_state, "
else:
query['body'] += "customer.customer_city AS customer_city, "
query['body'] += "customer.customer_state AS customer_state, "
query['body'] += "customer.customer_lat AS customer_latitude, "
query['body'] += "customer.customer_lng AS customer_longitude, "
if 'sellers' in used_table:
query['body'] += "seller.seller_id AS seller_id, "
query['body'] += "seller.seller_zip_code_prefix AS seller_zip_code_prefix, "
if 'geolocation' not in used_table:
query['body'] += "seller.seller_city AS seller_city, "
query['body'] += "seller.seller_state AS seller_state, "
else:
query['body'] += "seller.seller_city AS seller_city, "
query['body'] += "seller.seller_state AS seller_state, "
query['body'] += "seller.seller_lat AS seller_latitude, "
query['body'] += "seller.seller_lng AS seller_longitude, "
if 'orders' in used_table:
query['body'] += "orders.order_id AS order_id, "
query['body'] += "orders.customer_id AS order_customer_id, "
query['body'] += "orders.order_status AS order_status, "
query['body'] += "orders.order_purchase_timestamp AS order_purchase_timestamp, "
query['body'] += "orders.order_approved_at AS order_approved_at, "
query['body'] += "orders.order_delivered_carrier_date AS order_delivered_carrier_date, "
query['body'] += "orders.order_delivered_customer_date AS order_delivered_customer_date, "
query['body'] += "orders.order_estimated_delivery_date AS order_estimated_delivery_date, "
if "order_payments" in used_table:
query['body'] += "order_payments.order_id AS order_payments_order_id, "
query['body'] += "order_payments.payment_sequential AS payment_sequential, "
query['body'] += "order_payments.payment_type AS payment_type, "
query['body'] += "order_payments.payment_installments AS payment_installments, "
query['body'] += "order_payments.payment_value AS payment_value, "
if 'products' in used_table:
query['body'] += "products.product_id AS product_id, "
query['body'] += "products.product_category_name AS product_category_name, "
query['body'] += "products.product_name_length AS product_name_length, "
query['body'] += "products.product_description_length AS product_description_length, "
query['body'] += "products.product_photos_qty AS product_photos_qty, "
query['body'] += "products.product_weight_g AS product_weight_g, "
query['body'] += "products.product_length_cm AS product_length_cm, "
query['body'] += "products.product_height_cm AS product_height_cm, "
query['body'] += "products.product_width_cm AS product_width_cm, "
if 'order_items' in used_table:
query['body'] += "order_items.order_id AS order_items_order_id, "
query['body'] += "order_items.order_item_id AS order_item_id, "
query['body'] += "order_items.product_id AS order_items_product_id, "
query['body'] += "order_items.seller_id AS order_items_seller_id, "
query['body'] += "order_items.shipping_limit_date AS shipping_limit_date, "
query['body'] += "order_items.price AS price, "
query['body'] += "order_items.freight_value AS freight_value, "
if 'order_reviews' in used_table:
query['body'] += "order_reviews.review_id AS review_id, "
query['body'] += "order_reviews.order_id AS order_reviews_order_id, "
query['body'] += "order_reviews.review_score AS review_score, "
query['body'] += "order_reviews.review_creation_date AS review_creation_date, "
# clean last comma
query['body'] = query['body'][:-2]
query['body'] += " "
# FROM
query['body'] += "FROM "
# Add missed table back for building the bridge
missed_tables = []
used_table_full = used_table.copy()
used_table_pairs = list(itertools.combinations(used_table, 2))
for start_table, end_table in used_table_pairs:
missed_table = utils.bridge_tables(start_table, end_table)
if missed_table is not None:
for table in missed_table:
if (table not in missed_tables) and (table not in used_table):
missed_tables.append(table)
for table in missed_tables:
if table not in used_table:
used_table_full.append(table)
added_tables = []
special = ['geolocation', 'sellers', 'customers']
if len(used_table_full) == 1:
tmp_table = f"{used_table_full[0]}" if used_table_full[0] not in special[1:] else f"{used_table_full[0]} AS {used_table_full[0][:-1]}"
query['body'] += tmp_table
query['body'] += " "
elif (len(used_table_full) == 2):
if 'geolocation' in used_table_full:
if 'sellers' in used_table_full:
query['body'] += "(SELECT geolocation.geolocation_zip_code_prefix AS seller_zip_code_prefix, geolocation.geolocation_city AS seller_city, geolocation.geolocation_state AS seller_state, geolocation.geolocation_lat AS seller_lat, geolocation.geolocation_lng AS seller_lng, sellers.seller_id AS seller_id FROM geolocation INNER JOIN sellers ON geolocation.geolocation_zip_code_prefix = sellers.seller_zip_code_prefix) AS seller "
elif 'customers' in used_table_full:
query['body'] += " (SELECT geolocation.geolocation_zip_code_prefix AS customer_zip_code_prefix, geolocation.geolocation_city AS customer_city, geolocation.geolocation_state AS customer_state, geolocation.geolocation_lat AS customer_lat, geolocation.geolocation_lng AS customer_lng, customers.customer_id AS customer_id, customers.customer_unique_id AS customer_unique_id FROM geolocation INNER JOIN customers ON geolocation.geolocation_zip_code_prefix = customers.customer_zip_code_prefix) AS customer "
else:
first = f"{used_table_full[0]}" if used_table_full[0] not in special else f"{used_table_full[0]} AS {used_table_full[0][:-1]}"
first_table = f"{used_table_full[0]}" if used_table_full[0] not in special else f"{used_table_full[0][:-1]}"
second = f"{used_table_full[1]}" if used_table_full[1] not in special else f"{used_table_full[1]} AS {used_table_full[1][:-1]}"
second_table = f"{used_table_full[1]}" if used_table_full[1] not in special else f"{used_table_full[1][:-1]}"
joint_point = database_config['foreign_keys'][used_table_full[0]][used_table_full[1]]
query['body'] += f"{first} INNER JOIN {second} ON {first_table}.{joint_point['local']} = {second_table}.{joint_point['remote']} "
else:
if "sellers" in used_table_full and "geolocation" in used_table_full:
query['body'] += "(SELECT geolocation.geolocation_zip_code_prefix AS seller_zip_code_prefix, geolocation.geolocation_city AS seller_city, geolocation.geolocation_state AS seller_state, geolocation.geolocation_lat AS seller_lat, geolocation.geolocation_lng AS seller_lng, sellers.seller_id AS seller_id FROM geolocation INNER JOIN sellers ON geolocation.geolocation_zip_code_prefix = sellers.seller_zip_code_prefix) AS seller "
added_tables.append('sellers')
added_tables.append('geolocation')
elif "customers" in used_table_full and "geolocation" in used_table_full:
query['body'] += " (SELECT geolocation.geolocation_zip_code_prefix AS customer_zip_code_prefix, geolocation.geolocation_city AS customer_city, geolocation.geolocation_state AS customer_state, geolocation.geolocation_lat AS customer_lat, geolocation.geolocation_lng AS customer_lng, customers.customer_id AS customer_id, customers.customer_unique_id AS customer_unique_id FROM geolocation INNER JOIN customers ON geolocation.geolocation_zip_code_prefix = customers.customer_zip_code_prefix) AS customer "
added_tables.append('customers')
added_tables.append('geolocation')
else:
first_table = used_table_full[0]
start = f"{first_table}" if first_table not in special else f"{first_table} AS {first_table[:-1]}"
query['body'] += f"{start} "
added_tables.append(first_table)
# print(added_tables, used_table, used_table_full)
all_added = False
loop_limit = 20
while not(all_added):
for i in used_table_full:
is_added = False
if i not in added_tables:
for j in added_tables:
bridge = utils.bridge_tables(i, j)
if len(bridge) == 0 and j != "geolocation":
if i == "customers" and "geolocation" in added_tables:
query['body'] += "INNER JOIN (SELECT geolocation.geolocation_zip_code_prefix AS customer_zip_code_prefix, geolocation.geolocation_city AS customer_city, geolocation.geolocation_state AS customer_state, geolocation.geolocation_lat AS customer_lat, geolocation.geolocation_lng AS customer_lng, customers.customer_id AS customer_id, customers.customer_unique_id AS customer_unique_id FROM geolocation INNER JOIN customers ON geolocation.geolocation_zip_code_prefix = customers.customer_zip_code_prefix) AS customer "
joint_point = database_config['foreign_keys'][i][j]
query['body'] += f"ON customer.{joint_point['local']} = {j}.{joint_point['remote']} "
added_tables.append(i)
else:
new_long = f"{i}" if i not in special else f"{i} AS {i[:-1]}"
new_table = f"{i}" if i not in special else f"{i[:-1]}"
added_long = f"{j}" if j not in special else f"{j} AS {j[:-1]}"
added_table = f"{j}" if j not in special else f"{j[:-1]}"
joint_point = database_config['foreign_keys'][i][j]
query['body'] += f"INNER JOIN {new_long} ON {new_table}.{joint_point['local']} = {added_table}.{joint_point['remote']} "
added_tables.append(i)
is_added = True
break
else:
pass
if is_added:
break
counter = 0
for i in used_table_full:
if i in added_tables:
counter += 1
if counter == len(used_table_full):
all_added=True
# WHERE
query['body'] += "WHERE "
# Add filter
for name in used_table:
if name == "geolocation":
if "customers" not in used_table_full and "sellers" not in used_table_full:
key = used_filters[name]['geolocation_zip_code_prefix']
if key is not None:
query['body'] += f"geolocation.geolocation_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_lat']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"geolocation.geolocation_lat BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"geolocation.geolocation_lat BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_lng']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"geolocation.geolocation_lng BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"geolocation.geolocation_lng BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_city']
if key is not None:
query['body'] += f"geolocation.geolocation_city = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_state']
if key is not None:
query['body'] += f"geolocation.geolocation_state = ? AND "
query['value'] += (key,)
else:
if "customers" in used_table_full:
key = used_filters[name]['geolocation_zip_code_prefix']
if key is not None:
query['body'] += f"customer.customer_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_lat']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"customer.customer_lat BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"customer.customer_lat BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_lng']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"customer.customer_lng BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"customer.customer_lng BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_city']
if key is not None:
query['body'] += f"customer.customer_city = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_state']
if key is not None:
query['body'] += f"customer.customer_state = ? AND "
query['value'] += (key,)
if "sellers" in used_table_full:
key = used_filters[name]['geolocation_zip_code_prefix']
if key is not None:
query['body'] += f"seller.seller_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_lat']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"seller.seller_lat BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"seller.seller_lat BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_lng']
if key is not None:
if key[0] <= key[1]:
query['body'] += f"seller.seller_lng BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"seller.seller_lng BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]['geolocation_city']
if key is not None:
query['body'] += f"seller.seller_city = ? AND "
query['value'] += (key,)
key = used_filters[name]['geolocation_state']
if key is not None:
query['body'] += f"seller.seller_state = ? AND "
query['value'] += (key,)
if name == "sellers":
key = used_filters[name]['seller_id']
if key is not None:
query['body'] += f"seller.seller_id = ? AND "
query['value'] += (key,)
key = used_filters[name]['seller_zip_code_prefix']
if key is not None:
query['body'] += f"seller.seller_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['seller_city']
if key is not None:
query['body'] += f"seller.seller_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['seller_state']
if key is not None:
query['body'] += f"seller.seller_state = ? AND "
query['value'] += (key,)
if name == "customers":
key = used_filters[name]['customer_id']
if key is not None:
query['body'] += f"customer.customer_id = ? AND "
query['value'] += (key,)
key = used_filters[name]['customer_unique_id']
if key is not None:
query['body'] += f"customer.customer_unique_id = ? AND "
query['value'] += (key,)
key = used_filters[name]['customer_zip_code_prefix']
if key is not None:
query['body'] += f"customer.customer_zip_code_prefix = ? AND "
query['value'] += (key,)
key = used_filters[name]['customer_city']
if key is not None:
query['body'] += f"customer.customer_city = ? AND "
query['value'] += (key,)
key = used_filters[name]['customer_state']
if key is not None:
query['body'] += f"customer.customer_state = ? AND "
query['value'] += (key,)
if name == "orders":
key = used_filters[name]['order_id']
if key is not None:
query['body'] += f"orders.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["customer_id"]
if key is not None:
query['body'] += f"orders.customer_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["order_status"]
if key is not None:
query['body'] += f"orders.order_status = ? AND "
query['value'] += (key,)
key = used_filters[name]["order_purchase_timestamp"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"orders.order_purchase_timestamp BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"orders.order_purchase_timestamp BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["order_approved_at"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"orders.order_approved_at BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"orders.order_approved_at BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["order_delivered_carrier_date"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"orders.order_delivered_carrier_date BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"orders.order_delivered_carrier_date BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["order_delivered_customer_date"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"orders.order_delivered_customer_date BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"orders.order_delivered_customer_date BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["order_estimated_delivery_date"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"orders.order_estimated_delivery_date BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"orders.order_estimated_delivery_date BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
if name == "order_payments":
key = used_filters[name]["order_id"]
if key is not None:
query['body'] += f"order_payments.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["payment_sequential"]
if key is not None:
query['body'] += f"order_payments.payment_sequential = ? AND "
query['value'] += (key,)
key = used_filters[name]["payment_type"]
if key is not None:
query['body'] += f"order_payments.payment_type = ? AND "
query['value'] += (key,)
key = used_filters[name]["payment_installments"]
if key is not None:
query['body'] += f"order_payments.payment_installments = ? AND "
query['value'] += (key,)
key = used_filters[name]["payment_value"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_payments.payment_value BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"order_payments.payment_value BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
if name == "products":
key = used_filters[name]["product_id"]
if key is not None:
query['body'] += f"products.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["product_category_name"]
if key is not None:
query['body'] += f"products.product_category_name = ? AND "
query['value'] += (key,)
key = used_filters[name]["product_name_length"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_name_length BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_name_length BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_description_length"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_description_length BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_description_length BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_photos_qty"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_photos_qty BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_photos_qty BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_weight_g"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_photos_qty BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_photos_qty BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_length_cm"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_length_cm BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_length_cm BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_height_cm"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_height_cm BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_height_cm BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["product_width_cm"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"products.product_width_cm BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"products.product_width_cm BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
if name == "order_items":
key = used_filters[name]["order_id"]
if key is not None:
query['body'] += f"order_items.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["order_item_id"]
if key is not None:
query['body'] += f"order_items.order_item_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["product_id"]
if key is not None:
query['body'] += f"order_items.product_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["seller_id"]
if key is not None:
query['body'] += f"order_items.seller_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["shipping_limit_date"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_items.shipping_limit_date BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"order_items.shipping_limit_date BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["price"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_items.price BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"order_items.price BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["freight_value"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_items.freight_value BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"order_items.freight_value BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
if name == "order_reviews":
key = used_filters[name]["review_id"]
if key is not None:
query['body'] += f"order_items.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["order_id"]
if key is not None:
query['body'] += f"order_items.order_id = ? AND "
query['value'] += (key,)
key = used_filters[name]["review_score"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_reviews.review_score BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[0] > key[1]:
query['body'] += f"order_reviews.review_score BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
key = used_filters[name]["review_creation_date"]
if key is not None:
if key[0] <= key[1]:
query['body'] += f"order_reviews.review_creation_date BETWEEN ? AND ? AND "
query['value'] += (key[0], key[1])
elif key[1] < key[0]:
query['body'] += f"order_reviews.review_creation_date BETWEEN ? AND ? AND "
query['value'] += (key[1], key[0])
# clean last AND
# query['body'] = query['body'][:-4]
if query['body'].strip().endswith("AND"):
query['body'] = query['body'].rstrip()[:-3].rstrip()
if query['body'].strip().endswith("WHERE"):
query['body'] = query['body'].rstrip()[:-5].rstrip()
# end
query['body'] += ";"
# right_column.write(filter_area_buttom)
if filter_area_buttom:
result = st.session_state.connector.query(query['body'], query['value'])
st.session_state.result = result
st.session_state.query = query
# right_column.write(st.session_state.data_changed)
if st.session_state.data_changed:
if st.session_state.query['body'] == "":
right_column.write("Please click submit for search data.")
else:
st.session_state.result = st.session_state.connector.query(st.session_state.query['body'], st.session_state.query['value'])
right_column.dataframe(st.session_state.result, height = config.table_height, use_container_width = True)
st.session_state.data_changed = False
else:
if st.session_state.query['body'] == "":
right_column.write("Please click submit for search data.")
else:
# st.session_state.result = st.session_state.connector.query(st.session_state.query['body'])
right_column.dataframe(st.session_state.result, height = config.table_height, use_container_width = True)
# right_column.dataframe(connector.query(st.session_state.query['body']), height = config.table_height, use_container_width = True)
@st.dialog("Add", width="large")
def add_data():
# Preparation
prepared_name = utils.generate_random_string()
disable_button = False # If data illegal, disable_button = True
while prepared_name in st.session_state.stack:
prepared_name = utils.generate_random_string()
table_name_list = [
'geolocation',
'sellers',
'customers',
'orders',
'order_payments',
'products',
'order_items',
'order_reviews'
]
# tab_geolocation, tab_sellers, tab_customers, tab_orders, tab_order_payments, tab_products, tab_order_items, tab_order_reviews = st.tabs(table_name_list)
selected_dataset = st.radio(
"Choose a table:",
table_name_list
)
data = None