Skip to content
Open
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Laporan Kunjungan Kapal.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions blanks.py
Original file line number Diff line number Diff line change
@@ -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

Binary file added files/File Input.xlsx
Binary file not shown.
65 changes: 65 additions & 0 deletions general.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions json/clearance.json
Original file line number Diff line number Diff line change
@@ -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": []
}
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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()