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
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,9 @@ extensions = [ ...@@ -32,6 +32,9 @@ extensions = [
'sphinx.ext.autosummary' 'sphinx.ext.autosummary'
] ]
#autosummary_generate = True # Enable autosummary
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] 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! ...@@ -9,6 +9,6 @@ Welcome to sample's documentation!
Contents: Contents:
.. toctree:: .. toctree::
modules
usage usage
API API
formulaone
==========
.. toctree::
:maxdepth: 4
formulaone
import boto3
import os
import sys
import configparser import configparser
import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError
from boto3.dynamodb.conditions import Key from boto3.dynamodb.conditions import Key
import pandas as pd
from decimal import Decimal
def get_config(): def get_config():
""" """
...@@ -10,7 +17,17 @@ def get_config(): ...@@ -10,7 +17,17 @@ def get_config():
config: The config object. config: The config object.
""" """
config = configparser.ConfigParser() 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 return config
def get_dynamodb_resource(): def get_dynamodb_resource():
...@@ -21,6 +38,7 @@ def get_dynamodb_resource(): ...@@ -21,6 +38,7 @@ def get_dynamodb_resource():
dynamo_resource: The DynamoDB resource. dynamo_resource: The DynamoDB resource.
""" """
config = get_config() config = get_config()
aws_access_key_id = config['AWS']['aws_access_key_id'] aws_access_key_id = config['AWS']['aws_access_key_id']
aws_secret_access_key = config['AWS']['aws_secret_access_key'] aws_secret_access_key = config['AWS']['aws_secret_access_key']
region_name = config['AWS']['region_name'] region_name = config['AWS']['region_name']
...@@ -34,6 +52,7 @@ def get_dynamodb_resource(): ...@@ -34,6 +52,7 @@ def get_dynamodb_resource():
dynamo_resource = session.resource('dynamodb') dynamo_resource = session.resource('dynamodb')
return dynamo_resource return dynamo_resource
def list_dynamodb_tables(dynamo_resource): def list_dynamodb_tables(dynamo_resource):
""" """
Lists all tables in the DynamoDB resource. Lists all tables in the DynamoDB resource.
...@@ -91,3 +110,35 @@ def query_movies_by_year(table, year): ...@@ -91,3 +110,35 @@ def query_movies_by_year(table, year):
KeyConditionExpression=Key('year').eq(year) KeyConditionExpression=Key('year').eq(year)
) )
return response.get('Items', []) 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 ...@@ -6,20 +6,18 @@ import boto3
from botocore.exceptions import NoCredentialsError, PartialCredentialsError from botocore.exceptions import NoCredentialsError, PartialCredentialsError
# Add the formulaone model directory to the Python path # 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 ( module_path = os.path.abspath(os.path.join(os.getcwd(), 'formulaone'))
get_dynamodb_resource, sys.path.insert(0, module_path)
list_dynamodb_tables, print(sys.path.insert(0, module_path))
get_movies_table,
get_movie_item, from formulaone.dynamodb_helpers import *
query_movies_by_year
)
def test_aws_config_keys(): def test_aws_config_keys():
"""Test the necessary AWS config keys.""" """Test the necessary AWS config keys."""
config = configparser.ConfigParser() 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' in config, "AWS section is missing"
assert 'aws_access_key_id' in config['AWS'], "aws_access_key_id is missing in AWS" 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" 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(): ...@@ -28,7 +26,7 @@ def test_aws_config_keys():
def test_dynamodb_config_keys(): def test_dynamodb_config_keys():
"""Test the necessary DynamoDB config keys.""" """Test the necessary DynamoDB config keys."""
config = configparser.ConfigParser() 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 'DYNAMODB' in config, "DYNAMODB section is missing"
assert 'table_name' in config['DYNAMODB'], "table_name is missing in DYNAMODB" assert 'table_name' in config['DYNAMODB'], "table_name is missing in DYNAMODB"
...@@ -36,7 +34,7 @@ def test_dynamodb_connection(): ...@@ -36,7 +34,7 @@ def test_dynamodb_connection():
"""Test the DynamoDB connection using the provided credentials and configuration.""" """Test the DynamoDB connection using the provided credentials and configuration."""
# Read the config file # Read the config file
config = configparser.ConfigParser() 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 # Credentials and region
aws_access_key_id = config['AWS']['aws_access_key_id'] aws_access_key_id = config['AWS']['aws_access_key_id']
...@@ -71,5 +69,9 @@ def test_dynamodb_resource(): ...@@ -71,5 +69,9 @@ def test_dynamodb_resource():
dynamo_resource = get_dynamodb_resource() dynamo_resource = get_dynamodb_resource()
assert dynamo_resource is not None, "DynamoDB resource should be initialized" 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