<commit_before>from flask import Flask, jsonify

server = Flask(__name__)


def get_relays(relays):
    return jsonify({"relays": relays}), 200


def get_relay(relays, relay_name):
    code = 200
    try:
        relay = relays[relay_name]
    except KeyError:
        code = 404
        return "", code

    return jsonify({"relay": relay}), code<commit_msg>Change to get a dict with the relay instances<commit_after>from flask import Flask, jsonify
# import json

server = Flask(__name__)


def __serialize_relay(relays):
    if type(relays).__name__ == "relay":
        return jsonify({"gpio": relays.gpio,
                           "NC": relays.nc,
                           "state": relays.state})
    di = {}
    for r in relays:
        di[r] = {"gpio": relays[r].gpio,
                 "NC": relays[r].nc,
                 "state": relays[r].state}
    return jsonify(di)


def get_relays(relays_dict):
    return __serialize_relay(relays_dict), 200


def get_relay(relay):
    code = 200
    if not relay:
        code = 404
        return "", code
    return __serialize_relay(relay), code
{'fraction_non_alphanumeric': 0.11444141689373297, 'fraction_numerical': 0.01634877384196185, 'mean_word_length': 2.422360248447205, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '3359425', 'n_tokens_mistral': 378, 'n_tokens_neox': 352, 'n_words': 92}