from datetime import datetime
from django.shortcuts import render, redirect, reverse
from django.template import loader
from django.http import HttpResponse
from User.forms import MyForm,MyForm2,MyForm3
from django.contrib.auth import authenticate, login
from User import models as Umodels
from django.http import HttpResponseRedirect
from django.contrib import messages
import json

# -------------------   EF
import pandas as pd
import numpy as np
import math
import sklearn
import matplotlib.pyplot as plt
from datetime import datetime
from sklearn import metrics
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
# -------------------   EF


# Start  CompanyHome
def Homepage(request):
    return render(request, 'Admin/Homepage.html');
# End  CompanyHome




def Employee_Data(request):
    data1 = pd.read_csv('Data/WorkHistory.csv')
    data2 = pd.read_csv('Data/EmployeeStatus.csv')
    DateSet = pd.merge(data1, data2,  on='StaffID',   how='inner')
    grouped_df = DateSet.groupby("StaffID" )  # group job staff
    finalpt = grouped_df.head(10) # date from two datasets
    json_records = finalpt.reset_index().to_json(orient='records')
    arr = []
    arr = json.loads(json_records)
    context = {'d': arr}
    return render(request, 'Admin/Employee_Data.html',context);


def AdminLogin(request):
    if request.method == 'POST':
        myForm = MyForm2(request.POST)
        if myForm.is_valid():
            UserName = myForm.cleaned_data['UserName']
            Password = myForm.cleaned_data['Password']
            gotdata = Umodels.loginDataAdmin.objects.all().filter(UserName=UserName , Password=Password).count()
            if gotdata > 0:
                return render(request, 'Admin/AdminHome.html');
            else:
                messages.success(request, 'Login Info Not Found  , Please Check Your UserName and Password')
                return HttpResponseRedirect(request.path_info)
    else:
        form = MyForm2()
    return render(request, 'Admin/AdminLogin.html', {'form':form});


def AdminHome(request):
    return render(request,'Admin/AdminHome.html')




