Untitled

mail@pastecode.io avatar
unknown
python
16 days ago
13 kB
7
Indexable
Never
import csv
from datetime import datetime


# Kalkulator wyceny prac
def calculate_cost(worker_name, job_type, sqm):
    worker = next(worker for worker in workers if worker["name"] == worker_name)
    job = worker["jobs"][job_type]
    if job["sqm_rate"] is not None:
        cost = job["sqm_rate"] * sqm
    else:
        raise ValueError(f"Job {job_type} does not have an associated sqm rate.")
    return cost


# Kalkulator czasu wykonania
def calculate_time(worker_name, job_type, sqm):
    worker = next(worker for worker in workers if worker["name"] == worker_name)
    job = worker["jobs"][job_type]
    if job["time_per_sqm"] is not None:
        time = job["time_per_sqm"] * sqm
    else:
        raise ValueError(f"Job {job_type} does not have an associated time per sqm.")
    return time


# Automatyczne przypisanie pracownika
def assign_worker(job_type):
    available_workers = [worker for worker in workers if job_type in worker["jobs"]]
    if not available_workers:
        raise ValueError(f"No workers available for job {job_type}.")
    return available_workers[0]["name"]


# Generowanie wyceny
def generate_quote(job_type, sqm):
    worker_name = assign_worker(job_type)
    cost = calculate_cost(worker_name, job_type, sqm)
    time = calculate_time(worker_name, job_type, sqm)
    quote = {
        "worker": worker_name,
        "job_type": job_type,
        "sqm": sqm,
        "cost": cost,
        "time": time,
        "timestamp": datetime.now().isoformat()
    }
    return quote


# Zapis historii wycen
def save_quote_history(quote):
    with open('quote_history.csv', 'a', newline='') as file:
        writer = csv.writer(file)
        writer.writerow(
            [quote["timestamp"], quote["worker"], quote["job_type"], quote["sqm"], quote["cost"], quote["time"]])


# Analiza i raporty
def generate_report():
    try:
        with open('quote_history.csv', 'r') as file:
            reader = csv.reader(file)
            next(reader, None)  # Skip header if it exists
            total_cost = 0
            total_time = 0
            count = 0
            for row in reader:
                total_cost += float(row[4])
                total_time += float(row[5])
                count += 1

            if count == 0:
                return {"message": "No data available for report."}

            average_cost = total_cost / count
            average_time = total_time / count
            report = {
                "total_quotes": count,
                "total_cost": total_cost,
                "total_time": total_time,
                "average_cost": average_cost,
                "average_time": average_time
            }
    except FileNotFoundError:
        return {"message": "No quote history file found."}
    return report


if __name__ == "__main__":
    # Pracownicy i ich dane
    workers = [
        {"name": "Zdzisław", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 3},
                                      "Malowanie": {"hourly_rate": 50, "sqm_rate": 40, "time_per_sqm": 3},
                                      "Prace ziemne": {"hourly_rate": 50, "sqm_rate": 50, "time_per_sqm": 2},
                                      "Prace elektryczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                                      "Prace hydrauliczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                                      "Składanie mebli": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                      "Sprzątanie": {"hourly_rate": 40, "sqm_rate": 30, "time_per_sqm": 1},
                                      "Transport materiału": {"hourly_rate": 40, "sqm_rate": None, "time_per_sqm": 2},
                                      "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 10, "time_per_sqm": 2},
                                      "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 50, "time_per_sqm": 4},
                                      "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                      "Montaż elementów": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": 3},
                                      "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 2}}},
        {"name": "Andrzej", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 3},
                                     "Malowanie": {"hourly_rate": 50, "sqm_rate": 40, "time_per_sqm": 3},
                                     "Tapetowanie": {"hourly_rate": 50, "sqm_rate": 40, "time_per_sqm": 3},
                                     "Prace elektryczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                                     "Prace hydrauliczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                                     "Składanie kuchni": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                     "Sprzątanie": {"hourly_rate": 40, "sqm_rate": 30, "time_per_sqm": 1},
                                     "Transport materiału": {"hourly_rate": 40, "sqm_rate": None, "time_per_sqm": None},
                                     "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 10, "time_per_sqm": 2},
                                     "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 50, "time_per_sqm": 3},
                                     "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": 2},
                                     "Prace zewnętrzne": {"hourly_rate": 40, "sqm_rate": 40, "time_per_sqm": 4},
                                     "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                     "Odbiory łazienek": {"hourly_rate": 1000, "sqm_rate": None, "time_per_sqm": 1}}},
        {"name": "Bartosz", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 3},
                                     "wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                     "Malowanie": {"hourly_rate": 50, "sqm_rate": 30, "time_per_sqm": 3},
                                     "Składanie mebli": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": None},
                                     "Specjalistyczne prace związane z rozbiórką i transportem": {"hourly_rate": 40,
                                                                                                  "sqm_rate": 40,
                                                                                                  "time_per_sqm": 3},
                                     "Transport materiału": {"hourly_rate": 40, "sqm_rate": None, "time_per_sqm": None},
                                     "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 50, "time_per_sqm": 3},
                                     "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 70, "time_per_sqm": 6},
                                     "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None}}},
        {"name": "Bartłomiej", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 3},
                                        "Prace ziemne": {"hourly_rate": 40, "sqm_rate": 40, "time_per_sqm": None},
                                        "Składanie mebli": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": None},
                                        "Sprzątanie": {"hourly_rate": 40, "sqm_rate": 30, "time_per_sqm": 1},
                                        "Transport materiału": {"hourly_rate": 40, "sqm_rate": None,
                                                                "time_per_sqm": None},
                                        "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 50,
                                                                    "time_per_sqm": 3},
                                        "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 70, "time_per_sqm": 6},
                                        "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None},
                                        "Montaż elementów": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None},
                                        "Prace zewnętrzne": {"hourly_rate": 40, "sqm_rate": 40, "time_per_sqm": None},
                                        "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 6}}},
        {"name": "Bogdan",
         "jobs": {"Nadzór nad pracami budowlanymi": {"hourly_rate": 500, "sqm_rate": None, "time_per_sqm": None},
                  "Prace elektryczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                  "Prace hydrauliczne": {"hourly_rate": 60, "sqm_rate": None, "time_per_sqm": None},
                  "Prace dachowe": {"hourly_rate": 50, "sqm_rate": 40, "time_per_sqm": 6}}},
        {"name": "Kazimierz", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 6},
                                       "Malowanie": {"hourly_rate": 50, "sqm_rate": 40, "time_per_sqm": 3},
                                       "Składanie mebli": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": None},
                                       "Sprzątanie": {"hourly_rate": 40, "sqm_rate": 40, "time_per_sqm": 1},
                                       "Transport materiału": {"hourly_rate": 40, "sqm_rate": None,
                                                               "time_per_sqm": None},
                                       "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 50,
                                                                   "time_per_sqm": 3},
                                       "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 70, "time_per_sqm": 6},
                                       "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None},
                                       "Montaż elementów": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None},
                                       "Prace zewnętrzne": {"hourly_rate": 40, "sqm_rate": None, "time_per_sqm": None},
                                       "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3}}},
        {"name": "Cezary", "jobs": {"Murowanie": {"hourly_rate": 50, "sqm_rate": 100, "time_per_sqm": 3},
                                    "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 3},
                                    "Malowanie": {"hourly_rate": 50, "sqm_rate": 30, "time_per_sqm": 3},
                                    "Składanie mebli": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": None},
                                    "Specjalistyczne prace związane z rozbiórką i transportem": {"hourly_rate": 40,
                                                                                                 "sqm_rate": 40,
                                                                                                 "time_per_sqm": 3},
                                    "Specjalistyczne prace sprzątające": {"hourly_rate": 40, "sqm_rate": 40,
                                                                          "time_per_sqm": None},
                                    "Transport materiału": {"hourly_rate": 40, "sqm_rate": None, "time_per_sqm": None},
                                    "Rozkładanie rusztowania": {"hourly_rate": 50, "sqm_rate": 50, "time_per_sqm": 3},
                                    "Układanie płytek": {"hourly_rate": 60, "sqm_rate": 70, "time_per_sqm": 6},
                                    "Prace stolarskie": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": 3},
                                    "Montaż elementów": {"hourly_rate": 50, "sqm_rate": None, "time_per_sqm": None},
                                    "Wylewanie betonu": {"hourly_rate": 50, "sqm_rate": 70, "time_per_sqm": 6}}}
    ]

    # Przykład użycia
    try:
        quote = generate_quote("Murowanie", 10)
        save_quote_history(quote)
        print("Wygenerowana wycena:", quote)
        report = generate_report()
        print("Raport:", report)
    except ValueError as e:
        print("Error:", e)
Leave a Comment