Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.6 kB
1
Indexable
Never
@app.post("/run_recommendation/")
async def run_recommendation(request: Request):
    pdb.set_trace()
    if request.method ==['POST']:
        param_vals = await request.json()
        ## Getting all fields required for prediction
        ticket_category=param_vals['ticket_category']
        ticket_type=param_vals['ticket_type']
        ticket_item=param_vals['ticket_item']
        ticket_summary=param_vals['ticket_summary']
        ticket_severity=param_vals['ticket_severity']
        resolution_sla_violated=param_vals['resolution_sla_violated']
        reopen_count=param_vals['reopen_count']
        owner_user_id=param_vals['owner_user_id']
        role_name=param_vals['role_name']
        created_date=param_vals['created_date']
        ticket_resolution_date=param_vals['ticket_resolution_date']
        person_who_resolved=' '
        
        print("Param Vals",param_vals )
        print("Ticket Category ", ticket_category)
        print("Ticket Type ", ticket_type)
        
        data = pd.DataFrame({
        'ticket_category': [ticket_category],
        'ticket_type': [ticket_type],
        'ticket_item': [ticket_item],
        'ticket_summary': [ticket_summary],
        'ticket_severity': [ticket_severity],
        'resolution_sla_violated': [resolution_sla_violated],
        'reopen_count': [reopen_count],
        'owner_user_id': [owner_user_id],
        'role_name': [role_name],
        'created_date': [created_date],
        'ticket_resolution_date': [ticket_resolution_date],
        'person_who_resolved': [person_who_resolved]
    })
        print("Data",data)
        
        
        ## Making a function call for data pre-processing
        processed_data= feature_engineering(data)
        
        print("Processed Data : ",processed_data)
        
        df=processed_data
        label_enc = LabelEncoder()

        df['role_name_encoded'] = label_enc.fit_transform(df['role_name'])
        df['role_name_decoded'] = label_enc.inverse_transform(df['role_name_encoded'])
        
        # Link the X vector with index
        index = df.index.values
        
        recommendations=get_top_5_person_who_resolved(df, row, data ,distance_metric='cosine')
        
        print("Recommended users for the sample ticket:")
        for i, rec in enumerate(recommendations[0]):
            print(f"Recommendation {i+1}: User {rec[0]}, Owner User ID {rec[1]}, Role Name {rec[2]}")
            
        return recommendations
        
if __name__ == "__main__":
    app.run(host='100.87.2.56', port=8895, threaded=True)