From 18b0b057b322d9f350613afc4c32bcf6fba061d9 Mon Sep 17 00:00:00 2001 From: Tony Ford <tonyford@strategy-investor.de> Date: Fri, 25 Oct 2024 20:10:07 +0200 Subject: [PATCH] Datenaktualisierung optimiert --- html/_layouts/default.php | 84 ++++++++++++++++++++++++++++++++++++++- html/assets/js/script.js | 3 ++ 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/html/_layouts/default.php b/html/_layouts/default.php index de3353b..842ac34 100644 --- a/html/_layouts/default.php +++ b/html/_layouts/default.php @@ -12,6 +12,13 @@ include_once('functions/db_connect.php'); include_once('functions/db_methods.php'); if( !empty($_POST['csv']) ) $csv=$_POST['csv']; +if( !empty($_POST['p']) ){ + $PARTIEN = json_decode( $_POST['p'], true ); + //var_dump( $PARTIEN ); +} + + + $secret=''; if( !empty($csv) ){ @@ -21,6 +28,7 @@ if( !empty($csv) ){ if( $user ){ $C=preg_split('/ /',$csv); + /* if( trim($C[0]) == 'runde,spieltag,T,H,A,TH,TA,MID' ){ foreach( $C as $i=>$v ){ if( $i > 0 ) db_addErgebnisse(SAISON.','.$v,$secret); @@ -42,6 +50,77 @@ if( !empty($csv) ){ } else if( trim($C[0]) == 'SpielerID,Spieler,Alter,Nt,Saison,Liga,TeamID,Team,S,T,A,Z+,Z-,Zd,Bk,Bi+,Bi-,Attr,Face,Karriereende' ){ db_addSpieler(array_pop($C),$secret); } + */ + if( trim($C[0]) == 'runde,spieltag,T,H,A,TH,TA,MID' ){ + foreach( $C as $i=>$v ){ + if( $i > 0 ) db_addErgebnisse(SAISON.','.$v,$secret); + } + } else if( trim($C[0]) == 'Saison,Spieltag,MatchID,teamID,L,Pos,SpielerID,Spieler,Z+,Z-,T,A,Bk' ) { + $H=0; $A=0; $T=''; $runde=0; $spieltag=0; $TH=0; $TA=0; $MID=0; + $St = []; + foreach( $C as $i=>$v ){ + if( $i > 0 ) $St[]=$v; + $V = preg_split('/,/',$v); + if( $V[4] == 'H' && $V[5]*1 > 0 ){ + $TH+=$V[10]*1; + $H =$V[3]*1; + } + if( $V[4] == 'G' && $V[5]*1 > 0 ){ + $TA+=$V[10]*1; + $A =$V[3]*1; + } + $MID=$V[2]; + } + $inv = false; + $r = array_filter($PARTIEN, + function($v,$k){ + global $H; + global $A; + global $inv; + global $H_nt; + global $A_nt; + if( $v['MID']*1 == 0 && $v['H']*1 == $H && $v['A']*1 == $A ){ + $H_nt = $v['H_nt']; + $A_nt = $v['A_nt']; + return true; + } else if( $v['MID']*1 == 0 && $v['H'] == $A && $v['A'] == $H ){ + $H_nt = $v['H_nt']; + $A_nt = $v['A_nt']; + $inv = true; + return true; + } + },ARRAY_FILTER_USE_BOTH + ); + + if( sizeof($r) > 0 ){ + $r = array_values($r)[0]; + $runde = $r['runde']; + $spieltag = $r['spieltag']; + $T=$r['T']; + if( $inv == true ){ + db_addErgebnisse(implode( ',', [ SAISON, $runde, $spieltag, $T, $A_nt, $H_nt, $TA, $TH, $MID ] ), $secret); + } else { + db_addErgebnisse(implode( ',', [ SAISON, $runde, $spieltag, $T, $H_nt, $A_nt, $TH, $TA, $MID ] ), $secret); + } + + foreach( $St as $st ){ + db_addStatistik($st,$secret); + } + } + } else if( trim($C[0]) == 'TeamID,N,SpielerID,Attr,Spieler,Alter,Pos,S,T,A,Z+,Z-,Zd' ){ + $TEAMS=db_getIdNtFromTeams(); + foreach( $C as $i=>$v ){ + $w=preg_split('/,/',$v); + if( !empty($TEAMS[$w[0]]) ){ + if( $TEAMS[$w[0]] == $w[1] ){ + //db_addSpieler($v,$secret); + } + } + } + } else if( trim($C[0]) == 'SpielerID,Spieler,Alter,Nt,Saison,Liga,TeamID,Team,S,T,A,Z+,Z-,Zd,Bk,Bi+,Bi-,Attr,Face,Karriereende' ){ + db_addSpieler(array_pop($C),$secret); + } + } } @@ -331,10 +410,11 @@ if( !empty($csv) ){ </script> - <form method="POST"> + <form id="formu" method="POST"> <div id="copypaste" class="d-none" ondblclick="$(this).toggleClass('d-none')"> - <button type="submit">update</button> + <button type="button" onclick="$('#p').val(JSON.stringify( PARTIEN )); $('#formu').submit();">update</button> <input type="text" name="secret" placeholder="secret" value="<?=$secret?>"> + <input type="hidden" id="p" name="p" value=""> <textarea name="csv"></textarea> </div> </form> diff --git a/html/assets/js/script.js b/html/assets/js/script.js index 9698392..f533f9d 100644 --- a/html/assets/js/script.js +++ b/html/assets/js/script.js @@ -240,6 +240,7 @@ function calculatePartien(saison,date){ } var St=0; +var PARTIEN = []; function grpPartien( date,steps,saison,runde,spieltag,Bg ){ @@ -272,6 +273,8 @@ function grpPartien( date,steps,saison,runde,spieltag,Bg ){ if( h1 == -1 || a1 == -1 ) return; var ergebnis=ERGEBNISSE.filter( (a) => ( a.saison == saison && a.runde == runde && a.spieltag == spieltag && a.H.toLowerCase() == v[h1][0].nt.toLowerCase() && a.A.toLowerCase() == v[a1][0].nt.toLowerCase() ) ); + if( v[h1][0].id != undefined ) PARTIEN.push({ 'T' : new Date(date).toJSON().slice(0,10), 'runde' : runde, 'spieltag' : spieltag, 'H' : v[h1][0].id, 'H_nt' : v[h1][0].nt, 'A' : v[a1][0].id, 'A_nt' : v[a1][0].nt, 'MID' : ergebnis.length == 1 ? ergebnis[0].MID : 0 }); + if( ergebnis.length == 1 ){ ergebnis=ergebnis[0]; -- GitLab