forked from ariska/karung-web-admin
adjust api naming and endpoint
This commit is contained in:
1 parent
5b5d28ce52
commit
bb2c358157
3 files changed
+22
-22
No files matched your search
@@ -98,7 +98,7 @@ sudo systemctl daemon-reload
|
|||||||
```
|
```
|
||||||
|
|
||||||
Dashboard: `http://0.0.0.0:8090/`
|
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
|
## Environment
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ def get_db_data(db_path, table_name):
|
|||||||
for row in rows:
|
for row in rows:
|
||||||
data.append({
|
data.append({
|
||||||
'id': row[0],
|
'id': row[0],
|
||||||
'camera_name': row[1],
|
'name': row[1],
|
||||||
'date': row[2],
|
'date': row[2],
|
||||||
'counter_value': row[3]
|
'counter_value': row[3]
|
||||||
})
|
})
|
||||||
@@ -340,11 +340,11 @@ def filter_data_by_cycle(data, cycle_start, cycle_end):
|
|||||||
return filtered_data
|
return filtered_data
|
||||||
|
|
||||||
def is_masuk_out_item(item):
|
def is_masuk_out_item(item):
|
||||||
camera_name = str(item['camera_name']).lower().strip()
|
source_name = str(item.get('name', '')).lower().strip()
|
||||||
return (
|
return (
|
||||||
camera_name.endswith('_out')
|
source_name.endswith('_out')
|
||||||
or camera_name.endswith('-out')
|
or source_name.endswith('-out')
|
||||||
or camera_name.endswith(' out')
|
or source_name.endswith(' out')
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_counter_settings_from_dashboard(dashboard_settings):
|
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):
|
def get_json_counter_items(json_data):
|
||||||
items = []
|
items = []
|
||||||
for camera_name, camera_data in json_data.items():
|
for source_name, source_data in json_data.items():
|
||||||
karung_count = 0
|
karung_count = 0
|
||||||
if isinstance(camera_data, dict):
|
if isinstance(source_data, dict):
|
||||||
karung_count = camera_data.get('karung', 0)
|
karung_count = source_data.get('karung', 0)
|
||||||
|
|
||||||
items.append({
|
items.append({
|
||||||
'camera_name': camera_name,
|
'name': source_name,
|
||||||
'karung': karung_count,
|
'karung': karung_count,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ def format_history_items(data):
|
|||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'id': item['id'],
|
'id': item['id'],
|
||||||
'camera_name': item['camera_name'],
|
'name': item['name'],
|
||||||
'date': format_history_date(item['date']),
|
'date': format_history_date(item['date']),
|
||||||
'counter_value': item['counter_value'],
|
'counter_value': item['counter_value'],
|
||||||
}
|
}
|
||||||
@@ -650,8 +650,8 @@ def get_active_cycle_sections():
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@app.route('/api/k1/combined', methods=['GET'])
|
@app.route('/api/combined', methods=['GET'])
|
||||||
def get_k1_combined():
|
def get_combined():
|
||||||
history_days_raw = request.args.get('history_days', DEFAULT_COMBINED_HISTORY_DAYS)
|
history_days_raw = request.args.get('history_days', DEFAULT_COMBINED_HISTORY_DAYS)
|
||||||
try:
|
try:
|
||||||
history_days = int(history_days_raw)
|
history_days = int(history_days_raw)
|
||||||
@@ -683,7 +683,7 @@ def get_k1_combined():
|
|||||||
'totals': {
|
'totals': {
|
||||||
'tuang': tuang_payload['totals']['today'],
|
'tuang': tuang_payload['totals']['today'],
|
||||||
'masuk': sum(
|
'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
|
for item in masuk_today
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -717,11 +717,11 @@ def index():
|
|||||||
item['display_date'] = format_history_date(item['date'])
|
item['display_date'] = format_history_date(item['date'])
|
||||||
|
|
||||||
tuang_json_data = {
|
tuang_json_data = {
|
||||||
item['camera_name']: {'karung': item['karung']}
|
item['name']: {'karung': item['karung']}
|
||||||
for item in today_section['tuang']
|
for item in today_section['tuang']
|
||||||
}
|
}
|
||||||
masuk_json_data = {
|
masuk_json_data = {
|
||||||
item['camera_name']: {'karung': item['karung']}
|
item['name']: {'karung': item['karung']}
|
||||||
for item in today_section['masuk']
|
for item in today_section['masuk']
|
||||||
}
|
}
|
||||||
tuang_json_total = today_section['totals']['tuang']
|
tuang_json_total = today_section['totals']['tuang']
|
||||||
|
|||||||
@@ -1342,7 +1342,7 @@
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Camera Name</th>
|
<th>Nama</th>
|
||||||
<th>Tanggal</th>
|
<th>Tanggal</th>
|
||||||
<th>Jumlah Karung</th>
|
<th>Jumlah Karung</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1351,7 +1351,7 @@
|
|||||||
{% for item in tuang_db_data %}
|
{% for item in tuang_db_data %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<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>
|
||||||
<td>{{ item.display_date }}</td>
|
<td>{{ item.display_date }}</td>
|
||||||
<td>{{ item.counter_value }}</td>
|
<td>{{ item.counter_value }}</td>
|
||||||
@@ -1374,7 +1374,7 @@
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Camera Name</th>
|
<th>Nama</th>
|
||||||
<th>Tanggal</th>
|
<th>Tanggal</th>
|
||||||
<th>Jumlah Karung</th>
|
<th>Jumlah Karung</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -1383,7 +1383,7 @@
|
|||||||
{% for item in masuk_db_data %}
|
{% for item in masuk_db_data %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<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>
|
||||||
<td>{{ item.date }}</td>
|
<td>{{ item.date }}</td>
|
||||||
<td>{{ item.counter_value }}</td>
|
<td>{{ item.counter_value }}</td>
|
||||||
@@ -1458,12 +1458,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
listElement.innerHTML = items.map((item) => {
|
listElement.innerHTML = items.map((item) => {
|
||||||
const cameraName = escapeHtml(item.camera_name || '');
|
const sourceName = escapeHtml(item.name || '');
|
||||||
const karungCount = Number(item.karung || 0);
|
const karungCount = Number(item.karung || 0);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="camera-item">
|
<div class="camera-item">
|
||||||
<div class="camera-name">${cameraName}</div>
|
<div class="camera-name">${sourceName}</div>
|
||||||
<div class="karung-count">${karungCount} karung</div>
|
<div class="karung-count">${karungCount} karung</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in new issue
Block a user