feat: added tab with top lists
Browse files- app.py +10 -2
- utils/gradio_utils.py +32 -1
app.py
CHANGED
@@ -2,9 +2,17 @@ import gradio as gr
|
|
2 |
from utils.gradio_utils import *
|
3 |
import os
|
4 |
|
|
|
|
|
5 |
USER = os.getenv("USERNAME")
|
6 |
PASS = os.getenv("PASSWORD")
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
domains_template = """tenderax.com
|
9 |
reach-fortune.com
|
10 |
joyful-healthy-hair.com
|
@@ -98,8 +106,6 @@ thedropgears.com"""
|
|
98 |
|
99 |
|
100 |
with gr.Blocks() as aeon:
|
101 |
-
|
102 |
-
|
103 |
with gr.Tab(label="SWAKS"):
|
104 |
with gr.Row():
|
105 |
with gr.Column():
|
@@ -160,5 +166,7 @@ with gr.Blocks() as aeon:
|
|
160 |
mix_btn.click(fn=mix, inputs=[domains_raw, output_ips, num_of_ips],\
|
161 |
outputs=output_mix)
|
162 |
|
|
|
|
|
163 |
|
164 |
aeon.launch(auth=(USER, PASS))
|
|
|
2 |
from utils.gradio_utils import *
|
3 |
import os
|
4 |
|
5 |
+
|
6 |
+
|
7 |
USER = os.getenv("USERNAME")
|
8 |
PASS = os.getenv("PASSWORD")
|
9 |
|
10 |
+
list_iface = gr.Interface(fn=compute_offer,
|
11 |
+
inputs=[gr.File(label="Upload CSV", type="file"),
|
12 |
+
gr.Slider(1, 365, value=30, step=1, label="Days", info="Number of days to look back")
|
13 |
+
],
|
14 |
+
outputs="dataframe")
|
15 |
+
|
16 |
domains_template = """tenderax.com
|
17 |
reach-fortune.com
|
18 |
joyful-healthy-hair.com
|
|
|
106 |
|
107 |
|
108 |
with gr.Blocks() as aeon:
|
|
|
|
|
109 |
with gr.Tab(label="SWAKS"):
|
110 |
with gr.Row():
|
111 |
with gr.Column():
|
|
|
166 |
mix_btn.click(fn=mix, inputs=[domains_raw, output_ips, num_of_ips],\
|
167 |
outputs=output_mix)
|
168 |
|
169 |
+
with gr.Tab(label="Top Lists"):
|
170 |
+
list_iface.render()
|
171 |
|
172 |
aeon.launch(auth=(USER, PASS))
|
utils/gradio_utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import random
|
2 |
import ipaddress
|
|
|
3 |
|
4 |
|
5 |
### SWAKS ###
|
@@ -226,4 +227,34 @@ def generate_ips_per_subclass(ip_subclasses: str, num_of_ips: int) -> str:
|
|
226 |
|
227 |
# Assuming generate_ips_per_slash24 is the same as the previously discussed generate_ips function
|
228 |
ip_addresses.extend(generate_ips_per_slash24(ip_subclass_24, num_of_ips))
|
229 |
-
return "\n".join(ip_addresses)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import random
|
2 |
import ipaddress
|
3 |
+
import pandas as pd
|
4 |
|
5 |
|
6 |
### SWAKS ###
|
|
|
227 |
|
228 |
# Assuming generate_ips_per_slash24 is the same as the previously discussed generate_ips function
|
229 |
ip_addresses.extend(generate_ips_per_slash24(ip_subclass_24, num_of_ips))
|
230 |
+
return "\n".join(ip_addresses)
|
231 |
+
|
232 |
+
|
233 |
+
### GENERATE TOP LISTS ###
|
234 |
+
def compute_offer(csv_file, days_lookback):
|
235 |
+
cmp_list = ['MSP', 'HOM', 'NTU', 'HCK', 'DDS', 'MNP', 'PSC', 'DTL', 'GVS', 'ANP', 'WDR', 'BSG']
|
236 |
+
|
237 |
+
#raw_df = pd.read_csv('tools/data/30.08.2023.gabriel.sabau.campanii.csv', parse_dates=['Data'])
|
238 |
+
raw_df = pd.read_csv(csv_file.name, parse_dates=['Data'])
|
239 |
+
|
240 |
+
cols = ['Campanie', 'Oferta', 'Nume', 'Server', 'User',
|
241 |
+
'Lista Custom', 'Data', 'HClicks', 'Clicks', 'Unscribers', 'Openers',
|
242 |
+
'Click Open', 'Leads', 'CLike', 'Complains', 'Traps', 'Send']
|
243 |
+
comcast_df = raw_df[raw_df['Nume'].str.contains('|'.join(cmp_list))]
|
244 |
+
comcast_df = comcast_df[comcast_df['Domeniu'] == 'Comcast']
|
245 |
+
comcast_df = comcast_df[cols]
|
246 |
+
comcast_df['Click Open'] = comcast_df['Click Open'].str.replace('%', '').astype(float)
|
247 |
+
exclude_list = comcast_df[comcast_df['Data'] > (pd.Timestamp('now') - pd.Timedelta(days=days_lookback))]['Oferta'].unique()
|
248 |
+
comcast_df = comcast_df[~comcast_df['Oferta'].isin(exclude_list)]
|
249 |
+
comcast_df = comcast_df[comcast_df['Send'] > 350000]
|
250 |
+
comcast_df = comcast_df[comcast_df['Lista Custom'].str.contains('open')]
|
251 |
+
|
252 |
+
comcast_df.reset_index(drop=True, inplace=True)
|
253 |
+
|
254 |
+
final_df = comcast_df.groupby(["Oferta", "Nume"])\
|
255 |
+
.agg( N=('Oferta', 'count'), send_avg=('Send', 'mean'), CO=('Click Open', 'mean'))\
|
256 |
+
.sort_values(['CO', 'N'], ascending=False)
|
257 |
+
final_df['send_avg'] = final_df['send_avg'].round(2).astype(float)
|
258 |
+
final_df.reset_index(inplace=True)
|
259 |
+
|
260 |
+
return final_df
|