Skip to content

Commit

Permalink
Merge branch 'develop' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
slowy07 authored Sep 29, 2024
2 parents 24e8b14 + 4bf606a commit 82c032b
Show file tree
Hide file tree
Showing 25 changed files with 774 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ CONTRIBUTING.md
LICENSE
README.md
.github/*
.github
.github
20 changes: 20 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

pull_request_rules:
# membuat requirement dari automerge dengan sistem
# ketika workflow build passed maka akan dicentang
Expand Down
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# konfigurasi pre commit
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile.openseries_test
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Import image with tag version 3.12
FROM python:3.12.1-alpine

Expand Down
6 changes: 6 additions & 0 deletions OpenSeries/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from OpenSeries.dasar import bulat, akar, tan_hiperbolik, volume_kubus

if __name__ == "__main__":
list_dasar: list = [bulat, akar, tan_hiperbolik, volume_kubus]
for tipe in range(len(list_dasar)):
print(type(list_dasar[tipe]))
47 changes: 47 additions & 0 deletions OpenSeries/bilangan_istimewa.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import OpenSeries.util.error as error
from typing import Union

Expand Down Expand Up @@ -115,3 +135,30 @@ def angka_segitiga(angka: int) -> Union[int, error.ErrorTipeData, error.Error]:
if angka < 0:
return error.Error("angka tidak boleh negatif")
return angka * (angka + 1) // 2


def angka_katalan(angka: int) -> Union[int, error.Error, error.ErrorTipeData]:
"""
Angka katalan atau Catalan Number adalah urutan angka natural
yang terjadi dalam berbagai menghitung masalah, sering melibatkan
secara rekursif objek yang ditentukan.
Parameter:
angka (int): angka katalan yang ingin dikalkulasikan
Return:
int: hasil dari kalkulasi angka katalan
error.ErrorTipeData: jika tipe data yang diberikan berbeda
error.Error: jika angka negatif
"""
if not isinstance(angka, int):
return error.ErrorTipeData(["int"])
else:
if angka < 1:
return error.Error("angka tidak boleh negatif")
else:
angka_tmp = 1
for i in range(1, angka):
angka_tmp *= 4 * i - 2
angka_tmp //= i + 1
return angka_tmp
89 changes: 89 additions & 0 deletions OpenSeries/dasar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import OpenSeries.util.error as error
import numpy as np
from typing import Union
import math


def bulat(
angka: Union[int, float], cek: bool = False
) -> Union[int, bool, error.ErrorTipeData]:
"""
membuat fungsi untuk membulatkan angka
Parameter:
angka (int atau float): angka yang akan dibulatkan
Return:
int: hasil angka yang sudah dibulatkan
bool: jika di set true maka akan mengecek sebuah angka
error.ErrorTipeData: error jika tipe data tidak sesuai
"""
if not isinstance(angka, (int, float)):
return error.ErrorTipeData(["int", "float"])
if cek is True:
return int(angka) if angka - int(angka) >= 0 else int(angka) - 1
else:
return math.ceil(angka)


def akar(
value: Union[int, float], iterasi: int = 4
) -> Union[float, error.ErrorTipeData]:
"""
apromasi nilai akar pada angka
Args:
value (Union[int,float]): input nilai
iterasi (Optional[int]): mengsetup iterasi apporamasi. Defaults to 4.
Returns:
float: output dari angka yang telah di prediksi
error.ErrorTipeData: error jika data yang dimasukkan salah
"""

# ngecheck tipe data pada value
if not isinstance(value, (int, float)):
raise error.ErrorTipeData(["int", "float"])
# ngecheck tipe data pada iterasi
if not isinstance(iterasi, int):
raise error.ErrorTipeData(["int"])
result = value
for _ in range(iterasi + 1):
result = (result + (value / result)) / 2
return round(result, 2)


def tan_hiperbolik(x: np.ndarray) -> Union[np.ndarray, error.ErrorTipeData]:
"""
fungsi tangen hiperbolik
Parameter:
x (np.ndarray): nilai input yang ingin dikalkulasikan
Return:
np.ndarray: hasil dari kalkulasi tangen hiperbolik
error.ErrorTipeData: error jika tipe data yang diberikan salah
"""
if not isinstance(x, np.ndarray):
return error.ErrorTipeData(["numpy.ndarray"])
return (2 / (1 + np.exp(-2 * x))) - 1


def volume_kubus(
panjang_sisi: Union[float, int],
) -> Union[float, int, error.ErrorTipeData, error.Error]:
"""
menghitung volume kubus
Parameter:
panjang_sisi (int atau float): sisi yang akan dihitung
return:
float atau int: hasil dari perhitungan
ErrorTipeData: error jika diberikan tipe data yang salah
Error: error jika nilai yang diberikan negatif
"""
if not isinstance(panjang_sisi, (float, int)):
return error.ErrorTipeData(["float", "int"])
if panjang_sisi < 0:
return error.Error("panjang_sisi hanya menerima nilai positif")
return pow(panjang_sisi, 3)
20 changes: 20 additions & 0 deletions OpenSeries/fisika.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from OpenSeries.util import error as error
from typing import Union

Expand Down
65 changes: 64 additions & 1 deletion OpenSeries/matematika.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from OpenSeries.util import constant as constant
from OpenSeries.util import error as error
from typing import Union, Sequence, Callable
Expand Down Expand Up @@ -551,7 +571,9 @@ def integral(
return round(result * delta)


def turunan(f: Callable[[float], float], x: Union[int, float]) -> float:
def turunan(
f: Callable[[float], float], x: Union[int, float]
) -> Union[error.ErrorTipeData, float]:
"""
Args:
f (Callable[[float]float]: input fungsi
Expand All @@ -566,3 +588,44 @@ def turunan(f: Callable[[float], float], x: Union[int, float]) -> float:
return error.ErrorTipeData(["float", "int"])
else:
return (f(x + h) - f(x)) / h


def volume_bola(r: Union[int, float]) -> Union[float, error.ErrorTipeData]:
"""
Menghitung volume dari sebuah bola
Args:
r (Union[int, float]): input radius
Return:
float : volume dari bola
"""
if not isinstance(r, (float, int)):
return error.ErrorTipeData(["float", "int"])
else:
return (4 / 3) * constant.PI * r**3


def mean_absolut_deviasi(
nilai: list[int],
) -> Union[error.Error, error.ErrorTipeData, float]:
"""
Ukuran statistik untuk menggambarkan variabilitias kumpulan data.
Args:
nilai (list[int]): angka yang dihitung
Return:
float: hasil dari variabilitias kumpulan data
error.Error: jika list kosong
error.ErrorTipeData: jika tipe data float maka error
"""
if isinstance(nilai, list):
# mengecek apakah nilai dalam list kodong
if not nilai:
return error.Error("List tidak boleh kosong")
else:
for cek_nilai in nilai:
if not isinstance(cek_nilai, int):
return error.ErrorTipeData(["int"])
rata_rata = sum(nilai) / len(nilai)
return sum(abs(x - rata_rata) for x in nilai) / len(nilai)
else:
return error.ErrorTipeData(["list[int]"])
50 changes: 50 additions & 0 deletions OpenSeries/statistika.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Bellshade
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import numpy as np
from typing import Union
from OpenSeries.util import error as error
Expand Down Expand Up @@ -61,3 +81,33 @@ def standar_deviasi(
variansi = np.mean(squared_diff)
std_deviasi = np.sqrt(variansi)
return std_deviasi


def variance(
data: list[Union[int, float]],
) -> Union[float, error.ErrorTipeData, error.Error]:
"""
variance merupakan konsep matematika untuk mengetahui keragamaman
nilai pada data terhadap penyebaran nilai rata-rata.
Parameter:
data (list (int, float)): input data yang masuk
Return:
(float): hasil dari kalkulasi varian
error.ErrorTipeData: error jika tipe data salah
error.Error: jika vektor yang diberikan kosong
"""
# initial result
result: float = 0.0
if isinstance(data, list):
# mengecek apakah nilai dalam list kodong
if not data:
return error.Error("List tidak boleh kosong")
# membuat looping untuk memecah nilai yang terdapat pada list
for cek_nilai in data:
# mengecek nilai dalam list apakah semua tipe data berbentuk int
# atau float, jika tidak error
if not isinstance(cek_nilai, (int, float)):
return error.ErrorTipeData(["float", "int"])
result += (cek_nilai - np.mean(data)) * (cek_nilai - np.mean(data))
return result / len(data)
Loading

0 comments on commit 82c032b

Please sign in to comment.