Merge pull request 'feature/analysis-form' (#10) from feature/analysis-form into master

Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
2025-02-10 03:11:57 +01:00
28 changed files with 1362 additions and 195 deletions

View File

@@ -1,16 +1,100 @@
{% extends 'base.html' %}
{% block content %}
<section class="container-fluid d-flex justify-content-center">
<div class="container-md my-5 mx-2 shadow-lg p-4 ">
<div class="container-sm">
<div class="row">
<div class="col">
<h2>Analyze</h2>
</div>
<div class="col">
</div>
</div>
<section class="container-fluid d-flex justify-content-center">
<div class="container-md my-5 mb-3 mx-2 shadow-lg p-4">
<div class="container-sm">
<div class="row">
<div class="col">
<h2>User Activity Distribution</h2>
</div>
</div>
</section>
{% endblock content %}
<div class="row">
<div class="col">
<form method="POST" action="{{ url_for('views.analyze') }}">
<!-- Dropdown for selecting data file -->
<label for="data_file" class="form-label">Choose Data File:</label>
<select name="data_file" id="data_file" class="form-select">
{% if data_files %}
{% for file in data_files %}
{{ file }}
{{ selected_file }}
<option value="{{ file }}" {% if file == selected_file %}selected{% endif %}>{{ file.split('/')[-1] }}</option>
{% endfor %}
{% else %}
<option disabled>No CSV files found</option>
{% endif %}
</select>
<!-- Analysis Selection Table -->
<label for="analyses" class="form-label">Select Analyses:</label>
<table id="analysesTable" class="table table-bordered table-striped">
<thead>
<tr>
<th width="2%"><input type="checkbox" id="checkAllAnalyses" class="form-check-input" onclick="checkAllCheckboxes('analysesTable', 'checkAllAnalyses')"></th>
<th>Analysis Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{% if analyses %}
{% for analysis in analyses %}
<tr>
<td>
<input class="form-check-input" type="checkbox" name="analyses" value="{{ analysis.name }}"
{% if analysis.name in selected_analyses %}checked{% endif %}>
</td>
<td>{{ analysis.name }}</td>
<td>{{ analysis.description }}</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="3" class="text-center">No analyses available</td>
</tr>
{% endif %}
</tbody>
</table>
<button type="submit" class="btn btn-primary mt-3">Run Analyses</button>
</form>
</div>
</div>
{% include 'includes/error.html' %}
</div>
</div>
</section>
{% if plot_url %}
<section class="container-fluid d-flex justify-content-center">
<div class="container-md my-1 mx-2 shadow-lg p-4">
<div class="container-sm">
<div class="row mt-4">
<div class="col">
<h4>Selected File: {{ selected_file.split('/')[-1] }}</h4>
<img src="{{ plot_url }}" class="img-fluid rounded shadow" alt="User Activity Distribution">
</div>
</div>
</div>
</div>
</section>
{% endif %}
{% if results %}
{% for analysis_name, result in results.items() %}
<section class="container-fluid d-flex justify-content-center">
<div class="container-md my-2 mx-2 shadow p-4 pt-0">
<div class="container-sm">
<div class="results mt-4">
<h3>{{ analysis_name }}</h3>
<div class="analysis-output">
{{ result | safe }} <!-- This allows HTML output -->
</div>
</div>
</div>
</div>
</section>
{% endfor %}
{% endif %}
{% endblock %}

View File

@@ -1,68 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<section class="container-fluid d-flex justify-content-center">
<div class="container-md my-5 mx-2 shadow-lg p-4 ">
<div class="container-sm">
<div class="row">
<div class="col">
<h2>User Activity Distribution</h2>
</div>
<div class="col text-end">
<!-- Dropdown for selecting data file -->
<form method="POST" action="{{ url_for('views.data_visualization') }}">
<label for="data_file" class="form-label">Choose Data File:</label>
<select name="data_file" id="data_file" class="form-select" onchange="this.form.submit()">
{% for file in data_files %}
<option value="{{ file }}" {% if file == selected_file %}selected{% endif %}>
{{ file.split('/')[-1] }}
</option>
{% endfor %}
</select>
</form>
</div>
</div>
{% if error %}
<div class="alert alert-danger mt-3" role="alert">
{{ error }}
</div>
{% endif %}
{% if plot_url %}
<div class="row mt-4">
<div class="col">
<h4>Selected File: {{ selected_file.split('/')[-1] }}</h4>
<img src="{{ plot_url }}" class="img-fluid rounded shadow" alt="User Activity Distribution">
</div>
</div>
{% endif %}
{% if statistics %}
<div class="row mt-4">
<div class="col">
<h2>Activity Statistics</h2>
<table class="table table-bordered table-hover">
<thead class="table-dark">
<tr>
<th>Hour</th>
<th>Activity Count</th>
</tr>
</thead>
<tbody>
{% for hour, count in statistics.items() %}
<tr>
<td>{{ hour }}</td>
<td>{{ count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>
</div>
</section>
{% endblock content %}

View File

@@ -18,7 +18,7 @@
<table id="dataFilesTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="2%"><input type="checkbox" id="checkAllData" onclick="checkAllCheckboxes('dataFilesTable', 'checkAllData')"></th>
<th width="2%"><input type="checkbox" class="form-check-input" id="checkAllData" onclick="checkAllCheckboxes('dataFilesTable', 'checkAllData')"></th>
<th onclick="sortTable(1, 'dataFilesTable')">File Name</th>
<th onclick="sortTable(2, 'dataFilesTable')">Last Modified</th>
<th onclick="sortTable(3, 'dataFilesTable')">Created</th>
@@ -30,7 +30,7 @@
<tbody>
{% for file in files.data %}
<tr>
<td><input type="checkbox" name="fileCheckbox" value="{{ url_for('download_data_file', filename=file.name_display) }}"{{ ' disabled' if file.active }}></td>
<td><input type="checkbox" name="fileCheckbox" class="form-check-input" value="{{ url_for('download_data_file', filename=file.name_display) }}"{{ ' disabled' if file.active }}></td>
<td><a href="{{ url_for('download_data_file', filename=file.name_display) }}" target="_blank">{{ file.name_display }}</a></td>
<td>{{ file.last_modified | datetimeformat }}</td>
<td>{{ file.created | datetimeformat }}</td>
@@ -79,7 +79,7 @@
<tbody>
{% for file in files.log %}
<tr>
<td><input type="checkbox" name="fileCheckbox" value="{{ url_for('download_log_file', filename=file.name_display) }}"{{ ' disabled' if file.active }}></td>
<td><input type="checkbox" name="fileCheckbox" class="form-check-input" value="{{ url_for('download_log_file', filename=file.name_display) }}"{{ ' disabled' if file.active }}></td>
<td><a href="{{ url_for('download_log_file', filename=file.name_display) }}" target="_blank">{{ file.name_display }}</a></td>
<td>{{ file.last_modified | datetimeformat }}</td>
<td>{{ file.created | datetimeformat }}</td>
@@ -98,8 +98,5 @@
</table>
</div>
</section>
{% block scripts %}
{{ bootstrap.load_js() }}
<script src="{{url_for('.static', filename='download_results.js')}}"></script>
{% endblock %}
{% endblock content %}

View File

@@ -0,0 +1,6 @@
{% if error %}
<div class="alert alert-danger alert-dismissible fade show mt-3" role="alert">
<strong>Error:</strong> {{ error }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}

View File

@@ -3,7 +3,7 @@
<div class="container-fluid">
<a class="navbar-brand" href="/">Torn User Activity Scraper</a>
{% from 'bootstrap4/nav.html' import render_nav_item %}
{{ render_nav_item('views.data_visualization', 'Data Visualization') }}
{{ render_nav_item('views.analyze', 'Data Visualization') }}
{{ render_nav_item('download_results', 'Files') }}
{{ render_nav_item('log_viewer', 'Logs') }}
<div class="d-flex" id="color-mode-toggle">

View File

@@ -1,2 +1,3 @@
{{ bootstrap.load_js() }}
<script src="{{url_for('static', filename='color_mode.js')}}"></script>
<script src="{{url_for('static', filename='color_mode.js')}}"></script>
<script src="{{ url_for('static', filename='common.js') }}"></script>