Upload 14 files
Browse files- calculate.ipynb +2 -2
- calculate.py +66 -66
- data/dynamic.py +2 -2
- data/static.py +1 -1
calculate.ipynb
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2c762bc3d17afa304fcc1241f786bef217586f8042cdfb5aa69284d9461ff541
|
3 |
+
size 33137753
|
calculate.py
CHANGED
@@ -1,66 +1,66 @@
|
|
1 |
-
from flask import Flask, request, redirect, session, url_for
|
2 |
-
from data.static import generate as sg
|
3 |
-
from data.dynamic import generate as dg
|
4 |
-
|
5 |
-
import os
|
6 |
-
|
7 |
-
app = Flask(__name__)
|
8 |
-
app.secret_key = "secret_key_aman_diganti"
|
9 |
-
|
10 |
-
# Data login hardcoded
|
11 |
-
VALID_USER = os.getenv("VALID_USER")
|
12 |
-
VALID_PASS = os.getenv("VALID_PASS")
|
13 |
-
|
14 |
-
# Middleware: Cek login sebelum semua request (kecuali /login dan /static file)
|
15 |
-
@app.before_request
|
16 |
-
def require_login():
|
17 |
-
allowed_routes = ["login", "static"]
|
18 |
-
if request.endpoint not in allowed_routes and "user" not in session: return redirect(url_for("login"))
|
19 |
-
|
20 |
-
# Form login
|
21 |
-
@app.route("/login", methods=["GET", "POST"])
|
22 |
-
def login():
|
23 |
-
if request.method == "POST":
|
24 |
-
user = request.form.get("username")
|
25 |
-
password = request.form.get("password")
|
26 |
-
print(user, VALID_USER, password, VALID_PASS)
|
27 |
-
if user == VALID_USER and password == VALID_PASS:
|
28 |
-
session["user"] = user
|
29 |
-
return redirect(url_for("home"))
|
30 |
-
return "<h3>Login gagal!</h3><a href='/login'>Coba lagi</a>"
|
31 |
-
|
32 |
-
return """
|
33 |
-
<h2>Login</h2>
|
34 |
-
<form method='post'>
|
35 |
-
Username: <input name='username'><br>
|
36 |
-
Password: <input name='password' type='password'><br>
|
37 |
-
<input type='submit' value='Login'>
|
38 |
-
</form>
|
39 |
-
"""
|
40 |
-
|
41 |
-
# Logout
|
42 |
-
@app.route("/logout")
|
43 |
-
def logout():
|
44 |
-
session.pop("user", None)
|
45 |
-
return redirect(url_for("login"))
|
46 |
-
|
47 |
-
# Halaman utama
|
48 |
-
@app.route("/")
|
49 |
-
def home():
|
50 |
-
return """
|
51 |
-
<h2>Halaman Utama</h2>
|
52 |
-
<a href='/static/7'>Static 7 Hari</a><br>
|
53 |
-
<a href='/dynamic'>Dynamic</a><br>
|
54 |
-
<a href='/logout'>Logout</a>
|
55 |
-
"""
|
56 |
-
|
57 |
-
@app.route("/static")
|
58 |
-
def static_page(): return f"""<a href="/">β Kembali</a>{sg(90, request.args.get("img"))}"""
|
59 |
-
|
60 |
-
@app.route("/static/<int:days>")
|
61 |
-
def static_pages(days): return f"""<a href="/">β Kembali</a>{sg(days, request.args.get("img"))}"""
|
62 |
-
|
63 |
-
@app.route("/dynamic")
|
64 |
-
def dynamic_page(): return f"""<a href="/">β Kembali</a>{dg(request.args.get("img"))}"""
|
65 |
-
|
66 |
-
if __name__ == "__main__": app.run(host=os.getenv("HOST") or "0.0.0.0", port=os.getenv("PORT") or 8501, debug=True)
|
|
|
1 |
+
from flask import Flask, request, redirect, session, url_for
|
2 |
+
from data.static import generate as sg
|
3 |
+
from data.dynamic import generate as dg
|
4 |
+
|
5 |
+
import os
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
app.secret_key = "secret_key_aman_diganti"
|
9 |
+
|
10 |
+
# Data login hardcoded
|
11 |
+
VALID_USER = os.getenv("VALID_USER")
|
12 |
+
VALID_PASS = os.getenv("VALID_PASS")
|
13 |
+
|
14 |
+
# Middleware: Cek login sebelum semua request (kecuali /login dan /static file)
|
15 |
+
@app.before_request
|
16 |
+
def require_login():
|
17 |
+
allowed_routes = ["login", "static"]
|
18 |
+
if request.endpoint not in allowed_routes and "user" not in session: return redirect(url_for("login"))
|
19 |
+
|
20 |
+
# Form login
|
21 |
+
@app.route("/login", methods=["GET", "POST"])
|
22 |
+
def login():
|
23 |
+
if request.method == "POST":
|
24 |
+
user = request.form.get("username")
|
25 |
+
password = request.form.get("password")
|
26 |
+
print(user, VALID_USER, password, VALID_PASS)
|
27 |
+
if user == VALID_USER and password == VALID_PASS:
|
28 |
+
session["user"] = user
|
29 |
+
return redirect(url_for("home"))
|
30 |
+
return "<h3>Login gagal!</h3><a href='/login'>Coba lagi</a>"
|
31 |
+
|
32 |
+
return """
|
33 |
+
<h2>Login</h2>
|
34 |
+
<form method='post'>
|
35 |
+
Username: <input name='username'><br>
|
36 |
+
Password: <input name='password' type='password'><br>
|
37 |
+
<input type='submit' value='Login'>
|
38 |
+
</form>
|
39 |
+
"""
|
40 |
+
|
41 |
+
# Logout
|
42 |
+
@app.route("/logout")
|
43 |
+
def logout():
|
44 |
+
session.pop("user", None)
|
45 |
+
return redirect(url_for("login"))
|
46 |
+
|
47 |
+
# Halaman utama
|
48 |
+
@app.route("/")
|
49 |
+
def home():
|
50 |
+
return """
|
51 |
+
<h2>Halaman Utama</h2>
|
52 |
+
<a href='/static/7'>Static 7 Hari</a><br>
|
53 |
+
<a href='/dynamic'>Dynamic</a><br>
|
54 |
+
<a href='/logout'>Logout</a>
|
55 |
+
"""
|
56 |
+
|
57 |
+
@app.route("/static")
|
58 |
+
def static_page(): return f"""<a href="/">β Kembali</a>{sg(90, request.args.get("img"))}"""
|
59 |
+
|
60 |
+
@app.route("/static/<int:days>")
|
61 |
+
def static_pages(days): return f"""<a href="/">β Kembali</a>{sg(days, request.args.get("img"))}"""
|
62 |
+
|
63 |
+
@app.route("/dynamic")
|
64 |
+
def dynamic_page(): return f"""<a href="/">β Kembali</a>{dg(request.args.get("img"))}"""
|
65 |
+
|
66 |
+
if __name__ == "__main__": app.run(host=os.getenv("HOST") or "0.0.0.0", port=os.getenv("PORT") or 8501, debug=True)
|
data/dynamic.py
CHANGED
@@ -53,7 +53,7 @@ def generate(is_img=False):
|
|
53 |
tickvals_list["btn" if isBtn else "ss"].append(tickvals)
|
54 |
|
55 |
y_ax_rng_list["btn" if isBtn else "ss"].append(
|
56 |
-
[min(dfc["Harga Jual"]) - 100_000, max(dfc["Harga Beli"]) +
|
57 |
)
|
58 |
|
59 |
hasil = []
|
@@ -369,7 +369,7 @@ def generate(is_img=False):
|
|
369 |
title="Harga per Gram",
|
370 |
tickprefix="Rp ",
|
371 |
tickformat=",",
|
372 |
-
range=[min(dfc["Harga Jual"]) - 100_000, max(dfc["Harga Beli"]) +
|
373 |
),
|
374 |
)
|
375 |
|
|
|
53 |
tickvals_list["btn" if isBtn else "ss"].append(tickvals)
|
54 |
|
55 |
y_ax_rng_list["btn" if isBtn else "ss"].append(
|
56 |
+
[min(dfc["Harga Jual"]) - 100_000, max(dfc["Harga Beli"]) + 200_000]
|
57 |
)
|
58 |
|
59 |
hasil = []
|
|
|
369 |
title="Harga per Gram",
|
370 |
tickprefix="Rp ",
|
371 |
tickformat=",",
|
372 |
+
range=[min(dfc["Harga Jual"]) - 100_000, max(dfc["Harga Beli"]) + 200_000],
|
373 |
),
|
374 |
)
|
375 |
|
data/static.py
CHANGED
@@ -199,7 +199,7 @@ def generate(lama_hari, is_img=False):
|
|
199 |
title="Harga per Gram",
|
200 |
tickprefix="Rp ",
|
201 |
tickformat=",",
|
202 |
-
range=[min(df["Harga Jual"]) - 100_000, max(df["Harga Beli"]) +
|
203 |
)
|
204 |
)
|
205 |
|
|
|
199 |
title="Harga per Gram",
|
200 |
tickprefix="Rp ",
|
201 |
tickformat=",",
|
202 |
+
range=[min(df["Harga Jual"]) - 100_000, max(df["Harga Beli"]) + 200_000],
|
203 |
)
|
204 |
)
|
205 |
|