Update utils_gdmk.py
Browse files- utils_gdmk.py +12 -59
utils_gdmk.py
CHANGED
|
@@ -18,78 +18,31 @@ headers = {
|
|
| 18 |
"Content-Type": "application/json"
|
| 19 |
}
|
| 20 |
|
| 21 |
-
def cargar_normativas():
|
| 22 |
-
with open('normativas.json', 'r', encoding='utf-8') as f:
|
| 23 |
-
return json.load(f)
|
| 24 |
-
|
| 25 |
-
def cargar_estudiantes():
|
| 26 |
-
with open('estudiantes.json', 'r', encoding='utf-8') as f:
|
| 27 |
-
return json.load(f)
|
| 28 |
-
|
| 29 |
-
def crear_html(normativa):
|
| 30 |
-
return f"""
|
| 31 |
-
<div style="padding: 16px; border: 1px solid #ddd; border-radius: 8px;">
|
| 32 |
-
<h2>{normativa["nombre"]}</h2>
|
| 33 |
-
<h3>{normativa["titulo"]} ({normativa["a帽o"]})</h3>
|
| 34 |
-
<p><strong>ID:</strong> {normativa["id"]}</p>
|
| 35 |
-
<p><strong>Descripci贸n:</strong> {normativa["descripcion"]}</p>
|
| 36 |
-
<p><strong>Enfoque de Gesti贸n:</strong> {normativa["enfoque_riesgo"]}</p>
|
| 37 |
-
<p><strong>Opini贸n Docente:</strong> {normativa["opinion_docente"]}</p>
|
| 38 |
-
<p><strong>M谩s informaci贸n: <a href='{normativa["url"]}' target='_blank'>Sitio Web</a></strong></p>
|
| 39 |
-
</div>
|
| 40 |
-
"""
|
| 41 |
-
|
| 42 |
-
def mostrar_detalles(normativa_seleccionada):
|
| 43 |
-
if not normativa_seleccionada:
|
| 44 |
-
return "<p>Por favor selecciona una normativa</p>", ""
|
| 45 |
-
|
| 46 |
-
normativas = cargar_normativas()
|
| 47 |
-
id_normativa = normativa_seleccionada
|
| 48 |
-
|
| 49 |
-
for normativa in normativas["normativa_peruana_gestion_riesgos"]:
|
| 50 |
-
if id_normativa == normativa['nombre']:
|
| 51 |
-
return crear_html(normativa), normativa["nombre"]
|
| 52 |
-
|
| 53 |
-
return "<p>No se encontr贸 la normativa</p>", ""
|
| 54 |
-
|
| 55 |
def cargar_desde_airtable():
|
| 56 |
response = requests.get(url, headers=headers)
|
| 57 |
|
| 58 |
if response.status_code != 200:
|
| 59 |
print(f"Error: {response.status_code} - {response.text}")
|
| 60 |
-
return pd.DataFrame(columns=["Nombre", "
|
| 61 |
-
|
| 62 |
records = response.json().get("records", [])
|
| 63 |
-
|
| 64 |
aportes = [
|
| 65 |
[record["fields"].get("Nombre", ""),
|
| 66 |
-
record["fields"].get("
|
| 67 |
-
record["fields"].get("Norma", ""),
|
| 68 |
-
record["fields"].get("Texto_HF", "")] for record in records
|
| 69 |
]
|
| 70 |
-
|
| 71 |
-
return pd.DataFrame(aportes, columns=["Nombre", "Enfoque", "Norma", "Texto_HF"])
|
| 72 |
-
|
| 73 |
-
def wrap_text(text, width=10):
|
| 74 |
-
return "\n".join(textwrap.wrap(text, width=width))
|
| 75 |
|
| 76 |
def inicializar_grafo():
|
| 77 |
df = cargar_desde_airtable()
|
| 78 |
-
|
| 79 |
-
G.add_node("Determinista", color='red')
|
| 80 |
-
G.add_node("Sist茅mico", color='blue')
|
| 81 |
-
|
| 82 |
for _, row in df.iterrows():
|
| 83 |
-
nombre,
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
G.
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
data = {"fields": {"Nombre": nombre, "Enfoque": enfoque, "Norma": norma, "Texto_HF": texto}}
|
| 93 |
requests.post(url, headers=headers, json=data)
|
| 94 |
|
| 95 |
def agregar_aporte(nombre, enfoque, norma, texto):
|
|
|
|
| 18 |
"Content-Type": "application/json"
|
| 19 |
}
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def cargar_desde_airtable():
|
| 22 |
response = requests.get(url, headers=headers)
|
| 23 |
|
| 24 |
if response.status_code != 200:
|
| 25 |
print(f"Error: {response.status_code} - {response.text}")
|
| 26 |
+
return pd.DataFrame(columns=["Nombre", "Conceptos"])
|
|
|
|
| 27 |
records = response.json().get("records", [])
|
|
|
|
| 28 |
aportes = [
|
| 29 |
[record["fields"].get("Nombre", ""),
|
| 30 |
+
record["fields"].get("Conceptos", "")] for record in records
|
|
|
|
|
|
|
| 31 |
]
|
| 32 |
+
return pd.DataFrame(aportes, columns=["Nombre", "Conceptos"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def inicializar_grafo():
|
| 35 |
df = cargar_desde_airtable()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
for _, row in df.iterrows():
|
| 37 |
+
nombre, conceptos = row["Nombre"], row["Conceptos"]
|
| 38 |
+
for termino in conceptos:
|
| 39 |
+
if not G.has_node(termino):
|
| 40 |
+
G.add_node(termino, color='gray')
|
| 41 |
+
if not G.has_edge(nombre, termino):
|
| 42 |
+
G.add_edge(norma, enfoque)
|
| 43 |
+
|
| 44 |
+
def guardar_en_airtable(nombre, conceptos):
|
| 45 |
+
data = {"fields": {"Nombre": nombre, "Conceptos": conceptos}}
|
|
|
|
| 46 |
requests.post(url, headers=headers, json=data)
|
| 47 |
|
| 48 |
def agregar_aporte(nombre, enfoque, norma, texto):
|