Skip to content
Snippets Groups Projects
Commit ab308de7 authored by safer-lgtm's avatar safer-lgtm
Browse files

tests updated and docs created

parent 70c5bde3
Branches
No related tags found
No related merge requests found
......@@ -32,6 +32,9 @@ extensions = [
'sphinx.ext.autosummary'
]
#autosummary_generate = True # Enable autosummary
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
......
formulaone package
==================
Submodules
----------
formulaone.core module
----------------------
.. automodule:: formulaone.core
:members:
:undoc-members:
:show-inheritance:
formulaone.dynamodb\_helpers module
-----------------------------------
.. automodule:: formulaone.dynamodb_helpers
:members:
:undoc-members:
:show-inheritance:
formulaone.helpers module
-------------------------
.. automodule:: formulaone.helpers
:members:
:undoc-members:
:show-inheritance:
formulaone.load\_latest\_race module
------------------------------------
.. automodule:: formulaone.load_latest_race
:members:
:undoc-members:
:show-inheritance:
formulaone.prepare\_data module
-------------------------------
.. automodule:: formulaone.prepare_data
:members:
:undoc-members:
:show-inheritance:
formulaone.tidy\_data module
----------------------------
.. automodule:: formulaone.tidy_data
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: formulaone
:members:
:undoc-members:
:show-inheritance:
sample.helpers
==============
.. automodule:: sample.helpers
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Functions
.. autosummary::
:toctree: _autosummary
get_raw_data_path
get_dynamodb_resource
list_dynamodb_tables
get_movies_table
get_movie_item
query_movies_by_year
......@@ -9,6 +9,6 @@ Welcome to sample's documentation!
Contents:
.. toctree::
modules
usage
API
formulaone
==========
.. toctree::
:maxdepth: 4
formulaone
import boto3
import os
import sys
import configparser
import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
from boto3.dynamodb.conditions import Key
import pandas as pd
from decimal import Decimal
def get_config():
"""
......@@ -10,7 +17,17 @@ def get_config():
config: The config object.
"""
config = configparser.ConfigParser()
config.read('config.ini')
#config_file = os.path.join(os.path.dirname(__file__), 'config.ini')
#config_file = os.path.abspath(os.path.join(os.getcwd(), 'config.ini'))
config_file = 'config.ini'
if not os.path.exists(config_file):
raise FileNotFoundError(f"The configuration file was not found: {config_file}")
config.read(config_file)
if 'AWS' not in config or 'DYNAMODB' not in config:
raise KeyError("One or more required sections are missing in the configuration file.")
return config
def get_dynamodb_resource():
......@@ -21,6 +38,7 @@ def get_dynamodb_resource():
dynamo_resource: The DynamoDB resource.
"""
config = get_config()
aws_access_key_id = config['AWS']['aws_access_key_id']
aws_secret_access_key = config['AWS']['aws_secret_access_key']
region_name = config['AWS']['region_name']
......@@ -34,6 +52,7 @@ def get_dynamodb_resource():
dynamo_resource = session.resource('dynamodb')
return dynamo_resource
def list_dynamodb_tables(dynamo_resource):
"""
Lists all tables in the DynamoDB resource.
......@@ -91,3 +110,35 @@ def query_movies_by_year(table, year):
KeyConditionExpression=Key('year').eq(year)
)
return response.get('Items', [])
def tidy_movie_data(movies):
"""
Transforms the raw movie data into a tidy DataFrame.
Args:
movies (list): List of raw movie data.
Returns:
DataFrame: Tidy DataFrame containing movie data.
"""
tidy_data = []
for movie in movies:
year = movie['year']
title = movie['title']
info = movie['info']
tidy_data.append({
'year': int(year),
'title': title,
'actors': ', '.join(info['actors']),
'release_date': info['release_date'],
'plot': info['plot'],
'genres': ', '.join(info['genres']),
'image_url': info['image_url'],
'directors': ', '.join(info['directors']),
'rating': float(info['rating']),
'rank': int(info['rank']),
'running_time_secs': int(info['running_time_secs'])
})
return pd.DataFrame(tidy_data)
\ No newline at end of file
......@@ -6,20 +6,18 @@ import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
# Add the formulaone model directory to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
#sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from formulaone.dynamodb_helpers import (
get_dynamodb_resource,
list_dynamodb_tables,
get_movies_table,
get_movie_item,
query_movies_by_year
)
module_path = os.path.abspath(os.path.join(os.getcwd(), 'formulaone'))
sys.path.insert(0, module_path)
print(sys.path.insert(0, module_path))
from formulaone.dynamodb_helpers import *
def test_aws_config_keys():
"""Test the necessary AWS config keys."""
config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), '../config.ini'))
config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
assert 'AWS' in config, "AWS section is missing"
assert 'aws_access_key_id' in config['AWS'], "aws_access_key_id is missing in AWS"
assert 'aws_secret_access_key' in config['AWS'], "aws_secret_access_key is missing in AWS"
......@@ -28,7 +26,7 @@ def test_aws_config_keys():
def test_dynamodb_config_keys():
"""Test the necessary DynamoDB config keys."""
config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), '../config.ini'))
config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
assert 'DYNAMODB' in config, "DYNAMODB section is missing"
assert 'table_name' in config['DYNAMODB'], "table_name is missing in DYNAMODB"
......@@ -36,7 +34,7 @@ def test_dynamodb_connection():
"""Test the DynamoDB connection using the provided credentials and configuration."""
# Read the config file
config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(__file__), '../config.ini'))
config.read(os.path.join(os.path.dirname(__file__), 'config.ini'))
# Credentials and region
aws_access_key_id = config['AWS']['aws_access_key_id']
......@@ -71,5 +69,9 @@ def test_dynamodb_resource():
dynamo_resource = get_dynamodb_resource()
assert dynamo_resource is not None, "DynamoDB resource should be initialized"
if __name__ == "__main__":
pytest.main()
## Test ob die Tabelle da ist, noch da? Database da?
# Soll in tidy format bringen
# Doc erstellen lassen mit sphinx ( Aber zunächst soll die Methode gut kommentiert)
# Zip oder url bei gitlab, Prof hinzufügen
# log_transformation machen, testen ggf.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment