from ctgan import CTGAN
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import metrics 
from sklearn.metrics import *
from sklearn.neural_network import MLPClassifier
from sklearn import svm
from sklearn.neighbors import KNeighborsClassifier
from time import time
import sys
################
num = 49
dbName = str(num)+'.csv'

###############################
###Read data and preprocessing
################################
ds = pd.read_csv(dbName)         
#print(ds.head())

ds = ds.dropna(how='any')    #to drop if any value in the row has a nan
print(np.shape(ds))
########################################
discrete_columns = ['PP_1','PP_2','PP_3','PP_4','PP_5','PP_6','PP_7',	
                    'PP_8','PP_9','PP_10','PP_11','PP_12','PP_13','PR_1',	
                    'PR_2','PR_3','PR_4','PR_5','PR_6','PR_7','PR_8','PR_9',	
                    'PR_10','PR_11','PR_12','PR_13','PR_14','RR_1','RR_2','RR_3',	
                    'RR_4','RR_5','RR_6','RR_7','RR_8','RR_9','RR_10','RR_11',	
                    'RR_12','RR_13','RP_1','RP_2','RP_3','RP_4','RP_5',	
                    'RP_6','RP_7','RP_8','RP_9','RP_10','RP_11','RP_12','RP_13']

print("Num of F = "+str(len(discrete_columns)))   

ctgan = CTGAN(epochs=100)
ctgan.fit(ds, discrete_columns)

# Create synthetic data
n = 18 * 20
synthetic_data = ctgan.sample(n)

nameF = 'GDuser'+str(num)+'.csv'
synthetic_data.to_csv(nameF)

###############################################################
from sdv.metadata import SingleTableMetadata

metadata = SingleTableMetadata()
metadata.detect_from_dataframe(data=ds)

from sdv.evaluation.single_table import evaluate_quality

e =  evaluate_quality(synthetic_data, ds,metadata)
print(e)




