Alp57 commited on
Commit
833a381
·
verified ·
1 Parent(s): 6f12fcb

Upload api_logic.py

Browse files
Files changed (1) hide show
  1. src/api_logic.py +29 -4
src/api_logic.py CHANGED
@@ -70,17 +70,42 @@ def fetch_keyword_ideas(request: KeywordRequestModel):
70
  "monthly_searches": mv.monthly_searches
71
  })
72
 
 
 
 
 
 
 
73
  result_items.append({
74
  "keyword": idea.text,
75
  "avg_monthly_searches": metrics.avg_monthly_searches,
76
  "competition": metrics.competition.name,
77
  "competition_index": metrics.competition_index,
78
- "low_top_of_page_bid_micros": metrics.low_top_of_page_bid_micros,
79
- "high_top_of_page_bid_micros": metrics.high_top_of_page_bid_micros,
80
- "average_cpc_micros": metrics.average_cpc_micros,
81
- "monthly_search_volumes": monthly_volumes
 
 
 
82
  })
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  # --- Aggregate results ---
85
  aggregate = response.aggregate_metric_results
86
  aggregate_device = []
 
70
  "monthly_searches": mv.monthly_searches
71
  })
72
 
73
+
74
+ # According To "Rule Book For GKP With Code" Transform Some Values
75
+ raw_cpc = (((metrics.low_top_of_page_bid_micros) + (metrics.high_top_of_page_bid_micros)) / 2) / 1000000
76
+ log_cpc = np.log(raw_cpc + 1)
77
+
78
+
79
  result_items.append({
80
  "keyword": idea.text,
81
  "avg_monthly_searches": metrics.avg_monthly_searches,
82
  "competition": metrics.competition.name,
83
  "competition_index": metrics.competition_index,
84
+ "low_top_of_page_bid_micros": metrics.low_top_of_page_bid_micros / 1000000,
85
+ "high_top_of_page_bid_micros": metrics.high_top_of_page_bid_micros / 1000000,
86
+ # "average_cpc_micros": metrics.average_cpc_micros,
87
+ "monthly_search_volumes": monthly_volumes,
88
+ ##Created Features
89
+ "log_cpc": log_cpc
90
+
91
  })
92
 
93
+ #Normalize the Log CPC Values
94
+ log_values = [item["log_cpc"] for item in result_items]
95
+ min_log = min(log_values)
96
+ max_log = max(log_values)
97
+
98
+
99
+ def scale_0_100(x, min_val, max_val):
100
+ if max_val == min_val:
101
+ return 0
102
+ return ((x - min_val) / (max_val - min_val)) * 100
103
+
104
+ #Adding "log_cpc_norm_0_100" to Results_Items
105
+ for item in result_items:
106
+ item["log_cpc_norm_0_100"] = scale_0_100(item["log_cpc"], min_log, max_log)
107
+
108
+
109
  # --- Aggregate results ---
110
  aggregate = response.aggregate_metric_results
111
  aggregate_device = []