import pandas as pd

from utils.utils import execute_query
from models.item_model import Item


def get_latest_ml_pipeline_version() -> str:
    """Get the latest version of the pipeline from the DB."""

    return execute_query('''
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    ''')[0][0]


def save_ml_pipeline_version(model_version: str) -> None:
    """Save the new version of the pipeline to the DB."""
    execute_query('INSERT INTO ml_pipeline (pipeline_version) VALUES(%s)', (model_version,))


async def save_prediction(row: list) -> None:
    """Save features + prediction + pipeline version."""
    query = '''
INSERT INTO predictions (
crim, zn, indus, chas, nox, rm, age, dis, rad, tax, ptratio, b, lstat, prediction, pipeline_version
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
    '''
    execute_query(query, row)


def convert_item_to_df(item: Item) -> pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]

    return pd.DataFrame(items)

b83f4171a6277bd04839701e59fc0bead9d748a7
<mask token>


def get_latest_ml_pipeline_version() ->str:
    """Get the latest version of the pipeline from the DB."""
    return execute_query(
        """
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    """
        )[0][0]


<mask token>


def convert_item_to_df(item: Item) ->pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]
    return pd.DataFrame(items)

<mask token>


def get_latest_ml_pipeline_version() ->str:
    """Get the latest version of the pipeline from the DB."""
    return execute_query(
        """
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    """
        )[0][0]


def save_ml_pipeline_version(model_version: str) ->None:
    """Save the new version of the pipeline to the DB."""
    execute_query('INSERT INTO ml_pipeline (pipeline_version) VALUES(%s)',
        (model_version,))


<mask token>


def convert_item_to_df(item: Item) ->pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]
    return pd.DataFrame(items)

<mask token>


def get_latest_ml_pipeline_version() ->str:
    """Get the latest version of the pipeline from the DB."""
    return execute_query(
        """
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    """
        )[0][0]


def save_ml_pipeline_version(model_version: str) ->None:
    """Save the new version of the pipeline to the DB."""
    execute_query('INSERT INTO ml_pipeline (pipeline_version) VALUES(%s)',
        (model_version,))


async def save_prediction(row: list) ->None:
    """Save features + prediction + pipeline version."""
    query = """
INSERT INTO predictions (
crim, zn, indus, chas, nox, rm, age, dis, rad, tax, ptratio, b, lstat, prediction, pipeline_version
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
    """
    execute_query(query, row)


def convert_item_to_df(item: Item) ->pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]
    return pd.DataFrame(items)

import pandas as pd
from utils.utils import execute_query
from models.item_model import Item


def get_latest_ml_pipeline_version() ->str:
    """Get the latest version of the pipeline from the DB."""
    return execute_query(
        """
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    """
        )[0][0]


def save_ml_pipeline_version(model_version: str) ->None:
    """Save the new version of the pipeline to the DB."""
    execute_query('INSERT INTO ml_pipeline (pipeline_version) VALUES(%s)',
        (model_version,))


async def save_prediction(row: list) ->None:
    """Save features + prediction + pipeline version."""
    query = """
INSERT INTO predictions (
crim, zn, indus, chas, nox, rm, age, dis, rad, tax, ptratio, b, lstat, prediction, pipeline_version
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
    """
    execute_query(query, row)


def convert_item_to_df(item: Item) ->pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]
    return pd.DataFrame(items)

import pandas as pd

from utils.utils import execute_query
from models.item_model import Item


def get_latest_ml_pipeline_version() -> str:
    """Get the latest version of the pipeline from the DB."""

    return execute_query('''
        SELECT pipeline_version
        FROM ml_pipeline
        ORDER BY created_at DESC
        LIMIT 1
    ''')[0][0]


def save_ml_pipeline_version(model_version: str) -> None:
    """Save the new version of the pipeline to the DB."""
    execute_query('INSERT INTO ml_pipeline (pipeline_version) VALUES(%s)', (model_version,))


async def save_prediction(row: list) -> None:
    """Save features + prediction + pipeline version."""
    query = '''
INSERT INTO predictions (
crim, zn, indus, chas, nox, rm, age, dis, rad, tax, ptratio, b, lstat, prediction, pipeline_version
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
    '''
    execute_query(query, row)


def convert_item_to_df(item: Item) -> pd.DataFrame:
    """Convert Item to the pandas DataFrame"""
    items = {}
    for key, value in item.dict().items():
        items[key] = [value]

    return pd.DataFrame(items)
