Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,10 @@ import base64
|
|
| 9 |
from google.cloud import bigquery
|
| 10 |
from google.oauth2 import service_account
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
global_user_data = [] # For appending user_data
|
| 14 |
global_data_rows = [] # For appending data rows
|
|
@@ -262,6 +266,8 @@ company_name = st.sidebar.text_input("Company Name", help="Enter the company nam
|
|
| 262 |
currency = st.sidebar.radio("Currency", options= ["INR", "USD"], help= "Select the type of currency", index =None)
|
| 263 |
bundle_by = st.sidebar.radio(options=["Single value", "Feature specific"], label="Bundle by", help = "Select the bundle", index=None)
|
| 264 |
|
|
|
|
|
|
|
| 265 |
if bundle_by == "Feature specific":
|
| 266 |
|
| 267 |
plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
|
|
@@ -554,60 +560,62 @@ if bundle_by == "Feature specific":
|
|
| 554 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 555 |
|
| 556 |
|
|
|
|
| 557 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
|
| 559 |
-
|
| 560 |
-
# Save user data
|
| 561 |
-
user_data = {
|
| 562 |
-
"Business_Head": business_head,
|
| 563 |
-
"Company_ID": company_id,
|
| 564 |
-
"Company_Name": company_name,
|
| 565 |
-
"Currency": currency,
|
| 566 |
-
"Bundle_by": bundle_by,
|
| 567 |
-
"Plan_Name": plan_name,
|
| 568 |
-
"Plan_Description": plan_description,
|
| 569 |
-
"Product_lines": ordering_channels,
|
| 570 |
-
"Fulfilling_Location": fulfilling_location,
|
| 571 |
-
"Application_ID": application_id,
|
| 572 |
-
"Fee_Type": selected_fee_type,
|
| 573 |
-
"Variable_Type": selected_variable_type,
|
| 574 |
-
"Chargeable_on": selected_chargeable_on,
|
| 575 |
-
"Fee_Nature": selected_fee_nature,
|
| 576 |
-
"Commercial_value": user_input_3,
|
| 577 |
-
"Fee_reversal": 0,
|
| 578 |
-
"Reversal_%": 0,
|
| 579 |
-
"Usage_limit": usage_3,
|
| 580 |
-
"Threshold_value": Capping_or_Minimum_Guarantee_3,
|
| 581 |
-
"Threshold_option": threshold,
|
| 582 |
-
"Expected_Billing": expected_billing,
|
| 583 |
-
"Payment_Method": selected_payment_method,
|
| 584 |
-
"Plan_Validity": selected_plan_validity,
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
global_user_data.append((user_name, user_data))
|
| 588 |
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
|
| 597 |
-
|
| 598 |
|
| 599 |
-
|
| 600 |
-
|
| 601 |
|
|
|
|
| 602 |
if st.button("Export data to BQ"):
|
| 603 |
from google.oauth2 import service_account
|
| 604 |
from google.cloud import bigquery
|
| 605 |
-
|
| 606 |
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 607 |
-
|
| 608 |
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 609 |
-
|
| 610 |
-
|
| 611 |
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 612 |
|
| 613 |
# Specify the table reference
|
|
@@ -617,59 +625,59 @@ if bundle_by == "Feature specific":
|
|
| 617 |
# Insert form data into the table
|
| 618 |
rows_to_insert = [user_data]
|
| 619 |
errors = client.insert_rows_json(table, rows_to_insert)
|
| 620 |
-
|
| 621 |
if errors:
|
| 622 |
print(f"Errors occurred while inserting rows: {errors}")
|
| 623 |
else:
|
| 624 |
print("Insert successful")
|
| 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 |
elif bundle_by == "Single value":
|
| 675 |
user_input_1 = st.sidebar.number_input("Enter Commercial value:")
|
|
@@ -747,6 +755,7 @@ elif bundle_by == "Single value":
|
|
| 747 |
"PixelBin": ["Subscription"],
|
| 748 |
"Boltic": ["Subscription"],
|
| 749 |
"CoPilot": ["Subscription"],
|
|
|
|
| 750 |
|
| 751 |
}
|
| 752 |
}
|
|
@@ -854,120 +863,125 @@ elif bundle_by == "Single value":
|
|
| 854 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 855 |
|
| 856 |
|
|
|
|
| 857 |
|
|
|
|
| 858 |
# Submit button
|
| 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 |
-
save_user_data(user_data) # Save user data after submission
|
| 899 |
|
| 900 |
-
|
| 901 |
-
display_saved_records()
|
| 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 |
-
project_id = "fynd-db"
|
| 930 |
-
dataset_id = "finance_dwh"
|
| 931 |
-
table_id = "plan_v2"
|
| 932 |
-
user_data = {
|
| 933 |
-
"Business_Head": business_head,
|
| 934 |
-
"Company_ID": company_id,
|
| 935 |
-
"Company_Name": company_name,
|
| 936 |
-
"Currency": currency,
|
| 937 |
-
"Bundle_by": bundle_by,
|
| 938 |
-
"Plan_Name": plan_name,
|
| 939 |
-
"Plan_Description": plan_description,
|
| 940 |
-
"Product_lines": ordering_channels,
|
| 941 |
-
"Fulfilling_Location": fulfilling_location,
|
| 942 |
-
"Application_ID": application_id,
|
| 943 |
-
"Fee_Type": selected_fee_type,
|
| 944 |
-
"Variable_Type": selected_variable_type,
|
| 945 |
-
"Chargeable_on": selected_chargeable_on,
|
| 946 |
-
"Fee_Nature": "Flat currency",
|
| 947 |
-
"Commercial_value": user_input_3,
|
| 948 |
-
"Fee_reversal": 0,
|
| 949 |
-
"Reversal_%": 0,
|
| 950 |
-
"Usage_limit": usage_3,
|
| 951 |
-
"Threshold_value": 0,
|
| 952 |
-
"Threshold_option": 0,
|
| 953 |
-
"Expected_Billing": user_input_3,
|
| 954 |
-
"Payment_Method": selected_payment_method,
|
| 955 |
-
"Plan_Validity": selected_plan_validity
|
| 956 |
-
|
| 957 |
-
}
|
| 958 |
-
|
| 959 |
-
service_account_info = {
|
| 960 |
-
"type": "service_account",
|
| 961 |
-
"project_id": "fynd-db",
|
| 962 |
-
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 963 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2PQ4VBElLfCv4qbP9JGljvLsj5b\nC9UWe9rWgRrw2Z88LlVmFy3k4Om80Q57gW3hSYZpG4rBhC9+YRXjZ+Iq5SFEJQ+U\nj8ej7q6DnI8Prbvw/e13JH1pxm9AUQDm+sTsBmvjh4Ye02vKbfUP+pFOM0eC3Eoa\nOyG7unZnDuAaK9g87xVjd9HtD6MfaM0EHAEF1eyC4UqeiXTbVMwi7+0IGA2evEDZ\n3WRR2i+lAgMBAAECggEAF7Vis7NVsVqFfCS/moFTAMLfWLF87r67EIK/DwSpHloZ\n5YJdsDz3ORKmZC98aRSthDfC9UUyt270dXItAj0jmTFgWB6HgE8OQ1zUbmo3MHG+\ntPwMWmqwY2gsBMV2Xefot1QJxYH+AYkrxeFv5NgC+FaPSiy8QSHZlQqcxYtlP8kY\nzv8QFMgZ3b0sixK+YcSjCRXHu/DznnS/ZU7XlTALxANa50hT11rVLq6zYDF40fqC\nOWCOZvupjMOnNimXCWn7q6D1F8S/IMYlnHArJpEb7SdbJnJzxUvJC2rrMSoY896r\nyFEVhlElWp5GfTopu0WnL7iaw3pukM1OtpanFAk29wKBgQDW+yMzL7RiQ5LdElVP\n7Ml5hs+t6cjrUJTgBI8Uf9qGxE+tMe7Ye1fyJfbYslbOYO9xIUUT1jJmU6jadNWX\nA7UT59/IjvAOBIYyMEdh6Xo+H6ggW8DeU1HSdvixnQdgi0c03E6OCbOKi9E/UzK/\nTK2RBJJLN4MCiNL0FzrhTuxyEwKBgQDF1cz9Sb2UbrL5hr8LdcEH0ctatNlhJcSN\nnMd0Fn+e1EAkip+Hs9HmTvNdty4gQE+yEq/Tj0cRHXmjzK2AYx0WYRAhWGNSTlTS\n4OJdjE6vsoPu7Ouz1R/i/egKniUifEXYSgyL+oPBUrqqsnk9lgGBkJipN3u1f9+K\niuUJJP/OZwKBgF6ZvqCcom0HPU5I7f+wu+vdVfA6yy45lHmLqAamSFw7cLBPI8Jh\nbI7jA9/Rgn9oipUmxcX34M/Eiq4u8Xp1qC4tP/16YMpaVU8qjY7ZdfB2b75lgdaT\npZLOxZsq9X8Xauso8uxv+nDCG/8YtmEV9d61u0acE+t+mA3PVxqkZ0m/AoGBAI5c\nY76AqeN+JVxaEm/0tIsj9Om46hR2URJ2lzB6YCuzINUqy9GjHJBWj9oITzD2FmNV\n/yCGIeW3CClOyCtzJyNLhYf5Sr+XjoKRQVN/+7+C/l2YL6Sg4Ok/PRMm6iH+u2QB\nJTY1d0pOdfUPqR8gKsVJgBGE04iwE/RmLpp9/XZRAoGAFtaa9JeHk9dmZiST3lev\ns5syeOK1cCj1+nJer/GPEjqWMKxbCULvoEYBp7RaoEXjfGi7P4Mc6YHnbljHc+sL\niJzHhxrv/HYZdlCdTU3IRWT0sNHzqZemfYnsVTSp+4y61sGDxioDYL4CLnMq5T2F\nqzfc2qp3s8ApVloY3giuqnI=\n-----END PRIVATE KEY-----\n",
|
| 964 |
-
"client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
|
| 965 |
-
"client_id": "114883060650442183907",
|
| 966 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 967 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 968 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 969 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 970 |
-
"universe_domain": "googleapis.com"
|
| 971 |
-
}
|
| 972 |
|
| 973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
from google.cloud import bigquery
|
| 10 |
from google.oauth2 import service_account
|
| 11 |
|
| 12 |
+
## Single value - 268 --> 675
|
| 13 |
+
## Feature Specific - 676 --> 980
|
| 14 |
+
|
| 15 |
+
|
| 16 |
|
| 17 |
global_user_data = [] # For appending user_data
|
| 18 |
global_data_rows = [] # For appending data rows
|
|
|
|
| 266 |
currency = st.sidebar.radio("Currency", options= ["INR", "USD"], help= "Select the type of currency", index =None)
|
| 267 |
bundle_by = st.sidebar.radio(options=["Single value", "Feature specific"], label="Bundle by", help = "Select the bundle", index=None)
|
| 268 |
|
| 269 |
+
|
| 270 |
+
################################################## Feature Specific ##########################################################
|
| 271 |
if bundle_by == "Feature specific":
|
| 272 |
|
| 273 |
plan_name = st.sidebar.text_input("Plan Name", help="Enter the name of the plan")
|
|
|
|
| 560 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 561 |
|
| 562 |
|
| 563 |
+
col1, col2 = st.columns([0.16, 1])
|
| 564 |
|
| 565 |
+
with col1:
|
| 566 |
+
if st.button("Submit", key ='submit_button'):
|
| 567 |
+
# Save user data
|
| 568 |
+
user_data = {
|
| 569 |
+
"Business_Head": business_head,
|
| 570 |
+
"Company_ID": company_id,
|
| 571 |
+
"Company_Name": company_name,
|
| 572 |
+
"Currency": currency,
|
| 573 |
+
"Bundle_by": bundle_by,
|
| 574 |
+
"Plan_Name": plan_name,
|
| 575 |
+
"Plan_Description": plan_description,
|
| 576 |
+
"Product_lines": ordering_channels,
|
| 577 |
+
"Fulfilling_Location": fulfilling_location,
|
| 578 |
+
"Application_ID": application_id,
|
| 579 |
+
"Fee_Type": selected_fee_type,
|
| 580 |
+
"Variable_Type": selected_variable_type,
|
| 581 |
+
"Chargeable_on": selected_chargeable_on,
|
| 582 |
+
"Fee_Nature": selected_fee_nature,
|
| 583 |
+
"Commercial_value": user_input_3,
|
| 584 |
+
"Fee_reversal": 0,
|
| 585 |
+
"Reversal_%": 0,
|
| 586 |
+
"Usage_limit": usage_3,
|
| 587 |
+
"Threshold_value": Capping_or_Minimum_Guarantee_3,
|
| 588 |
+
"Threshold_option": threshold,
|
| 589 |
+
"Expected_Billing": expected_billing,
|
| 590 |
+
"Payment_Method": selected_payment_method,
|
| 591 |
+
"Plan_Validity": selected_plan_validity,
|
| 592 |
+
}
|
| 593 |
|
| 594 |
+
global_user_data.append((user_name, user_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
|
| 596 |
+
# Generate PM_id and add it to user_data
|
| 597 |
+
rule_id = generate_rule_id(user_data)
|
| 598 |
+
user_data['rule_id'] = rule_id
|
| 599 |
|
| 600 |
+
# Generate Plan ID and add it to user_data
|
| 601 |
+
plan_id = generate_plan_id(user_data)
|
| 602 |
+
user_data['plan_id'] = plan_id
|
| 603 |
|
| 604 |
+
save_user_data(user_data) # Save user data after submission
|
| 605 |
|
| 606 |
+
# Display saved records
|
| 607 |
+
display_saved_records()
|
| 608 |
|
| 609 |
+
with col2:
|
| 610 |
if st.button("Export data to BQ"):
|
| 611 |
from google.oauth2 import service_account
|
| 612 |
from google.cloud import bigquery
|
| 613 |
+
|
| 614 |
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 615 |
+
# Use from_service_account_info instead of from_service_account_file
|
| 616 |
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 617 |
+
|
| 618 |
+
# Initialize a BigQuery client
|
| 619 |
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 620 |
|
| 621 |
# Specify the table reference
|
|
|
|
| 625 |
# Insert form data into the table
|
| 626 |
rows_to_insert = [user_data]
|
| 627 |
errors = client.insert_rows_json(table, rows_to_insert)
|
| 628 |
+
|
| 629 |
if errors:
|
| 630 |
print(f"Errors occurred while inserting rows: {errors}")
|
| 631 |
else:
|
| 632 |
print("Insert successful")
|
| 633 |
|
| 634 |
+
project_id = "fynd-db"
|
| 635 |
+
dataset_id = "finance_dwh"
|
| 636 |
+
table_id = "plan_v2"
|
| 637 |
+
user_data = {
|
| 638 |
+
"Business_Head": business_head,
|
| 639 |
+
"Company_ID": company_id,
|
| 640 |
+
"Company_Name": company_name,
|
| 641 |
+
"Currency": currency,
|
| 642 |
+
"Bundle_by": bundle_by,
|
| 643 |
+
"Plan_Name": plan_name,
|
| 644 |
+
"Plan_Description": plan_description,
|
| 645 |
+
"Product_lines": ordering_channels,
|
| 646 |
+
"Fulfilling_Location": fulfilling_location,
|
| 647 |
+
"Application_ID": application_id,
|
| 648 |
+
"Fee_Type": selected_fee_type,
|
| 649 |
+
"Variable_Type": selected_variable_type,
|
| 650 |
+
"Chargeable_on": selected_chargeable_on,
|
| 651 |
+
"Fee_Nature": "Flat currency",
|
| 652 |
+
"Commercial_value": user_input_3,
|
| 653 |
+
"Fee_reversal": 0,
|
| 654 |
+
"Reversal_%": 0,
|
| 655 |
+
"Usage_limit": usage_3,
|
| 656 |
+
"Threshold_value": Capping_or_Minimum_Guarantee_3,
|
| 657 |
+
"Threshold_option": threshold,
|
| 658 |
+
"Expected_Billing": expected_billing,
|
| 659 |
+
"Payment_Method": selected_payment_method,
|
| 660 |
+
"Plan_Validity": selected_plan_validity
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
service_account_info = {
|
| 664 |
+
"type": "service_account",
|
| 665 |
+
"project_id": "fynd-db",
|
| 666 |
+
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 667 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2PQ4VBElLfCv4qbP9JGljvLsj5b\nC9UWe9rWgRrw2Z88LlVmFy3k4Om80Q57gW3hSYZpG4rBhC9+YRXjZ+Iq5SFEJQ+U\nj8ej7q6DnI8Prbvw/e13JH1pxm9AUQDm+sTsBmvjh4Ye02vKbfUP+pFOM0eC3Eoa\nOyG7unZnDuAaK9g87xVjd9HtD6MfaM0EHAEF1eyC4UqeiXTbVMwi7+0IGA2evEDZ\n3WRR2i+lAgMBAAECggEAF7Vis7NVsVqFfCS/moFTAMLfWLF87r67EIK/DwSpHloZ\n5YJdsDz3ORKmZC98aRSthDfC9UUyt270dXItAj0jmTFgWB6HgE8OQ1zUbmo3MHG+\ntPwMWmqwY2gsBMV2Xefot1QJxYH+AYkrxeFv5NgC+FaPSiy8QSHZlQqcxYtlP8kY\nzv8QFMgZ3b0sixK+YcSjCRXHu/DznnS/ZU7XlTALxANa50hT11rVLq6zYDF40fqC\nOWCOZvupjMOnNimXCWn7q6D1F8S/IMYlnHArJpEb7SdbJnJzxUvJC2rrMSoY896r\nyFEVhlElWp5GfTopu0WnL7iaw3pukM1OtpanFAk29wKBgQDW+yMzL7RiQ5LdElVP\n7Ml5hs+t6cjrUJTgBI8Uf9qGxE+tMe7Ye1fyJfbYslbOYO9xIUUT1jJmU6jadNWX\nA7UT59/IjvAOBIYyMEdh6Xo+H6ggW8DeU1HSdvixnQdgi0c03E6OCbOKi9E/UzK/\nTK2RBJJLN4MCiNL0FzrhTuxyEwKBgQDF1cz9Sb2UbrL5hr8LdcEH0ctatNlhJcSN\nnMd0Fn+e1EAkip+Hs9HmTvNdty4gQE+yEq/Tj0cRHXmjzK2AYx0WYRAhWGNSTlTS\n4OJdjE6vsoPu7Ouz1R/i/egKniUifEXYSgyL+oPBUrqqsnk9lgGBkJipN3u1f9+K\niuUJJP/OZwKBgF6ZvqCcom0HPU5I7f+wu+vdVfA6yy45lHmLqAamSFw7cLBPI8Jh\nbI7jA9/Rgn9oipUmxcX34M/Eiq4u8Xp1qC4tP/16YMpaVU8qjY7ZdfB2b75lgdaT\npZLOxZsq9X8Xauso8uxv+nDCG/8YtmEV9d61u0acE+t+mA3PVxqkZ0m/AoGBAI5c\nY76AqeN+JVxaEm/0tIsj9Om46hR2URJ2lzB6YCuzINUqy9GjHJBWj9oITzD2FmNV\n/yCGIeW3CClOyCtzJyNLhYf5Sr+XjoKRQVN/+7+C/l2YL6Sg4Ok/PRMm6iH+u2QB\nJTY1d0pOdfUPqR8gKsVJgBGE04iwE/RmLpp9/XZRAoGAFtaa9JeHk9dmZiST3lev\ns5syeOK1cCj1+nJer/GPEjqWMKxbCULvoEYBp7RaoEXjfGi7P4Mc6YHnbljHc+sL\niJzHhxrv/HYZdlCdTU3IRWT0sNHzqZemfYnsVTSp+4y61sGDxioDYL4CLnMq5T2F\nqzfc2qp3s8ApVloY3giuqnI=\n-----END PRIVATE KEY-----\n",
|
| 668 |
+
"client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
|
| 669 |
+
"client_id": "114883060650442183907",
|
| 670 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 671 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 672 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 673 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 674 |
+
"universe_domain": "googleapis.com"
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
|
|
|
|
| 678 |
|
| 679 |
|
| 680 |
+
###################################################### Single value ###########################################################
|
| 681 |
|
| 682 |
elif bundle_by == "Single value":
|
| 683 |
user_input_1 = st.sidebar.number_input("Enter Commercial value:")
|
|
|
|
| 755 |
"PixelBin": ["Subscription"],
|
| 756 |
"Boltic": ["Subscription"],
|
| 757 |
"CoPilot": ["Subscription"],
|
| 758 |
+
"CoPilot": ["Subscription"],
|
| 759 |
|
| 760 |
}
|
| 761 |
}
|
|
|
|
| 863 |
st.markdown(button_styles, unsafe_allow_html=True)
|
| 864 |
|
| 865 |
|
| 866 |
+
col1, col2 = st.columns([0.16, 1])
|
| 867 |
|
| 868 |
+
with col1:
|
| 869 |
# Submit button
|
| 870 |
+
if st.button("Submit"):
|
| 871 |
+
# Save user data
|
| 872 |
+
user_data = {
|
| 873 |
+
"Business Head": business_head,
|
| 874 |
+
"Company ID": company_id,
|
| 875 |
+
"Company Name": company_name,
|
| 876 |
+
"Currency": currency,
|
| 877 |
+
"Bundle by": bundle_by,
|
| 878 |
+
"Plan Name": plan_name,
|
| 879 |
+
"Plan Description": plan_description,
|
| 880 |
+
"Product lines": ordering_channels,
|
| 881 |
+
"Fulfilling Location": fulfilling_location,
|
| 882 |
+
"Application ID": application_id,
|
| 883 |
+
"Fee Type": selected_fee_type,
|
| 884 |
+
"Variable Type": selected_variable_type,
|
| 885 |
+
"Chargeable on": selected_chargeable_on,
|
| 886 |
+
"Fee Nature": "Flat currency",
|
| 887 |
+
"Commercial value": user_input_3,
|
| 888 |
+
"Fee reversal": 0,
|
| 889 |
+
"Reversal %": 0,
|
| 890 |
+
"Usage limit": usage_3,
|
| 891 |
+
"Threshold value": 0,
|
| 892 |
+
"Threshold option": 0,
|
| 893 |
+
"Expected Billing": user_input_3,
|
| 894 |
+
"Plan Validity": selected_plan_validity,
|
| 895 |
+
"Payment Method": selected_payment_method,
|
| 896 |
+
|
| 897 |
+
}
|
| 898 |
|
| 899 |
+
global_user_data.append((user_name, user_data))
|
| 900 |
|
| 901 |
+
# Generate PM_id and add it to user_data
|
| 902 |
+
rule_id = generate_rule_id(user_data)
|
| 903 |
+
user_data['rule_id'] = rule_id
|
| 904 |
|
| 905 |
+
# Generate Plan ID and add it to user_data
|
| 906 |
+
plan_id = generate_plan_id(user_data)
|
| 907 |
+
user_data['plan_id'] = plan_id
|
| 908 |
|
|
|
|
| 909 |
|
| 910 |
+
save_user_data(user_data) # Save user data after submission
|
|
|
|
| 911 |
|
| 912 |
+
# Display saved records
|
| 913 |
+
display_saved_records()
|
| 914 |
|
| 915 |
+
with col2:
|
| 916 |
+
if st.button("Export data to BQ"):
|
| 917 |
|
| 918 |
+
from google.oauth2 import service_account
|
| 919 |
+
from google.cloud import bigquery
|
| 920 |
+
|
| 921 |
+
def insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info):
|
| 922 |
+
# Use from_service_account_info instead of from_service_account_file
|
| 923 |
+
credentials = service_account.Credentials.from_service_account_info(service_account_info)
|
| 924 |
+
|
| 925 |
+
# Initialize a BigQuery client
|
| 926 |
+
client = bigquery.Client(credentials=credentials, project=project_id)
|
| 927 |
+
|
| 928 |
+
# Specify the table reference
|
| 929 |
+
table_ref = f"{project_id}.{dataset_id}.{table_id}"
|
| 930 |
+
table = client.get_table(table_ref)
|
| 931 |
+
|
| 932 |
+
# Insert form data into the table
|
| 933 |
+
rows_to_insert = [user_data]
|
| 934 |
+
errors = client.insert_rows_json(table, rows_to_insert)
|
| 935 |
+
|
| 936 |
+
if errors:
|
| 937 |
+
print(f"Errors occurred while inserting rows: {errors}")
|
| 938 |
+
else:
|
| 939 |
+
print("Insert successful")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 940 |
|
| 941 |
+
project_id = "fynd-db"
|
| 942 |
+
dataset_id = "finance_dwh"
|
| 943 |
+
table_id = "plan_v2"
|
| 944 |
+
user_data = {
|
| 945 |
+
"Business_Head": business_head,
|
| 946 |
+
"Company_ID": company_id,
|
| 947 |
+
"Company_Name": company_name,
|
| 948 |
+
"Currency": currency,
|
| 949 |
+
"Bundle_by": bundle_by,
|
| 950 |
+
"Plan_Name": plan_name,
|
| 951 |
+
"Plan_Description": plan_description,
|
| 952 |
+
"Product_lines": ordering_channels,
|
| 953 |
+
"Fulfilling_Location": fulfilling_location,
|
| 954 |
+
"Application_ID": application_id,
|
| 955 |
+
"Fee_Type": selected_fee_type,
|
| 956 |
+
"Variable_Type": selected_variable_type,
|
| 957 |
+
"Chargeable_on": selected_chargeable_on,
|
| 958 |
+
"Fee_Nature": "Flat currency",
|
| 959 |
+
"Commercial_value": user_input_3,
|
| 960 |
+
"Fee_reversal": 0,
|
| 961 |
+
"Reversal_%": 0,
|
| 962 |
+
"Usage_limit": usage_3,
|
| 963 |
+
"Threshold_value": 0,
|
| 964 |
+
"Threshold_option": 0,
|
| 965 |
+
"Expected_Billing": user_input_3,
|
| 966 |
+
"Payment_Method": selected_payment_method,
|
| 967 |
+
"Plan_Validity": selected_plan_validity
|
| 968 |
+
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
service_account_info = {
|
| 972 |
+
"type": "service_account",
|
| 973 |
+
"project_id": "fynd-db",
|
| 974 |
+
"private_key_id": "48954327ef172acc3091a91881840dc353ff0413",
|
| 975 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCmIs0vgXflZmHD\n0IeHCiDEXavRb2GvRQqkCZGLy/EHFO7XLmpNrFzZHTSQach6HErARWTMsd2AMIA5\nHbmjEyt9deTOMUmICszkwNwpn6pzuoF2v4+fL2PQ4VBElLfCv4qbP9JGljvLsj5b\nC9UWe9rWgRrw2Z88LlVmFy3k4Om80Q57gW3hSYZpG4rBhC9+YRXjZ+Iq5SFEJQ+U\nj8ej7q6DnI8Prbvw/e13JH1pxm9AUQDm+sTsBmvjh4Ye02vKbfUP+pFOM0eC3Eoa\nOyG7unZnDuAaK9g87xVjd9HtD6MfaM0EHAEF1eyC4UqeiXTbVMwi7+0IGA2evEDZ\n3WRR2i+lAgMBAAECggEAF7Vis7NVsVqFfCS/moFTAMLfWLF87r67EIK/DwSpHloZ\n5YJdsDz3ORKmZC98aRSthDfC9UUyt270dXItAj0jmTFgWB6HgE8OQ1zUbmo3MHG+\ntPwMWmqwY2gsBMV2Xefot1QJxYH+AYkrxeFv5NgC+FaPSiy8QSHZlQqcxYtlP8kY\nzv8QFMgZ3b0sixK+YcSjCRXHu/DznnS/ZU7XlTALxANa50hT11rVLq6zYDF40fqC\nOWCOZvupjMOnNimXCWn7q6D1F8S/IMYlnHArJpEb7SdbJnJzxUvJC2rrMSoY896r\nyFEVhlElWp5GfTopu0WnL7iaw3pukM1OtpanFAk29wKBgQDW+yMzL7RiQ5LdElVP\n7Ml5hs+t6cjrUJTgBI8Uf9qGxE+tMe7Ye1fyJfbYslbOYO9xIUUT1jJmU6jadNWX\nA7UT59/IjvAOBIYyMEdh6Xo+H6ggW8DeU1HSdvixnQdgi0c03E6OCbOKi9E/UzK/\nTK2RBJJLN4MCiNL0FzrhTuxyEwKBgQDF1cz9Sb2UbrL5hr8LdcEH0ctatNlhJcSN\nnMd0Fn+e1EAkip+Hs9HmTvNdty4gQE+yEq/Tj0cRHXmjzK2AYx0WYRAhWGNSTlTS\n4OJdjE6vsoPu7Ouz1R/i/egKniUifEXYSgyL+oPBUrqqsnk9lgGBkJipN3u1f9+K\niuUJJP/OZwKBgF6ZvqCcom0HPU5I7f+wu+vdVfA6yy45lHmLqAamSFw7cLBPI8Jh\nbI7jA9/Rgn9oipUmxcX34M/Eiq4u8Xp1qC4tP/16YMpaVU8qjY7ZdfB2b75lgdaT\npZLOxZsq9X8Xauso8uxv+nDCG/8YtmEV9d61u0acE+t+mA3PVxqkZ0m/AoGBAI5c\nY76AqeN+JVxaEm/0tIsj9Om46hR2URJ2lzB6YCuzINUqy9GjHJBWj9oITzD2FmNV\n/yCGIeW3CClOyCtzJyNLhYf5Sr+XjoKRQVN/+7+C/l2YL6Sg4Ok/PRMm6iH+u2QB\nJTY1d0pOdfUPqR8gKsVJgBGE04iwE/RmLpp9/XZRAoGAFtaa9JeHk9dmZiST3lev\ns5syeOK1cCj1+nJer/GPEjqWMKxbCULvoEYBp7RaoEXjfGi7P4Mc6YHnbljHc+sL\niJzHhxrv/HYZdlCdTU3IRWT0sNHzqZemfYnsVTSp+4y61sGDxioDYL4CLnMq5T2F\nqzfc2qp3s8ApVloY3giuqnI=\n-----END PRIVATE KEY-----\n",
|
| 976 |
+
"client_email": "plan-maker@fynd-db.iam.gserviceaccount.com",
|
| 977 |
+
"client_id": "114883060650442183907",
|
| 978 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 979 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 980 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 981 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/plan-maker%40fynd-db.iam.gserviceaccount.com",
|
| 982 |
+
"universe_domain": "googleapis.com"
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
|
| 986 |
+
|
| 987 |
+
insert_into_bq(user_data, project_id, dataset_id, table_id, service_account_info)
|