<jupyter_start><jupyter_text>PC assemble production line simulation (human edition)  Initialization Import the required libraries.<jupyter_code>%matplotlib inline
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'
from modsim import *
import random
import statistics
import matplotlib.pyplot as plt
import matplotlib.lines as mlines

np.random.seed(7)<jupyter_output><empty_output><jupyter_text>Initialize the state object<jupyter_code>pcs = State(left = 0)
time = State(elapsed = 0)<jupyter_output><empty_output><jupyter_text>Initialize the TimeSeries objects<jupyter_code>assembled_pcs = TimeSeries()<jupyter_output><empty_output><jupyter_text>Declaration Declare the `random events` object<jupyter_code># Key: event name, value: probability
events = {
    'ausentismo': 0.05,
    'accidente': 0.05,
    'error': 0.15
}<jupyter_output><empty_output><jupyter_text>Declare the `randomness` function:<jupyter_code># When called, returns an array of events happened
def randomness():
    events_happened = []
    for key in events:
        if flip(events[key]):
            events_happened.append(key)
            if key == 'ausentismo':
                return events_happened
    return events_happened<jupyter_output><empty_output><jupyter_text>Declare the `assemble_pcs` function.<jupyter_code>def assemble_pcs(employees, productivity):
    total_time = 0
    for i in range(employees):
        random_events_index = 1
        # Implementation of random events
        events_happened = randomness()
        # Checks events happened
        if 'accidente' in events_happened:
            random_events_index += 0.25
        if 'error' in events_happened:
            random_events_index += 0.50
        if 'ausentismo' in events_happened:
            random_events_index = 0

        build_time = random.randint(1800, 2900)
        
        productivity_index = (1 - productivity) + 1
        total_time += build_time * productivity_index * random_events_index
    average_time = total_time / employees
    return average_time<jupyter_output><empty_output><jupyter_text>Declare the `get_productivity` function.<jupyter_code>def get_productivity(time_elapsed):
    if (time.elapsed > 10800):
        if (time.elapsed < 14400):
            return 0.8
        if (time.elapsed > 21600):
            return 0.5
    return 1.0<jupyter_output><empty_output><jupyter_text>Declare the `draw` function.<jupyter_code>def draw():
    plot(assembled_pcs, color='blue', label='Assembled pcs')

    decorate(title='Assembled pcs by persons per day',
            xlabel='Time step (work days)', 
            ylabel='Number of pcs')

    savefig('figs/chap02-fig01.pdf')<jupyter_output><empty_output><jupyter_text>Declare the `run_simulation` function.<jupyter_code>def run_simulation(employees, pc_quantity):
    pcs.left = pc_quantity
    
    time_limit = 7 * 60 * 60 # work day time in seconds

    day = 1
    while True:
        productivity = get_productivity(time.elapsed)
        assemble_time = assemble_pcs(employees, productivity)
        time.elapsed += assemble_time
        pcs.left -= employees

        if (time.elapsed >= time_limit):
            assembled_pcs[day] = pc_quantity - pcs.left
            time.elapsed = 0
            print("Day " + str(day) + ": " + str(pc_quantity - pcs.left))
            day += 1
        if (pcs.left <= 0):
            assembled_pcs[day] = pc_quantity
            print("Finished " + str(pc_quantity) + " pcs in " + str(day) + " days!")
            break
    draw()<jupyter_output><empty_output><jupyter_text>Run simulation - Employees: - Pc_quantity:<jupyter_code>run_simulation(20, 1500)<jupyter_output>Day 1: 200
Day 2: 400
Day 3: 600
Day 4: 800
Day 5: 1000
Day 6: 1200
Day 7: 1400
Finished 1500 pcs in 8 days!
Saving figure to file figs/chap02-fig01.pdf<jupyter_text>PC assemble production line simulation (machine edition)  Initialization Import the required libraries.<jupyter_code>%matplotlib inline
%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'
from modsim import *
import random
import statistics
import matplotlib.pyplot as plt
import matplotlib.lines as mlines

np.random.seed(7)<jupyter_output><empty_output><jupyter_text>Initialize the state object<jupyter_code>pcs = State(left = 0)
time = State(elapsed = 0)<jupyter_output><empty_output><jupyter_text>Initialize the TimeSeries objects<jupyter_code>assembled_pcs = TimeSeries()<jupyter_output><empty_output><jupyter_text>Declaration Declare the `assemble_pcs` function.<jupyter_code>def assemble_pcs():
    total_time = 0
    machine_parallel_processes = 18
    time = random.randint(669, 934)
    total_time = time / machine_parallel_processes
    return total_time<jupyter_output><empty_output><jupyter_text>Declare the `draw` function.<jupyter_code>def draw():
    plot(assembled_pcs, color='green', label='Assembled pcs')

    decorate(title='Assembled pcs by persons per day',
            xlabel='Time step (work days)', 
            ylabel='Number of pcs')

    savefig('figs/chap02-fig01.pdf')<jupyter_output><empty_output><jupyter_text>Declare the `run_simulation` function.<jupyter_code>def run_simulation(pc_quantity):
    pcs.left = pc_quantity
    
    time_limit = 8 * 60 * 60 # work day time in seconds

    day = 1
    while True:
        assemble_time = assemble_pcs()
        time.elapsed += assemble_time
        pcs.left -= 1

        if (time.elapsed >= time_limit):
            assembled_pcs[day] = pc_quantity - pcs.left
            time.elapsed = 0
            print("Day " + str(day) + ": " + str(pc_quantity - pcs.left))
            day += 1
            
        if (pcs.left <= 0):
            assembled_pcs[day] = pc_quantity
            print("Finished " + str(pc_quantity) + " pcs in " + str(day) + " days!")
            break
    draw()<jupyter_output><empty_output><jupyter_text>Run simulation - Pc_quantity:<jupyter_code>run_simulation(1500)<jupyter_output>Day 1: 655
Day 2: 1311
Finished 1500 pcs in 3 days!
Saving figure to file figs/chap02-fig01.pdf
{'fraction_non_alphanumeric': 0.09917081260364842, 'fraction_numerical': 0.0263681592039801, 'mean_word_length': 3.6499614494988433, 'pattern_counts': {'":': 2, '<': 70, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '545263', 'license': 'MIT', 'n_tokens_mistral': 2137, 'n_tokens_neox': 1954, 'n_words': 428, 'path': 'notebooks/human_prod_line.ipynb', 'repo_name': 'dfeliz/ModSimPy', 'size': '6030'}