From 283d019d16040c859a5c04a881c39df1d9754544 Mon Sep 17 00:00:00 2001 From: muhammad-fiaz Date: Fri, 15 Nov 2024 22:43:05 +0530 Subject: [PATCH] improved home page ui and added some new pages and renamed history to records --- app.py | 102 +++++++- database.py | 2 +- fetch_alerts.py | 2 +- templates/analysis.html | 75 ++++-- templates/index.html | 319 +++++++++++++++++------ templates/license.html | 105 ++++++++ templates/notice.html | 134 ++++++++++ templates/{history.html => records.html} | 113 ++++---- templates/report.html | 2 + templates/reports.html | 129 ++++----- 10 files changed, 747 insertions(+), 236 deletions(-) create mode 100644 templates/license.html create mode 100644 templates/notice.html rename templates/{history.html => records.html} (80%) diff --git a/app.py b/app.py index 5935c4c..e0b0aca 100644 --- a/app.py +++ b/app.py @@ -110,27 +110,94 @@ def loading(): # Respond with a JSON object indicating that processing is complete return jsonify({'status': 'completed'}) +@app.route('/analysis-data', methods=['GET']) +def fetch_analysis_data(): + """ + Fetches distinct values for locations, tags, priorities, and keywords from the database, + along with future prediction durations and additional timeframes for past data. + + Returns: + json: A dictionary with lists of locations, tags, priorities, keywords, prediction durations, and past date ranges. + """ + # Connect to the database + conn = sqlite3.connect('disaster_alerts.db') + c = conn.cursor() + + # Fetch distinct locations + c.execute("SELECT DISTINCT country FROM alerts") + locations = [row[0] for row in c.fetchall()] + + # Fetch and process distinct tags + c.execute("SELECT DISTINCT tags FROM alerts") + raw_tags = [row[0] for row in c.fetchall()] + distinct_tags = set() + for tag_list in raw_tags: + if tag_list: + distinct_tags.update([tag.strip() for tag in tag_list.split(',') if not tag.strip().isdigit()]) + + # Fetch and process distinct keywords + c.execute("SELECT DISTINCT keywords FROM alerts") + raw_keywords = [row[0] for row in c.fetchall()] + distinct_keywords = set() + for keyword_list in raw_keywords: + if keyword_list: + distinct_keywords.update( + [keyword.strip() for keyword in keyword_list.split(',') if not keyword.strip().isdigit()]) + # Fetch distinct priorities + c.execute("SELECT DISTINCT priority FROM alerts") + priorities = [row[0] for row in c.fetchall()] + + conn.close() -@app.route('/history', methods=['GET']) + # Define prediction durations (future intervals) + prediction_durations = { + "durations": [ + {"label": "1 Week", "value": 7}, # 7 days + {"label": "2 Weeks", "value": 14}, # 14 days + {"label": "1 Month", "value": 30}, # 30 days + {"label": "3 Months", "value": 90} # 90 days + ] + } + + # Define past date ranges + past_date_ranges = [ + {"label": "Last Year to This Month", "value": "last_year_to_this_month"}, + {"label": "Last Week", "value": "last_week"}, + {"label": "Last 7 Days", "value": "last_7_days"} + ] + + # Return data as JSON + return jsonify({ + 'locations': locations, + 'tags': sorted(distinct_tags), + 'priorities': priorities, + 'keywords': sorted(distinct_keywords), + 'prediction_durations': prediction_durations, + 'past_date_ranges': past_date_ranges + }) + + + +@app.route('/records', methods=['GET']) def history(): """ - Retrieves all historical alert data from the database and renders the history page. + Retrieves all historical alert data from the database and renders the records page. Returns: - str: Rendered HTML template for the history page with fetched data. + str: Rendered HTML template for the records page with fetched data. """ # Connect to the database conn = sqlite3.connect('disaster_alerts.db') c = conn.cursor() - # Retrieve all history data in descending order (most recent first) + # Retrieve all records data in descending order (most recent first) c.execute("SELECT * FROM alerts ORDER BY id DESC") - history_data = c.fetchall() + records_data = c.fetchall() conn.close() - logly.info(f"Retrieved history data") - # Render the history template with the fetched data - return render_template('history.html', history=history_data) + logly.info(f"Retrieved records data") + # Render the records template with the fetched data + return render_template('records.html', records=records_data) @app.route('/report', methods=['GET']) @@ -275,3 +342,22 @@ def analysis(): +@app.route('/license', methods=['GET']) +def license(): + """ + Renders the License page. + + Returns: + str: Rendered HTML template for the License page. + """ + return render_template('license.html') + +@app.route('/notice', methods=['GET']) +def notice(): + """ + Renders the Notice page. + + Returns: + str: Rendered HTML template for the Notice page. + """ + return render_template('notice.html') diff --git a/database.py b/database.py index 53ed3db..6cf7bf3 100644 --- a/database.py +++ b/database.py @@ -27,7 +27,7 @@ def init_db(): conn = sqlite3.connect('disaster_alerts.db') c = conn.cursor() - # Create the alerts history table if it does not exist + # Create the alerts records table if it does not exist c.execute(''' CREATE TABLE IF NOT EXISTS alerts ( id INTEGER PRIMARY KEY AUTOINCREMENT, diff --git a/fetch_alerts.py b/fetch_alerts.py index 60ca199..00dbabe 100644 --- a/fetch_alerts.py +++ b/fetch_alerts.py @@ -100,7 +100,7 @@ def store_results_in_current_db(alerts): def store_results_in_db(alerts): """ - Stores the fetched alerts in the alerts history table in the database. + Stores the fetched alerts in the alerts records table in the database. Args: alerts (list): A list of tuples containing the alert details. diff --git a/templates/analysis.html b/templates/analysis.html index aee71ac..f9ebd16 100644 --- a/templates/analysis.html +++ b/templates/analysis.html @@ -1,4 +1,4 @@ - + @@ -20,43 +20,38 @@

Future Prediction Analysis

+

Filter Options

- +
- +
+
+ + +
+ +
@@ -64,7 +59,7 @@

Future Prediction Analysis

- -
+
+ +
- +

Prediction Timeline

- +
@@ -112,6 +108,34 @@

Line Chart

+ + + diff --git a/templates/index.html b/templates/index.html index 06f71c0..d5c6b71 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,7 @@ - + EMSUGI + + + diff --git a/templates/license.html b/templates/license.html new file mode 100644 index 0000000..9e437cf --- /dev/null +++ b/templates/license.html @@ -0,0 +1,105 @@ + + + + + + + + + + + + MIT License + + + + + +
+ Go Back +
+ + +
+

MIT License

+ +
+

MIT License

+

+ Copyright (c) 2024 Muhammad Fiaz +

+

+ 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. +

+
+
+ + + + + + + diff --git a/templates/notice.html b/templates/notice.html new file mode 100644 index 0000000..bd8703a --- /dev/null +++ b/templates/notice.html @@ -0,0 +1,134 @@ + + + + + + + + + + + EMSUGI Project Notice + + + + +
+ Go Back +
+ +
+

EMSUGI Project Disclaimer

+ +
+ +

Project Overview

+

+ The EMSUGI project is an advanced emergency management system that uses artificial intelligence and machine learning to predict and analyze emergency incidents. By collecting real-time data from various sources such as articles, reports, and case studies, EMSUGI aims to assist in emergency response planning and preparedness. However, the project's predictions and alerts are based on historical and real-time data and should be used with caution. +

+ +

Research and Development Purpose Only

+

+ The EMSUGI project is being developed for research and development purposes only. The insights and predictions generated by the system are based on data retrieved from publicly available sources. While EMSUGI aims to provide useful information for emergency management, the data it generates may not reflect real-world conditions accurately. +

+ +

Prediction Limitations

+

+ The predictions made by EMSUGI are based on real-time data fetching from various news articles, reports, and case studies. While these predictions may offer insight into potential emergency incidents, they do not guarantee real-world outcomes. The prediction models are built on historical trends and may not account for unforeseen variables that could impact emergency situations. +

+

+ It is essential to understand that the predictions provided by EMSUGI should not be relied upon for critical decisions or emergency planning. The data generated might not reflect actual future events and should only be used for informational purposes or academic research. +

+ +

How It Works

+

+ EMSUGI collects data from various real-time sources, including: +

+
    +
  • News articles related to emergencies and disasters.
  • +
  • Reports and statistics from government and emergency response organizations.
  • +
  • Historical case studies of past emergency incidents.
  • +
+

+ This data is then processed by generative AI models that analyze trends and predict potential future incidents. The system generates reports and predictions based on this analysis, providing users with insights into possible emergency events that may occur in the future. +

+ +

Disclaimer of Accuracy

+

+ EMSUGI makes no claims regarding the accuracy, reliability, or safety of the predictions and insights generated by the system. The data and predictions should be treated as exploratory and not as definitive conclusions or recommendations for emergency planning. +

+

+ Users should independently verify all predictions and reports before making any critical decisions based on them. The creators of this system do not assume any responsibility for the outcomes of actions taken based on the generated data. +

+ +

Intended Use

+

+ EMSUGI is intended to serve as a tool for research, data analysis, and educational purposes. It is not designed for direct application in real-time emergency response or decision-making. The system may provide valuable insights for improving emergency management strategies, but users should not rely on it as a sole resource for critical operations. +

+ +

Future Enhancements

+

+ The EMSUGI system is still under active development, and future versions of the platform will include enhancements in prediction accuracy, data integration, and usability. The development team is continuously working to improve the models and expand the dataset to provide more valuable insights. +

+

+ As this project evolves, new features may be added, and the current capabilities may be adjusted or refined. Users are encouraged to follow updates and participate in providing feedback to help improve the platform. +

+ +
+
+ + + + + diff --git a/templates/history.html b/templates/records.html similarity index 80% rename from templates/history.html rename to templates/records.html index 91306c3..52bb0c7 100644 --- a/templates/history.html +++ b/templates/records.html @@ -1,55 +1,58 @@ - - - - - - - - - Search History - - - -
- Go Back -
- -
-

Search History

- - -
- - - - - - - - - - - - - - - {% for item in history %} - - - - - - - - - - - {% endfor %} - -
IDTitleLinkCountrySummaryKeywordsTagsDate
{{ item[0] }} {{ item[1] }} - Source - {{ item[3] }} {{ item[4] }} {{ item[5] }} {{ item[6] }} {{ item[7] }}
-
-
- - + + + + + + + + + Search Records + + + +
+ Go Back +
+ +
+

Search Records

+ + +
+ + + + + + + + + + + + + + + + {% for item in records %} + + + + + + + + + + + + {% endfor %} + +
IDTitleLinkCountrySummaryKeywordsTagsDatePriority
{{ item[0] }} {{ item[1] }} + Source + {{ item[3] }} {{ item[4] }} {{ item[5] }} {{ item[6] }} {{ item[7] }} {{ item[8] }}
+
+
+ + + diff --git a/templates/report.html b/templates/report.html index 4a3bf37..2d293dc 100644 --- a/templates/report.html +++ b/templates/report.html @@ -117,6 +117,7 @@

Reference

+ + diff --git a/templates/reports.html b/templates/reports.html index 3462b15..0341074 100644 --- a/templates/reports.html +++ b/templates/reports.html @@ -1,64 +1,65 @@ - - - - - - - - - Gemini Reports - - - - -
- Go Back -
-
-

Stored Reports

- - - -
- - + + + + + + + + + Gemini Reports + + + + +
+ Go Back +
+
+

Stored Reports

+ + + +
+ + +