So I am trying to update the parquet file as well as google sheet at the same time, it works, but also doesn’t it does seem to update the file at first glace from the reading in the file, but only if I filter it a specific way, the way i filter it in order to edit the information, but if i were to niot filter it like that it doesn’t seem to update same goes if I dont filter it at all as well. the google sheet part of it works fine, but the parquet filr it self is not. for context as well, I have 2 pages at play in this case, add qr page dediicated to assign customer’s name and the status to the selected qr, and the main update oage in order to post a customer’s follow up on another lets call it update page
this is my current code for the update function:
<code>def update_qr(sname, customer, status, qr):
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sheet = client.open('qr_report').sheet1
# Load existing CSV data into a DataFrame
csv_file_path = f'{sname}_qr_report.parquet'
filter_condition1 = df['QR Number'] == qr
print(df[filter_condition1])
df.loc[filter_condition1, ['cus_name', 'status', 'followup plan', 'update date', 'usernmae'][customer, status, get_followup_plan(status), now, sname]
df.to_parquet(csv_file_path, index=False)
print(df[filter_condition1])
df.to_parquet(csv_file_path, engine='pyarrow', index=False)
print(f"DataFrame written to {csv_file_path} successfully.")
df_read = pd.read_parquet(csv_file_path, engine='pyarrow')
print(df_read[filter_condition1])
sheet.update_cell(row, 3, customer)
sheet.update_cell(row, 4, status)
sheet.update_cell(row, 5, get_followup_plan(status))
sheet.update_cell(row, 10, sname)
raise ValueError(f'Cannot find a cell with {qr} as the QR Number')
<code>def update_qr(sname, customer, status, qr):
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sheet = client.open('qr_report').sheet1
# Load existing CSV data into a DataFrame
csv_file_path = f'{sname}_qr_report.parquet'
df = qr_report
filter_condition1 = df['QR Number'] == qr
print(df[filter_condition1])
df.loc[filter_condition1, ['cus_name', 'status', 'followup plan', 'update date', 'usernmae'][customer, status, get_followup_plan(status), now, sname]
df.to_parquet(csv_file_path, index=False)
print(df[filter_condition1])
try:
df.to_parquet(csv_file_path, engine='pyarrow', index=False)
print(f"DataFrame written to {csv_file_path} successfully.")
except Exception as e:
print(f"Error: {e}")
df_read = pd.read_parquet(csv_file_path, engine='pyarrow')
print(df_read[filter_condition1])
cell = sheet.find(qr)
if cell:
row = cell.row
sheet.update_cell(row, 3, customer)
sheet.update_cell(row, 4, status)
sheet.update_cell(row, 5, get_followup_plan(status))
sheet.update_cell(row, 10, sname)
else:
raise ValueError(f'Cannot find a cell with {qr} as the QR Number')
get_file_df(sname)
</code>
def update_qr(sname, customer, status, qr):
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sheet = client.open('qr_report').sheet1
# Load existing CSV data into a DataFrame
csv_file_path = f'{sname}_qr_report.parquet'
df = qr_report
filter_condition1 = df['QR Number'] == qr
print(df[filter_condition1])
df.loc[filter_condition1, ['cus_name', 'status', 'followup plan', 'update date', 'usernmae'][customer, status, get_followup_plan(status), now, sname]
df.to_parquet(csv_file_path, index=False)
print(df[filter_condition1])
try:
df.to_parquet(csv_file_path, engine='pyarrow', index=False)
print(f"DataFrame written to {csv_file_path} successfully.")
except Exception as e:
print(f"Error: {e}")
df_read = pd.read_parquet(csv_file_path, engine='pyarrow')
print(df_read[filter_condition1])
cell = sheet.find(qr)
if cell:
row = cell.row
sheet.update_cell(row, 3, customer)
sheet.update_cell(row, 4, status)
sheet.update_cell(row, 5, get_followup_plan(status))
sheet.update_cell(row, 10, sname)
else:
raise ValueError(f'Cannot find a cell with {qr} as the QR Number')
get_file_df(sname)
here is the filter on the add qr page:
<code>def get_qrlist_to_add(sname):
salecode = get_salecode(sname)
df['sale code'] = df['sale code'].astype(str)
data = df[df['cus_name']==''][df['sale code'].isin(salecode)][['QR Number', 'description']].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False).values.tolist()
result = [' '.join(map(str, x)) for x in data]
print(f'it takes {end-start} seconds to add qrs.')
<code>def get_qrlist_to_add(sname):
start = time.time()
df = qr_report
salecode = get_salecode(sname)
print(salecode)
df['sale code'] = df['sale code'].astype(str)
data = df[df['cus_name']==''][df['sale code'].isin(salecode)][['QR Number', 'description']].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False).values.tolist()
result = [' '.join(map(str, x)) for x in data]
end = time.time()
print(f'it takes {end-start} seconds to add qrs.')
return result
</code>
def get_qrlist_to_add(sname):
start = time.time()
df = qr_report
salecode = get_salecode(sname)
print(salecode)
df['sale code'] = df['sale code'].astype(str)
data = df[df['cus_name']==''][df['sale code'].isin(salecode)][['QR Number', 'description']].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False).values.tolist()
result = [' '.join(map(str, x)) for x in data]
end = time.time()
print(f'it takes {end-start} seconds to add qrs.')
return result
here is the filter for the update page:
<code>def filter_qrlist(sname, cname):
# Open the workbook using gspread_pandas
df = qr_report # Assuming the data is in 'Sheet1'
sf = pd.read_parquet('status qr.parquet', engine='pyarrow')
df['status'] = df['status'].astype(str)
df = pd.merge(df, sf, on='status', how='left')
# Filter the DataFrame based on the customer name and sort it in descending alphabetical order
filtered_df = df[df['cus_name'] == cname][df['username'] == sname].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False)
bad_status = ['Win', 'Lose', 'ปรับสเปค-ปรับราคา', 'ไม่พบ QR']
qrs = filtered_df[~filtered_df['Follow up Plan'].isin(bad_status)][['QR Number', 'description']].values.tolist()
qr_list = [' '.join(map(str, qr)) for qr in qrs]
<code>def filter_qrlist(sname, cname):
# Open the workbook using gspread_pandas
df = qr_report # Assuming the data is in 'Sheet1'
sf = pd.read_parquet('status qr.parquet', engine='pyarrow')
df['status'] = df['status'].astype(str)
df = pd.merge(df, sf, on='status', how='left')
# Filter the DataFrame based on the customer name and sort it in descending alphabetical order
filtered_df = df[df['cus_name'] == cname][df['username'] == sname].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False)
bad_status = ['Win', 'Lose', 'ปรับสเปค-ปรับราคา', 'ไม่พบ QR']
qrs = filtered_df[~filtered_df['Follow up Plan'].isin(bad_status)][['QR Number', 'description']].values.tolist()
qr_list = [' '.join(map(str, qr)) for qr in qrs]
return qr_list
</code>
def filter_qrlist(sname, cname):
# Open the workbook using gspread_pandas
df = qr_report # Assuming the data is in 'Sheet1'
sf = pd.read_parquet('status qr.parquet', engine='pyarrow')
df['status'] = df['status'].astype(str)
df = pd.merge(df, sf, on='status', how='left')
# Filter the DataFrame based on the customer name and sort it in descending alphabetical order
filtered_df = df[df['cus_name'] == cname][df['username'] == sname].drop_duplicates(keep='last', subset=['QR Number']).sort_values(by='QR Number', ascending=False)
bad_status = ['Win', 'Lose', 'ปรับสเปค-ปรับราคา', 'ไม่พบ QR']
qrs = filtered_df[~filtered_df['Follow up Plan'].isin(bad_status)][['QR Number', 'description']].values.tolist()
qr_list = [' '.join(map(str, qr)) for qr in qrs]
return qr_list
what would happen is i would select a qr on the add qr page, and it would be just fine, the qr would be removed from the list as it is updated through the parquet file, but the problem comes when I take a look at the update page, as no matter how much i tired to update the list the new ones would not show up. i also checked the parquet file and it is some how not updated either.
I expected the code to update the parquet file properly. and also update the qrlist as well here is the update qrlist function for both of the file:
addqr:
<code>def update_qrlist(self):
for widget in self.qrlist_inner_frame.winfo_children():
qrlist_items = connection.get_qrlist_to_add(self.sname)
for item in qrlist_items:
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, bg="white", font=('Arial', 14))
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk
for widget in self.qrlist_inner_frame.winfo_children():
selected_company = self.company_var.get()
if not self.qrlist_filtered:
qrlist_items = ['None'] + connection.get_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Filter QR')
qrlist_items = ['None'] + connection.filter_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Show All QR')
for item in qrlist_items:
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, command=self.qrlist_select, bg="white", font=("Arial", 14))
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk
<code>def update_qrlist(self):
for widget in self.qrlist_inner_frame.winfo_children():
widget.destroy()
qrlist_items = connection.get_qrlist_to_add(self.sname)
self.qrlist_vars = {}
self.qrlist_checks = {}
for item in qrlist_items:
var = tk.BooleanVar()
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, bg="white", font=('Arial', 14))
chk.pack(anchor="w")
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk
update page:
def update_qrlist(self):
for widget in self.qrlist_inner_frame.winfo_children():
widget.destroy()
selected_company = self.company_var.get()
if not self.qrlist_filtered:
qrlist_items = ['None'] + connection.get_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Filter QR')
else:
qrlist_items = ['None'] + connection.filter_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Show All QR')
self.qrlist_vars = {}
self.qrlist_checks = {}
for item in qrlist_items:
var = tk.BooleanVar()
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, command=self.qrlist_select, bg="white", font=("Arial", 14))
chk.pack(anchor="w")
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk
</code>
def update_qrlist(self):
for widget in self.qrlist_inner_frame.winfo_children():
widget.destroy()
qrlist_items = connection.get_qrlist_to_add(self.sname)
self.qrlist_vars = {}
self.qrlist_checks = {}
for item in qrlist_items:
var = tk.BooleanVar()
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, bg="white", font=('Arial', 14))
chk.pack(anchor="w")
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk
update page:
def update_qrlist(self):
for widget in self.qrlist_inner_frame.winfo_children():
widget.destroy()
selected_company = self.company_var.get()
if not self.qrlist_filtered:
qrlist_items = ['None'] + connection.get_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Filter QR')
else:
qrlist_items = ['None'] + connection.filter_qrlist(sname=self.sname, cname=selected_company)
self.change_qrlist_button.config(text='Show All QR')
self.qrlist_vars = {}
self.qrlist_checks = {}
for item in qrlist_items:
var = tk.BooleanVar()
chk = tk.Checkbutton(self.qrlist_inner_frame, text=item, variable=var, command=self.qrlist_select, bg="white", font=("Arial", 14))
chk.pack(anchor="w")
self.qrlist_vars[item] = var
self.qrlist_checks[item] = chk