diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Laporan Kunjungan Kapal.iml b/.idea/Laporan Kunjungan Kapal.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Laporan Kunjungan Kapal.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a6218fe --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3a8abf4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 545bbe7..a28de38 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,22 @@ -# Hi... +# Monthly Report Maker ## My Motive I saw staff at my office doing a monthly recapitulation using Microsoft Excel manually. It takes around 3 to 5 days for one person to finish. Then I started to write this program, hoping to ease the pressure and speed up the time to complete the work. ## Disclaimer -This program's design would process raw data into a hard-coded output. In my case, the data contains every ship's information that docked at the harbor. If anyone would use this code, they will need to re-write the properties of both the input and output. +This program's design would process raw data into a hard-coded output. If anyone would use this code, they will need to re-write the properties of both the input and output. -## How Does My Code Work? -(To be documented) +## Program's workflow + +### A. File preparations +1. Manually input data to an `xlsx` file +2. Place the `xlsx` file inside `files` folder + +### B. Running Sequence in main.py +1. Reads the `xlsx` file +2. Sorts data by date and time +3. Split data into categories +4. Re-create data into some column formats +5. Write sheets using newly generated data +6. Write load's resumes for some sheets +7. Program stopped diff --git a/blanks.py b/blanks.py new file mode 100644 index 0000000..b82efce --- /dev/null +++ b/blanks.py @@ -0,0 +1,30 @@ +import json +import general +import operator as op + +def clearance(dataframe=None): + source_dict = dataframe.to_dict(orient='list') + openjson = open('json/clearance.json') + destination_dict, len_source = json.load(openjson), 0 + + # Collect length of value's list + for key in source_dict: + if len(source_dict[key]) > 0: + len_source = len(source_dict[key]) + break + + # Add necessary new column(s) + for key in destination_dict: + if key not in source_dict: + destination_dict[key] = ['--' * len_source] + if key in source_dict: + destination_dict[key] = source_dict[key] + + # Add a new column (Number) to destination + destination_dict['NUMBER'] = list(range(1, len_source+1)) + + # Mark keys in dictionary that contains ";" + marked_keys = general.semicolon_list(destination_dict) + + # Using marked_keys to add new rows for ';' occurrence + diff --git a/files/File Input.xlsx b/files/File Input.xlsx new file mode 100644 index 0000000..d5096d9 Binary files /dev/null and b/files/File Input.xlsx differ diff --git a/general.py b/general.py new file mode 100644 index 0000000..078783c --- /dev/null +++ b/general.py @@ -0,0 +1,65 @@ +from typing import List, Any + +import pandas as pd +import operator as op +from pandas import DataFrame + + +def reader(filename='None'): + dataframe_name = pd.read_excel(filename) + del dataframe_name['NO'] + dataframe_name = sorter(dataframe_name, ['TANGGAL BERTOLAK', 'JAM BERTOLAK']) + + return dataframe_name + + +def sorter(dataframe=None, sorted_by=None): + dataframe.sort_values(by=sorted_by, inplace=True) + + return dataframe + + +def contain(data=None, type_name=None): + return all(isinstance(item, type_name) for item in data) or any(isinstance(item, type_name) for item in data) + + +def classifier(dataframe=None, column_name=None, value=None, model: str = None): + model.lower() + if model == 'ssib': + filtered: DataFrame = dataframe.loc[dataframe[column_name] <= value] + filtered.reset_index(drop=True, inplace=True) + + return filtered + + elif model == 'bsib': + filtered: DataFrame = dataframe.loc[dataframe[column_name] > value] + filtered.reset_index(drop=True, inplace=True) + + return filtered + + elif model == 'other': + filtered: DataFrame = dataframe.loc[dataframe[column_name] == value] + filtered.reset_index(drop=True, inplace=True) + + return filtered + + else: + print('Specify correct data label!') + + +def semicolon_list(dict_data): + result: list[Any] = [] + for key in dict_data: + if contain(dict_data[key], str): + for item in dict_data[key]: + try: + op.contains(item, '; ') + except TypeError: + item = str(item) + finally: + if op.contains(item, '; '): + result.append(key) + break + break + + return result diff --git a/json/clearance.json b/json/clearance.json new file mode 100644 index 0000000..ad509fe --- /dev/null +++ b/json/clearance.json @@ -0,0 +1,21 @@ +{ + "NO SPB TOLAK": [], + "PPK 27": [], + "PPK 29": [], + "NAMA KAPAL": [], + "NAHKODA": [], + "BENDERA": [], + "GT": [], + "SIPI": [], + "SIKPI": [], + "SLO": [], + "TIBA DARI": [], + "TANGGAL TIBA": [], + "CREW": [], + "TUJUAN": [], + "TANGGAL BERTOLAK": [], + "MUATAN MUAT": [], + "JUMLAH MUATAN MUAT": [], + "SATUAN MUATAN MUAT": [], + "PEMILIK / AGEN": [] +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..46db925 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +import general +import blanks +from pandas import DataFrame + + +def main(): + data_from_excel: DataFrame = general.reader(filename='files/File Input.xlsx') + # with pd.ExcelWriter('files/File Output.xlsx', engine='xlsxwriter') as writer: + blanks.clearance(data_from_excel) + + +if __name__ == '__main__': + main()