File size: 2,306 Bytes
1897667
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# utils.py
import pandas as pd
import glob
import re
import os

def extract_employee_data(employee_name):
    """Extract employee details using name from the Markdown file."""
    details = {}
    directory = "hrdataset/employees"
    
    # Search for employee markdown file
    search_pattern = f"{directory}/*_{employee_name.replace(' ', '_')}.md"
    matching_files = glob.glob(search_pattern)
    
    if not matching_files:
        return f"Error: Employee file for {employee_name} not found."
    
    employee_path = matching_files[0]
    
    # Read the employee markdown file
    with open(employee_path, "r", encoding="utf-8") as file:
        content = file.read()

    # Extract employee details using regex
    details["name"] = re.search(r"\*\*Name:\*\* (.+)", content).group(1)
    details["role"] = re.search(r"\*\*Role:\*\* (.+)", content).group(1)
    details["joining_date"] = re.search(r"\*\*Joining Date:\*\* (\d{4}-\d{2}-\d{2})", content).group(1)
    
    # Calculate experience
    joining_year = int(details["joining_date"].split("-")[0])
    details["experience"] = 2024 - joining_year

    # Extract performance ratings
    rating_match = re.findall(r"\*\*(\d{4}):\*\* ([\d.]+)", content)
    if rating_match:
        latest_rating = sorted(rating_match, key=lambda x: int(x[0]))[-1]
        details["rating"] = float(latest_rating[1])

    return details

def get_survey_sentiment(employee_name):
    """Retrieve sentiment analysis for an employee from survey data."""
    survey_file_path = "hrdataset/surveys/Employee_Culture_Survey_Responses.csv"
    
    if not os.path.exists(survey_file_path):
        return "Error: Survey data not found."
    
    survey_df = pd.read_csv(survey_file_path)
    filtered_df = survey_df[survey_df['Employee'].str.strip().str.lower() == employee_name.strip().lower()]
    
    if filtered_df.empty:
        return "Error: No survey data found for this employee."
    
    sentiment_counts = filtered_df['Sentiment'].str.strip().str.lower().value_counts()
    positive_count = sentiment_counts.get('positive', 0)
    negative_count = sentiment_counts.get('negative', 0)

    if positive_count > negative_count:
        return "Positive"
    elif negative_count > positive_count:
        return "Negative"
    else:
        return "Neutral"