component-lifetime-analysis
Tools to report and analyse component lifetimes
https://github.com/jelle-zonder-k/component-lifetime-analysis
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.5%) to scientific vocabulary
Repository
Tools to report and analyse component lifetimes
Basic Info
- Host: GitHub
- Owner: Jelle-zonder-k
- Language: Python
- Default Branch: develop
- Size: 38.1 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 1
Metadata Files
readme.md
Component Lifetime Data Project
This project is dedicated to cataloging and analyzing the lifetime data of components associated with storm surge barriers. At its core, this system utilizes FastAPI to offer accessible endpoints for CRUD operations. This way, users can easily capture, insert, and fetch data related to component lifetimes. The primary storage for this data is a PostgreSQL database. The convenient DBeaver tool allows for easy database management.
Introduction
Storm surge barriers are integral in safeguarding low-lying areas from potential flood threats due to rising sea levels and frequent storm surges. Maintaining the reliability of these barriers means monitoring the lifetimes and reliability of individual components. This project provides a specialized database system to hold component lifetime data, which in turn, facilitates a better understanding of storm surge barriers' reliability over time. By employing the FastAPI framework, this project offers a robust, user-friendly API for seamless interaction with the database. Whether you are looking to conduct research on component lifetimes or need a reliable system for data storage, this project is tailored to serve your needs.
Tools and Methods Used
- FastAPI: A modern web framework to build efficient and scalable APIs.
- Uvicorn: An ASGI server to run the FastAPI application and handle external requests.
- SQLAlchemy: A versatile ORM for database operations.
- PostgreSQL: A powerful relational database system.
- DBeaver: A database management tool suitable for developers and database administrators.
- Alembic: A database migration tool that works with SQLAlchemy to manage and version database schema. ## Setting Up Development Environment
Creating a Python Virtual Environment
- Open your terminal and navigate to the project directory.
Run the command to generate a virtual environment named
venv:bash python3 -m venv venvActivate the virtual environment:
- Windows:
bash .\\venv\\Scripts\\Activate
- Windows:
- **macOS and Linux**:
```bash
source venv/bin/activate
```
Installing Required Packages
A
requirements.txtfile should contain all essential packages, such as:fastapi uvicorn sqlalchemy python-dotenvInstall these packages using the command:
bash pip install -r requirements.txt
Running the FastAPI application
- FastAPI is a state-of-the-art web framework built on Starlette and Pydantic, allowing swift and effective API creation.
- Uvicorn serves as the ASGI server, acting as the bridge between the FastAPI application and external requests.
Launch the FastAPI application using:
bash uvicorn your_component_lifetime_app:app --reload
Replace your_component_lifetime_app with your application file's name (excluding the .py).
4. Access the application at http://127.0.0.1:8000.
Generating a Database
Installing and Setting up DBeaver
- Fetch DBeaver from the official website.
- After installation, initiate DBeaver.
- Navigate to
Databasein the menu, and selectNew Database Connection. - Choose
PostgreSQLand enter your database credentials.
Setting up a Local PostgreSQL Server in DBeaver
- Within DBeaver, right-click on
Databaseslocated in theDatabase Navigator. - Navigate to
Create->Database. - Name your new database
componentLifetimeData. - Modify other properties if needed, and click
OK.
Running the Database Initialization Script
- Configure your
.envfile with the proper database details. - Open a terminal in the project's root directory.
- Activate the Python virtual environment:
- Windows:
bash .\\venv\\Scripts\\Activate
- Windows:
- **macOS and Linux**:
```bash
source venv/bin/activate
```
- Execute the database initialization script:
bash python create_database.py
This action will structure the tables in the componentLifetimeData database based on the pre-defined models.
Incorporating Records to the Database
For bulk data insertion:
Prepare a JSON file with the required records. Each entry should adhere to this structure:
json { "StartDate": "YYYY-MM-DD", "StartTime": "HH:MM:SS", "EndDate": "YYYY-MM-DD", "EndTime": "HH:MM:SS" }Use the supplied API endpoints (or tools like
curlor Postman) to transmit records to the server. If needed, account for rate limits and segment your data.
For easy conversion from Excel to JSON, consider the following online utility: https://tableconvert.com/excel-to-json.
Inserting Initial Lifetime Records for Components
As we began observing the components' lifetimes on 20 May 2010, it's essential to initialize each component's record with this start date. Although we don't possess information on the exact lifetimes of these components before this date, we make the working assumption that their observations effectively began from this point.
To set the initial start date for each object in the database: ```sql INSERT INTO public."ObjectLifetime" ("ID", "ObjectCodeID", "StartDate") SELECT genrandomuuid(), "ID", '2010-05-20' FROM public."ObjectCode";
Alembic for Database Migrations
Alembic is a database migration tool for SQLAlchemy, the ORM (Object Relational Mapper) that we are using in our project. It helps manage database schema changes by providing a way to define and track schema changes using "migration scripts." Alembic is especially useful when collaborating with others or when deploying updates to a live environment, as it ensures consistent database states across different environments.
Setting Up Alembic
- First, make sure you've already created and activated your virtual environment as outlined above.
Install Alembic by running:
bash pip install alembicNext, initialize Alembic within your project:
bash alembic init alembic
This command will generate an alembic directory at your project root with configuration files and a versions folder.
- Modify
alembic.iniand adjust the following line:ini sqlalchemy.url = driver://user:password@localhost/dbname
Replace the placeholder values (driver, user, password, localhost, dbname) with the appropriate connection string for your PostgreSQL database.
- In
alembic/env.py, adjust the target metadata:python from your_component_lifetime_app.models import Base # Import the base from your SQLAlchemy models target_metadata = Base.metadata
Generating and Running Migrations
Whenever you modify the database models in your FastAPI application, you can auto-generate migration scripts:
bash alembic revision --autogenerate -m "Short description of changes"This command will produce a new script in the
alembic/versionsdirectory.To apply the migrations and update the database schema:
bash alembic upgrade headIf you need to revert a migration:
bash alembic downgrade -1This command will undo the most recent migration.
Additional Resources
For more comprehensive details on Alembic, refer to the official documentation.
For a deeper dive into FastAPI and its capabilities, check out the official FastAPI documentation.
For detailed documenation on the Surpyval library, check out the Surpyval Documenation
Owner
- Name: Jelle
- Login: Jelle-zonder-k
- Kind: user
- Repositories: 1
- Profile: https://github.com/Jelle-zonder-k
Citation (CITATION.cff)
cff-version: 1.0.0
message: "If you use this software, please cite it as below."
authors:
- family-names: Epema
given-names: Jelle Hendrik
title: "Component Lifetime Database API Software"
version: 1.0.0
date-released: 29-09-2023
GitHub Events
Total
Last Year
Dependencies
- alembic *
- fastapi ==0.95.1
- numpy *
- pandas *
- psycopg2 *
- python-dotenv *
- reliability *
- sqlalchemy >=2.0.10
- surpyval *
- uvicorn >=0.2.3