poemsforaphrodite commited on
Commit
99665c0
1 Parent(s): d513d9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -120,6 +120,8 @@ def init_session_state():
120
  st.session_state.custom_start_date = datetime.date.today() - datetime.timedelta(days=7)
121
  if 'custom_end_date' not in st.session_state:
122
  st.session_state.custom_end_date = datetime.date.today()
 
 
123
  #logging.info("Session state initialized")
124
 
125
  # -------------
@@ -258,7 +260,7 @@ def analyze_competitors(row, co, custom_url=None, country_code=None):
258
  })
259
 
260
  # Retrieve "Our Score" from the main data table
261
- our_score = st.session_state['relevancy_scores'].get(our_url, 0)
262
 
263
  if not any(r['is_our_url'] for r in results):
264
  results.append({
@@ -401,11 +403,11 @@ def fetch_gsc_data(webproperty, search_type, start_date, end_date, dimensions, d
401
 
402
 
403
  def calculate_relevancy_scores(df, model_type):
404
- st.session_state['relevancy_scores'] = {}
405
- # Existing code to calculate scores
406
- # After calculation
407
  for index, row in df.iterrows():
408
- st.session_state['relevancy_scores'][row['page']] = row['relevancy_score']
 
 
 
409
  return df
410
 
411
  # -------------
 
120
  st.session_state.custom_start_date = datetime.date.today() - datetime.timedelta(days=7)
121
  if 'custom_end_date' not in st.session_state:
122
  st.session_state.custom_end_date = datetime.date.today()
123
+ if 'relevancy_scores' not in st.session_state:
124
+ st.session_state.relevancy_scores = {}
125
  #logging.info("Session state initialized")
126
 
127
  # -------------
 
260
  })
261
 
262
  # Retrieve "Our Score" from the main data table
263
+ our_score = st.session_state.relevancy_scores.get(our_url, 0)
264
 
265
  if not any(r['is_our_url'] for r in results):
266
  results.append({
 
403
 
404
 
405
  def calculate_relevancy_scores(df, model_type):
 
 
 
406
  for index, row in df.iterrows():
407
+ if pd.isna(row['relevancy_score']) or row['relevancy_score'] == 0:
408
+ score = calculate_single_relevancy(row)
409
+ df.at[index, 'relevancy_score'] = score
410
+ st.session_state.relevancy_scores[normalize_url(row['page'])] = score
411
  return df
412
 
413
  # -------------