-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
107 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from file_handler.file_handler import FileHandler | ||
from pandas import read_excel | ||
|
||
|
||
class ExcelFileHandler(FileHandler): | ||
def __init__(self, folder_path, file_name): | ||
super().__init__(folder_path, file_name) | ||
|
||
def read_file_data(self): | ||
self.file_data = read_excel(self.file_path) | ||
|
||
def format_file_data(self): | ||
formatted_rows = self.file_data.to_dict('records') | ||
return formatted_rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class FileHandler: | ||
def __init__(self, folder_path, file_name): | ||
self.folder_path = folder_path | ||
self.file_name = file_name | ||
self.file_path = folder_path + file_name | ||
self.file_data = [] | ||
self.formatted_data = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from file_handler.text_file_handler import TextFileHandler | ||
from file_handler.excel_file_handler import ExcelFileHandler | ||
from file_handler.tsv_file_handler import TSVFileHandler | ||
|
||
|
||
class FileProcessor: | ||
def __init__(self, folder_path, file_name): | ||
self.folder_path = folder_path | ||
self.file_name = file_name | ||
|
||
def format_file_data(self): | ||
if self.file_name.endswith('.txt'): | ||
text_file = TextFileHandler(self.folder_path, self.file_name) | ||
text_file.read_file_data() | ||
return text_file.format_file_data() | ||
elif self.file_name.endswith('.xlsx'): | ||
excel_file = ExcelFileHandler(self.folder_path, self.file_name) | ||
excel_file.read_file_data() | ||
return excel_file.format_file_data() | ||
elif self.file_name.endswith('.tsv'): | ||
tsv_file = TSVFileHandler(self.folder_path, self.file_name) | ||
tsv_file.read_file_data() | ||
return tsv_file.format_file_data() | ||
else: | ||
raise Exception('Invalid file extension') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from file_handler.file_handler import FileHandler | ||
|
||
|
||
class TextFileHandler(FileHandler): | ||
def __init__(self, folder_path, file_name): | ||
super().__init__(folder_path, file_name) | ||
|
||
def read_file_data(self): | ||
with open(self.file_path, 'r') as file_ref: | ||
self.file_data = file_ref.read() | ||
|
||
def format_file_data(self): | ||
rows = self.file_data.split('\n') | ||
rows = list(filter(None, rows)) | ||
header = rows.pop(0).split(',') | ||
header = list(map(str.strip, header)) | ||
formatted_rows = [] | ||
for row in rows: | ||
row_dict = {} | ||
row_data = row.split(',') | ||
for idx, value in enumerate(row_data): | ||
row_dict[header[idx]] = value | ||
formatted_rows.append(row_dict) | ||
return formatted_rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from file_handler.file_handler import FileHandler | ||
import csv | ||
|
||
|
||
class TSVFileHandler(FileHandler): | ||
def __init__(self, folder_path, file_name): | ||
super().__init__(folder_path, file_name) | ||
|
||
def read_file_data(self): | ||
with open(self.file_path) as file_ref: | ||
rows = csv.reader(file_ref, delimiter="\t", quotechar='"') | ||
self.file_data = list(rows) | ||
|
||
def format_file_data(self): | ||
data = list(filter(None, self.file_data)) | ||
header = data.pop(0) | ||
formatted_rows = [] | ||
for row in data: | ||
row_dict = {} | ||
for idx, value in enumerate(row): | ||
row_dict[header[idx]] = value | ||
formatted_rows.append(row_dict) | ||
return formatted_rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
bar_chart_generator.py → values_calculator/bar_chart_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
highest_value_calculator.py → ...es_calculator/highest_value_calculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters