Unable to Pass Values in Function using Tkinter

79 Views Asked by At

I am trying to get input MNC using Tkinter and then trying to use the value to compare with a datarframe df with column header "GNB_MNC[DIGIT]",and trying to get all values except the value entered,but some how i am unable to pass the value to the function....

import os as os
import pandas as pd
import numpy as np
import tkinter as tk
import time
from tkinter import *

from tkinter import filedialog

top = tk.Tk()  
top.geometry("420x420")


#creating a canvas
#c = Canvas(top,bg = "SteelBlue") 
top.title('Neighbour Analyzer-NOKIA')
top.configure(background='slate gray')

credits = Label(top,text = "Credit : [email protected]",bg='white',font=("Helvetica", 8, "bold")).place(x = 10,y = 400)

# Entry for MNC name
usernameLabel = Label(top, text="MNC")
usernameLabel.place(x=20,y=138)

# Entry for user input MNC
usernameEntry = Entry(top,width=5)
usernameEntry.place(x=20,y=160)

def printDetails(usernameEntry) :
    usernameText = usernameEntry.get()
#    print("user entered :", usernameText)
    return


stop = Button(top,text = "Stop", command=top.destroy,height=1,width=13,font=("Helvetica", 8, "bold"))



#path for input Dump
initial=0
def input_file_path():
    
    global directory
#Open and return file path
    directory=filedialog.askdirectory(initialdir="C:/",title="Select Input Directory Folder")

#    filename_5G = filedialog.askopenfilename(initialdir="C:/", title="Select 5G MDB")
    
def output_file_path():
    global directory_out
#Open and return file path
    directory_out=filedialog.askdirectory(initialdir="C:/",title="Select output Directory Folder")

    
# RTRV Dump Processing Start  
def RTRV_Dump():
    global df
    global intial_time
    global final_time
    initial_time=time.time()
#Changing Directory to input Path
    os.chdir(directory)

#Printing directory
    os.listdir()

#Combining files in the directory
    files = [file for file in os.listdir()]

#Redind the CSV for processing
    df = pd.concat(map(pd.read_csv, files), ignore_index=True)
    
#    JCP_Site_Status=df_4G[df_4G['JCP Site Status']!='ONAIR'].index
#    df_4G.drop(JCP_Site_Status, inplace=True)
    
    
    
    #Convering to string values    
    df["Sapid"] = df["Sapid"].astype(str)
    df["CELL_NUM"] = df["CELL_NUM"].astype(str)
    df["PHY_CELL_ID_NR"] = df["PHY_CELL_ID_NR"].astype(str)
    df["SSB_FREQUENCY"] = df["SSB_FREQUENCY"].astype(str)


#Concatenation
    df["SAP-GNBPCI"] = df[["Sapid", "CELL_NUM","PHY_CELL_ID_NR","SSB_FREQUENCY"]].apply(lambda x: "_".join(x), axis =1)    

    
#Pivot to count duplicate values    
    series = df.pivot_table(index = ['SAP-GNBPCI'], aggfunc ='size')    
    
#Vlookup to add the duplicates in datatable    
    df = inner_join = pd.merge(df,  
                      series.rename('Duplicacy'),  
                      on ='SAP-GNBPCI',  
                      how ='inner') 
    inner_join

    
    r=len(df.axes[0])
    c=len(df.axes[1])
    
    #Dropping Handover not allowed cases

    
    df=df[df['IS_HOALLOWED']!=False]
    
    
    
    final_time=time.time()
    total_time=final_time-initial_time
    total_time=round(total_time,2)
    d="Process Completed for "+str(r)+" Rows & "+str(c)+" Columns in "+str(total_time)+" sec"
    tk.messagebox.showinfo("Done",d)    
    return df
    
# L to N PCI Confusion start        
def LtoNStart():
    global df
    global PCI_Confusion
#Getting only Duplicate rows from the data table
    PCI_Confusion = df[df["Duplicacy"] > 1]
#Dropping the cocatenated Columns and unwanted column
    PCI_Confusion = PCI_Confusion.drop(['SAP-GNBPCI'], axis=1)
    
    
#Changing to output directory for printing file
    os.chdir(directory_out)
    PCI_Confusion.to_csv('PCI_Confusion.csv',index=False)


def Inter_plmn_nbr():
    global PCI_Confusion
#Getting only Duplicate rows from the data table
#    PCI_Confusion = PCI_Confusion.drop(['SAP-GNBPCI'], axis=1)

#Telangana MNC=854
#TAMILNADU MNC=869
    printDetailsCallable = partial(printDetails, usernameEntry)
    
    Inter_plmn_nbr = df[df["GNB_MNC[DIGIT]"] != usernameText]
    
#    drop_ho_notallowed=Inter_plmn_nbr[Inter_plmn_nbr['IS_HOALLOWED']=='TRUE'].index
#    Inter_plmn_nbr.drop(drop_ho_notallowed, inplace=True)
    
    
    
    
#Changing to output directory for printing file
    os.chdir(directory_out)
    Inter_plmn_nbr.to_csv('Inter_plmn_nbr.csv',index=False)
    
    
    
def SAP_GNB_Map():
    global file_SAP_GNB
    
    file_SAP_GNB = filedialog.askopenfilename(initialdir="C:/", title="Select SAP-GNB Mapping")

    os.system(file_SAP_GNB)
    
   # xls = pd.ExcelFile(file_SAP_GNB,engine='openpyxl')
#    df_SAP_GNB = pd.read_csv(file_SAP_GNB)
    return file_SAP_GNB
    

    
def FiveG_TA():
    global df_TA_5G
    global df_SAP_GNB
    
    TA_5G = filedialog.askopenfilename(initialdir="C:/", title="Select 5G TA Report")

    os.system(TA_5G)
    #Reading the TA File

    df_TA_5G = pd.read_csv(TA_5G)

    #Reading the SAP GNB file here
    df_SAP_GNB = pd.read_csv(file_SAP_GNB)
    
    
    #more than 3Km Calculation in TA Report
    df_TA_5G['More_Than_3Km']=df_TA_5G['154449-5G_Nokia_TDD_%TA Samples between 3 to 6 Km']+df_TA_5G['154466-5G_Nokia_TDD_%TA Samples more than 6 Km']
    
    #Renaming before vlookup 
    df_TA_5G.rename(columns = {'SapId':'SAP ID'}, inplace = True)
    
    #Lookup 5G GNB ID into TA Report from SAP_GNB databse
    df_TA_5G = inner_join = pd.merge(df_TA_5G,df_SAP_GNB,
                                  on ='SAP ID',
                                  how ='inner')
    inner_join

    # Creating Cell id corresponding to cNum of 5G (60=0,61=1,62=2 & 70=16,71=17,72=18)
    df_TA_5G.loc[df_TA_5G['cNum'] == 60, 'Cell_Id'] = '0'
    df_TA_5G.loc[df_TA_5G['cNum'] == 61, 'Cell_Id'] = '1'
    df_TA_5G.loc[df_TA_5G['cNum'] == 62, 'Cell_Id'] = '2'

    df_TA_5G.loc[df_TA_5G['cNum'] == 70, 'Cell_Id'] = '16'
    df_TA_5G.loc[df_TA_5G['cNum'] == 71, 'Cell_Id'] = '17'
    df_TA_5G.loc[df_TA_5G['cNum'] == 72, 'Cell_Id'] = '18'
    
    #Concatenating Cell id with GNB id

    df_TA_5G["GNBID"]=df_TA_5G["GNBID"].astype(str)
    df_TA_5G["Cell_Id"]=df_TA_5G["Cell_Id"].astype(str)
    df_TA_5G["GNB_CI"] = df_TA_5G[["GNBID", "Cell_Id"]].apply(lambda x: "_".join(x), axis =1)
    
    
    
#FourG MDB Import
def FiveG_MDB():
    global df_SAP_GNB
    global df_5G
    
    filename_5G = filedialog.askopenfilename(initialdir="C:/", title="Select 5G MDB")

    os.system(filename_5G)    
    #Reading 5G MDB
    xls = pd.ExcelFile(filename_5G)
    df_5G = pd.read_excel(xls,'Sheet1')

    
    #Dropping not onair rows
    PROGRESS_STATE=df_5G[df_5G['PROGRESS_STATE']!='ONAIR'].index
    df_5G.drop(PROGRESS_STATE, inplace=True)
    
    #Vlookup 5G GNB id in 5G Master
    df_5G = inner_join = pd.merge(df_5G,df_SAP_GNB,
                                  on ='SAP ID',
                                  how ='inner')
    inner_join
    #print(df_5G.head())
    
    
    
#FourG MDB Import
def FourG_MDB():
    global df_4G
    filename_4G = filedialog.askopenfilename(initialdir="C:/", title="Select 4G MDB")
    os.system(filename_4G)
    xls = pd.ExcelFile(filename_4G)
    df_4G = pd.read_excel(xls,'Visualized Sites',skiprows=1)
    #stripping whitespaces in header
    df_4G = df_4G.rename(columns=lambda x: x.strip())

    #Dropping not onair Rows
    JCP_Site_Status=df_4G[df_4G['JCP Site Status']!='ONAIR'].index
    df_4G.drop(JCP_Site_Status, inplace=True)
    

    
def LtoNStart_Dis():
    #Concatenating Target GNB id with target NR Cell id


    df["GNB_ID"]=df["GNB_ID"].astype(str)
    df["TARGET_CELL_ID_NR"]=df["TARGET_CELL_ID_NR"].astype(str)
    df["GNB_CI"] = df[["GNB_ID", "TARGET_CELL_ID_NR"]].apply(lambda x: "_".join(x), axis =1)

    
    #Vlookup 5G >3Km Samples from TA report to rtrv
    df['More_Than3Km_Samp'] = df.GNB_CI.map(df_TA_5G.set_index('GNB_CI')['More_Than_3Km'])

    #Converting to sting before Vlookup
    df['GNB_ID']=df['GNB_ID'].astype(str)
    df_5G['GNBID']=df_5G['GNBID'].astype(str)
    
    
    #vlookup only 2 columns Getting Lat long for source
    df['S_Lat'] = df.Sapid.map(df_4G.set_index('SAPID')['JCP\nLatitude'])
    df['S_Long'] = df.Sapid.map(df_4G.set_index('SAPID')['JCP\nLongitude'])

    #Getting Lat long for Target
    df['T_Lat'] = df.GNB_ID.map(df_5G.set_index('GNBID')['LATITUDE'])
    df['T_Long'] = df.GNB_ID.map(df_5G.set_index('GNBID')['LONGITUDE'])

    
    
    #calculating the distance between source and Target lat long

# vectorized haversine function
    
    def haversine(S_Lat, S_Long, T_Lat, T_Long, to_radians=True, earth_radius=6371):
        """
        slightly modified version: of http://stackoverflow.com/a/29546836/2901002

        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees or in radians)

        All (lat, lon) coordinates must have numeric dtypes and be of equal length.

        """
        if to_radians:
            S_Lat, S_Long, T_Lat, T_Long = np.radians([S_Lat, S_Long, T_Lat, T_Long])

        a = np.sin((T_Lat-S_Lat)/2.0)**2 + \
            np.cos(S_Lat) * np.cos(T_Lat) * np.sin((T_Long-S_Long)/2.0)**2

        return earth_radius * 2 * np.arcsin(np.sqrt(a))


    df['Nbr_Dist_km'] =haversine(df.S_Lat, df.S_Long,df.T_Lat,df.T_Long)
    
    
    #More thank 10km neighbour
    df_More_Than_10Km = df[df["Nbr_Dist_km"] > 10]
    df_More_Than_30pc10km_Sample=df_More_Than_10Km[df_More_Than_10Km['More_Than3Km_Samp']>30]
    
    
    #Dropping Lat Longs
    df_More_Than_30pc10km_Sample=df_More_Than_30pc10km_Sample.drop(['S_Lat','S_Long','T_Lat','T_Long','GNB_CI'], axis=1)

    #Changing to output directory for printing file
    os.chdir(directory_out)
    df_More_Than_30pc10km_Sample.to_csv('More_Than_30pc10km_Sample.csv',index=False)
    

    
    
    
#Path for input

Input_Path = Button(top,text = "1.  Path for Input",activeforeground = "yellow",activebackground = "steelblue",height=1,width=15,font=("Helvetica", 8, "bold"),command=input_file_path,anchor='w')

Input_Path.place(x=150,y=20)


#Path for output dump
Output_Path = Button(top,text = "2.  Path for Output",activeforeground = "yellow",activebackground = "PaleTurquoise3",height=1,width=15,font=("Helvetica", 8, "bold"),command=output_file_path,anchor='w')
Output_Path.place(x=150,y=50)

#Trigger to start processing RTRV Dump
RTRV = Button(top,text = "3.   Dump RTRV",activeforeground = "yellow",activebackground = "green",height=1,width=15,font=("Helvetica", 8, "bold"),command=RTRV_Dump,anchor='w')
#Trigger Processing Finish
RTRV.place(x=150,y=90)


#Trigger to start Processing PCI Confusion
LtoN = Button(top,text = "4. 4G-5G Confusion",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=LtoNStart,anchor='w')
#Trigger Processing Finish
LtoN.place(x=80,y=130)

#Trigger to start Processing PCI Confusion
Inter_PLMN = Button(top,text = "5. Inter PLMN NBR",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=Inter_plmn_nbr,anchor='w')
#Trigger Processing Finish
Inter_PLMN.place(x=80,y=160)





#Trigger to SAP vs GNB Id Mappping
SAPvsGNB_Database = Button(top,text = "4.SAP GNB Mapping",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=SAP_GNB_Map,anchor='w')
#Trigger Processing Finish
SAPvsGNB_Database.place(x=220,y=130)


#Trigger to TA Report
FiveG_TA_Database = Button(top,text = "5. 5G TA Report",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=FiveG_TA,anchor='w')
#Trigger Processing Finish
FiveG_TA_Database.place(x=220,y=160)



#Trigger to IMport 5G MDB
FiveG_Database = Button(top,text = "6. 5G MDB",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=FiveG_MDB,anchor='w')
#Trigger Processing Finish
FiveG_Database.place(x=220,y=190)

#Trigger to IMport 4G MDB
FourG_Database = Button(top,text = "7. 4G MDB",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=FourG_MDB,anchor='w')
#Trigger Processing Finish
FourG_Database.place(x=220,y=220)



#Trigger to start Processing Distance
LtoN_Dis = Button(top,text = "8.Over Shooting NBR",activeforeground = "yellow",activebackground = "green",height=1,width=16,font=("Helvetica", 8, "bold"),command=LtoNStart_Dis,anchor='w')
#Trigger Processing Finish
LtoN_Dis.place(x=220,y=250)

#Changing the current directory to the input directory

#SAP_GNB=SAP_GNB_Map()


#stopping process and Exit
stop.place(x=150,y=350)

#c.pack()
top.mainloop()

Below is the Example of the dataframe im tryin to compare the values in

Sapid   Command Hostname    InvocationId    CELL_NUM    RELATION_IDX    STATUS  GNB_ID_BIT_LENGTH   GNB_ID  TARGET_CELL_ID_NR   GNB_MCC[DIGIT]  GNB_MNC[DIGIT]  MCC0[DIGIT] MNC0[DIGIT] MCC1[DIGIT] MNC1[DIGIT] MCC2[DIGIT] MNC2[DIGIT] MCC3[DIGIT] MNC3[DIGIT] MCC4[DIGIT] MNC4[DIGIT] MCC5[DIGIT] MNC5[DIGIT] MCC6[DIGIT] MNC6[DIGIT] MCC7[DIGIT] MNC7[DIGIT] PHY_CELL_ID_NR  FIVE_GS_TAC CONFIG_TAC  DUPLEX_TYPE ARFCN_UL    ARFCN_DL    BANDWIDTH_UL_SCS    BANDWIDTH_DL_SCS    BANDWIDTH_UL_NRB    BANDWIDTH_DL_NRB    UL_NRFREQUENCY_BAND0    DL_NRFREQUENCY_BAND0    UL_NRFREQUENCY_BAND1    DL_NRFREQUENCY_BAND1    UL_NRFREQUENCY_BAND2    DL_NRFREQUENCY_BAND2    UL_NRFREQUENCY_BAND3    DL_NRFREQUENCY_BAND3    IS_REMOVE_ALLOWED   IS_ENDCALLOWED  OWNER_TYPE  CURRENT_RANK    PREVIOUS_RANK   IS_COLOCATED    IS_COLOCATED_FOR_ES_CELL_OFF    SSB_FREQUENCY   IS_HOALLOWED    DSS_CELL_INDICATOR
I-TN-VLLR-ENB-I020  RTRV-NBR-NR;    TN-TN-REM-14-MS-1   1.70564E+12 12  15  EQUIP   22  270191  2   405 857 405 869 FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF 144 H'00B4  H'0000  TDD 0   0   scs30   scs30   nrb273  nrb273  78  78  -1  -1  -1  -1  -1  -1  removeAllowed   TRUE    CreatedByUserCommand    0   0   FALSE   FALSE   634080  TRUE    FALSE
I-TN-VLLR-ENB-I020  RTRV-NBR-NR;    TN-TN-REM-14-MS-1   1.70564E+12 12  16  EQUIP   22  270191  1   405 869 405 869 FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF 146 H'00B4  H'0000  TDD 0   0   scs30   scs30   nrb273  nrb273  78  78  -1  -1  -1  -1  -1  -1  removeAllowed   TRUE    CreatedByUserCommand    0.1 0.1 FALSE   FALSE   634080  TRUE    FALSE
I-TN-VLLR-ENB-I020  RTRV-NBR-NR;    TN-TN-REM-14-MS-1   1.70564E+12 12  17  EQUIP   22  270191  0   405 869 405 869 FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF 145 H'00B4  H'0000  TDD 0   0   scs30   scs30   nrb273  nrb273  78  78  -1  -1  -1  -1  -1  -1  removeAllowed   TRUE    CreatedByUserCommand    0   0   FALSE   FALSE   634080  TRUE    FALSE
I-TN-VLLR-ENB-I020  RTRV-NBR-NR;    TN-TN-REM-14-MS-1   1.70564E+12 12  18  EQUIP   22  270230  18  405 869 405 869 FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF FFF 353 H'008B  H'0000  TDD 0   1   scs15   scs15   nrb52   nrb52   28  28  -1  -1  -1  -1  -1  -1  removeAllowed   TRUE    CreatedByUserCommand    0.1 0.1 FALSE   FALSE   156510  TRUE    FALSE

0

There are 0 best solutions below