FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Comparar matrices, arreglos
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM

Comparar matrices, arreglos

Posted: Tue Aug 27, 2024 11:07 PM

Saludos fivewiners

Al Grano.

Recibo informacion de 3 turnos por dia en una empresa, para 4 procesos productivos

-------------1 Turno ----- 2 Turno ------- 3 Turno

Cepillado---- 25 ------------ 36 ------------ 30

Corte------- 20 ------------ 32 ------------ 28

Ensamble--- 18 ------------ 28 ------------ 27

Despacho-- 16 ------------ 24 ------------ 25

Todo en metros cubicos. Un informe diario. Debo comparar los dias en cuanto a turno y proceso, todos los informes del mes en algun momento los tengo en arreglos.

Hay alguna forma de comparar estos arreglos entre dias del mes.

Que dias fueron muy iguales, cuales muy distintos, que mezcla de turno y proceso vario mas.

Algo asi como EQUALS() de java

Cualquier ayuda sera bienvenida, podria darme el trabajo de iteracion repetitiva, pero si alguien tiene alguna idea distinta la considerare.

Desde Chile,

Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Comparar matrices, arreglos

Posted: Wed Aug 28, 2024 03:06 PM
Estimado Adolfo,

Le he preguntado a Claude ya que lo id贸neo es comenzar con el an谩lisis de la IA:
Code (fw): Select all Collapse
#include "hbclass.ch"

CREATE CLASS InformeProduccion
聽 聽VAR fecha
聽 聽VAR datos

聽 聽METHOD New(cFecha, aDatos)
聽 聽METHOD Equals(oOtro)
聽 聽METHOD Diferencia(oOtro)
ENDCLASS

METHOD New(cFecha, aDatos) CLASS InformeProduccion
聽 聽::fecha := cFecha
聽 聽::datos := aDatos
RETURN Self

METHOD Equals(oOtro) CLASS InformeProduccion
聽 聽LOCAL nI, nJ
聽 聽
聽 聽FOR nI := 1 TO Len(::datos)
聽 聽 聽 FOR nJ := 1 TO Len(::datos[nI])
聽 聽 聽 聽 聽IF ::datos[nI][nJ] != oOtro:datos[nI][nJ]
聽 聽 聽 聽 聽 聽 RETURN .F.
聽 聽 聽 聽 聽ENDIF
聽 聽 聽 NEXT
聽 聽NEXT
RETURN .T.

METHOD Diferencia(oOtro) CLASS InformeProduccion
聽 聽LOCAL nDif := 0, nI, nJ
聽 聽
聽 聽FOR nI := 1 TO Len(::datos)
聽 聽 聽 FOR nJ := 1 TO Len(::datos[nI])
聽 聽 聽 聽 聽nDif += (::datos[nI][nJ] - oOtro:datos[nI][nJ]) ^ 2
聽 聽 聽 NEXT
聽 聽NEXT
RETURN SQRT(nDif)

FUNCTION CompararInformes(aInformes)
聽 聽LOCAL aSimilitudes := {}, aDiferencias := {}
聽 聽LOCAL nI, nJ, oInf1, oInf2, nDif
聽 聽
聽 聽FOR nI := 1 TO Len(aInformes) - 1
聽 聽 聽 oInf1 := aInformes[nI]
聽 聽 聽 FOR nJ := nI + 1 TO Len(aInformes)
聽 聽 聽 聽 聽oInf2 := aInformes[nJ]
聽 聽 聽 聽 聽IF oInf1:Equals(oInf2)
聽 聽 聽 聽 聽 聽 AAdd(aSimilitudes, {oInf1:fecha, oInf2:fecha})
聽 聽 聽 聽 聽ELSE
聽 聽 聽 聽 聽 聽 nDif := oInf1:Diferencia(oInf2)
聽 聽 聽 聽 聽 聽 AAdd(aDiferencias, {oInf1:fecha, oInf2:fecha, nDif})
聽 聽 聽 聽 聽ENDIF
聽 聽 聽 NEXT
聽 聽NEXT
RETURN {aSimilitudes, aDiferencias}

FUNCTION AnalizarVariacion(aInformes)
聽 聽LOCAL aVariacion := {}, nMaxVar := 0
聽 聽LOCAL nProceso, nTurno, nI, nJ, nK, nSum, nMedia, nVar
聽 聽LOCAL nMaxProceso := 0, nMaxTurno := 0
聽 聽
聽 聽// Inicializar array de variaci贸n
聽 聽FOR nI := 1 TO 4
聽 聽 聽 AAdd(aVariacion, Array(3))
聽 聽 聽 AFill(aVariacion[nI], 0)
聽 聽NEXT
聽 聽
聽 聽// Calcular variaci贸n para cada celda
聽 聽FOR nProceso := 1 TO 4
聽 聽 聽 FOR nTurno := 1 TO 3
聽 聽 聽 聽 聽nSum := 0
聽 聽 聽 聽 聽FOR nK := 1 TO Len(aInformes)
聽 聽 聽 聽 聽 聽 nSum += aInformes[nK]:datos[nProceso][nTurno]
聽 聽 聽 聽 聽NEXT
聽 聽 聽 聽 聽nMedia := nSum / Len(aInformes)
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽nVar := 0
聽 聽 聽 聽 聽FOR nK := 1 TO Len(aInformes)
聽 聽 聽 聽 聽 聽 nVar += (aInformes[nK]:datos[nProceso][nTurno] - nMedia) ^ 2
聽 聽 聽 聽 聽NEXT
聽 聽 聽 聽 聽nVar := nVar / Len(aInformes)
聽 聽 聽 聽 聽aVariacion[nProceso][nTurno] := SQRT(nVar)
聽 聽 聽 聽 聽
聽 聽 聽 聽 聽IF aVariacion[nProceso][nTurno] > nMaxVar
聽 聽 聽 聽 聽 聽 nMaxVar := aVariacion[nProceso][nTurno]
聽 聽 聽 聽 聽 聽 nMaxProceso := nProceso
聽 聽 聽 聽 聽 聽 nMaxTurno := nTurno
聽 聽 聽 聽 聽ENDIF
聽 聽 聽 NEXT
聽 聽NEXT
RETURN {nMaxProceso, nMaxTurno}

PROCEDURE Main()
聽 聽LOCAL aInformes := {}
聽 聽LOCAL aSimilitudes, aDiferencias, aMaxVar
聽 聽
聽 聽// Crear informes de ejemplo
聽 聽AAdd(aInformes, InformeProduccion():New("2024-08-01", ;
聽 聽 聽 {{25, 36, 30}, ;
聽 聽 聽 聽{20, 32, 28}, ;
聽 聽 聽 聽{18, 28, 27}, ;
聽 聽 聽 聽{16, 24, 25}}))
聽 聽
聽 聽AAdd(aInformes, InformeProduccion():New("2024-08-02", ;
聽 聽 聽 {{24, 35, 31}, ;
聽 聽 聽 聽{21, 33, 27}, ;
聽 聽 聽 聽{19, 29, 26}, ;
聽 聽 聽 聽{17, 25, 24}}))
聽 聽
聽 聽// Comparar informes
聽 聽aSimilitudes := CompararInformes(aInformes)[1]
聽 聽aDiferencias := CompararInformes(aInformes)[2]
聽 聽
聽 聽// Mostrar resultados
聽 聽? "Informes id茅nticos:"
聽 聽AEval(aSimilitudes, {|x| QOut(x[1] + " y " + x[2])})
聽 聽
聽 聽? "Diferencias entre informes:"
聽 聽AEval(aDiferencias, {|x| QOut(x[1] + " y " + x[2] + ": " + AllTrim(Str(x[3])))})
聽 聽
聽 聽// Analizar variaci贸n
聽 聽aMaxVar := AnalizarVariacion(aInformes)
聽 聽? "La mayor variaci贸n ocurri贸 en el proceso " + AllTrim(Str(aMaxVar[1])) + ;
聽 聽 聽" y turno " + AllTrim(Str(aMaxVar[2]))
聽 聽
RETURN
Definimos una clase InformeProduccion que representa un informe diario de producci贸n.
Implementamos m茅todos Equals() y Diferencia() en la clase para comparar informes.
La funci贸n CompararInformes() compara todos los pares de informes, identificando los id茅nticos y calculando las diferencias.
La funci贸n AnalizarVariacion() encuentra qu茅 combinaci贸n de proceso y turno vari贸 m谩s a lo largo del per铆odo.
En la funci贸n Main(), creamos algunos informes de ejemplo y mostramos c贸mo usar las funciones de comparaci贸n y an谩lisis.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Comparar matrices, arreglos

Posted: Wed Aug 28, 2024 03:14 PM
Tambi茅n le he preguntado acerca de cual ser铆a la forma de compararlos visualmente y directamente ha construido esto:
Puedes pedirle el c贸digo en HTML con lo que lo podr铆as visualizar usando la clase TWebView2

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM

Re: Comparar matrices, arreglos

Posted: Wed Aug 28, 2024 08:25 PM

Muchisimas gracias Antonio

Le meto prueba y codigo y te comento como me va

Saludos desde Chile

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650

Continue the discussion