adjust api naming and endpoint

This commit is contained in:
Alberto-Audrix committed 2026-09-01 11:24:02 +07:00
1 parent 5b5d28ce52
commit bb2c358157
3 files changed
+22 -22

No files matched your search

+1 -1
View File
@@ -98,7 +98,7 @@ sudo systemctl daemon-reload
```
Dashboard: `http://0.0.0.0:8090/`
Combined API: `GET /api/k1/combined?history_days=30`
Combined API: `GET /api/combined?history_days=30`
## Environment
+15 -15
View File
@@ -95,7 +95,7 @@ def get_db_data(db_path, table_name):
for row in rows:
data.append({
'id': row[0],
'camera_name': row[1],
'name': row[1],
'date': row[2],
'counter_value': row[3]
})
@@ -340,11 +340,11 @@ def filter_data_by_cycle(data, cycle_start, cycle_end):
return filtered_data
def is_masuk_out_item(item):
camera_name = str(item['camera_name']).lower().strip()
source_name = str(item.get('name', '')).lower().strip()
return (
camera_name.endswith('_out')
or camera_name.endswith('-out')
or camera_name.endswith(' out')
source_name.endswith('_out')
or source_name.endswith('-out')
or source_name.endswith(' out')
)
def get_counter_settings_from_dashboard(dashboard_settings):
@@ -427,13 +427,13 @@ def filter_data_by_date(data, target_date):
def get_json_counter_items(json_data):
items = []
for camera_name, camera_data in json_data.items():
for source_name, source_data in json_data.items():
karung_count = 0
if isinstance(camera_data, dict):
karung_count = camera_data.get('karung', 0)
if isinstance(source_data, dict):
karung_count = source_data.get('karung', 0)
items.append({
'camera_name': camera_name,
'name': source_name,
'karung': karung_count,
})
@@ -443,7 +443,7 @@ def format_history_items(data):
return [
{
'id': item['id'],
'camera_name': item['camera_name'],
'name': item['name'],
'date': format_history_date(item['date']),
'counter_value': item['counter_value'],
}
@@ -650,8 +650,8 @@ def get_active_cycle_sections():
},
})
@app.route('/api/k1/combined', methods=['GET'])
def get_k1_combined():
@app.route('/api/combined', methods=['GET'])
def get_combined():
history_days_raw = request.args.get('history_days', DEFAULT_COMBINED_HISTORY_DAYS)
try:
history_days = int(history_days_raw)
@@ -683,7 +683,7 @@ def get_k1_combined():
'totals': {
'tuang': tuang_payload['totals']['today'],
'masuk': sum(
item['karung'] if not is_masuk_out_item({'camera_name': item['camera_name']}) else -item['karung']
item['karung'] if not is_masuk_out_item(item) else -item['karung']
for item in masuk_today
),
},
@@ -717,11 +717,11 @@ def index():
item['display_date'] = format_history_date(item['date'])
tuang_json_data = {
item['camera_name']: {'karung': item['karung']}
item['name']: {'karung': item['karung']}
for item in today_section['tuang']
}
masuk_json_data = {
item['camera_name']: {'karung': item['karung']}
item['name']: {'karung': item['karung']}
for item in today_section['masuk']
}
tuang_json_total = today_section['totals']['tuang']
+6 -6
View File
@@ -1342,7 +1342,7 @@
<table>
<thead>
<tr>
<th>Camera Name</th>
<th>Nama</th>
<th>Tanggal</th>
<th>Jumlah Karung</th>
</tr>
@@ -1351,7 +1351,7 @@
{% for item in tuang_db_data %}
<tr>
<td>
<span class="camera-cell"><span class="badge badge-tuang">TUANG</span> {{ item.camera_name }}</span>
<span class="camera-cell"><span class="badge badge-tuang">TUANG</span> {{ item.name }}</span>
</td>
<td>{{ item.display_date }}</td>
<td>{{ item.counter_value }}</td>
@@ -1374,7 +1374,7 @@
<table>
<thead>
<tr>
<th>Camera Name</th>
<th>Nama</th>
<th>Tanggal</th>
<th>Jumlah Karung</th>
</tr>
@@ -1383,7 +1383,7 @@
{% for item in masuk_db_data %}
<tr>
<td>
<span class="camera-cell"><span class="badge badge-masuk">MASUK</span> {{ item.camera_name }}</span>
<span class="camera-cell"><span class="badge badge-masuk">MASUK</span> {{ item.name }}</span>
</td>
<td>{{ item.date }}</td>
<td>{{ item.counter_value }}</td>
@@ -1458,12 +1458,12 @@
}
listElement.innerHTML = items.map((item) => {
const cameraName = escapeHtml(item.camera_name || '');
const sourceName = escapeHtml(item.name || '');
const karungCount = Number(item.karung || 0);
return `
<div class="camera-item">
<div class="camera-name">${cameraName}</div>
<div class="camera-name">${sourceName}</div>
<div class="karung-count">${karungCount} karung</div>
</div>
`;