import logging

from app.service.design_fast.utils.redis_utils import Redis

logger = logging.getLogger(__name__)


def update_progress(process_id, total):
    # logger.info(f"{process_id} , {total}")
    r = Redis()
    progress = r.read(key=process_id)
    if progress and total != 1:
        if int(progress) <= 100:
            r.write(key=process_id, value=int(progress) + int(100 / total))
        else:
            r.write(key=process_id, value=99)
        return progress
    elif total == 1:
        r.write(key=process_id, value=100)
        return progress
    else:
        r.write(key=process_id, value=int(100 / total))
    return progress


def final_progress(process_id):
    r = Redis()
    progress = r.read(key=process_id)
    r.write(key=process_id, value=100)
    return progress
