Beispiel #1
0
def get_data():
    if len(request.args["from"]) < 10 or len(request.args["to"]) < 10:
        return "date must have following format: 'yyyy-mm-dd'"

    statistics.update("data_calls")

    database = Database()
    result = database.get_data(request.args["from"], request.args["to"])

    compressed = False
    if "compressed" in request.args.keys():
        compressed = True

    fetched_data = {}
    row_count = 0
    last_date = 0

    for row in result:
        row["weight"] = row["weight"] - config.tare[0]

        for i in range(1, len(row.keys())):
            if str(i) in row.keys() and row[str(i)] is not None:
                if i in config.tare.keys():
                    row[str(i)] = row[str(i)] - config.tare[i]
                else:
                    row[str(i)] = row[str(i)] - config.tare[0]

        fetched_data[row_count] = row

        row_count += 1

    if compressed == True:
        compressed_data = []

        # All values for one day (for later calculating average value)
        temp = []
        weight = []
        humidity = []

        last_date = 0
        for row in fetched_data:
            if last_date == 0:
                last_date = fetched_data[row]["measured"].date()

            if last_date == fetched_data[row]["measured"].date():
                temp.append(fetched_data[row]["temperature"])
                weight.append(fetched_data[row]["weight"])
                humidity.append(fetched_data[row]["humidity"])
            else:
                # Get an average int of all ints in array
                temp_avg = sum(temp) / len(temp)
                weight_avg = sum(weight) / len(weight)
                humidity_avg = sum(humidity) / len(humidity)

                # Clear all arrays for next day
                temp.clear()
                weight.clear()
                humidity.clear()

                # Append average value for day to compressed_data array
                compressed_data.append({
                    "temperature": round(temp_avg, 2),
                    "weight": round(weight_avg, 2),
                    "humidity": round(humidity_avg, 2),
                    "measured": last_date
                })
                last_date = fetched_data[row]["measured"].date()

        return jsonify(compressed_data)

    return jsonify(fetched_data)
Beispiel #2
0
def getData():
    statistics.update("data_calls")
    return get_data.get_data(request.args)
Beispiel #3
0
def mainPage():
    statistics.update("website")
    return render_template("index.html")
Beispiel #4
0
def insertData():
    statistics.update("insert_calls")
    return insert_data.insert_data(request.args)
Beispiel #5
0
def dashboard():
    statistics.update("website")
    return render_template("index.html", pages=config.embedded_pages)
Beispiel #6
0
def define_production_statistics(parameters):
    """
    Statistik-Arrays for performance evaluation
    """
    statistics = dict()
    stat_episode = dict()

    statistics.update({
        'stat_machines_working':
        np.array([0.0] * parameters['NUM_MACHINES'])
    })
    statistics.update(
        {'stat_machines_broken': np.array([0.0] * parameters['NUM_MACHINES'])})
    statistics.update(
        {'stat_machines_idle': np.array([0.0] * parameters['NUM_MACHINES'])})
    statistics.update({
        'stat_machines_changeover':
        np.array([0.0] * parameters['NUM_MACHINES'])
    })
    statistics.update({
        'stat_machines_processed_orders':
        np.array([0.0] * parameters['NUM_MACHINES'])
    })
    statistics.update({
        'stat_machines': [
            statistics['stat_machines_working'],
            statistics['stat_machines_broken'],
            statistics['stat_machines_idle'],
            statistics['stat_machines_changeover']
        ]
    })

    statistics.update({
        'stat_transp_working':
        np.array([0.0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp_walking':
        np.array([0.0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp_handling':
        np.array([0.0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp_idle':
        np.array([0.0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp':
        [statistics['stat_transp_walking'], statistics['stat_transp_idle']]
    })
    statistics.update({
        'stat_transp_selected_idle':
        np.array([0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp_forced_idle':
        np.array([0] * parameters['NUM_TRANSP_AGENTS'])
    })
    statistics.update({
        'stat_transp_threshold_waiting_reached':
        np.array([0] * parameters['NUM_TRANSP_AGENTS'])
    })

    statistics.update({'stat_order_sop': defaultdict(int)})
    statistics.update({'stat_order_eop': defaultdict(int)})
    statistics.update({'stat_order_waiting': defaultdict(int)})
    statistics.update({'stat_order_processing': defaultdict(int)})
    statistics.update({'stat_order_handling': defaultdict(int)})
    statistics.update({'stat_order_leadtime': defaultdict(int)})

    statistics.update({
        'stat_order': [
            statistics['stat_order_sop'], statistics['stat_order_eop'],
            statistics['stat_order_waiting'],
            statistics['stat_order_processing'],
            statistics['stat_order_handling'],
            statistics['stat_order_leadtime']
        ]
    })

    statistics.update(
        {'stat_inv_buffer_in': np.array([0.0] * parameters['NUM_RESOURCES'])})
    statistics.update(
        {'stat_inv_buffer_out': np.array([0.0] * parameters['NUM_RESOURCES'])})
    statistics.update({
        'stat_inv_buffer_in_mean': [
            np.array([0.0] * parameters['NUM_RESOURCES']),
            np.array([0.0] * parameters['NUM_RESOURCES'])
        ]
    })
    statistics.update({
        'stat_inv_buffer_out_mean': [
            np.array([0.0] * parameters['NUM_RESOURCES']),
            np.array([0.0] * parameters['NUM_RESOURCES'])
        ]
    })
    statistics.update({
        'stat_inv':
        [statistics['stat_inv_buffer_in'], statistics['stat_inv_buffer_out']]
    })
    statistics.update({'stat_inv_episode': [[0.0, 0]]})

    statistics.update(
        {'stat_agent_reward': [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]})

    statistics.update({
        'agent_reward_log':
        open(parameters['PATH_TIME'] + "_agent_reward_log.txt", "w")
    })
    statistics.update({
        'episode_log':
        open(parameters['PATH_TIME'] + "_episode_log.txt", "w")
    })
    statistics.update({
        'episode_statistics': [
            'stat_machines_working', 'stat_machines_changeover',
            'stat_machines_broken', 'stat_machines_idle',
            'stat_machines_processed_orders', 'stat_transp_working',
            'stat_transp_walking', 'stat_transp_handling', 'stat_transp_idle'
        ]
    })

    statistics.update({'sim_start_time': ""})
    statistics.update({'sim_end_time': ""})

    statistics.update({'stat_prefilled_orders': ""})

    # Episode KPI Logger
    statistics.update({
        'episode_log_header': [
            'episode_counter', 'sim_step', 'sim_time', 'dt', 'dt_real_time',
            'valid_actions', 'total_reward', 'machines_working',
            'machines_changeover', 'machines_broken', 'machines_idle',
            'processed_orders', 'transp_working', 'transp_walking',
            'transp_handling', 'transp_idle', 'machines_total',
            'selected_idle', 'forced_idle', 'threshold_waiting',
            'finished_orders', 'order_waiting_time', 'alpha', 'inventory'
        ]
    })
    string = ""
    for x in statistics['episode_log_header']:
        string = string + x + ","
    string = string[:-1]
    statistics['episode_log'].write("%s\n" % (string))

    # Reward Agent Logger
    string = "episode,sim_step,sim_time,action,reward,action_valid,state"
    statistics['agent_reward_log'].write("%s\n" % (string))
    statistics['agent_reward_log'].close()

    # Temp statistics
    for stat in statistics['episode_statistics']:
        stat_episode.update({stat: np.array([0.0] * len(statistics[stat]))})

    statistics.update({'orders_done': deque()})

    return statistics, stat_episode