def top_open_opportunities_callback(df): edge1 = pd.read_csv('/home/ubuntu/bjur27r-gmail.com/model/upward.csv', sep="\t", encoding='utf8') edge1 = pd.read_csv('/home/ubuntu/bjur27r-gmail.com/model/upward.csv', sep="\t", encoding='utf8') df = edge1[['source', 'level', 'amount']].groupby(['source', 'level']).agg( sum_trans_adrs=pd.NamedAgg(column='amount', aggfunc='sum'), count_trans_adrs=pd.NamedAgg(column='amount', aggfunc='count')) df = df.reset_index() df = df[['level', 'count_trans_adrs', 'sum_trans_adrs']].groupby(['level']).agg( count_trans_adrs_levl=pd.NamedAgg(column='count_trans_adrs', aggfunc='count'), mean_trans_adrs_levl=pd.NamedAgg(column='count_trans_adrs', aggfunc='mean'), mean_trans_val_levl=pd.NamedAgg(column='sum_trans_adrs', aggfunc='mean'), sum_trans_val_levl=pd.NamedAgg(column='sum_trans_adrs', aggfunc='sum')) # count_trans_adrs_levl: numero de address distintos por nivel. # mean_trans_adrs_levl: transacciones medias de address. # mean_trans_val_levl : transaccion media por nivel # sum_trans_val_levl : suma todas las transacciones por nivel df = df.reset_index() df_2 = pd.DataFrame() df_2['Level'] = df['level'] df_2['Distinct_Senders'] = round(df['count_trans_adrs_levl'], 1) df_2['Average_Trans'] = round(df['mean_trans_adrs_levl'], 1) df_2['Average_Trans_Value'] = round(df['mean_trans_val_levl'], 1) df_2['Total_Trans_Value'] = round(df['sum_trans_val_levl'], 1) return df_to_table(df_2)
def top_open_opportunities(df): df = df.sort_values("Amount", ascending=True) cols = ["CreatedDate", "Name", "Amount", "StageName"] df = df[cols].iloc[:5] # only display 21 characters df["Name"] = df["Name"].apply(lambda x: x[:30]) return df_to_table(df)
def top_lost_opportunities(df): df = df[df["StageName"] == "Closed Lost"] cols = ["CreatedDate", "Name", "Amount", "StageName"] df = df[cols].sort_values("Amount", ascending=False).iloc[:5] # only display 21 characters df["Name"] = df["Name"].apply(lambda x: x[:30]) return df_to_table(df)
def prod_mas_vendido(jsondf): df = pd.read_json(jsondf, orient='split') columns = [ 'Etapa', 'Numero Unidad', 'Nombre', 'Estado', 'Programa', 'Nro Personas' ] return df_to_table(df[columns].head())
def prod_menor_vendido(jsondf): df = pd.read_json(jsondf, orient='split') df = df.sort_values(by='Nro Personas', ascending=True) columns = [ 'Etapa', 'Numero Unidad', 'Nombre', 'Estado', 'Programa', 'Nro Personas' ] return df_to_table(df[columns].head())
def tables(endDate, startDate, db, coll): # print(type(startDate),startDate,endDate) # if endDate==None: # stDate = '2018-11-13' # endDate = '2018-11-14' print(startDate, endDate) stDate = datetime.strptime(startDate, "%Y-%m-%d") edDate = datetime.strptime(endDate, "%Y-%m-%d") print("---------------", stDate, edDate) return df_to_table(cpkinitalTable(stDate, edDate, db, coll))
def leads_table_callback(status, df): df = pd.read_json(df, orient="split") if status == "open": df = df[(df["Status"] == "Open - Not Contacted") | (df["Status"] == "Working - Contacted")] elif status == "converted": df = df[df["Status"] == "Closed - Converted"] elif status == "lost": df = df[df["Status"] == "Closed - Not Converted"] df = df[["CreatedDate", "Status", "Company", "State", "LeadSource"]] return df_to_table(df)
def nodes_des(df): df_node_3 = df_nodes() df_nodes_out = df_node_3[['level', 'label', 'cluster', 'prob_1']].groupby([ 'level', 'label', 'cluster' ]).agg(LookAlike=pd.NamedAgg(column='prob_1', aggfunc='median')) df_nodes_out = df_nodes_out.reset_index() df_nodes_out['Level'] = df_nodes_out['level'] df_nodes_out['LookAlike'] = round(df_nodes_out['LookAlike'] * 100, 1) df_nodes_out['Sannity Check'] = df_nodes_out['LookAlike'].apply( lambda x: 'SUSPICIOUS' if x > 50 else "OK") return df_to_table(df_nodes_out)
def top_lost_opportunities_callback(df): df = pd.read_json(df, orient="split") # df_clust= clusterice(df,10) # df_clust.to_csv("c:\BC_DS\df_result_b.csv", sep = "\t", encoding='utf8') df['Cluster'] = df['cluster'] df['Sample_Share(%)'] = round(df['cluster_Pob'] * 100, 0) df['Lifetime(days)'] = round(df['lifetime_d'], 0) df['Trans_In(x)'] = round(df['TX_IN'], 0) df['Trans_Out(x)'] = round(df['TX_OUT'], 0) df['Ratio_IN/OUT(x)'] = round(df['Trans_In(x)'] / df['Trans_Out(x)'], 2) df['Average_Value_In(USD)'] = round(df['value_IN'] / df['Trans_In(x)'], 0) df['Average_Value_Out(USD)'] = round(df['value_OUT'] / df['Trans_Out(x)'], 0) df['Phising Lookalike(%)'] = round(df['prob_1'] * 100, 0) df['balance_mean'] = round(df['TX_OUT'], 0) df_Out = df[['Cluster', 'Sample_Share(%)', 'Lifetime(days)', 'Trans_In(x)', 'Trans_Out(x)', 'Ratio_IN/OUT(x)', 'Average_Value_In(USD)', 'Average_Value_Out(USD)', 'Phising Lookalike(%)']] return df_to_table(df_Out)
def strategy_table_callback(df): df = pd.read_json(df, orient="split") return df_to_table(df)
margin=dict( l=100, r=25, b=20, t=0, pad=4), paper_bgcolor='white', plot_bgcolor='white'))), ], className="four columns chart_div"), ], className="row", style={"marginTop": "5"}, ), html.Div( id="leads_table", # className="row", children=[ df_to_table( cpkinitalTable(datetime(2018, 10, 12), datetime(2018, 10, 13), '1521900003T0', 'DsQAM')) ], style={ "maxHeight": "550px", "overflowY": "scroll", "padding": "10", "marginTop": "5", "backgroundColor": "white", "border": "1px solid #C8D4E3", "borderRadius": "3px" }, ), modal(), html.Div([ html.Div([
"width": '100%', "Height": '40%' }), ], style={ "display": "inline-block", "margin-left": 30, "width": '45%' }) ], ), #TM列表 html.Div( id="TM_Table", className="chart_div pretty_container", children=df_to_table(), ), #TM图表 html.Div( id="TM_Chart", className="chart_div pretty_container", children=[ dcc.Graph( id='lead_source', figure={ 'data': [ { 'x': [ "Topic 1", "Topic 2", "Topic 3", "Topic 4", "Topic 5" ],