Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ class DataFrameHandler:
class: [DataFrameHandler]. \n
"""
# ?####? Attributes #####
__configsJsonValues: dict = {}
__configs_json_values: dict = {}
__commands = []
__uniqueColumns: ndarray = []
__mainDF: DataFrame = None
__studentsDF = []
__orderedListOfDFStudents: list = []
__unique_columns: ndarray = []
__main_df: DataFrame = None
__students_df = []
__ordered_list_of_df_students: list = []
# ?####? End Attributes #####

def __init__(self) -> None:
pass

# ?####? Properties #####
# ?####? PROPERTIES - Getters #####

@property
def OrderListOfDFStudents(self) -> list:
Expand All @@ -46,16 +46,7 @@ def OrderListOfDFStudents(self) -> list:
Returns:
[list]: [The list of ordered dataframes]. \n
"""
return self.__orderedListOfDFStudents

@OrderListOfDFStudents.setter
def OrderListOfDFStudents(self, df: DataFrame) -> None:
"""[summary] \n
Set the list of ordered dataframes. \n
Args:
df (DataFrame): [The ordered dataframes]. \n
"""
self.__orderedListOfDFStudents.append(df)
return self.__ordered_list_of_df_students

@property
def ConfigsJsonValues(self) -> dict:
Expand All @@ -64,16 +55,7 @@ def ConfigsJsonValues(self) -> dict:
Returns:
[dict]: [The configs of the json]. \n
"""
return self.__configsJsonValues

@ConfigsJsonValues.setter
def ConfigsJsonValues(self, value: dict) -> None:
"""[summary] \n
Set the configs of the json. \n
Args:
value (dict): [The configs of the json]. \n
"""
self.__configsJsonValues = value
return self.__configs_json_values

@property
def MainDataFrame(self) -> DataFrame:
Expand All @@ -82,16 +64,7 @@ def MainDataFrame(self) -> DataFrame:
Returns:
[DataFrame]: [The main dataframe]. \n
"""
return self.__mainDF

@MainDataFrame.setter
def MainDataFrame(self, df: DataFrame):
"""[summary] \n
Set the main dataframe. \n
Args:
df (DataFrame): [The dataframe to set]. \n
"""
self.__mainDF = df
return self.__main_df

@property
def UniqueColumns(self) -> ndarray:
Expand All @@ -100,16 +73,7 @@ def UniqueColumns(self) -> ndarray:
Returns:
[ndarray]: [The unique values of the column 'columnValue' [Division]]. \n
"""
return self.__uniqueColumns

@UniqueColumns.setter
def UniqueColumns(self, uniqueColumns: ndarray):
"""[summary] \n
Set the unique values of the column 'columnValue' [Division]. \n
Args:
uniqueColumns (ndarray): [The unique values of the column 'columnValue' [Division]]. \n
"""
self.__uniqueColumns = uniqueColumns
return self.__unique_columns

@property
def Commands(self) -> list:
Expand All @@ -120,6 +84,55 @@ def Commands(self) -> list:
"""
return self.__commands

@property
def StudentsDF(self) -> list:
"""[summary] \n
Get the dataframe with the students. \n
Returns:
[DataFrame]: [The dataframe with the students]. \n
"""
return self.__students_df

# ?####? End PROPERTIES - GETTERS #####

# ?####? PROPERTIES - Setters #####

@OrderListOfDFStudents.setter
def OrderListOfDFStudents(self, frame: DataFrame) -> None:
"""[summary] \n
Set the list of ordered dataframes. \n
Args:
frame (DataFrame): [The ordered dataframes]. \n
"""
self.__ordered_list_of_df_students.append(frame.reset_index(drop=True))

@ConfigsJsonValues.setter
def ConfigsJsonValues(self, value: dict) -> None:
"""[summary] \n
Set the configs of the json. \n
Args:
value (dict): [The configs of the json]. \n
"""
self.__configs_json_values = value

@MainDataFrame.setter
def MainDataFrame(self, frame: DataFrame):
"""[summary] \n
Set the main dataframe. \n
Args:
frame (DataFrame): [The dataframe to set]. \n
"""
self.__main_df = frame

@UniqueColumns.setter
def UniqueColumns(self, unique_columns: ndarray):
"""[summary] \n
Set the unique values of the column 'columnValue' [Division]. \n
Args:
unique_columns (ndarray): [The unique values of the column 'columnValue' [Division]]. \n
"""
self.__unique_columns = unique_columns

@Commands.setter
def Commands(self, command: str) -> None:
"""[summary] \n
Expand All @@ -129,73 +142,66 @@ def Commands(self, command: str) -> None:
"""
self.__commands.append(command)

@property
def StudentsDF(self) -> list:
"""[summary] \n
Get the dataframe with the students. \n
Returns:
[DataFrame]: [The dataframe with the students]. \n
"""
return self.__studentsDF

@StudentsDF.setter
def StudentsDF(self, df: DataFrame) -> None:
def StudentsDF(self, frame: DataFrame) -> None:
"""[summary] \n
Set the dataframe with the students. \n
Args:
df (DataFrame): [The dataframe with the students]. \n
frame (DataFrame): [The dataframe with the students]. \n
"""
self.__studentsDF.append(df)
self.__students_df.append(frame)

# ?####? End Properties #####
# ?####? End PROPERTIES - SETTERS #####

# ?####? Methods #####
# ?####? METHODS #####

def GetSpecificStudentsDF(self, df: DataFrame, column: str, value: str) -> DataFrame:
def OrderIndexedDFBy(self, frame: DataFrame, first_field: str, second_field: str, third_field: str) -> DataFrame:
"""[summary] \n
Order the dataframe by the specified fields. \n
Args:
frame (DataFrame): [The dataframe to order]. \n
first_field (str): [The first field to order]. \n
second_field (str): [The second field to order]. \n
third_field (str): [The third field to order]. \n
Returns:
[DataFrame]: [The dataframe ordered by the three fields in the specified order]. \n
"""
sorted_df = frame.sort_values(
by=[first_field, second_field, third_field], ascending=[True, True, True])
return sorted_df

def GetSpecificStudentsDF(self, frame: DataFrame, column: str, value: str) -> DataFrame:
"""[summary] \n
Get the students that have the specified index value in the specified column. \n
The DataFrame MUST be indexed by the 'value' column. \n
Args:
df (DataFrame): [The dataframe to filter]. \n
frame (DataFrame): [The dataframe to filter]. \n
column (str): [The column to filter]. \n
value (str): [The value to filter]. \n
Returns:
[DataFrame]: [The dataframe with the filtered students ordered by Course, Surname & Name]. \n
[DataFrame]: [The dataframe with the filtered students \n
ordered by Course, Surname & Name]. \n
"""
specificDF: DataFrame = df[df[column] == value]
orderedDF: DataFrame = self.OrderIndexedDFBy(
specificDF, self.ConfigsJsonValues['Course'],
specific_df: DataFrame = frame[frame[column] == value]
ordered_data_frame: DataFrame = self.OrderIndexedDFBy(
specific_df, self.ConfigsJsonValues['Course'],
self.ConfigsJsonValues['Surname'],
self.ConfigsJsonValues['Name']
)
return orderedDF
return ordered_data_frame

def CreateListDFStudentsBy(self, df: DataFrame, column: str, columnValue: str):
def CreateListDFStudentsBy(self, frame: DataFrame, column: str, column_value: str):
"""[summary] \n
Creates a list of the students that have the specified index value in the specified column. \n
Creates a list of the students that have the specified index \n
value in the specified column. \n
The DataFrame MUST be indexed by the 'value' column. \n
Args:
df (DataFrame): [The dataframe to filter]. \n
frame (DataFrame): [The dataframe to filter]. \n
column (str): [The column to filter]. \n
value (list): [The values to filter]. \n
column_value (list): [The values to filter]. \n
"""
self.OrderListOfDFStudents = self.GetSpecificStudentsDF(
df, column, columnValue)

def OrderIndexedDFBy(self, df: DataFrame, firstField: str, secondField: str, thirdField: str) -> DataFrame:
"""[summary] \n
Order the dataframe by the specified fields. \n
Args:
df (DataFrame): [The dataframe to order]. \n
firstField (str): [The first field to order]. \n
secondField (str): [The second field to order]. \n
thirdField (str): [The third field to order]. \n
Returns:
[DataFrame]: [The dataframe ordered by the three fields in the specified order]. \n
"""
sortedDF = df.sort_values(
by=[firstField, secondField, thirdField], ascending=[True, True, True])
return sortedDF
frame, column, column_value)

def ConfigUniqueValuesInColumn(self, column: str):
"""[summary] \n
Expand All @@ -208,38 +214,52 @@ def ConfigUniqueValuesInColumn(self, column: str):
self.UniqueColumns = self.MainDataFrame[column].unique()
self.UniqueColumns.sort()

def CreateJsonOfEveryDF(self):
def createJSONofDF(self, frame: DataFrame, name: str):
"""[summary] \n
Create a json file for every dataframe. \n
Create a json file for the specified dataframe. \n
Args:
frame (DataFrame): [The dataframe to create the json file]. \n
name (str): [The name of the json file]. \n
"""
frame.to_json(f'{name}.json', orient='table',
indent=4, force_ascii=True)

for i in range(len(self.OrderListOfDFStudents)):
frame: DataFrame = self.OrderListOfDFStudents[i]
name = frame.at[frame.index.values[0],
def createJsonOfEveryDF(self):
"""[summary] \n
Create a json file for every dataframe. \n
"""
for students_df in self.OrderListOfDFStudents:
name = students_df.at[students_df.index.values[0],
self.ConfigsJsonValues['Course']]
filename: str = f'{name}.json'
frame.to_json(f'{filename}', orient='table',
indent=4, force_ascii=True)
self.createJSONofDF(students_df, filename)
# for i in range(len(self.OrderListOfDFStudents)):
# frame: DataFrame = self.OrderListOfDFStudents[i]
# name = frame.at[frame.index.values[0],
# self.ConfigsJsonValues['Course']]
# filename: str = f'{name}.json'
# self.createJSONofDF(frame, filename)

# ?####? End Methods #####
# ?####? End METHODS #####

# *####* Main Method #####
# *####* MAIN METHOD #####

def ConfigurateDataFrame(self, columnValue: str) -> None:
def ConfigurateDataFrame(self, column_value: str) -> None:
"""[summary] \n
Configurate the dataframe with the specified column value. \n
Args:
columnValue (str): [The column value to configurate]. \n
column_value (str): [The column value to configurate]. \n
"""

# *# Gets the unique values of the column 'columnValue' [Division]
self.ConfigUniqueValuesInColumn(columnValue)
# *# For each unique value of the column 'columnValue' [Division]
# *# Gets the unique values of the column 'column_value' [Division]
self.ConfigUniqueValuesInColumn(column_value)
# *# For each unique value of the column 'column_value' [Division]
# *# Creates a list of dataframes with the students that have the
# *# specified value in the column 'columnValue' [Division]
# *# specified value in the column 'column_value' [Division]
for unique in self.UniqueColumns:
self.CreateListDFStudentsBy(
self.MainDataFrame, columnValue, unique)
self.CreateJsonOfEveryDF()
self.MainDataFrame, column_value, unique
)
self.createJsonOfEveryDF()

# *####* End Main Method #####
# *####* END MAIN METHOD #####
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import os
import requests

from Modules.DataFrameHandler_Mod.DFHandler import DataFrameHandler as DFH
from Modules.PrintMessage_Mod.CloneMessenger import CloneMessenger as CM
from Modules.DataFrameHandler_Mod.df_handler import DataFrameHandler as DFH
from Modules.PrintMessage_Mod.clone_messenger import CloneMessenger as CM
from pandas import DataFrame


Expand Down Expand Up @@ -336,7 +336,7 @@ def MakeCloneCommands(self, dfHandler: DFH) -> None:
git (str): [The url of the git's repository]. \n
"""
for frame in dfHandler.OrderListOfDFStudents:
self.MakeCloneCommandsForDF(frame.reset_index(drop=True), dfHandler)
self.MakeCloneCommandsForDF(frame, dfHandler)

def MakeCloneCommandsForDF(self, df: DataFrame, dfHandler: DFH) -> None:
"""[summary] \n
Expand Down
Loading