faraz.yashar Posted January 15, 2007 Share Posted January 15, 2007 I have two text files CALC1.txt and CALC2.txtThe both resemble the following:CALC1[code]Florida Mu Alpha Theta Math Competition 01/13/07Jan. 13, 2007 Buchholz Regional page 1CALCULUS Individual Scores Report BR # # NoPlace ID # Student Name School Name CNT Crct Wrng Ans Score----- ------- ------------------- ----------------- ---- ---- ---- ---- ------- 1 2805133 LIM SAM EASTSIDE 0 30 0 0 120 2 2505101 JOHNS JEREMY PAXON 0 29 1 0 115 3 2955155 HO BRENT BUCHHOLZ 0 27 2 1 106 4 1815164 LIU GAKU LAWTON CHILES HI 0 27 2 1 106 5 1815180 WANG ROLAND LAWTON CHILES HI 0 27 3 0 105 6 2805160 BANASZEK MICHAEL EASTSIDE 0 26 3 1 101 7 2965137 Lu JUSTIN STANTON PREP A 0 25 5 0 95 8 2955137 JIA DAVID BUCHHOLZ 1 24 3 3 93 9 2965135 PERERA CHRIS STANTON PREP A 0 24 3 3 93 10 7675176 OKASHA SAMER SPRUCE CREEK 0 24 6 0 90 11 2955148 ZHENG SUE BUCHHOLZ 0 23 4 3 88 12 2495149 WYMER DAVID OAK HALL 0 22 3 5 85 13 2955367 BUCHHOLZ 0 22 4 4 84 14 7955142 REN CHRISTINA BUCHHOLZ 0 22 4 4 84 15 7955138 LU LEI BUCHHOLZ 0 22 5 3 83 16 2965136 STANTON PREP A 0 22 6 2 82 17 2955133 CHOU VICTOR BUCHHOLZ 2 22 7 1 81 18 1815179 VU CLARA LAWTON CHILES HI 0 21 5 4 79 19 2675175 MILLER JORDAN SPRUCE CREEK HIG 0 20 2 8 78 20 6815175 SMITH PATRICK LAWTON CHILES HI 0 20 3 7 77 21 2805388 EASTSIDE 0 20 3 7 77 22 7675121 AUGAT MERIC SPRUCE CREEK 0 20 3 7 77 23 1815169 PERKO ASHLEY LAWTON CHILES HI 0 21 7 2 77 24 7685116 LUI JIANWEN GAINERVILLE 0 21 9 0 75 25 2215112 DAMIANI JASON FLAGLER PALM COA 0 20 6 4 74 26 2505102 KITTO ALEXANDER PAXON 0 18 1 11 71 27 6815177 STRUK KIM LAWTON CHILES HI 0 19 6 5 70 28 7505105 FRKETIC DAVID PAXON 0 18 2 10 70 29 2495109 FRIEDMAN DAVID OAK HALL 0 19 6 5 70 30 2675138 WILSON CHASE SPRUCE CREEK HIG 0 18 5 7 67 31 2215116 PHILLIPS ANDY FLAGLER PALM COA 0 19 10 1 66 32 6815155 DIETRICH ANN LAWTON CHILES HI 0 17 4 9 64 33 7955141 OUYANG BO BUCHHOLZ 2 18 9 3 63 34 2955371 BUCHHOLZ 0 17 5 8 63 35 2505103 CHERN ALEX PAXON 0 18 9 3 63 36 2955336 BUCHHOLZ 0 16 4 10 60 37 6815162 JAMES NOLIYANDA LAWTON CHILES HI 0 15 3 12 57 38 2495106 TUSING TIM OAK HALL 11 16 7 7 57 39 2965138 STANTON PREP A 0 15 5 10 55 40 7965141 STANTON PREP B 0 17 13 0 55 41 7685114 YU JENNIFER GAINERVILLE 1 16 10 4 54 42 7215138 LENNON DAVID FLAGLER PALM COA 0 14 3 13 53 43 1815363 LAWTON CHILES HI 5 15 8 7 52 44 7805168 JIN BOHAN EASTSIDE 0 16 12 2 52 45 1815376 LAWTON CHILES HI 0 13 3 14 49 46 2505106 COX BRAIN PAXON 0 14 7 9 49 47 2955370 BUCHHOLZ 0 13 5 12 47 48 2675136 REYNOLDS CAITLIN SPRUCE CREEK HIG 0 12 1 17 47 49 7675137 WHALEN MEGAN SPRUCE CREEK 0 12 2 16 46 50 2495392 OAK HALL 0 13 6 11 46 51 2805177 SHOCKLEY SAMANTHA EASTSIDE 3 14 11 5 45 52 7805162 CHENG DANIELLE EASTSIDE 0 13 7 10 45 Key: BBBEDDCCCBBDEBADBDDBDEBDCCEACC Florida Mu Alpha Theta Math Competition 01/13/07Jan. 13, 2007 Buchholz Regional page 2CALCULUS Individual Scores Report BR # # NoPlace ID # Student Name School Name CNT Crct Wrng Ans Score----- ------- ------------------- ----------------- ---- ---- ---- ---- ------- 53 7495151 BAUM RUDY OAK HALL 0 13 8 9 44 54 2675326 SPRUCE CREEK HIG 0 13 9 8 43 55 2675123 GAINES RYAN SPRUCE CREEK HIG 0 12 6 12 42 56 2805379 EASTSIDE 0 12 6 12 42 57 2215309 FLAGLER PALM COA 0 12 6 12 42 58 7805167 JIANG TIANYU EASTSIDE 2 13 11 6 41 59 7505104 STRICKLAND DANIEL PAXON 1 12 7 11 41 60 7955147 WU JUNE BUCHHOLZ 0 12 7 11 41 61 2985103 NEWCOMB DAVID RIDGEVIEW 0 12 11 7 37 62 7495125 FAISAL FARHA OAK HALL 0 11 7 12 37 63 7215103 NEWTON REBECCA FLAGLER PALM COA 0 11 9 10 35 64 2675328 SPRUCE CREEK HIG 9 11 9 10 35 65 2215135 WILSON HEATHER FLAGLER PALM COA 3 10 6 14 34 66 2955330 BUCHHOLZ 0 10 6 14 34 67 2985101 BUSSE JON RIDGEVIEW 0 11 10 9 34 68 2685117 GORDON LEE GAINESVILLE 0 10 8 12 32 69 2955339 BUCHHOLZ 0 10 8 12 32 70 7495108 WANNENWETSCH JARED OAK HALL 0 11 12 7 32 71 7965139 STANTON PREP B 0 9 6 15 30 72 7805175 SHAO DI EASTSIDE 0 12 18 0 30 73 2675327 SPRUCE CREEK HIG 0 12 18 0 30 74 7495191 OAK HALL 1 10 10 10 30 75 2215322 FLAGLER PALM COA 0 10 11 9 29 76 7675132 ALPERT GRAIG SPRUCE CREEK 1 9 8 13 28 77 2495385 OAK HALL 0 10 12 8 28 78 2685113 VO DAT GAINESVILLE 0 9 9 12 27 79 2525129 BADANOWSKI MARK BOLLES SCHOOL 0 9 9 12 27 80 7965147 YU NINA STANTON PREP B 0 11 19 0 25 81 2495107 MANSFIELD SCOTT OAK HALL 0 11 19 0 25 82 2175114 AN PATRICK WEST PORT HIGH 0 11 19 0 25 83 2495328 OAK HALL 1 7 5 18 23 84 2215136 PARKS ALISON FLAGLER PALM COA 0 6 2 22 22 85 2495327 OAK HALL 0 7 6 17 22 86 2175115 MITCHELL BRYAN WEST PORT HIGH 0 9 14 7 22 87 7805364 EASTSIDE 0 8 12 10 20 88 2685115 YOZGAT MATTHEW GAINESVILLE 0 7 9 14 19 89 2805172 PENG MAGGIE EASTSIDE 0 6 5 19 19 90 7215105 CHEBAN LYUDMILA FLAGLER PALM COA 0 6 8 16 16 91 2945102 BRADFORD DEIRDRE TRINITY CATHOLIC 0 9 21 0 15 92 2175113 BADAL SANTUSCHA WEST PORT HIGH 0 6 10 14 14 93 2495326 OAK HALL 1 3 2 25 10 94 7215113 IDICA JENNIFER FLAGLER PALM COA 0 4 7 19 9 95 2495324 OAK HALL 1 3 3 24 9 96 2175116 LARROQUE MICHAEL WEST PORT HIGH 0 5 14 11 6 97 2215324 FLAGLER PALM COA 0 3 7 20 5 98 2215308 FLAGLER PALM COA 0 2 6 22 2 99 2495383 OAK HALL 2 2 7 21 1100 2945113 RAMIREZ JESSICA TRINITY CATHOLIC 0 6 24 0 0101 2495384 OAK HALL 0 1 8 21 -4102 2945114 SPINELLI ANGELA TRINITY CATHOLIC 0 3 20 7 -8 Key: BBBEDDCCCBBDEBADBDDBDEBDCCEACC [/code]CALC2[code]Florida Mu Alpha Theta Math Competition 01/14/07Florida Atlantic University Jan 13,2007 page 1CALCULUS Individual Scores Report BR # # NoPlace ID # Student Name School Name CNT Crct Wrng Ans Score----- ------- ------------------- ----------------- ---- ---- ---- ---- ------- 1 5885166 RAGHUNANDAN ANEESH CYPRESS BAY HIGH 0 30 0 0 120 2 5825132 CRAVERO WALTER MIAMI SPRINGS SR 0 29 1 0 115 3 5825126 BUSTOS JUAN MIAMI SPRINGS SR 0 28 2 0 110 4 5335107 CURREN DARREL JP TARAVELLA 0 28 2 0 110 5 5325113 NUNEZ MARCEL STONEMAN DOUGLAS 0 28 2 0 110 6 5885136 CHEKMASOVA SVETLANA CYPRESS BAY HIGH 0 27 2 1 106 7 5415179 YANG RUI MIAMI PALMETTO S 0 27 3 0 105 8 5065121 REGALADO CHRISTIAN AMERICAN HERITAG 0 26 1 3 103 9 5885168 ROTTARO GIULIO CYPRESS BAY HIGH 0 26 2 2 102 10 5355100 ARES LUIS BELEN JESUIT PRE 0 26 3 1 101 11 3575369 IORDANOV RUMEN ATLANTIC COMMUNI 0 26 4 0 100 12 5285183 WESTERDALE SHAWN CORAL GLADES 0 26 4 0 100 13 5825144 FIGUEREDO OSMEL MIAMI SPRINGS SR 0 25 5 0 95 14 5065129 ZHAO MICHAEL AMERICAN HERITAG 0 25 5 0 95 15 5325101 BABCHICK ELLIOT STONEMAN DOUGLAS 0 24 2 4 94 16 5065123 ROBINSON KYLE AMERICAN HERITAG 0 24 3 3 93 17 5415153 BRONSON STEVEN MIAMI PALMETTO S 2 24 3 3 93 18 5355104 CABAL-UGAZ JOSE BELEN JESUIT PRE 0 24 3 3 93 19 5885350 HUANG SIDA CYPRESS BAY HIGH 1 24 5 1 91 20 3575327 LING GEORGE CB ATLANTIC COMMUNI 7 24 5 1 91 21 3575310 SHANKAR NIKHIL ATLANTIC COMMUNI 0 23 3 4 89 22 5165325 SPATZ BRANDON CARDINAL GIBBONS 0 23 4 3 88 23 5885346 GUTERMUTH LISA CYPRESS BAY HIGH 0 23 4 3 88 24 5325122 LAM KEVIN STONEMAN DOUGLAS 0 22 1 7 87 25 5335123 MEHTA AMBAR JP TARAVELLA 1 23 5 2 87 26 5775330 PARIKH UJAS DEERFIELD BEACH 0 22 1 7 87 27 5885357 KREAFLE CAROLINE CYPRESS BAY HIGH 1 22 3 5 85 28 5775144 THOMAS BEN DEERFIELD BEACH 9 23 7 0 85 29 5455113 MCSHEA SKIPPER NAPLES 0 21 1 8 83 30 5625122 DEJONG GABE COMMUNITY SCHOOL 0 21 2 7 82 31 3575334 JIN SHELLY ATLANTIC COMMUNI 0 21 3 6 81 32 5415369 LIU CUI MIAMI PALMETTO S 0 22 7 1 81 33 5915117 CRAMER LUKE CW FLANAGAN 0 21 4 5 80 34 3575113 KAMALOV ANDREI ATLANTIC COMMUNI 0 22 8 0 80 35 5325111 MIAO WILL STONEMAN DOUGLAS 0 20 2 8 78 36 5065118 NASIRULLAH HASIB AMERICAN HERITAG 0 19 1 10 75 37 5455306 FERNANDEZ ALEX NAPLES 0 20 5 5 75 38 5775107 DRAPER JORDAN DEERFIELD BEACH 0 20 5 5 75 39 3575132 KAPLAN LASER ATLANTIC COMMUNI 0 20 7 3 73 40 5335129 ROSENBAUM ANDY JP TARAVELLA 0 20 8 2 72 41 3575148 CHEN YIMIN ATLANTIC COMMUNI 0 19 4 7 72 42 5455115 TAI CHIA-HUNG NAPLES 0 19 4 7 72 43 5885370 SANCHEZ CARLOS CYPRESS BAY HIGH 0 19 5 6 71 44 5305104 ARBALEAZ ANDRES EVERGLADES HIGH 12 18 2 10 70 Key: BBBEDDCCCBBDEBADBDDBDEBDCCEACC [/code]What I want to do is create one 3d array based on the data with the first 20 people from both lists, then sorting the array according to the scores and echoing the first 20 results.Not quite sure how to do that though.Thanks! Quote Link to comment Share on other sites More sharing options...
effigy Posted January 15, 2007 Share Posted January 15, 2007 You can use regular expressions to pull out the data; see my signature. Quote Link to comment Share on other sites More sharing options...
faraz.yashar Posted January 15, 2007 Author Share Posted January 15, 2007 I wrote a little test script:[code]<?php$file = fopen("CALC1.txt", "r");$score = fscanf($file, "%[^ ]*$");echo "$score[0] <br> $score[4]$?> [/code]Just to see how the array would act with just a space delimiter... Why aren't there any elements in the array beyond item 0? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 16, 2007 Share Posted January 16, 2007 fscanf does not take regular expressions. Try this:[code]<pre><?php $data = file_get_contents('CALC1.txt'); $pattern = '% ^\s+ ### BOL (\d+)\s+ ### Place (\d+)\s+ ### ID (\S+)\s(\S+)\s+ ### First/Last Name (\D+)\s+ ### School (\d+)\s+ ### Count (\d+)\s+ ### Correct (\d+)\s+ ### Wrong (\d+)\s+ ### No Answer (\d+)\s+ ### Score $ ### EOL %mx'; preg_match_all($pattern, $data, $matches, PREG_SET_ORDER); print_r($matches);?></pre>[/code] Quote Link to comment Share on other sites More sharing options...
faraz.yashar Posted January 16, 2007 Author Share Posted January 16, 2007 Doesn't work... just prints out the data type:[tt]Array{}[/tt] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 16, 2007 Share Posted January 16, 2007 I'm guessing that (1) you don't have error reporting on; and (2) that the file isn't opening; apparently it's not located in the same directory as your script, or there are permission problems. Please turn on error reporting (for now) via[tt] error_reporting(E_ALL); [/tt]and point[tt] file_get_contents [/tt]to the proper file. Quote Link to comment Share on other sites More sharing options...
faraz.yashar Posted January 16, 2007 Author Share Posted January 16, 2007 Error reporting is on already (I'm 100% sure). I have attached the original CALC1.TXT file.[attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 16, 2007 Share Posted January 16, 2007 Ah. I was copying your data which was saving in Windows format, while your file is in Unix. Change[tt] (\d+)\s+ ### Score [/tt]to[tt] (\d+)\s* ### Score [/tt] and you should see some data. Quote Link to comment Share on other sites More sharing options...
faraz.yashar Posted January 17, 2007 Author Share Posted January 17, 2007 [code]<?php $data2 = file_get_contents('2/ALG2.txt'); $data5 = file_get_contents('5/ALG2.txt'); $pattern = '% ^\s+ ### BOL (\d+)\s+ ### Place (\d+)\s+ ### ID (\S+)\s(\S+)\s+ ### First/Last Name (\D+)\s+ ### School (\d+)\s+ ### Count (\d+)\s+ ### Correct (\d+)\s+ ### Wrong (\d+)\s+ ### No Answer (\d+)\s* ### Score $ ### EOL %mx'; preg_match_all($pattern, $data2, $scores2, PREG_SET_ORDER); preg_match_all($pattern, $data5, $scores5, PREG_SET_ORDER); $statewide = array_merge ($scores2, $scores5); print_r($statewide);?>[/code]How can I organize each statewide array such that the people are organized by ascending scores? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 17, 2007 Share Posted January 17, 2007 [code] ### ... foreach ($matches as $index => $data) { $sort_for[$index] = $data[10]; } array_multisort($sort_for, SORT_ASC, SORT_NUMERIC, $matches); print_r($matches);[/code] Quote Link to comment Share on other sites More sharing options...
faraz.yashar Posted January 17, 2007 Author Share Posted January 17, 2007 What about the individuals who are missing a name (have a bunch of spaces instead of a name)?It reads the school name as the first and last name. Quote Link to comment Share on other sites More sharing options...
effigy Posted January 18, 2007 Share Posted January 18, 2007 [code] $pattern = '% ^\s+ ### BOL (\d+)\s+ ### Place ### ID with atomically grouped whitespace. In other words, ### gobble the whitespace and do NOT allow backtracking. (\d+)(?>\s+) ### Attempt to match First/Last Name; this could be missing. ### To differentiate the First/Last Name from the School name, ### make sure it is not more than 3 words, and that the ### following field does not start with a digit--this will fail ### if the school names ever start with a number. (?:(\S+)\s(\S+)(?!\s\S|\s+\d))? (?(3)\s+|) ### Match whitespace if the names matched (\D+)\s+ ### School (\d+)\s+ ### Count (\d+)\s+ ### Correct (\d+)\s+ ### Wrong (\d+)\s+ ### No Answer (\d+)\s* ### Score $ ### EOL %mx';[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.