From 01ed2f0b15b29259dac8fad25ad5fcbb652caaa9 Mon Sep 17 00:00:00 2001 From: "kris@sentientgeeks.com" Date: Tue, 9 Feb 2021 10:26:46 +0530 Subject: [PATCH] initial Commit --- Dockerfile | 66 + app/classes/class.lexicon.php | 1301 +++++++++++++ app/classes/class.parser.php | 610 ++++++ app/classes/class.parserutility.php | 254 +++ app/classes/class.recordline.php | 243 +++ app/classes/class.reportmatrix.php | 588 ++++++ app/data-ripper.php | 136 ++ app/data/text1.data | 525 ++++++ app/data/text2.data | 1853 ++++++++++++++++++ app/data/text3.data | 285 +++ app/data/text4.data | 839 +++++++++ app/data/text5.data | 480 +++++ app/data/text6.data | 429 +++++ app/data/text7.data | 54 + app/data/text8.data | 5 + app/data/text9.data | 408 ++++ app/index.php | 136 ++ app/parser.php | 16 + app/scraper.php | 84 + docker-compose.yml | 55 + extract_data.php | 2705 +++++++++++++++++++++++++++ index.php | 3 + js/bootstrap.js | 2276 ++++++++++++++++++++++ js/bootstrap.min.js | 7 + js/npm.js | 13 + 25 files changed, 13371 insertions(+) create mode 100644 Dockerfile create mode 100644 app/classes/class.lexicon.php create mode 100644 app/classes/class.parser.php create mode 100644 app/classes/class.parserutility.php create mode 100644 app/classes/class.recordline.php create mode 100644 app/classes/class.reportmatrix.php create mode 100644 app/data-ripper.php create mode 100644 app/data/text1.data create mode 100644 app/data/text2.data create mode 100644 app/data/text3.data create mode 100644 app/data/text4.data create mode 100644 app/data/text5.data create mode 100644 app/data/text6.data create mode 100644 app/data/text7.data create mode 100644 app/data/text8.data create mode 100644 app/data/text9.data create mode 100644 app/index.php create mode 100644 app/parser.php create mode 100644 app/scraper.php create mode 100644 docker-compose.yml create mode 100644 extract_data.php create mode 100644 index.php create mode 100644 js/bootstrap.js create mode 100644 js/bootstrap.min.js create mode 100644 js/npm.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4ee8073 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +FROM php:7.2-apache + +RUN apt-get update + +# 1. development packages +RUN apt-get install -y \ + git \ + zip \ + vim \ + curl \ + sudo \ + unzip \ + libicu-dev \ + libbz2-dev \ + libpng-dev \ + libjpeg-dev \ + libmcrypt-dev \ + libreadline-dev \ + libfreetype6-dev \ + g++ + +# 2. apache configs + document root +ENV APACHE_DOCUMENT_ROOT=/var/www/html +RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf +RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf + +# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin- +RUN a2enmod rewrite headers + +# 4. start with base php config, then add extensions +RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" + +RUN docker-php-ext-install \ + bz2 \ + intl \ + iconv \ + bcmath \ + opcache \ + calendar \ + mbstring \ + pdo_mysql \ + zip + +# 5. composer +# COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# 6. we need a user with the same UID/GID with host user +# so when we execute CLI commands, all the host file's ownership remains intact +# otherwise command from inside container will create root-owned files and directories + +#WORKDIR /var/www/html +#ADD . /var/www/html + +COPY ./ /var/www/html +RUN chown -R www-data:www-data /var/www/html + +#USER root + +#ARG uid +#RUN useradd -G www-data,root -u $uid -d /home/soumya soumya +#RUN mkdir -p /var/www/.composer && \ +# chown -R www-data:www-data /var/www + +#RUN chmod -R 777 /var/www + +#EXPOSE 8000 diff --git a/app/classes/class.lexicon.php b/app/classes/class.lexicon.php new file mode 100644 index 0000000..6afbcc5 --- /dev/null +++ b/app/classes/class.lexicon.php @@ -0,0 +1,1301 @@ +sentence = $sentence; + } + + function __initiate() + { + $now = intval(date("YmdHis")); + if(($now - self::$initiatedOn) > 30)//(30*60*60) + { + self::$initiatedOn = $now; + + $this->__generateMETRICs(); + $this->__generateGENDERs(); + $this->__generateGENDERCLASSIFIERs(); + $this->__generateSPORTCLASSIFIERs(); + + $this->__generate2GRAMIDENTIFIERSs(); + $this->__generate3GRAMIDENTIFIERSs(); + $this->__generate4GRAMIDENTIFIERSs(); + $this->__generate5GRAMIDENTIFIERSs(); + + $this->__generateNOUNs(); + $this->__generatePRONOUNs(); + $this->__generateVERBs(); + $this->__generateADJECTIVEs(); + $this->__generateADVERBs(); + $this->__generatePREPOSITIONs(); + $this->__generateCONJUNCTIONs(); + $this->__generateINTERJECTIONs(); + + $this->__generateHEADERCOLs(); + } + } + + function preAnalyse() + { + $this->__initiate(); + + $this->words = self::getWords($this->sentence); + $this->word_count = count($this->words); + $this->word_analyzed = $this->__analyzeSentence($this->sentence); + + $this->wordTally = $this->__createWordTally($this->word_analyzed); + + $this->generalContext = $this->__inferGeneralContext($this->wordTally); + } + + function analyse() + { + + $this->preAnalyse(); + + $gram1Analysis = $this->__createPrecise($this->word_analyzed); + + $this->precise['CONTEXT'] = $gram1Analysis; + $this->precise['CLARITY'] = array(); + + $gram1Analysis = $this->__1GramAnalysis($this->word_analyzed); + $this->__updateContext($gram1Analysis); + + $gram2Analysis = $this->__2GramAnalysis($this->words); + $this->__updateContext($gram2Analysis); + + $gram3Analysis = $this->__3GramAnalysis($this->words); + $this->__updateContext($gram3Analysis); + + $gram4Analysis = $this->__4GramAnalysis($this->words); + $this->__updateContext($gram4Analysis); + + $gram5Analysis = $this->__5GramAnalysis($this->words); + $this->__updateContext($gram5Analysis); + + $this->precise['CONTEXT'] = array_unique($this->precise['CONTEXT']); + } + + function getAnalysisForNames() + { + $this->analyse(); + + $nameAnalysis = array(); + $nameParts = array(); + + if($this->words[0]==="#") + { + if(is_numeric($this->words[1])) + { + $nameAnalysis['ROLL-NO'] = $this->words[0].' '.$this->words[1]; + } + for($i=2; $iwords);$i++) + { + $nameParts[] = $this->words[$i]; + } + } + else + { + $nameParts = $this->words; + } + + $nameStartFrom = 0; + $nameEndsAt = sizeof($nameParts); + if(strpos($nameParts[0],",")!==false) + { + @$nameAnalysis['LAST-NAME'] = str_replace(",","",$nameParts[0]); + $nameStartFrom = 1; + } + else + { + @$nameAnalysis['LAST-NAME'] = $nameParts[$nameEndsAt-1]; + $nameEndsAt = $nameEndsAt-1; + } + + for($i=$nameStartFrom; $i<$nameEndsAt; $i++) + { + @$nameAnalysis['FIRST-NAME'] .= ' '.$nameParts[$i]; + } + + $nameAnalysis['FULL-NAME'] = trim(@$nameAnalysis['FIRST-NAME'].' '.@$nameAnalysis['LAST-NAME']); + + return $nameAnalysis; + } + + function getGeneralContext() + { + return $this->generalContext; + } + + function getPrecise() + { + return $this->precise; + } + + function getLeadPhrase() + { + $return = ""; + if(in_array('2W-PHRASE',$this->precise['CONTEXT'])) + { + $w2Phrase = $this->precise['CLARITY']['2W-PHRASE'][0]; + $wordStEnd = ParserUtility::get_start_end_pos(trim($this->sentence), $w2Phrase); + if($wordStEnd[0]['START-POSITION']==0) + { + $return = $w2Phrase; + } + } + if(in_array('3W-PHRASE',$this->precise['CONTEXT'])) + { + $w3Phrase = $this->precise['CLARITY']['3W-PHRASE'][0]; + $wordStEnd = ParserUtility::get_start_end_pos(trim($this->sentence), $w3Phrase); + if($wordStEnd[0]['START-POSITION']==0) + { + $return = $w3Phrase; + } + } + return $return; + } + + function getOtherPhrases() + { + $return = array(); + if(in_array('2W-PHRASE',$this->precise['CONTEXT'])) + { + $cnt = 0; + foreach($this->precise['CLARITY']['2W-PHRASE'] as $phrase) + { + if($cnt>0) + { + $return[] = $phrase; + } + $cnt++; + } + } + if(in_array('3W-PHRASE',$this->precise['CONTEXT'])) + { + $return = array(); + foreach($this->precise['CLARITY']['3W-PHRASE'] as $phrase) + { + if($cnt>0) + { + $return[] = $phrase; + } + $cnt++; + } + } + if(in_array('4W-PHRASE',$this->precise['CONTEXT'])) + { + $return = array(); + foreach($this->precise['CLARITY']['4W-PHRASE'] as $phrase) + { + if($cnt>0) + { + $return[] = $phrase; + } + $cnt++; + } + } + if(in_array('5W-PHRASE',$this->precise['CONTEXT'])) + { + $return = array(); + foreach($this->precise['CLARITY']['5W-PHRASE'] as $phrase) + { + if($cnt>0) + { + $return[] = $phrase; + } + $cnt++; + } + } + return $return; + } + + function getMetricPhrase() + { + $return = ""; + if(in_array('METRIC-PHRASE',$this->precise['CONTEXT'])) + { + $return = $this->precise['CLARITY']['METRIC-PHRASE'][0]; + } + return $return; + } + + function getGender() + { + $return = ""; + if(in_array('MALE',$this->precise['CONTEXT'])) + { + $return = 'MALE'; + } + elseif(in_array('FEMALE',$this->precise['CONTEXT'])) + { + $return = 'FEMALE'; + } + + return $return; + } + + function getSports() + { + $return = ""; + foreach($this->precise['CONTEXT'] as $context) + { + if(in_array($context, self::$dictionary['SPORTS_CLASSIFIER'])) + { + $return = $this->precise['CLARITY'][$context][0]; + } + } + + return $return; + } + + function getSportsType() + { + $return = ""; + foreach($this->precise['CONTEXT'] as $context) + { + if(in_array($context,self::$dictionary['SPORTS_CLASSIFIER'])) + { + $return = $context; + } + } + return $return; + } + + function getSportsRound() + { + $return = ""; + if(is_array(@$this->precise['CONTEXT'])) + { + foreach(@$this->precise['CONTEXT'] as $context) + { + if(in_array($context,self::$dictionary['SPORTS-ROUND'])) + { + $return = $context; + } + } + } + return $return; + } + + function getSportsLevel() + { + $return = ""; + if(is_array(@$this->precise['CONTEXT'])) + { + foreach(@$this->precise['CONTEXT'] as $context) + { + if(in_array($context,self::$dictionary['SPORTS-LEVEL'])) + { + $return = $context; + } + } + } + return $return; + } + + static function getDictionary() + { + return self::$dictionary; + } + + function __updateContext($analysis) + { + if(sizeof($analysis) > 0) + { + foreach($analysis as $keyWord => $gram) + { + if(in_array($keyWord,self::$dictionary['SPORTS_CLASSIFIER'])) + { + foreach($this->precise['CONTEXT'] as $key => $lookpSportsClassifier) + { + if(in_array($lookpSportsClassifier,self::$dictionary['SPORTS_CLASSIFIER'])) + { + unset($this->precise['CONTEXT'][$key]); + unset($this->precise['CLARITY'][$lookpSportsClassifier]); + } + } + } + + array_push($this->precise['CONTEXT'], $keyWord); + $this->precise['CLARITY'][$keyWord] = $gram; + } + } + } + + function __analyzeSentence($sentence) + { + $word_analyzed = array(); + $words = self::getWords($sentence); + foreach($words as $word) + { + $found = false; + foreach(self::$dictionary as $classification=>$dicElement) + { + if(in_array(strtolower($word),$dicElement)) + { + $found = true; + $word_analyzed[$word]['CLASSIFICATION'][] = $classification; + } + } + + if(!$found) + { + $classification = 'NOUN'; + if(is_numeric($word)) + { + $classification = 'NUMBER'; + } + elseif(strpos($word, ":")!==false) + { + $expld = explode(":",$word); + foreach($expld as $exp) + { + $classification = 'NUMBER'; + if(is_numeric($exp)===false) + { + $classification = 'NOUN'; + break; + } + } + } + elseif(strpos($word, "-")!==false) + { + $expld = explode("-",$word); + foreach($expld as $exp) + { + $classification = 'NUMBER'; + if(is_numeric($exp)===false) + { + $classification = 'NOUN'; + break; + } + } + } + $word_analyzed[$word]['CLASSIFICATION'][] = $classification; + } + } + + return $word_analyzed; + } + + function __createPrecise($word_analyzed,$analyze=true) + { + $precise = array(); + $thisPrecise = array(); + foreach($word_analyzed as $analysis) + { + foreach($analysis['CLASSIFICATION'] as $analogy) + { + $precise[] = $analogy; + $thisPrecise[] = $analogy; + } + } + + if($analyze) + { + $thisPrecise = array(); + foreach($precise as $preci) + { + if(in_array($preci, self::$gram1highlighters)) + { + $thisPrecise[] = $preci; + } + } + } + return $thisPrecise; + } + + function __createWordTally($word_analyzed) + { + $wordCount = count($word_analyzed); + $tally = array(); + $tally["WORDCOUNT"] = $wordCount; + $cntr = 0; + foreach($word_analyzed as $wrd=>$analysis) + { + $tally["WORD"][$wrd]['COUNT'] = (@$tally["WORD"][$wrd]['COUNT'])+1; + $tally["WORD"][$wrd]['POSITION'][] = $cntr; + $tally["WORD"][$wrd]['PERCENT'] = round(($tally["WORD"][$wrd]['COUNT'] / $wordCount )*100,3); + + $analogy = $analysis['CLASSIFICATION'][0]; + + $tally["WORDTYPE"][$analogy]['COUNT'] = (@$tally["WORDTYPE"][$analogy]['COUNT'])+1; + $tally["WORDTYPE"][$analogy]['POSITION'][] = $cntr; + $tally["WORDTYPE"][$analogy]['PERCENT'] = round(($tally["WORDTYPE"][$analogy]['COUNT'] / $wordCount )*100,3); + + $cntr++; + } + return $tally; + } + + function __inferGeneralContext($wordTally) + { + $wordCount = $wordTally['WORDCOUNT']; + + if($wordCount==0) + { + return "LINE-BREAK"; + } + + if($wordCount==1) + { + foreach($wordTally["WORD"] as $_wrd=>$restOfIt) + { + $tally = array(); + $len = strlen("".$_wrd.""); + for ($i = 0; $i < $len; $i++) + { + $tally[$_wrd[$i]]['COUNT'] = (@$tally[$_wrd[$i]]['COUNT']) + 1; + $tally[$_wrd[$i]]['PERCENT'] = ($tally[$_wrd[$i]]['COUNT']/$len) * 100; + } + + if(count($tally)==1 && $len > 5) + { + return "DECORATOR"; + } + } + } + + $nounPercent = @$wordTally['WORDTYPE']['NOUN']['PERCENT']; + $headerPercent = @$wordTally['WORDTYPE']['HEADER-COL']['PERCENT']; + + $sportsLvlPercent = 0; + + foreach(self::$dictionary['SPORTS-ROUND'] as $slevel) + { + $sLvlPc = @$wordTally['WORDTYPE'][$slevel]['PERCENT']; + if($sportsLvlPercent < $sLvlPc) + { + $sportsLvlPercent = $sLvlPc; + } + } + + + if($wordCount == 1 && $sportsLvlPercent == 100) + { + return "SPORTS-ROUND"; + } + elseif($wordCount > 1 && $headerPercent >= 50) + { + return "HEADER"; + } + elseif($nounPercent >= 50) + { + return "SENTENCE"; + } + else + { + return "INFO"; + } + } + + function __1GramAnalysis($word_analyzed) + { + $gram1Analysis = array(); + + foreach($word_analyzed as $word=>$class) + { + if(in_array('GENDER',$class['CLASSIFICATION'])) + { + $gram1Analysis[$class['CLASSIFICATION'][1]][] = $word; + } + + if(in_array($class['CLASSIFICATION'][0],self::$dictionary['SPORTS_CLASSIFIER'])) + { + $gram1Analysis[$class['CLASSIFICATION'][0]][] = $word; + } + } + return $gram1Analysis; + } + + function __2GramAnalysis($words) + { + $gram2Analysis = array(); + $precise = $this->__nGramAnalysis(2,$this->words); + + if(is_array(@$precise['PRECIS'])) + { + foreach($precise['PRECIS'] as $preci) + { + $ph = implode(" ",$preci['DET']); + $jw = strtolower($preci['JWORDS']); + + $found = false; + foreach(self::$dictionary as $keyWord=>$keyPhrases) + { + if(in_array(strtolower($jw),$keyPhrases)) + { + $found = true; + $gram2Analysis[$keyWord][] = $preci['JWORDS']; + } + } + + if(!$found) + { + foreach(self::$gram2Highlighters as $keyWord=>$keyPhrases) + { + if(@in_array($ph,$keyPhrases)) + { + $gram2Analysis[$keyWord][] = $preci['JWORDS']; + } + if(@in_array($jw,$keyPhrases)) + { + $gram2Analysis[$keyWord][] = $preci['JWORDS']; + } + } + } + } + } + return $gram2Analysis; + } + + function __3GramAnalysis($words) + { + $gram3Analysis = array(); + $precise = $this->__nGramAnalysis(3,$this->words); + + if(is_array(@$precise['PRECIS'])) + { + foreach($precise['PRECIS'] as $preci) + { + $ph = implode(" ",$preci['DET']); + $jw = strtolower($preci['JWORDS']); + + $found = false; + foreach(self::$dictionary as $keyWord=>$keyPhrases) + { + if(in_array(strtolower($jw),$keyPhrases)) + { + $found = true; + $gram3Analysis[$keyWord][] = $preci['JWORDS']; + } + } + + if(!$found) + { + foreach(self::$gram3Highlighters as $keyWord=>$keyPhrases) + { + if(@in_array($ph,$keyPhrases)) + { + $gram3Analysis[$keyWord][] = $preci['JWORDS']; + } + if(@in_array($jw,$keyPhrases)) + { + $gram3Analysis[$keyWord][] = $preci['JWORDS']; + } + } + } + } + } + return $gram3Analysis; + } + + function __4GramAnalysis($words) + { + $gram4Analysis = array(); + $precise = $this->__nGramAnalysis(4,$this->words); + + if(is_array(@$precise['PRECIS'])) + { + foreach($precise['PRECIS'] as $preci) + { + $ph = implode(" ",$preci['DET']); + $jw = strtolower($preci['JWORDS']); + + $found = false; + foreach(self::$dictionary as $keyWord=>$keyPhrases) + { + if(in_array(strtolower($jw),$keyPhrases)) + { + $found = true; + $gram4Analysis[$keyWord][] = $preci['JWORDS']; + } + } + + if(!$found) + { + foreach(self::$gram4Highlighters as $keyWord=>$keyPhrases) + { + if(@in_array($ph,$keyPhrases)) + { + $gram4Analysis[$keyWord][] = $preci['JWORDS']; + } + if(@in_array($jw,$keyPhrases)) + { + $gram4Analysis[$keyWord][] = $preci['JWORDS']; + } + } + } + } + } + return $gram4Analysis; + } + + function __5GramAnalysis($words) + { + $gram5Analysis = array(); + $precise = $this->__nGramAnalysis(5,$this->words); + + if(is_array(@$precise['PRECIS'])) + { + foreach($precise['PRECIS'] as $preci) + { + $ph = implode(" ",$preci['DET']); + $jw = strtolower($preci['JWORDS']); + + $found = false; + foreach(self::$dictionary as $keyWord=>$keyPhrases) + { + if(in_array(strtolower($jw),$keyPhrases)) + { + $found = true; + $gram5Analysis[$keyWord][] = $preci['JWORDS']; + } + } + + if(!$found) + { + foreach(self::$gram5Highlighters as $keyWord=>$keyPhrases) + { + if(@in_array($ph,$keyPhrases)) + { + $gram5Analysis[$keyWord][] = $preci['JWORDS']; + } + if(@in_array($jw,$keyPhrases)) + { + $gram5Analysis[$keyWord][] = $preci['JWORDS']; + } + } + } + } + } + return $gram5Analysis; + } + + function __nGramAnalysis($n,$words) + { + $joinedWords = array(); + $precise = array(); + + foreach($words as $index=>$word) + { + if(($index+$n) <= (count($words))) + { + $jWord = $word; + for($i=1;$i<$n;$i++) + { + $jWord .= ' '.$words[$index+$i]; + } + } + else + { + break; + } + $joinedWords[] = $jWord; + if($this->debug) $this->precise['nGrams-'.$n]['SENTENCE'][] = $jWord; + } + + $cntr = 0; + foreach($joinedWords as $jWord) + { + $word_analyzed = $this->__analyzeSentence($jWord); + + if($this->debug) $this->precise['nGrams-'.$n]['ANALYSED'][] = $word_analyzed; + + $precis = $this->__createPrecise($word_analyzed,false); + $precise['PRECIS'][$cntr]['JWORDS'] = $jWord; + $precise['PRECIS'][$cntr]['DET'] = $precis; + + if($this->debug) $this->precise['nGrams-'.$n]['PRECIS'][$cntr]['JWORDS'] = $jWord; + if($this->debug) $this->precise['nGrams-'.$n]['PRECIS'][$cntr]['DET'] = $precis; + + $cntr++; + } + + return $precise; + } + + function __generateMETRICs() + { + $metric[] = strtolower('Meter'); + $metric[] = strtolower('Mile'); + + self::$dictionary['METRIC'] = $metric; + } + + function __generateGENDERs() + { + $gender[] = strtolower('Boy'); + $gender[] = strtolower('Boys'); + $gender[] = strtolower('Girl'); + $gender[] = strtolower('Girls'); + $gender[] = strtolower('Man'); + $gender[] = strtolower('Men'); + $gender[] = strtolower('Woman'); + $gender[] = strtolower('Women'); + $gender[] = strtolower('Male'); + $gender[] = strtolower('Female'); + + self::$dictionary['GENDER'] = $gender; + } + + function __generateGENDERCLASSIFIERs() + { + $male[] = strtolower('Boy'); + $male[] = strtolower('Boys'); + $male[] = strtolower('Man'); + $male[] = strtolower('Men'); + $male[] = strtolower('Male'); + + self::$dictionary['MALE'] = $male; + self::$gram1highlighters[] = "MALE"; + + $female[] = strtolower('Girl'); + $female[] = strtolower('Girls'); + $female[] = strtolower('Woman'); + $female[] = strtolower('Women'); + $female[] = strtolower('Female'); + + self::$dictionary['FEMALE'] = $female; + self::$gram1highlighters[] = "FEMALE"; + } + + function __generateSPORTCLASSIFIERs() + { + $running = array(); + $running[] = strtolower('Dash'); + $running[] = strtolower('Marathon'); + $running[] = strtolower('Race Walking'); + $running[] = strtolower('Hurdles'); + $running[] = strtolower('Run'); + $running[] = strtolower('Steeplechase'); + $running[] = strtolower('Race'); + $running[] = strtolower('Race Walk'); + self::$dictionary[ParserUtility::$_RUNNING_] = $running; + self::$gram1highlighters[] = ParserUtility::$_RUNNING_; + + $relay = array(); + $relay[] = strtolower('Relay'); + $relay[] = strtolower('Sprint Medley'); + $relay[] = strtolower('Distance Medley'); + $relay[] = strtolower('Shuttle'); + self::$dictionary[ParserUtility::$_RELAY_] = $relay; + self::$gram1highlighters[] = ParserUtility::$_RELAY_; + + $throw = array(); + $throw[] = strtolower('Discus'); + $throw[] = strtolower('Hammer'); + $throw[] = strtolower('Hammer Throw'); + $throw[] = strtolower('Javelin'); + $throw[] = strtolower('Shot Put'); + $throw[] = strtolower('Weight Throw'); + self::$dictionary[ParserUtility::$_THROWING_] = $throw; + self::$gram1highlighters[] = ParserUtility::$_THROWING_; + + $jumping = array(); + $jumping[] = strtolower('High Jump'); + $jumping[] = strtolower('Long Jump'); + $jumping[] = strtolower('Pole Vault'); + $jumping[] = strtolower('Triple Jump'); + self::$dictionary[ParserUtility::$_JUMPING_] = $jumping; + self::$gram1highlighters[] = ParserUtility::$_JUMPING_; + + $mixed = array(); + $mixed[] = strtolower('Decathlon'); + $mixed[] = strtolower('Heptathlon'); + $mixed[] = strtolower('Pentathlon'); + self::$dictionary[ParserUtility::$_MIXED_EVENT_] = $mixed; + self::$gram1highlighters[] = ParserUtility::$_MIXED_EVENT_; + + $team_jump = array(); + self::$dictionary[ParserUtility::$_JUMPING_TEAM_] = $team_jump; + self::$gram1highlighters[] = ParserUtility::$_JUMPING_TEAM_; + + $team_throw = array(); + self::$dictionary[ParserUtility::$_THROWING_TEAM_] = $team_throw; + self::$gram1highlighters[] = ParserUtility::$_THROWING_TEAM_; + + $classifiers = array(); + $classifiers[] = ParserUtility::$_RUNNING_; + $classifiers[] = ParserUtility::$_JUMPING_; + $classifiers[] = ParserUtility::$_THROWING_; + $classifiers[] = ParserUtility::$_RELAY_; + $classifiers[] = ParserUtility::$_JUMPING_TEAM_; + $classifiers[] = ParserUtility::$_THROWING_TEAM_; + $classifiers[] = ParserUtility::$_MIXED_EVENT_; + self::$dictionary['SPORTS_CLASSIFIER'] = $classifiers; + + //// + + $sportLevel = array(); + $sportLevel[] = strtolower('Final'); + $sportLevel[] = strtolower('Finals'); + self::$dictionary[ParserUtility::$_ROUND_FINAL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_ROUND_FINAL_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Semi'); + $sportLevel[] = strtolower('Semis'); + $sportLevel[] = strtolower('Semi-Final'); + $sportLevel[] = strtolower('Semi-Finals'); + $sportLevel[] = strtolower('SemiFinal'); + $sportLevel[] = strtolower('SemiFinals'); + self::$dictionary[ParserUtility::$_ROUND_SEMI_FINAL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_ROUND_SEMI_FINAL_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Priliminary'); + $sportLevel[] = strtolower('Priliminaries'); + $sportLevel[] = strtolower('Preliminaries'); + $sportLevel[] = strtolower('Prilim'); + $sportLevel[] = strtolower('Prilims'); + self::$dictionary[ParserUtility::$_ROUND_PRILIMINARY_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_ROUND_PRILIMINARY_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Trials'); + $sportLevel[] = strtolower('Trial'); + self::$dictionary[ParserUtility::$_ROUND_TRIAL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_ROUND_TRIAL_; + + + $classifiers = array(); + $classifiers[] = ParserUtility::$_ROUND_FINAL_; + $classifiers[] = ParserUtility::$_ROUND_SEMI_FINAL_; + $classifiers[] = ParserUtility::$_ROUND_PRILIMINARY_; + $classifiers[] = ParserUtility::$_ROUND_TRIAL_; + self::$dictionary['SPORTS-ROUND'] = $classifiers; + + + ///// + + $sportLevel = array(); + $sportLevel[] = strtolower('Open'); + self::$dictionary[ParserUtility::$_LEVEL_OPEN_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_OPEN_; + + $sportLevel = array(); + $sportLevel[] = strtolower('FROSH / SOPH'); + $sportLevel[] = strtolower('FROSH/ SOPH'); + $sportLevel[] = strtolower('FROSH /SOPH'); + $sportLevel[] = strtolower('FROSH/SOPH'); + $sportLevel[] = strtolower('Freshman/Sophomore'); + self::$dictionary[ParserUtility::$_LEVEL_FROS_SOPH_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_FROS_SOPH_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Freshman'); + $sportLevel[] = strtolower('Freshwoman'); + $sportLevel[] = strtolower('Freshmen'); + $sportLevel[] = strtolower('Freshwomen'); + $sportLevel[] = strtolower('FROSH'); + self::$dictionary[ParserUtility::$_LEVEL_FRESHMAN_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_FRESHMAN_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Sophomore'); + $sportLevel[] = strtolower('SOPH'); + self::$dictionary[ParserUtility::$_LEVEL_SOPHOMORE_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_SOPHOMORE_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Junior'); + self::$dictionary[ParserUtility::$_LEVEL_JUNIOR_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_JUNIOR_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Senior'); + self::$dictionary[ParserUtility::$_LEVEL_SENIOR_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_SENIOR_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Varsity'); + $sportLevel[] = strtolower('Individual Varsity'); + self::$dictionary[ParserUtility::$_LEVEL_UNIVARSITY_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_UNIVARSITY_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Conference'); + self::$dictionary[ParserUtility::$_LEVEL_CONFERENCE_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_CONFERENCE_; + + $sportLevel = array(); + $sportLevel[] = strtolower('League'); + self::$dictionary[ParserUtility::$_LEVEL_LEAGUE_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_LEAGUE_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Junior Varsity'); + $sportLevel[] = strtolower('Junior Varsi'); + $sportLevel[] = strtolower('Jr. Varsity'); + $sportLevel[] = strtolower('JV'); + self::$dictionary[ParserUtility::$_LEVEL_JV_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_JV_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Sub Midget'); + $sportLevel[] = strtolower('Sub-Midget'); + self::$dictionary[ParserUtility::$_LEVEL_SUB_MIDGET_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_SUB_MIDGET_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Midget'); + self::$dictionary[ParserUtility::$_LEVEL_MIDGET_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_MIDGET_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Junior Weigh'); + $sportLevel[] = strtolower('Jr. Weigh'); + $sportLevel[] = strtolower('Jr Weigh'); + self::$dictionary[ParserUtility::$_LEVEL_JUNIOR_WEIGH_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_JUNIOR_WEIGH_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Novice'); + self::$dictionary[ParserUtility::$_LEVEL_NOVICE_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_NOVICE_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Class'); + self::$dictionary[ParserUtility::$_LEVEL_CLASS_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_CLASS_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Division'); + self::$dictionary[ParserUtility::$_LEVEL_DIVISION_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_DIVISION_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Crossover'); + self::$dictionary[ParserUtility::$_LEVEL_CROSSOVER_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_CROSSOVER_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Indiv. Team'); + $sportLevel[] = strtolower('Individual Team'); + self::$dictionary[ParserUtility::$_LEVEL_INDIV_TEAM_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_INDIV_TEAM_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Junior-Senior'); + $sportLevel[] = strtolower('Junior- Senior'); + $sportLevel[] = strtolower('Junior -Senior'); + $sportLevel[] = strtolower('Junior - Senior'); + $sportLevel[] = strtolower('Jr.-Sr.'); + $sportLevel[] = strtolower('Jr.- Sr.'); + $sportLevel[] = strtolower('Jr. -Sr.'); + $sportLevel[] = strtolower('Jr. - Sr.'); + self::$dictionary[ParserUtility::$_LEVEL_JR_SR_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_JR_SR_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Unseeded'); + self::$dictionary[ParserUtility::$_LEVEL_UNSEEDED_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_UNSEEDED_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Championship'); + self::$dictionary[ParserUtility::$_LEVEL_CHAMPIONSHIP_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_CHAMPIONSHIP_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Elite'); + $sportLevel[] = strtolower('Elit'); + self::$dictionary[ParserUtility::$_LEVEL_ELITE_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_ELITE_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Small Schools'); + $sportLevel[] = strtolower('Small School'); + self::$dictionary[ParserUtility::$_LEVEL_SMALL_SCHOOL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_SMALL_SCHOOL_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Large Schools'); + $sportLevel[] = strtolower('Large School'); + self::$dictionary[ParserUtility::$_LEVEL_LARGE_SCHOOL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_LARGE_SCHOOL_; + + $sportLevel = array(); + $sportLevel[] = strtolower('Invitational'); + self::$dictionary[ParserUtility::$_LEVEL_INVITATIONAL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_INVITATIONAL_; + + $sportLevel = array(); + $sportLevel[] = strtolower('PSAL'); + self::$dictionary[ParserUtility::$_LEVEL_PSAL_] = $sportLevel; + self::$gram1highlighters[] = ParserUtility::$_LEVEL_PSAL_; + + $classifiers = array(); + $classifiers[] = ParserUtility::$_LEVEL_OPEN_; + $classifiers[] = ParserUtility::$_LEVEL_FROS_SOPH_; + $classifiers[] = ParserUtility::$_LEVEL_FRESHMAN_; + $classifiers[] = ParserUtility::$_LEVEL_SOPHOMORE_; + $classifiers[] = ParserUtility::$_LEVEL_JUNIOR_; + $classifiers[] = ParserUtility::$_LEVEL_SENIOR_; + $classifiers[] = ParserUtility::$_LEVEL_UNIVARSITY_; + $classifiers[] = ParserUtility::$_LEVEL_CONFERENCE_; + $classifiers[] = ParserUtility::$_LEVEL_JV_; + $classifiers[] = ParserUtility::$_LEVEL_SUB_MIDGET_; + $classifiers[] = ParserUtility::$_LEVEL_MIDGET_; + $classifiers[] = ParserUtility::$_LEVEL_JUNIOR_WEIGH_; + $classifiers[] = ParserUtility::$_LEVEL_NOVICE_; + $classifiers[] = ParserUtility::$_LEVEL_CLASS_; + $classifiers[] = ParserUtility::$_LEVEL_DIVISION_; + $classifiers[] = ParserUtility::$_LEVEL_CROSSOVER_; + $classifiers[] = ParserUtility::$_LEVEL_INDIV_TEAM_; + $classifiers[] = ParserUtility::$_LEVEL_JR_SR_; + $classifiers[] = ParserUtility::$_LEVEL_UNSEEDED_; + $classifiers[] = ParserUtility::$_LEVEL_CHAMPIONSHIP_; + $classifiers[] = ParserUtility::$_LEVEL_ELITE_; + $classifiers[] = ParserUtility::$_LEVEL_SMALL_SCHOOL_; + $classifiers[] = ParserUtility::$_LEVEL_LARGE_SCHOOL_; + $classifiers[] = ParserUtility::$_LEVEL_INVITATIONAL_; + $classifiers[] = ParserUtility::$_LEVEL_PSAL_; + self::$dictionary['SPORTS-LEVEL'] = $classifiers; + + ///////// + } + + function __generateHEADERCOLs() + { + $gender[] = strtolower('Name'); + $gender[] = strtolower('Year'); + $gender[] = strtolower('Seed'); + $gender[] = strtolower('School'); + $gender[] = strtolower('Finals'); + $gender[] = strtolower('Prelims'); + $gender[] = strtolower('H#'); + $gender[] = strtolower('Comp#'); + $gender[] = strtolower('Points'); + $gender[] = strtolower('Time'); + $gender[] = strtolower('Team'); + + self::$dictionary['HEADER-COL'] = $gender; + } + + function __generate2GRAMIDENTIFIERSs() + { + $wordPattern = array(); + $wordPattern[] = strtoupper('NOUN NOUN'); + $wordPattern[] = strtoupper('NOUN NUMBER'); + self::$gram2Highlighters['2W-PHRASE'] = $wordPattern; + + $wordPattern = array(); + $wordPattern[] = strtoupper('NUMBER METRIC'); + $wordPattern[] = strtoupper('NOUN METRIC'); + self::$gram2Highlighters['METRIC-PHRASE'] = $wordPattern; + + $specificPhrase = array(); + $specificPhrase[] = strtolower('Sprint Medley'); + self::$gram2Highlighters['RELAY'] = $specificPhrase; + } + + function __generate3GRAMIDENTIFIERSs() + { + $wordPattern[] = strtoupper('NOUN NOUN NOUN'); + $wordPattern[] = strtoupper('NOUN NOUN NUMBER'); + $wordPattern[] = strtoupper('NUMBER NOUN NOUN'); + self::$gram3Highlighters['3W-PHRASE'] = $wordPattern; + } + + function __generate4GRAMIDENTIFIERSs() + { + $wordPattern[] = strtoupper(''); + self::$gram4Highlighters['4W-PHRASE'] = $wordPattern; + + $specificPhrase = array(); + $specificPhrase[] = strtolower('Hurdles 2 Person Rel'); + self::$gram4Highlighters[ParserUtility::$_RELAY_] = $specificPhrase; + } + + function __generate5GRAMIDENTIFIERSs() + { + $wordPattern[] = strtoupper(''); + self::$gram5Highlighters['4W-PHRASE'] = $wordPattern; + + $specificPhrase = array(); + $specificPhrase[] = strtolower('Long Jump 2 Person Rel'); + $specificPhrase[] = strtolower('Triple Jump 2 Person Rel'); + $specificPhrase[] = strtolower('High Jump 2 Person Rel'); + $specificPhrase[] = strtolower('Pole Vault 2 Person Rel'); + self::$gram5Highlighters[ParserUtility::$_JUMPING_TEAM_] = $specificPhrase; + + $specificPhrase = array(); + $specificPhrase[] = strtolower('Shot Put 2 Person Rel'); + $specificPhrase[] = strtolower('Discus Throw 2 Person Re'); + self::$gram5Highlighters[ParserUtility::$_THROWING_TEAM_] = $specificPhrase; + } + + function __generateNOUNs() + { + $noun[] = strtolower(''); + self::$dictionary['NOUN'] = $noun; + } + + function __generatePRONOUNs() + { + $pronoun[] = strtolower(''); + self::$dictionary['PRONOUN'] = $pronoun; + } + + function __generateVERBs() + { + $verb[] = strtolower(''); + self::$dictionary['VERB'] = $verb; + } + + function __generateADJECTIVEs() + { + $adjective[] = strtolower(''); + self::$dictionary['ADJECTIVE'] = $adjective; + } + + function __generateADVERBs() + { + $adverb[] = strtolower(''); + self::$dictionary['ADVERB'] = $adverb; + } + + function __generatePREPOSITIONs() + { + $preposition[] = strtolower('of'); + $preposition[] = strtolower('with'); + $preposition[] = strtolower('at'); + $preposition[] = strtolower('from'); + $preposition[] = strtolower('into'); + $preposition[] = strtolower('during'); + $preposition[] = strtolower('including'); + $preposition[] = strtolower('until'); + $preposition[] = strtolower('against'); + $preposition[] = strtolower('among'); + $preposition[] = strtolower('throughout'); + $preposition[] = strtolower('despite'); + $preposition[] = strtolower('towards'); + $preposition[] = strtolower('upon'); + $preposition[] = strtolower('concerning'); + $preposition[] = strtolower('to'); + $preposition[] = strtolower('in'); + $preposition[] = strtolower('for'); + $preposition[] = strtolower('on'); + $preposition[] = strtolower('by'); + $preposition[] = strtolower('about'); + $preposition[] = strtolower('like'); + $preposition[] = strtolower('through'); + $preposition[] = strtolower('over'); + $preposition[] = strtolower('before'); + $preposition[] = strtolower('between'); + $preposition[] = strtolower('after'); + $preposition[] = strtolower('since'); + $preposition[] = strtolower('without'); + $preposition[] = strtolower('under'); + $preposition[] = strtolower('within'); + $preposition[] = strtolower('along'); + $preposition[] = strtolower('following'); + $preposition[] = strtolower('across'); + $preposition[] = strtolower('behind'); + $preposition[] = strtolower('beyond'); + $preposition[] = strtolower('plus'); + $preposition[] = strtolower('except'); + $preposition[] = strtolower('but'); + $preposition[] = strtolower('up'); + $preposition[] = strtolower('out'); + $preposition[] = strtolower('around'); + $preposition[] = strtolower('down'); + $preposition[] = strtolower('off'); + $preposition[] = strtolower('above'); + $preposition[] = strtolower('near'); + + self::$dictionary['PREPOSITION'] = $preposition; + } + + function __generateCONJUNCTIONs() + { + $conjunctions[] = strtolower(''); + self::$dictionary['CONJUNCTION'] = $conjunctions; + } + + function __generateINTERJECTIONs() + { + $interjections[] = strtolower(''); + self::$dictionary['INTERJECTION'] = $interjections; + } + + static function getWords($sentence, $trim=true) + { + $words = array(); + $ws = explode(" ", $sentence); + $counter = 0; + + foreach($ws as $wds) + { + if($trim && trim($wds)=='') + { + continue; + } + + if(false && $trim) + { + for ($i = 0; $i < strlen($wds); $i++) + { + if (strstr('.,!?;:()[]{}""\'\'',$wds[$i])) + { + if ($i == 0) + { + $wds = substr($wds, $i+1); + } + else if ($i == strlen($wds)-1) + { + $wds = substr($wds, 0, strlen($wds)-1); + } + else + { + $wds[$i] = ' '; + } + } + } + + $eplded = explode(" ",$wds); + + if(sizeof($eplded) > 1) + { + $wds = array_pop($eplded); + foreach($eplded as $w) + { + $words[] = trim($w); + } + } + } + + $words[] = trim($wds); + //$words[$counter]['REPORT'] = self::detectWord($wds); + $counter++; + } + + return $words; + } +} +?> \ No newline at end of file diff --git a/app/classes/class.parser.php b/app/classes/class.parser.php new file mode 100644 index 0000000..902417a --- /dev/null +++ b/app/classes/class.parser.php @@ -0,0 +1,610 @@ +meet_name = $meet_name; + $this->meet_id = $meet_id; + $this->gender = $gender; + + $this->schoolId = $schoolId; + $this->seasonId = $seasonId; + $this->seasonYear = $seasonYear; + } + + function setRawInputData($data) + { + if(is_string($data)) + { + $data = str_replace("&", "&", $data); + + $dataArray = explode("\n", trim($data)); + $lineCount = 0; + $intermediateArray = array(); + foreach($dataArray as $lnNo=>$ln) + { + if($lineCount == 0 && trim($ln) == '') + { + continue; + } + + $this->rawDataLines[] = $ln; + $lineCount++; + } + } + + } + + function getData() + { + return $this->processedDataLines; + } + + function getFormatedData() + { + $nameCountArray = array(); + $return = array(); + $parsedData = $this->processedDataLines; + if(is_array($parsedData) && sizeof($parsedData)>0) + { + $reportCnt = 0; + foreach($parsedData as $data) + { + $lineType = $data->getType(); + $dispData = $data->getComposedData(); + if($lineType=="license-header") + { + $return['LICENCED-TO'] = @$dispData['LICENCE TO']; + $return['SUB-LICENSE'] = @$dispData['SUB-LICENSE']; + $return['LICENSE-DATE'] = @$dispData['LICENSE DATE']; + } + else if($lineType=="school-report-head") + { + $return['EVENT-NAME'] = @$dispData['EVENT NAME']; + $return['EVENT-DATE'] = @$dispData['EVENT DATE']; + } + else if($lineType=="school-name-head") + { + $return['SCHOOL-NAME'] = @$dispData['SCHOOL NAME']; + } + else if($lineType=="report-data") + { + $reportMatrix = $data->getReportMatrix(); + + $return['REPORT'][$reportCnt]['HEADER']['FULL-TEXT'] = @$dispData['HEADER']; + + $headerAnalysis = @$dispData['HEADER-ANALYSIS']; + + $eventName = trim(str_replace($headerAnalysis->getLeadPhrase(),"",@$dispData['HEADER'])); + + $eventName = $this->__cleanUpEventname($eventName); + + $return['REPORT'][$reportCnt]['HEADER']['EVENT-NAME'] = trim($eventName); + $return['REPORT'][$reportCnt]['HEADER']['EVENT-LEVEL'] = $headerAnalysis->getLeadPhrase(); + + if(trim($return['REPORT'][$reportCnt]['HEADER']['EVENT-NAME'])=='') + { + $return['REPORT'][$reportCnt]['HEADER']['EVENT-NAME'] = $headerAnalysis->getLeadPhrase(); + $return['REPORT'][$reportCnt]['HEADER']['EVENT-LEVEL'] = ''; + } + + $return['REPORT'][$reportCnt]['HEADER']['GENDER'] = $headerAnalysis->getGender(); + $return['REPORT'][$reportCnt]['HEADER']['SPORTS'] = $headerAnalysis->getSports(); + $return['REPORT'][$reportCnt]['HEADER']['SPORT-TYPE'] = $headerAnalysis->getSportsType(); + $return['REPORT'][$reportCnt]['HEADER']['SPORT-LEVEL'] = $headerAnalysis->getSportsLevel(); + $return['REPORT'][$reportCnt]['HEADER']['SPORT-LEVEL-SQ'] = $headerAnalysis->getSportsLevel(); + $return['REPORT'][$reportCnt]['HEADER']['METRIC'] = $headerAnalysis->getMetricPhrase(); + $return['REPORT'][$reportCnt]['HEADER']['ADDLN-NOTE'] = $headerAnalysis->getOtherPhrases(); + + if($reportMatrix->isUsable()) + { + $return['REPORT'][$reportCnt]['HAS-RECORDS'] = true; + $return['REPORT'][$reportCnt]['COLUMNS'][]="SL"; + foreach($reportMatrix->getHeaders() as $head) + { + $return['REPORT'][$reportCnt]['COLUMNS'][]=$head; + } + $return['REPORT'][$reportCnt]['COLUMNS'][]="ROUND"; + $return['REPORT'][$reportCnt]['COLUMNS'][]="REMARKS"; + + $recCnt=0; + foreach($reportMatrix->getMatrix() as $matrix) + { + $theFinalVal=''; + foreach($return['REPORT'][$reportCnt]['COLUMNS'] as $col) + { + if($col!=='REMARKS') + { + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['RAW']=@$matrix[$col]['COMBINED']; + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['FINAL']=@$matrix[$col]['DATA']; + + if(isset($matrix[$col]['FIRST-NAME'])) + { + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['FIRST-NAME']=@$matrix[$col]['FIRST-NAME']; + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['LAST-NAME']=@$matrix[$col]['LAST-NAME']; + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['ROLL-NO']=@$matrix[$col]['ROLL-NO']; + } + $theFinalVal.=@$matrix[$col]['DATA']; + } + + if($col==='SL') + { + if(trim(@$matrix[$col]['DATA'])!=='' && is_numeric(trim(@$matrix[$col]['DATA']))===false) + { + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['RAW']=''; + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['FINAL']=''; + } + } + + if( ($return['REPORT'][$reportCnt]['HEADER']['SPORT-TYPE'] == ParserUtility::$_RELAY_ + || $return['REPORT'][$reportCnt]['HEADER']['SPORT-TYPE'] == ParserUtility::$_THROWING_TEAM_ + || $return['REPORT'][$reportCnt]['HEADER']['SPORT-TYPE'] == ParserUtility::$_JUMPING_TEAM_ ) + && trim(strtolower($col))==='school') + { + $schoolName = $this->__removeQuotedAlphabets(@$matrix[$col]['DATA']); + $return['REPORT'][$reportCnt]['DATA'][$recCnt][$col]['FINAL'] = $schoolName; + } + } + + $return['REPORT'][$reportCnt]['DATA'][$recCnt]['UN-FORMATED']['FINAL'] = @$matrix['RAW-LINE']['DATA']; + $return['REPORT'][$reportCnt]['DATA'][$recCnt]['REMARKS']['FINAL'] = trim(@$matrix['MARK']['DATA'].' '.@$matrix['REMARKS']['DATA']); + + + if(trim(@$return['REPORT'][$reportCnt]['DATA'][$recCnt]['REMARKS']['FINAL']) !== '') + { + $finesse = $this->__extractNumericFromRemarks($return['REPORT'][$reportCnt]['DATA'][$recCnt]['REMARKS']['FINAL']); + if($finesse!==false) + { + $return['REPORT'][$reportCnt]['DATA'][$recCnt]['FINESSE'] = $finesse; + } + } + + if(strlen(trim($theFinalVal))>0) + { + $recCnt++; + } + else + { + array_pop($return['REPORT'][$reportCnt]['DATA']); + } + } + } + else + { + $return['REPORT'][$reportCnt]['HAS-RECORDS'] = false; + $return['REPORT'][$reportCnt]['ERROR'] = $reportMatrix->getProblem(); + } + + $return['REPORT'][$reportCnt]['RAW-RECORDS'] = implode("\n",$reportMatrix->getReportLines()); + + $reportCnt++; + } + } + } + + if(!isset($return['REPORT'])) + { + $return['REPORT']=array(); + } + + foreach($return['REPORT'] as $ind=>$rptData) + { + if(!isset($rptData['DATA'])) + { + $return['REPORT'][$ind]['DATA']=array(); + } + } + + return $return; + } + + function process() + { + $this-> __processLines(); + } + + function __processLines() + { + if($this->debug) echo 'starting
'; + + $previousStatus = ''; + $currentStatus = 'license-header'; + $concatenator = ""; + $lineObj = null; + $reportPartStarts = false; + $reportPartLevel = ''; + + foreach($this->rawDataLines as $lnNo=>$ln) + { + if($this->debug) echo '
PROCESSING ............. '.$ln; + if($this->debug) echo '
previousStatus ......... '.$previousStatus; + + $analysis = new Lexicon($ln); + $analysis->preAnalyse(); + + if($this->debug) { echo '
ANALYSIS :::
'; print_r($analysis); echo "
"; } + + if(!$reportPartStarts) + { + if($previousStatus=='') + { + //echo '
--->0-out~'.$analysis->getGeneralContext(); + + $currentStatus = 'license-header'; + if($analysis->getGeneralContext() != 'DECORATOR' && $analysis->getGeneralContext() != 'LINE-BREAK' && ParserUtility::startsWithOneOfThem(trim($ln), ParserUtility::$terms_headerStartsWith) ) + { + //echo '
--->0~'.$analysis->getGeneralContext(); + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + } + $previousStatus = 'license-header'; + } + else if($previousStatus=='license-header') + { + //if($this->debug) echo '
`'.$ln.'` is a '.$analysis->getGeneralContext() ; + //echo '
--->1/2-out~'.trim($ln).'~'.implode('#',ParserUtility::$terms_headerStartsWith); + //echo '
--->1/2-out~'.$analysis->getGeneralContext().'~>'.ParserUtility::containsOneOfThem(trim($ln), ParserUtility::$terms_headerLicenseTos).'<'; + + if($analysis->getGeneralContext() != 'DECORATOR' && $analysis->getGeneralContext() != 'LINE-BREAK' && ParserUtility::startsWithOneOfThem(trim($ln), ParserUtility::$terms_headerLicenseTos) ) + { + //echo '
--->1~'.$analysis->getGeneralContext(); + + $lineObj->setOriginalContent($ln); + $lineObj->process(); + + } + elseif($analysis->getGeneralContext() != 'DECORATOR' && $analysis->getGeneralContext() != 'LINE-BREAK') + { + //echo '
--->2~'.$analysis->getGeneralContext(); + + $currentStatus = 'school-report-head'; + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + $previousStatus = 'school-report-head'; + } + } + else if($previousStatus=='school-report-head') + { + //echo '
--->3-out~'.$analysis->getGeneralContext(); + if($analysis->getGeneralContext() != 'DECORATOR' && $analysis->getGeneralContext() != 'LINE-BREAK') + { + //echo '
--->3~'.$analysis->getGeneralContext(); + + $currentStatus = 'school-name-head'; + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + $previousStatus = 'school-name-head'; + + } + } + else if($previousStatus=='school-name-head') + { + //echo '
--->4-out~'.$analysis->getGeneralContext(); + if($analysis->getGeneralContext() != 'DECORATOR' && $analysis->getGeneralContext() != 'LINE-BREAK') + { + //echo '
--->4~'.$analysis->getGeneralContext(); + + $currentStatus = 'result-label'; + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + $previousStatus = 'result-label'; + $reportPartStarts = true; + $currentStatus = ''; + } + } + + /* + if($analysis->getGeneralContext() == 'DECORATOR') + { + $reportPartStarts = true; + $previousStatus='decorator-start'; + + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + + $reportMatrix = $lineObj->getReportMatrix(); + $reportMatrix->setDecoratorLength(strlen($ln)); + } + */ + + } + else + { + if(trim($ln)==='' || $analysis->getGeneralContext() == 'LINE-BREAK') + { + if($previousStatus=='line-break' || $previousStatus=='decorator-start') + { + $lineObj->setOriginalContent($ln); + $lineObj->process(); + $previousStatus = 'line-break'; + } + else + { + $reportPartLevel = ''; + $currentStatus = 'line-break'; + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + $previousStatus = 'line-break'; + } + } + else + { + if($previousStatus=='line-break' || $previousStatus=='decorator-start') + { + $currentStatus = "report-data"; + $lineObj = $this->__getOneLineObject($currentStatus,$lineObj); + $lineObj->setOriginalContent($ln); + $lineObj->process(); + + $reportMatrix = $lineObj->getReportMatrix(); + + if($analysis->getGeneralContext() == 'HEADER') + { + $reportMatrix->parseHeaders($ln); + $lineObj->setComposedData("SPORT-ROUND",$reportMatrix->getSportsRound()); + } + $previousStatus = "report-data"; + } + elseif($previousStatus == 'report-data') + { + $reportMatrix = $lineObj->getReportMatrix(); + $lineObj->setComposedData("SPORT-ROUND",$reportMatrix->getSportsRound()); + + if($analysis->getGeneralContext() == 'DECORATOR') + { + $reportMatrix->setDecoratorLength(strlen($ln)); + } + else if($analysis->getGeneralContext() == 'HEADER') + { + $reportMatrix->parseHeaders($ln); + } + else if($analysis->getGeneralContext() == 'SPORTS-ROUND') + { + $reportMatrix->parseData($ln); + $analysis->analyse(); + $reportMatrix->setSportsLevel($analysis->getSportsRound()); + $lineObj->setComposedData("SPORTS-ROUND",$reportMatrix->getSportsRound()); + } + else + { + $reportMatrix->parseData($ln); + } + + + /* + if(ParserUtility::startsWith(trim($ln), "=====")) + { + if($reportPartLevel == '') + { + $reportPartLevel = 'DecoratorStart'; + $reportMatrix->setDecoratorLength(strlen($ln)); + } + else + { + $reportPartLevel = 'DecoratorEnd'; + } + continue; + } + else + { + if($reportPartLevel == 'DecoratorStart') + { + $reportMatrix->parseHeaders($ln); + } + else if($reportPartLevel == 'DecoratorEnd') + { + $reportMatrix->parseData($ln); + } + } + */ + } + } + //$lineObj = null; + //$lineObj = $this->__getOneLineObject("",$lineObj); + //$lineObj->process(); + } + + if($this->debug) echo '
currentStatus ......... '.$currentStatus; + if($this->debug) echo '
previousStatus ......... '.$previousStatus; + + if($this->debug) { echo '
LINE OBJECT :::
'; print_r($lineObj); echo "
"; } + + if($this->debug) echo '

:-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-:


'; + } + $this->__getOneLineObject("",$lineObj); + } + + function __getOneLineObject($currentStatus,$previousLineObject) + { + if($previousLineObject !== null) + { + $this->processedDataLines[] = $previousLineObject; + } + return new RecordLine($currentStatus); + } + + function __removeQuotedAlphabets($text) + { + $alphabets = array(); + $alphabets[] = 'a'; + $alphabets[] = 'b'; + $alphabets[] = 'c'; + $alphabets[] = 'd'; + $alphabets[] = 'e'; + $alphabets[] = 'f'; + $alphabets[] = 'g'; + $alphabets[] = 'h'; + $alphabets[] = 'i'; + $alphabets[] = 'j'; + $alphabets[] = 'k'; + $alphabets[] = 'l'; + $alphabets[] = 'm'; + $alphabets[] = 'n'; + $alphabets[] = 'o'; + $alphabets[] = 'p'; + $alphabets[] = 'q'; + $alphabets[] = 'r'; + $alphabets[] = 's'; + $alphabets[] = 't'; + $alphabets[] = 'u'; + $alphabets[] = 'v'; + $alphabets[] = 'w'; + $alphabets[] = 'x'; + $alphabets[] = 'y'; + $alphabets[] = 'z'; + + foreach($alphabets as $alphabet) + { + $text = trim(str_replace(" '".strtoupper($alphabet)."' "," ",$text)); + $text = trim(str_replace(" '".$alphabet."' "," ",$text)); + + $text = trim(str_replace("'".strtoupper($alphabet)."' "," ",$text)); + $text = trim(str_replace("'".$alphabet."' "," ",$text)); + + $text = trim(str_replace(" '".strtoupper($alphabet)."'"," ",$text)); + $text = trim(str_replace(" '".$alphabet."'"," ",$text)); + } + + return trim($text); + } + + function __cleanUpEventname($eventName, $specific=false) + { + $eventName = trim($eventName); + + $endCharacters = array("/","-","[","(","{"); + $dictionary = Lexicon::getDictionary(); + + if(ParserUtility::endsWithOneOfThem($eventName, $endCharacters)) + { + $eventName = substr($eventName, 0, -1); + } + foreach($dictionary['GENDER'] as $gender) + { + if($specific) + { + $eventName = trim(str_replace(ucwords($gender),"",$eventName)); + $eventName = trim(str_replace(strtoupper($gender),"",$eventName)); + $eventName = trim(str_replace($gender,"",$eventName)); + } + else + { + $eventName = trim(str_replace(' '.ucwords($gender).' '," ",$eventName)); + $eventName = trim(str_replace(' '.strtoupper($gender).' '," ",$eventName)); + $eventName = trim(str_replace(' '.$gender.' '," ",$eventName)); + + $eventName = trim(str_replace(ucwords($gender).' '," ",$eventName)); + $eventName = trim(str_replace(strtoupper($gender).' '," ",$eventName)); + $eventName = trim(str_replace($gender.' '," ",$eventName)); + + $eventName = trim(str_replace(' '.ucwords($gender)," ",$eventName)); + $eventName = trim(str_replace(' '.strtoupper($gender)," ",$eventName)); + $eventName = trim(str_replace(' '.$gender," ",$eventName)); + } + } + foreach($dictionary['SPORTS-LEVEL'] as $levels) + { + foreach($dictionary[$levels] as $level) + { + if($specific) + { + $eventName = trim(str_replace(ucwords($level),"",$eventName)); + $eventName = trim(str_replace(strtoupper($level),"",$eventName)); + $eventName = trim(str_replace($level,"",$eventName)); + } + else + { + $eventName = trim(str_replace(' '.ucwords($level).' '," ",$eventName)); + $eventName = trim(str_replace(' '.strtoupper($level).' '," ",$eventName)); + $eventName = trim(str_replace(' '.$level.' '," ",$eventName)); + + $eventName = trim(str_replace(ucwords($level).' '," ",$eventName)); + $eventName = trim(str_replace(strtoupper($level).' '," ",$eventName)); + $eventName = trim(str_replace($level.' '," ",$eventName)); + + $eventName = trim(str_replace(' '.ucwords($level)," ",$eventName)); + $eventName = trim(str_replace(' '.strtoupper($level)," ",$eventName)); + $eventName = trim(str_replace(' '.$level," ",$eventName)); + } + } + } + + $eventName = trim($eventName); + + foreach($dictionary['GENDER'] as $gender) + { + if(stripos($eventName, $gender)!==false) + { + $eventName = $this->__cleanUpEventname($eventName,true); + } + } + foreach($dictionary['SPORTS-LEVEL'] as $levels) + { + foreach($dictionary[$levels] as $level) + { + if(stripos($eventName, $level)!==false) + { + $eventName = $this->__cleanUpEventname($eventName,true); + } + } + } + if(ParserUtility::endsWithOneOfThem($eventName, $endCharacters)!==false) + { + $eventName = $this->__cleanUpEventname($eventName,true); + } + return trim($eventName); + } + + function __extractNumericFromRemarks($remarks) + { + if(strpos($remarks,'QUALIFIED')!==false) + { + $remrk = trim(str_replace('QUALIFIED','',$remarks)); + $expld = explode(' ',$remrk); + if(sizeof($expld)==1) + { + if(is_numeric($remrk)) + { + return array("RAW" => $remrk,"FINAL" => $remrk); + } + elseif(strpos($remrk,"-") ) + { + $remrkF = ParserUtility::numerizeLength($remrk); + if(is_numeric($remrkF)) + { + return array("RAW" => $remrk,"FINAL" => $remrkF); + } + } + elseif(strpos($remrk,":")) + { + $remrkF = ParserUtility::numerizeTime($remrk); + if(is_numeric($remrkF)) + { + return array("RAW" => $remrk,"FINAL" => $remrkF); + } + } + } + } + return false; + } +} +?> \ No newline at end of file diff --git a/app/classes/class.parserutility.php b/app/classes/class.parserutility.php new file mode 100644 index 0000000..9f785f3 --- /dev/null +++ b/app/classes/class.parserutility.php @@ -0,0 +1,254 @@ +"string", + "Year"=>"int", + "Seed"=>"float", + "School"=>"string", + "Finals"=>"float", + "Comp#"=>"int", + "H#"=>"int", + "Points"=>"int", + "SL"=>"int", + "Prelims"=>"float", + "Time"=>"float", + "ROUND"=>"string"); + + public static $keys_fld_Place = array("SL"); + public static $keys_fld_perform_time_char = array("Time","Prelim","Prelims","Final","Finals"); + public static $keys_fld_school_name = array("School"); + public static $keys_fld_athlete_name = array("Name"); + public static $keys_fld_class_year = array("Year"); + + static function startsWithOneOfThem($haystack, $needles) + { + foreach($needles as $k=>$needle) + { + if(self::startsWith($haystack, $needle)) + { + return true; + } + } + return false; + } + + static function startsWith ($haystack, $needle) + { + $len = strlen($needle); + return (substr(strtolower($haystack), 0, $len) === strtolower($needle)); + } + + static function endsWithOneOfThem($haystack, $needles) + { + foreach($needles as $k=>$needle) + { + if(self::endsWith($haystack, $needle)) + { + return true; + } + } + return false; + } + + static function endsWith($haystack, $needle) + { + $len = strlen($needle); + if ($len == 0) { + return true; + } + return (substr(strtolower($haystack), -$len) === strtolower($needle)); + } + + static function containsWhichOneOfThem($haystack, $needles) + { + foreach($needles as $k=>$needle) + { + if(self::contains($haystack, $needle)) + { + return $needle; + } + } + return false; + } + + static function containsOneOfThem($haystack, $needles) + { + foreach($needles as $k=>$needle) + { + if(self::contains($haystack, $needle)) + { + return true; + } + } + return false; + } + + static function contains($haystack, $needle) + { + foreach($haystack as $k=>$hay) + { + if(strtolower($hay)===strtolower($needle)) + { + return true; + } + } + return false; + } + + static function getWords($sentence,$trim=true) + { + $words = array(); + $ws = explode(" ", $sentence); + + foreach($ws as $wds) + { + if($trim && trim($wds)=='') + { + continue; + } + + $words[] = trim($wds); + } + + return $words; + } + + static function in_array_i($haystack, $needle) + { + return in_array(strtolower($needle), array_map("strtolower", $haystack)); + } + + static function array_key_exists_i($haystack, $needle) + { + foreach(array_keys($haystack) as $key) + { + if(strtolower($key)===strtolower($needle)) + { + return true; + } + } + return false; + } + + static function get_start_end_pos($haystack, $needle) + { + $lastPos = 0; + $positions = array(); + $return = array(); + + while (($lastPos = strpos($haystack, $needle, $lastPos))!== false) { + $positions[] = $lastPos; + $lastPos = $lastPos + strlen($needle); + } + + $ind=0; + foreach ($positions as $value) { + $return[$ind]['START-POSITION'] = $value; + $return[$ind]['END-POSITION'] = ($return[$ind]['START-POSITION'] + strlen($needle))-1; + $return[$ind]['LENGTH'] = strlen($needle); + $ind++; + } + return $return; + } + + static function get_array_value_i($array, $key) + { + foreach($array as $k=>$val) + { + if(strtolower(trim($k))===strtolower(trim($key))) + { + return $val; + } + } + return ''; + } + + static function parse_host($url) + { + return parse_url($url,PHP_URL_HOST); + } + + static function removeAlphabetsOnly($string) + { + return preg_replace("/[^0-9.:\-]/", "", $string); + } + + static function numerizeTime($string) + { + $calcData = $string; + $expld = explode(":",$string); + if(sizeof($expld)==3) + { + $calcData = (floatval($expld[0])*60*60)+(floatval($expld[1])*60*60)+floatval($expld[2]); + } + else if(sizeof($expld)==2) + { + $calcData = (floatval($expld[0])*60)+floatval($expld[1]); + } + else + { + $calcData = floatval($expld[0]); + } + return $calcData; + } + + static function numerizeLength($string) + { + $calcData = $string; + $expld = explode("-",$string); + if(sizeof($expld)==2) + { + $calcData = (floatval($expld[0])*12)+floatval($expld[1]); + } + else + { + $calcData = floatval($expld[0]); + } + return $calcData; + } + } +?> \ No newline at end of file diff --git a/app/classes/class.recordline.php b/app/classes/class.recordline.php new file mode 100644 index 0000000..f0a1a75 --- /dev/null +++ b/app/classes/class.recordline.php @@ -0,0 +1,243 @@ +type = $type; + //$this->hash = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM)); + } + + function setOriginalContent($line,$refresh=false) + { + if($refresh) + { + $this->originalContent = array(); + } + $this->originalContent[] = trim($line); + $this->lineCount = count($this->originalContent); + $this->composedContent = implode(" ",$this->originalContent); + } + + function setComposedData($key,$value) + { + $this->composedData[$key] = $value; + } + + function getType() + { + return $this->type; + } + + function getComposedData() + { + return $this->composedData; + } + + function getReportMatrix() + { + return $this->reportMatrix; + } + + function process() + { + + switch($this->type) + { + case 'license-header': + if($this->debug) echo "
Top Label(lh) - Parsing -> ".$this->composedContent; + $this->__processLicenseHeader(); + break; + case 'school-report-head': + if($this->debug) echo "
Top Label(rh) - Parsing -> ".$this->composedContent; + $this->__processSchoolReportHead(); + break; + case 'school-name-head': + if($this->debug) echo "
Top Label(sh) - Parsing -> ".$this->composedContent; + $this->__processSchoolNameHead(); + break; + case 'result-label': + if($this->debug) echo "
Top Label(rl) - Parsing -> ".$this->composedContent; + $this->__processResultLabel(); + break; + case 'line-break': + if($this->debug) echo "
Content - Parsing -> Blank Line"; + $this->__processLineBreak(); + break; + case 'report-data': + $this->__processReportData(); + break; + + } + } + + function __processLicenseHeader() + { + $info_divider = "-"; + + $words = ParserUtility::getWords($this->composedContent); + + $licenseToPart = array(); + $subLicencePart = array(); + $subLicenceToPart = array(); + $subLicenceDatePart = array(); + + $foundDivider = false; + + foreach($words as $word) + { + if( !$foundDivider && trim($word)===$info_divider) + { + $foundDivider = true; + continue; + } + + if(!$foundDivider) + { + $licenseToPart[] = trim($word); + } + else + { + $subLicencePart[] = trim($word); + } + } + + $foundDivider = false; + foreach($subLicencePart as $word) + { + if(preg_match("/^(((0)[0-9])|((1)[0-2]))(\/)([0-2][0-9]|(3)[0-1])(\/)\d{4}$/i", $word) + || preg_match("/^\d{1,2}(\/)\d{1,2}(\/)\d{4}$/i", $word) ) { + $foundDivider = true; + + } + + if(!$foundDivider) + { + $subLicenceToPart[] = trim($word); + } + else + { + $subLicenceDatePart[] = trim($word); + } + } + + $this->composedData["LICENCE TO"] = implode(" ",$licenseToPart); + $this->composedData["SUB-LICENSE"] = implode(" ",$subLicenceToPart); + $this->composedData["LICENSE DATE"] = implode(" ",$subLicenceDatePart); + } + + function __processSchoolReportHead() + { + $info_divider = "-"; + + $words = ParserUtility::getWords($this->composedContent); + + $eventNamePart = array(); + $datePart = array(); + + $foundDivider = false; + + foreach($words as $word) + { + if( !$foundDivider && trim($word)===$info_divider) + { + $foundDivider = true; + continue; + } + + if(!$foundDivider) + { + $eventNamePart[] = trim($word); + } + else + { + $datePart[] = trim($word); + } + } + + $this->composedData["EVENT NAME"] = implode(" ",$eventNamePart); + $this->composedData["EVENT DATE"] = implode(" ",$datePart); + } + + function __processSchoolNameHead() + { + $words = ParserUtility::getWords($this->composedContent); + + $schoolNamePart = array(); + + foreach($words as $word) + { + $schoolNamePart[] = trim($word); + } + + $this->composedData["SCHOOL NAME"] = implode(" ",$schoolNamePart); + } + + function __processResultLabel() + { + $words = ParserUtility::getWords($this->composedContent); + + $resultLabelPart = array(); + + foreach($words as $word) + { + $resultLabelPart[] = trim($word); + } + + $this->composedData["LABEL"] = implode(" ",$resultLabelPart); + } + + function __processLineBreak() + { + $this->composedData["LINE-COUNT"] = count($this->originalContent); + } + + function __processReportData() + { + $this->__processReportHeaderLabel(); + $this->reportMatrix = new ReportMatrix(@$this->composedData["SPORT-GROUP"], @$this->composedData["SPORT"]); + $this->reportMatrix->setSportsLevel(@$this->composedData["SPORT-ROUND"]); + } + + function __processReportHeaderLabel() + { + if($this->debug) echo "
LINE - Parsing -> ".$this->composedContent; + $words = ParserUtility::getWords($this->composedContent); + + $labelPart = array(); + + foreach($words as $word) + { + $labelPart[] = trim($word); + } + + $this->composedData["HEADER"] = implode(" ",$labelPart); + + $hAnalysis = new Lexicon($this->composedData["HEADER"]); + $hAnalysis->analyse(); + + $this->composedData["HEADER-ANALYSIS"] = $hAnalysis; + + $this->composedData["GENDER"] = $hAnalysis->getGender(); + $this->composedData["SPORT-GROUP"] = $hAnalysis->getSportsType(); + $this->composedData["SPORT"] = $hAnalysis->getSports(); + $this->composedData["SPORT-ROUND"] = $hAnalysis->getSportsRound(); + + if($this->debug) { echo '
LINE - Parsed ->
';print_r($this->composedData); echo '
'; } + } +} +?> \ No newline at end of file diff --git a/app/classes/class.reportmatrix.php b/app/classes/class.reportmatrix.php new file mode 100644 index 0000000..b08ef7c --- /dev/null +++ b/app/classes/class.reportmatrix.php @@ -0,0 +1,588 @@ +sportGroup = $sportGroup; + $this->sport = $sport; + } + + function setSportsLevel($sportLevel) + { + $this->sportLevel = $sportLevel; + } + + function getSportsRound() + { + return $this->sportLevel; + } + + function getHeaders() + { + return $this->header; + } + + function getMatrix() + { + return $this->matrix; + } + + function getReportLines() + { + return $this->reportLines; + } + + function isUsable() + { + return $this->usable; + } + + function getProblem() + { + return $this->problem; + } + + function setDecoratorLength($decoratorLen) + { + $this->decoratorLen = $decoratorLen; + } + + function parseHeaders($line) + { + $this->reportLines[] = $line; + + $hAnalysis = new Lexicon($line); + $hAnalysis->preAnalyse(); + + $dictionary = Lexicon::getDictionary(); + + $words = ParserUtility::getWords($line); + + $count = 1; + foreach($words as $word) + { + //echo '
~'.$word.'~IN~'.implode("#",$dictionary['HEADER-COL']) ; + if(ParserUtility::in_array_i($dictionary['HEADER-COL'], $word)===false) + { + $this->usable = false; + $this->problem = "Unknown Header ".$word; + $this->__resetObj(); + return; + } + $this->header[$count] = $word; + $count++; + } + $this->headerCount = count($this->header); + + $previousHead = "SL"; + $this->headerPositions[$previousHead]['INDEX'] = 0; + $this->headerPositions[$previousHead]['POSITION-START'] = 0; + $this->headerPositions[$previousHead]['TEXT-END'] = strlen($previousHead); + $this->headerPositions[$previousHead]['TEXT-LENGTH'] = strlen($previousHead); + + foreach($this->header as $head) + { + if($this->debug) echo "
Header - Parsing '".$head."' IN -> ".$line; + + $stEnd = ParserUtility::get_start_end_pos($line, $head); + + $startEnd = $stEnd[0]; + + //if($this->debug) { echo "
POSITION - "; print_r($startEnd); } + + + $this->headerPositions[$previousHead]['POSITION-END'] = $startEnd['START-POSITION']-1; + $this->headerPositions[$previousHead]['POSITION-LENGTH'] = ($this->headerPositions[$previousHead]['POSITION-END'] - $this->headerPositions[$previousHead]['POSITION-START'])+1; + + $this->headerPositions[$head]['INDEX'] = $this->headerPositions[$previousHead]['INDEX']+1; + $this->headerPositions[$head]['POSITION-START'] = $startEnd['START-POSITION']; + $this->headerPositions[$head]['TEXT-END'] = $startEnd['END-POSITION']; + $this->headerPositions[$head]['TEXT-LENGTH'] = $startEnd['LENGTH']; + + $previousHead = $head; + + if($this->debug) echo "
Header - Set position data of '".$head."' "; + if($this->debug) echo "

:::::::::::::::::::::::::::::

"; + } + $this->headerPositions[$previousHead]['POSITION-END'] = $this->decoratorLen; + } + + function parseData($line) + { + $this->reportLines[] = $line; + + if($this->usable) + { + $hAnalysis = new Lexicon($line); + $hAnalysis->analyse(); + + $words = ParserUtility::getWords($line); + + if($this->debug) echo "
Line - Operating on '".$line."' which is >>".$hAnalysis->getGeneralContext(); + + if($hAnalysis->getGeneralContext() == 'SPORTS-ROUND') + { + $this->sportLevel = $hAnalysis->getSportsRound(); + + if($this->debug) echo "
SETTING SPORTS-ROUND >> '".$hAnalysis->getSportsRound()."'"; + if($this->debug) echo "

---------------------------------

"; + } + else + { + $headerIndex = 0; + $incrementRow = true; + + $hasSL = false; + $wordStEnd = ParserUtility::get_start_end_pos($line, $words[0]); + if(@$wordStEnd[0]['END-POSITION']<=@$this->headerPositions['SL']['POSITION-END'] + && @$wordStEnd[0]['END-POSITION']>@$this->headerPositions['SL']['POSITION-START']) + { + $hasSL = true; + } + + foreach($words as $indx=>$wrd) + { + $word = ' '.$wrd.' '; + + if($this->debug) echo "
Line - Parsing '".$word."' IN -> ".$line." for ".$this->sportGroup; + + switch($this->sportGroup) + { + case ParserUtility::$_RUNNING_ : + case ParserUtility::$_RELAY_ : + if($hasSL===true) + { + $headerIndex = $this->__processRowFor_jump($indx, $word, $line, $headerIndex); + if($headerIndex<0) + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + } + else + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + break; + case ParserUtility::$_JUMPING_ : + case ParserUtility::$_JUMPING_TEAM_ : + if($hasSL===true) + { + $headerIndex = $this->__processRowFor_jump($indx, $word, $line, $headerIndex); + if($headerIndex<0) + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + } + else + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + break; + case ParserUtility::$_THROWING_ : + case ParserUtility::$_THROWING_TEAM_ : + if($hasSL===true) + { + $headerIndex = $this->__processRowFor_throw($indx, $word, $line, $headerIndex); + if($headerIndex<0) + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + } + else + { + $this->__processRowFor_addnlData($indx, $word, $line, $headerIndex); + $incrementRow = false; + } + break; + default : + $this->usable = false; + $this->problem = "PARSER NOT IMPLEMENTED"; + $this->__resetObj(); + break; + } + } + $this->__processCombinatorData(); + $this->prc = $this->rowCounter; + $this->rowCounter++; + } + + if($this->debug) echo "

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

"; + } + } + + function __processRowFor_addnlData($indx, $word, $line, $hIndex) + { + $this->matrix[$this->prc]['ADDTIONAL-DATA'][$line]['COMBINATOR'][] = $word; + } + + function __processRowFor_run($indx, $word, $line, $hIndex) + { + return $this->__pattern1($indx, $word, $line, $hIndex); + } + + function __processRowFor_jump($indx, $word, $line, $hIndex) + { + return $this->__pattern1($indx, $word, $line, $hIndex); + } + + function __processRowFor_throw($indx, $word, $line, $hIndex) + { + return $this->__pattern1($indx, $word, $line, $hIndex); + } + + function __pattern1($indx, $word, $line, $hIndex) + { + $wordStEnd = ParserUtility::get_start_end_pos($line, $word); + + if(sizeof($wordStEnd)==0) + { + $wordStEnd = ParserUtility::get_start_end_pos($line, ' '.trim($word)); + } + + if(sizeof($wordStEnd)==0) + { + $wordStEnd = ParserUtility::get_start_end_pos($line, trim($word).' '); + } + + + $headerIndex = -1; + + if($this->debug) { echo "
POSITION - "; print_r($wordStEnd); } + if($this->debug) { echo "
HEADER - "; print_r($this->headerPositions); } + + if($indx==0 + && @$wordStEnd[0]['END-POSITION']<=$this->headerPositions['SL']['POSITION-END'] + && @$wordStEnd[0]['END-POSITION']>$this->headerPositions['SL']['POSITION-START'])//&& is_numeric(trim($word))===true + { + $this->matrix[$this->rowCounter]['RAW-LINE']["COMBINATOR"][0] = trim($line); + $this->matrix[$this->rowCounter]['ROUND']["COMBINATOR"][0] = $this->getSportsRound(); + + $this->matrix[$this->rowCounter]["SL"]["COMBINATOR"][0] = trim($word); + if($this->debug) echo "
Putting '".$word."' AT -> SL"; + if($this->debug) echo "

---------------------------------

"; + } + else if(isset($this->matrix[$this->rowCounter]['SL'])) + { + foreach($wordStEnd as $wordStartEnd) + { + if($wordStartEnd['END-POSITION']<=$this->decoratorLen) + { + $headerIndex = 0; + foreach($this->headerPositions as $header=>$headerPos) + { + if($this->debug) echo "
Matching end 'w-".$wordStartEnd['END-POSITION']."' between 'h-".$headerPos['POSITION-START']."' and 'h-".$headerPos['POSITION-END']."' @ ".$header.' HAVING hIndex=>'.$hIndex; + + if($wordStartEnd['END-POSITION']<=$headerPos['POSITION-END'] + && $wordStartEnd['END-POSITION']>$headerPos['POSITION-START'] + && $headerIndex >= $hIndex) + { + if($this->debug) echo "
-- Success Matching 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-END']."' and 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-START']."' @ ".$header.' HAVING hIndex=>'.$hIndex.''; + $this->matrix[$this->rowCounter][$header]['COMBINATOR'][] = trim($word); + if($this->debug) echo "
Line - Putting '".$word."' AT -> ".$header; + if($this->debug) echo "

---------------------------------

"; + + if(count($wordStEnd)>1) + { + $headerIndex++; + } + + return $headerIndex; + } + elseif(($wordStartEnd['END-POSITION']-$headerPos['POSITION-END'])==1) + { + if($this->debug) echo "
-- Force Matching 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-END']."' and 'w-".$wordStartEnd['END-POSITION']."' with 'h-".$headerPos['POSITION-START']."' @ ".$header.''; + $this->matrix[$this->rowCounter][$header]['COMBINATOR'][] = trim($word); + if($this->debug) echo "
Line - Putting '".$word."' AT -> ".$header; + if($this->debug) echo "

---------------------------------

"; + return $headerIndex; + } + $headerIndex++; + } + } + else + { + //echo "IN~".$word.' >> '.$line; + $this->matrix[$this->rowCounter]['REMARKS']['COMBINATOR'][] = trim($word); + } + } + } + + return $headerIndex; + } + + function __processCombinatorData() + { + if(is_array($this->matrix) && sizeof($this->matrix) > 0) + { + if(is_array(@$this->matrix[$this->rowCounter])) + { + foreach($this->matrix[$this->rowCounter] as $header=>$rowData) + { + if($header==='ADDTIONAL-DATA') + { + $toDelete = array(); + $cntr = 0; + foreach($this->matrix[$this->rowCounter]['ADDTIONAL-DATA'] as $lnn=>$addlnRec) + { + $this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$cntr]["COMBINATOR"] = $addlnRec['COMBINATOR']; + $this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$cntr]["COMBINED"] = implode(" ",$addlnRec['COMBINATOR']); + $cntr++; + $toDelete[] = $lnn; + } + + foreach($toDelete as $lndl) + { + unset($this->matrix[$this->rowCounter]['ADDTIONAL-DATA'][$lndl]); + } + } + else + { + if(is_array(@$rowData['COMBINATOR'])) + { + $this->matrix[$this->rowCounter][$header]["COMBINED"] = implode(" ",$rowData['COMBINATOR']); + if(strtolower($header)==='name') + { + $analysis = new Lexicon(implode(" ",$rowData['COMBINATOR'])); + $nameAnalysis = $analysis->getAnalysisForNames(); + + $this->matrix[$this->rowCounter][$header]["COMBINED"] = @$nameAnalysis['FULL-NAME']; + $this->matrix[$this->rowCounter][$header]["ROLL-NO"] = @$nameAnalysis['ROLL-NO']; + $this->matrix[$this->rowCounter][$header]["FIRST-NAME"] = @$nameAnalysis['FIRST-NAME']; + $this->matrix[$this->rowCounter][$header]["LAST-NAME"] = @$nameAnalysis['LAST-NAME']; + } + } + } + } + } + switch($this->sportGroup) + { + case ParserUtility::$_RUNNING_ : + case ParserUtility::$_RELAY_ : + $this->__processDataFor_run(); + break; + case ParserUtility::$_JUMPING_ : + case ParserUtility::$_JUMPING_TEAM_ : + $this->__processDataFor_jump(); + break; + case ParserUtility::$_THROWING_ : + case ParserUtility::$_THROWING_TEAM_ : + $this->__processDataFor_throw(); + break; + default : + break; + } + } + } + + function __processDataFor_run() + { + if(is_array(@$this->matrix[$this->rowCounter])) + { + foreach($this->matrix[$this->rowCounter] as $header=>$rowData) + { + $rec = @ParserUtility::$terms_reportHeader_dType[$header]; + switch($rec) + { + case "string": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + break; + case "int": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + $this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + break; + case "float": + if(trim( $rowData['COMBINED'])!=='') + { + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + $this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + + if(strpos($rowData['COMBINED'],":")) + { + $calcData = ParserUtility::numerizeTime($rowData['COMBINED']); + $this->matrix[$this->rowCounter][$header]["DATA"] = $calcData; + } + else + { + $this->matrix[$this->rowCounter][$header]["DATA"] = floatval($rowData['COMBINED']); + } + } + break; + default: + if($header!=='ADDTIONAL-DATA') + { + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + } + break; + } + } + } + } + + function __processDataFor_jump() + { + if(is_array(@$this->matrix[$this->rowCounter])) + { + foreach($this->matrix[$this->rowCounter] as $header=>$rowData) + { + $rec = @ParserUtility::$terms_reportHeader_dType[$header]; + switch($rec) + { + case "string": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + break; + case "int": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + $this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + break; + case "float": + if(trim( $rowData['COMBINED'])!=='') + { + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + + $theData = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + + $this->matrix[$this->rowCounter][$header]["COMBINED"] = $theData ; + + if(strpos($theData,"-")) + { + $calcData = ParserUtility::numerizeLength($theData); + $this->matrix[$this->rowCounter][$header]["DATA"] = $calcData; + } + else + { + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + } + } + break; + default: + if($header!=='ADDTIONAL-DATA') + { + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + } + break; + } + } + } + } + + function __processDataFor_throw() + { + if(is_array(@$this->matrix[$this->rowCounter])) + { + foreach($this->matrix[$this->rowCounter] as $header=>$rowData) + { + $rec = @ParserUtility::$terms_reportHeader_dType[$header]; + switch($rec) + { + case "string": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + break; + case "int": + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + $this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + break; + case "float": + if(trim( $rowData['COMBINED'])!=='') + { + if(strpos(strtoupper($rowData['COMBINED']),"Q")!==false) + { + $this->matrix[$this->rowCounter]["MARK"]["DATA"] = "QUALIFIED"; + } + $this->matrix[$this->rowCounter][$header]["COMBINED"] = ParserUtility::removeAlphabetsOnly($rowData['COMBINED']); + + if(strpos($rowData['COMBINED'],"-")) + { + $calcData = ParserUtility::numerizeLength($rowData['COMBINED']); + $this->matrix[$this->rowCounter][$header]["DATA"] = $calcData; + } + else + { + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + } + } + break; + default: + if($header==='ADDTIONAL-DATA') + { + } + else + { + $this->matrix[$this->rowCounter][$header]["DATA"] = $rowData['COMBINED']; + } + break; + } + } + } + } + + function __resetObj() + { + $this->decoratorLen = 0; + $this->header = array(); + $this->headerCount = 0; + $this->headerPositions = array(); + + $this->matrix = array(); + $this->rowCounter = 0; + } +} +?> \ No newline at end of file diff --git a/app/data-ripper.php b/app/data-ripper.php new file mode 100644 index 0000000..94db72a --- /dev/null +++ b/app/data-ripper.php @@ -0,0 +1,136 @@ +loadHTML($response); + libxml_clear_errors(); + $xpath = new DOMXpath($dom); + $values = array(); + $row = $xpath->query('//div[@id="meetResultsBody"]/pre'); + + foreach($row as $value) { + $values[] = trim($value->textContent); + } + + + return $values[0]; + + } + + function just_time_in_racing($url) + { + + + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $response = curl_exec($curl); + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML($response); + libxml_clear_errors(); + $xpath = new DOMXpath($dom); + $values = array(); + $row = $xpath->query('//body/pre'); + + foreach($row as $value) { + $values[] = trim($value->textContent); + } + + return @$values[0]; + + + + } + + function mysplitdrilldrowncase($url) + { + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $response = curl_exec($curl); + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML($response); + libxml_clear_errors(); + $xpath = new DOMXpath($dom); + $values = array(); + $row = $xpath->query('//table[contains(@class,"meetResultsList")]/tbody/tr/td/a/@href'); + + foreach($row as $value) { + + $values[] = milesplit('https://ny.milesplit.com'.str_replace('auto','raw',trim($value->textContent))); + } + + $body=implode(chr(13).chr(13).chr(13), $values); + + $html=''; + $html .= "Licensed to ".forHeader($url,'//div[contains(@class,"hostedBy")]/a').chr(13); + $html .=" ".forHeader($url,'//h1[contains(@class,"meetName")]').chr(13); + $html .=" ".forHeader($url,'//div[contains(@class,"venueName")]').chr(13); + $html .="Results".chr(13).chr(13); + $html .=$body; + + return $html; + + + } + + function forHeader($url,$parseHtml) + { + + $curl = curl_init($url); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $response = curl_exec($curl); + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML($response); + libxml_clear_errors(); + $xpath = new DOMXpath($dom); + $values = array(); + $row = $xpath->query($parseHtml); + + foreach($row as $value) { + $values[] = trim($value->textContent); + } + + return @$values[0]; + + } + + + + + +?> \ No newline at end of file diff --git a/app/data/text1.data b/app/data/text1.data new file mode 100644 index 0000000..a89d7fa --- /dev/null +++ b/app/data/text1.data @@ -0,0 +1,525 @@ + \ No newline at end of file diff --git a/app/data/text2.data b/app/data/text2.data new file mode 100644 index 0000000..17ced6b --- /dev/null +++ b/app/data/text2.data @@ -0,0 +1,1853 @@ + \ No newline at end of file diff --git a/app/data/text3.data b/app/data/text3.data new file mode 100644 index 0000000..25de28d --- /dev/null +++ b/app/data/text3.data @@ -0,0 +1,285 @@ + \ No newline at end of file diff --git a/app/data/text4.data b/app/data/text4.data new file mode 100644 index 0000000..ba1790c --- /dev/null +++ b/app/data/text4.data @@ -0,0 +1,839 @@ + \ No newline at end of file diff --git a/app/data/text5.data b/app/data/text5.data new file mode 100644 index 0000000..d771f58 --- /dev/null +++ b/app/data/text5.data @@ -0,0 +1,480 @@ + \ No newline at end of file diff --git a/app/data/text6.data b/app/data/text6.data new file mode 100644 index 0000000..08d1800 --- /dev/null +++ b/app/data/text6.data @@ -0,0 +1,429 @@ + \ No newline at end of file diff --git a/app/data/text7.data b/app/data/text7.data new file mode 100644 index 0000000..3194530 --- /dev/null +++ b/app/data/text7.data @@ -0,0 +1,54 @@ + \ No newline at end of file diff --git a/app/data/text8.data b/app/data/text8.data new file mode 100644 index 0000000..3e36cce --- /dev/null +++ b/app/data/text8.data @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/data/text9.data b/app/data/text9.data new file mode 100644 index 0000000..d51d9e7 --- /dev/null +++ b/app/data/text9.data @@ -0,0 +1,408 @@ + \ No newline at end of file diff --git a/app/index.php b/app/index.php new file mode 100644 index 0000000..a2b8b0f --- /dev/null +++ b/app/index.php @@ -0,0 +1,136 @@ +setRawInputData($text); + + + + echo "
";
+    $parser->process();
+    echo '

FORMATTED DATA

'; + print_r($parser->getFormatedData()); + echo "
"; + + $parsedData = $parser->getFormatedData(); + + if(is_array($parsedData) && sizeof($parsedData)>0) + { +?> +

+

PRESENTATION

+
+ +
+ + + + + +

+     +

+ [ + + ] +

+ + +

+ +

+ +


+ +

+ + + + + + + + + + + + + + + +
+ +
+
+

INTRICACIES

";
+    print_r($parser->getData());
+    echo "
"; + + +?> \ No newline at end of file diff --git a/app/parser.php b/app/parser.php new file mode 100644 index 0000000..2b64ed0 --- /dev/null +++ b/app/parser.php @@ -0,0 +1,16 @@ +setRawInputData($text); + $parser->process(); + return $parser->getFormatedData(); + } +?> \ No newline at end of file diff --git a/app/scraper.php b/app/scraper.php new file mode 100644 index 0000000..b07a9ec --- /dev/null +++ b/app/scraper.php @@ -0,0 +1,84 @@ + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..16327ce --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.5' + +services: + # lumen-app + sports_data_extractor: + build: + context: '.' + container_name: sports_data_extractor + volumes: + - ./app:/var/www/html + depends_on: + - sports_data_extractor_mysql_db + ports: + - 80:80 + networks: + - backend + + # mysql-db + sports_data_extractor_mysql_db: + image: mysql:5.7.22 + container_name: sports_data_extractor_mysql_db + restart: unless-stopped + tty: true + ports: + - "3306:3306" + expose: + - "3306" + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: sports_data_extractor_db + MYSQL_USER: root + MYSQL_PASSWORD: root + SERVICE_NAME: mysql + networks: + - backend + + # phpmyadmin + sports_data_extractor_phpmyadmin: + depends_on: + - sports_data_extractor_mysql_db + image: phpmyadmin/phpmyadmin + container_name: sports_data_extractor_phpmyadmin + restart: always + ports: + - '8081:80' + environment: + PMA_HOST: sports_data_extractor_mysql_db + MYSQL_ROOT_PASSWORD: root + networks: + - backend + +networks: + backend: + driver: bridge + diff --git a/extract_data.php b/extract_data.php new file mode 100644 index 0000000..f62e827 --- /dev/null +++ b/extract_data.php @@ -0,0 +1,2705 @@ +"; + //$_SESSION['extract_data_sajan'] = $output; + + // Save log master + $url = "extract_data.php?season_id=".$_REQUEST['season_id']."&step=2&master_id=".$master_id; + $url = $url."&log_id=".$log_id; + header("location: ".$url); + die(); + + } + //End:- Step 1: Extract data ******************************************************* + + //Begin:- RE-PROCESS pending records ************************************************** + if(isset($_REQUEST['reprocess']) && $_REQUEST['reprocess']=='1' && $step == 2) + { + $sql = "delete from ath_Importdatatable"; + $rs = sqlsrv_query($conn, $sql); + + $sql = "insert into ath_Importdatatable (Meet,Event,race_level,Round,Place,perform_time_char,performance,Number,meet_id,event_id,athlete_id,perform_time,Sex,performance_id,school_id,school_name,athlete_name,header_row,detail_row,event_type, class_year, event_unit, group_id) + select Meet,Event,race_level,Round,Place,perform_time_char,performance,Number,meet_id,event_id,athlete_id,perform_time,Sex,performance_id,school_id,school_name,athlete_name,header_row,detail_row,event_type,class_year, event_unit, group_id from ath_Importdatatable_history + where master_id = ".$_REQUEST['master_id']." and log_id =".$_REQUEST['log_id']. " order by Event,race_level,Round,Sex,Place"; + $rs = sqlsrv_query($conn, $sql); + $rows_affected = sqlsrv_rows_affected( $rs); + + $arrParams[]= ""; + $sql = "insert into ath_Importdatatable_Master_Log (master_id,entry_date, process_status) values ('".$_REQUEST['master_id']."',getdate(),0); SELECT SCOPE_IDENTITY()"; + $result = sqlsrv_query($conn, $sql, $arrParams); + sqlsrv_next_result($result); + sqlsrv_fetch($result); + $log_id = sqlsrv_get_field($result, 0); + + $sql = "UPDATE ath_Importdatatable_Master_Log SET total_result = ".$rows_affected." WHERE id =".$log_id; + $rs = sqlsrv_query($conn, $sql); + + $url = "extract_data.php?season_id=".$_REQUEST['season_id']."&step=2&master_id=".$_REQUEST['master_id']; + $url = $url."&log_id=".$log_id; + header("location: ".$url); + die(); + + } + //End:- RE-PROCESS pending records ************************************************** + + //Begin:- Step 2: Update School ID **************************************************** + if(((isset($_REQUEST['bStep2']) && $_REQUEST['bStep2'] == 'Update School Id') || (isset($_REQUEST['bStep2Reprocess']) && $_REQUEST['bStep2Reprocess'] == 'Reprocess') ) && $step == 2) + { + $row_count = 0; + $sql = "select * from ath_Importdatatable where isnull(school_id,0) = 0 and isnull(school_name,'') != '' order by id"; + $result = sqlsrv_query($conn,$sql); + while ($row = sqlsrv_fetch_array($result)) + { + $sql = "select id from ath_schools where School_name_long = '". str_replace("'","''", trim($row['school_name']))."' or School_name = '". str_replace("'","''", trim($row['school_name']))."' or LTRIM(RTRIM(alt_names)) = '". str_replace("'","''", trim($row['school_name']))."' or (',' + LTRIM(RTRIM(alt_names)) + ',') LIKE '%,' + '".str_replace("'","''", trim($row['school_name']))."' + ',%' "; + //echo $sql; + $rsSchool = sqlsrv_query($conn,$sql); + $rowSchool = sqlsrv_fetch_array($rsSchool); + $school_id = 0+$rowSchool['id']; + if($school_id>0) + { + $sql = "update ath_Importdatatable set school_id = ".$school_id." where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + } + } + + if(isset($_REQUEST['bStep2Save']) && $_REQUEST['bStep2Save'] == 'Save Changes') + { + $school_count = $_REQUEST['hSchoolCount']; + + for($i=0; $i<$school_count; $i++) + { + $id = $_REQUEST['hId'.$i]; + $athlete_name = $_REQUEST['athleteName'.$id]; + $school_name = $_REQUEST['schoolName'.$id]; + $sql = "update ath_Importdatatable set school_name = '". str_replace("'","''",$school_name)."', athlete_name = '". str_replace("'","''",$athlete_name)."' where id = ".$id; + + $rs = sqlsrv_query($conn, $sql); + + } + } + + if(isset($_REQUEST['bStep2Next']) && $_REQUEST['bStep2Next'] == 'Next') + { + $master_id = $_REQUEST['master_id']; + // Save log master + $url ="extract_data.php?season_id=".$_REQUEST['season_id']."&step=3&master_id=".$master_id; + if(isset($_REQUEST['log_id'])) + { + $log_id = $_REQUEST['log_id']; + $url = $url."&log_id=".$log_id; + } + header("location: ".$url); + die(); + } + //End:- Step 2: Update School ID **************************************************** + + + //Begin:- Step 3: Update Event ID *************************************************** + if(((isset($_REQUEST['bStep3']) && $_REQUEST['bStep3'] == 'Update Event Id') || (isset($_REQUEST['bStep3Reprocess']) && $_REQUEST['bStep3Reprocess'] == 'Reprocess') ) && $step == 3) + { + ini_set('max_execution_time', 300); + $row_count = 0; + $sql = "select * from ath_Importdatatable where isnull(event_id,0) = 0 and isnull(Event,'') != '' order by id"; + $result = sqlsrv_query($conn,$sql); + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + $sql = "select id, unit from ath_events where event_name = '". str_replace("'","''", trim($row['Event']))."' or LTRIM(RTRIM(alt_event_names)) = '". str_replace("'","''", trim($row['Event']))."' or (',' + LTRIM(RTRIM(alt_event_names)) + ',') LIKE '%,' + '".str_replace("'","''", trim($row['Event']))."' + ',%' "; + $rsEvent = sqlsrv_query($conn,$sql); + $rowEvent = sqlsrv_fetch_array($rsEvent); + $event_id = 0+$rowEvent['id']; + $event_unit = $rowEvent['unit']; + if($event_id>0) + { + $sql = "update ath_Importdatatable set event_id = ".$event_id.", event_unit = '".$event_unit."' where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + } + } + + if(isset($_REQUEST['bStep3Save']) && $_REQUEST['bStep3Save'] == 'Save Changes') + { + $group_id_count = $_REQUEST['hEventCount']; + for($i=1; $i<=$group_id_count; $i++) + { + $id = $_REQUEST['hId'.$i]; + $event_name = $_REQUEST['eventName'.$id]; + $race_level = $_REQUEST['raceLevel'.$id]; + $round = $_REQUEST['Round'.$id]; + $sql = "update ath_Importdatatable set race_level = '".str_replace("'","''",$race_level)."', round = '".str_replace("'","''",$round)."', Event = '". str_replace("'","''",$event_name)."' where group_id = ".$id; + $rs = sqlsrv_query($conn, $sql); + } + } + + if(isset($_REQUEST['bStep3Next']) && $_REQUEST['bStep3Next'] == 'Next') + { + $master_id = $_REQUEST['master_id']; + // Save log master + $url ="extract_data.php?season_id=".$_REQUEST['season_id']."&step=4&master_id=".$master_id; + if(isset($_REQUEST['log_id'])) + { + $log_id = $_REQUEST['log_id']; + $url = $url."&log_id=".$log_id; + } + header("location: ".$url); + die(); + } + //End:- Step 3: Update Event ID *************************************************** + + + //Begin:- Step 4: Update Athlete ID *********************************************** + if(((isset($_REQUEST['bStep4']) && $_REQUEST['bStep4'] == 'Update Athlete Id') || (isset($_REQUEST['bStep4Reprocess']) && $_REQUEST['bStep4Reprocess'] == 'Reprocess') ) && $step == 4) + { + ini_set('max_execution_time', 300); + $row_count = 0; + $sql = "select * from ath_Importdatatable where isnull(athlete_id,0) = 0 and isnull(Athlete_name,'') != '' order by id"; + $result = sqlsrv_query($conn,$sql); + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + if( strpos($row["athlete_name"],",") !== false) + { + $name_array = explode(",", $row["athlete_name"]); + if(count($name_array) == 2) + { + $firstname = $name_array[1]; + $lastname = $name_array[0]; + } + else + { + $lastname = $name_array[0]; + $lastname = ""; + for($i=1; $i0) + { + $sql = "update ath_Importdatatable set athlete_id = ".$athlete_id." where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + else + { + $sql = "select id from ath_athletes_all where school_id = ".$row['school_id']." and sex = '".$row['Sex']."' and (ltrim(rtrim(firstname)) + ' ' + ltrim(rtrim(lastname)) = '". str_replace("'","''", trim($athlete_name))."' or ltrim(rtrim(lastname)) + ' ' + ltrim(rtrim(firstname)) = '". str_replace("'","''", trim($athlete_name))."' or alt_names like '%". str_replace("'","''", trim($athlete_name))."%') "; + + $rsAthlete = sqlsrv_query($conn,$sql); + $rowAthlete = sqlsrv_fetch_array($rsAthlete); + $athlete_id = 0+$rowAthlete['id']; + if($athlete_id>0) + { + $sql = "update ath_Importdatatable set athlete_id = ".$athlete_id." where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + } + } + } + + + if(isset($_REQUEST['bStep4Save']) && $_REQUEST['bStep4Save'] == 'Save Changes') + { + $school_count = $_REQUEST['hAthleteCount']; + for($i=0; $i<$school_count; $i++) + { + + $id = $_REQUEST['hId'.$i]; + $classYear = isset($_REQUEST['tClassYear'.$id]) && $_REQUEST['tClassYear'.$id] != "" && is_numeric($_REQUEST['tClassYear'.$id])?$_REQUEST['tClassYear'.$id]:0; + $athlete_name = $_REQUEST['athleteName'.$id]; + $sql = "update ath_Importdatatable set athlete_name = '". str_replace("'","''",$athlete_name)."'"; + if($classYear>0) + $sql .= ", class_year = ".$classYear.""; + $sql .= " where id = ".$id; + $rs = sqlsrv_query($conn, $sql); + + if($classYear>0) + { + $sql = "update ath_athletes_all set class_year = ".$classYear." where ID = ".$_REQUEST['hAthleteId'.$id]; + $rs = sqlsrv_query($conn, $sql); + } + } + } + + if(isset($_REQUEST['bStep4Next']) && $_REQUEST['bStep4Next'] == 'Next') + { + $master_id = $_REQUEST['master_id']; + // Save log master + $url ="extract_data.php?season_id=".$_REQUEST['season_id']."&step=5&master_id=".$master_id; + if(isset($_REQUEST['log_id'])) + { + $log_id = $_REQUEST['log_id']; + $url = $url."&log_id=".$log_id; + } + header("location: ".$url); + die(); + } + //End:- Step 4: Update Athlete ID *********************************************** + + //Begin:- Step 5: Update Time/Distance ****************************************** + if(((isset($_REQUEST['bStep5']) && $_REQUEST['bStep5'] == 'Update Time/Distance') || (isset($_REQUEST['bStep5Reprocess']) && $_REQUEST['bStep5Reprocess'] == 'Reprocess') ) && $step == 5) + { + ini_set('max_execution_time', 300); + $sql = "update ath_Importdatatable set perform_time_char = replace(perform_time_char,'-',' Ft ') where isnull(perform_time_char,'') != '' and event_unit = 'D'"; + $rs = sqlsrv_query($conn, $sql); + + $sql = "update ath_Importdatatable set perform_time_char = perform_time_char + ' In.' where isnull(perform_time_char,'') != '' and charindex('In.',perform_time_char)=0 and event_unit = 'D'"; + $rs = sqlsrv_query($conn, $sql); + + $row_count = 0; + $sql = "select * from ath_Importdatatable where isnull(perform_time,0.00) = 0 and isnull(perform_time_char,'') != '' order by id"; + $result = sqlsrv_query($conn,$sql); + + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + try + { + if($row['perform_time_char'] != "" && $row['event_unit'] == "T") + { + $sql = "update ath_Importdatatable set perform_time = dbo.timetoInt(perform_time_char) where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + if($row['perform_time_char'] != "" && $row['event_unit'] == "D") + { + $sql = "update ath_Importdatatable set perform_time = dbo.distancetoInt(perform_time_char) where id = ".$row['id']; + $rs = sqlsrv_query($conn, $sql); + $row_count++; + } + } + catch(Exception $e) + { + + } + } + } + + if(isset($_REQUEST['bStep5Save']) && $_REQUEST['bStep5Save'] == 'Save Changes') + { + $time_count = $_REQUEST['hTimeCount']; + for($i=0; $i<$time_count; $i++) + { + $id = $_REQUEST['hId'.$i]; + $perform_time_char = $_REQUEST['Time'.$id]; + + $sql = "update ath_Importdatatable set perform_time_char = '". str_replace("'","''",$perform_time_char)."' where id = ".$id; + $rs = sqlsrv_query($conn, $sql); + } + } + + if(isset($_REQUEST['bStep5Next']) && $_REQUEST['bStep5Next'] == 'Next') + { + $master_id = $_REQUEST['master_id']; + // Save log master + $url ="extract_data.php?season_id=".$_REQUEST['season_id']."&step=6&master_id=".$master_id; + if(isset($_REQUEST['log_id'])) + { + $log_id = $_REQUEST['log_id']; + $url = $url."&log_id=".$log_id; + } + header("location: ".$url); + die(); + } + //End:- Step 5: Update Time/Distance *********************************************** + + //Begin:- Step 6: Insert into performance table *********************************************** + if(isset($_REQUEST['bStep6']) && $_REQUEST['bStep6'] == 'Insert into performance table' && $step == 6) + { + ini_set('max_execution_time', 300); + $master_id = $_REQUEST['master_id']; + if(isset($_REQUEST['log_id'])) + { + $log_id = $_REQUEST['log_id']; + } + + //updating performance_id for individual performances + $sql = "UPDATE ath_Importdatatable + SET performance_id = ath_Performances_all.id + FROM ath_Importdatatable + INNER JOIN ath_Performances_all ON + ath_Importdatatable.meet_id = ath_Performances_all.meet_id + and ath_Importdatatable.event_id = ath_Performances_all.event_id + and ath_Importdatatable.athlete_id = ath_Performances_all.athlete_id + and ath_Importdatatable.perform_time = ath_Performances_all.perform_time + and ath_Importdatatable.round = ath_Performances_all.race_round + and ath_Importdatatable.race_level = ath_Performances_all.race_level + where ath_Importdatatable.performance_id is null and isnull(event_type,'I') = 'I'"; + $rs = sqlsrv_query($conn, $sql); + + //updating performance_id for relay performances + $sql = "UPDATE ath_Importdatatable + SET performance_id = ath_Performances_Relay.id + FROM ath_Importdatatable + INNER JOIN ath_Performances_Relay ON + ath_Importdatatable.meet_id = ath_Performances_Relay.meet_id + and ath_Importdatatable.event_id = ath_Performances_Relay.event_id + and ath_Importdatatable.perform_time = ath_Performances_Relay.perform_time + and ath_Importdatatable.round = ath_Performances_Relay.race_round + and ath_Importdatatable.race_level = ath_Performances_Relay.race_level + where ath_Importdatatable.performance_id is null and isnull(event_type,'') = 'R'"; + $rs = sqlsrv_query($conn, $sql); + + /* + $sql = "select timing from ath_meets_all where id = (select top 1 meet_id from ath_Importdatatable)" ; + $rsMeet = sqlsrv_query($conn, $sql); + $rowMeet = sqlsrv_fetch_array($rsMeet); + if($rowMeet['timing'] == "A") + { + $electronic_timer = 1; + } + else + { + $electronic_timer = 0; + } + */ + $params = array(); + $params[] = ""; + $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); + + //inserting induvidual performances + $sql = "insert into ath_Performances_all (athlete_id,place,perform_time_char,perform_time,meet_id,event_id,race_round,race_level,entry_date,verified_status,user_id,electronic_timer) + select athlete_id,place,perform_time_char,perform_time,meet_id,event_id,round,race_level, convert(varchar(10), getdate(),101) as entry_date, 0 as verified_status,10 as user_id,electronic_timer from ath_Importdatatable + where isnull(event_id,0) <> 0 and isnull(school_id,0) <> 0 and isnull(athlete_id,0) <> 0 and isnull(perform_time,0.00) <> 0 and isnull(performance_id,0) = 0 and isnull(event_type,'') = 'I'"; + //echo $sql."
"; + $rs = sqlsrv_query($conn, $sql, $params, $options); + $row_count = sqlsrv_num_rows($rs); + + //inserting new roster + /* + $sqlroster = "insert into ath_athlete_roster(Athlete_Id,Season_Id,create_date,status) + select distinct athlete_id,".$_REQUEST['season_id']." as Season_Id,getdate() as create_date,0 as status from ath_Importdatatable + where isnull(event_id,0) <> 0 and isnull(school_id,0) <> 0 and isnull(athlete_id,0) <> 0 + and isnull(perform_time,0.00) <> 0 and isnull(performance_id,0) = 0 and isnull(event_type,'') = 'I' + and athlete_id NOT IN(select distinct Athlete_Id + from ath_athlete_roster where Season_Id=".$_REQUEST['season_id'].")"; + $rsroster = sqlsrv_query($conn, $sqlroster, $params, $options); + */ + //inserting new roster end + + /* + $sql = "insert into ath_Performances_all (athlete_id,place,perform_time_char,perform_time,meet_id,event_id,race_round,race_level,entry_date,verified_status,user_id) + select athlete_id,place,performance,perform_time,meet_id,event_id,round,race_level, convert(varchar(10), getdate(),101) as entry_date,0 as verified_status,10 as user_id from ath_Importdatatable + where isnull(event_id,0) <> 0 and isnull(school_id,0) <> 0 and isnull(athlete_id,0) <> 0 and isnull(performance,'') <> '' and isnull(perform_time,0.00) <> 0 and isnull(performance_id,0) = 0 and isnull(event_type,'I') = 'I'"; + $rs = sqlsrv_query($conn, $sql, $params, $options); + $row_count += sqlsrv_num_rows($rs); + */ + //inserting relay performances + $sql = "insert into ath_Performances_Relay(school_id, place, perform_time_char, perform_time, meet_id, event_id, sex, race_round, race_level) + select school_id, place, perform_time_char, perform_time, meet_id, event_id, sex, round, race_level from ath_Importdatatable + where isnull(event_id,0) <> 0 and isnull(school_id,0) <> 0 and isnull(perform_time,0.00) <> 0 and isnull(performance_id,0) = 0 and isnull(event_type,'') = 'R'"; + + $rs = sqlsrv_query($conn, $sql, $params, $options); + $row_count += sqlsrv_num_rows($rs); + + // Save log master + $sql = "insert into ath_Importdatatable_History (Meet,Event,race_level,Round,Place,perform_time_char,performance,Number,meet_id,event_id,athlete_id,perform_time,Sex,performance_id,school_id,school_name,athlete_name,header_row,detail_row,master_id,log_id, event_type,class_year,event_unit, group_id) + select Meet,Event,race_level,Round,Place,perform_time_char,performance,Number,meet_id,event_id,athlete_id,perform_time,Sex,performance_id,school_id,school_name,athlete_name,header_row,detail_row,".$master_id." as master_id,".$log_id.", event_type,class_year,event_unit, group_id from ath_Importdatatable + where ( (isnull(event_type,'I') = 'I' and (athlete_id is null OR school_id is null OR event_id is null OR perform_time is null)) or (isnull(event_type,'') = 'R' and (school_id is null OR event_id is null OR perform_time is null)) )"; + $rs = sqlsrv_query($conn, $sql,$params, $options); + $pending_count = sqlsrv_num_rows($rs); + + // Save log master + + $sql = "UPDATE ath_Importdatatable_Master_Log SET process_status = 1,pending_result =".$pending_count." WHERE id =".$log_id; + $rs = sqlsrv_query($conn, $sql); + // Save text data + //echo "Continue to enter results"; + } + //End:- Step 6: Insert into performance table *********************************************** + + + if(isset($_REQUEST['bStep6Continue']) && $_REQUEST['bStep6Continue'] == 'Continue to enter results' && $step == 6) + { + header("location: extract_data.php?season_id=".$_REQUEST['season_id']); + die(); + } +} +?> + + + + + +Extract Data + + + + + + + + + + + + + + + + + + + + +
+
+
+ Update RaceID |  + Update Relay RaceID +
+ + +
+
+

Step 1: Extract performanace data into temp. table

+
+
+
+ +
+
+ + + +

+ +    + + + + + + Select file format: + + +
+
+
+
+
+ +
+
+
+ +
+ +
+
+
+ + + +
+
+
+

Step 2: Update School ID

+
+ +
+

+
+ +
+ + +   + +   + +   + +   + + + + +
+
+
+ + + + + + + + + + + + + + SQLSRV_CURSOR_KEYSET ); + + if(((isset($_REQUEST['bStep2']) && $_REQUEST['bStep2'] == 'Update School Id') || (isset($_REQUEST['bStep2Reprocess']) && $_REQUEST['bStep2Reprocess'] == 'Reprocess') || (isset($_REQUEST['bStep2Save']) && $_REQUEST['bStep2Save'] == 'Save Changes')) && $step == 2) + $sql = "select * from ath_Importdatatable order by id"; //where school_id is null + else + $sql = "select * from ath_Importdatatable order by id"; + + $result = sqlsrv_query($conn,$sql,$params,$options); + $cnt = sqlsrv_num_rows($result); + $i=0; + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + ?> + + + + + + + + + + + + + + + +
Race LevelRoundSexEventPlaceAthleteSchoolSchool IdTime/DistancePerformance data
+ + + + +   Add as: + );' /> + );' /> +
+ +
+
+
+ + +   + +   + + + + +
+
+ + 0) + { + ?> +

FAILED RECORDS

+
+ + + + + + + +
. +
+						
+ +
+
+ +
+ +
+ + + +
+
+
+

Step 3: Update Event ID

+
+ +
+

+
+ +
+ + +   + +   + + + + +
+
+
+ + + + + + + + + + + + + + + SQLSRV_CURSOR_KEYSET ); + + /* + if(((isset($_REQUEST['bStep3']) && $_REQUEST['bStep3'] == 'Update Event Id') || (isset($_REQUEST['bStep3Reprocess']) && $_REQUEST['bStep3Reprocess'] == 'Reprocess') || (isset($_REQUEST['bStep3Save']) && $_REQUEST['bStep3Save'] == 'Save Changes')) && $step == 3) + $sql = "select * from ath_Importdatatable where event_id is null order by id"; + else + $sql = "select * from ath_Importdatatable order by id"; + */ + + $sql = "select * from ath_Importdatatable where isnull(school_id,0) > 0 order by id"; //isnull(event_id,0) = 0 and + $result = sqlsrv_query($conn,$sql,$params,$options); + $cnt = sqlsrv_num_rows($result); + $i=0; + $group_id_change = -1; + $group_id_max = -1; + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + ?> + + + + + + + + + + + + + + + + +
Race LevelRoundSexEvent NameEvent IdPlaceAthleteSchoolSchool IdTime / DistancePerfomance data
+ + + + + + + + + + + + + + );' /> + +
+ +
+
+
+ + +   + +   + + + + +
+
+
+ + + +
+
+
+

Step 4: Update Athlete ID

+
+ +
+

+
+ +
+
 Stands for sec8 schools result.
+
 Stands for Chsaa schools result. +
+
+ + + + +   + +   + +   + + + + +
+
+
+ + + + + + + + + + + + + + + + SQLSRV_CURSOR_KEYSET ); + /* + if(((isset($_REQUEST['bStep4']) && $_REQUEST['bStep4'] == 'Update Athlete Id') || (isset($_REQUEST['bStep4Reprocess']) && $_REQUEST['bStep4Reprocess'] == 'Reprocess') || (isset($_REQUEST['bStep4Save']) && $_REQUEST['bStep4Save'] == 'Save Changes')) && $step == 4) + $sql = "select * from ath_Importdatatable where athlete_id is null order by id"; + else + $sql = "select * from ath_Importdatatable order by id"; + */ + + $sql = "select * from ath_Importdatatable where isnull(event_id,0) > 0 and isnull(school_id,0) > 0 order by id"; // isnull(athlete_id,0) = 0 and + $result = sqlsrv_query($conn,$sql,$params,$options); + $cnt = sqlsrv_num_rows($result); + $i=0; + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + //To identify section8 league + $sql_sec8_league = "select league_id from ath_schools where id=".$row['school_id']; // isnull(athlete_id,0) = 0 and + $league_result = sqlsrv_query($conn,$sql_sec8_league); + $schools_league = ""; + while ($league_row = sqlsrv_fetch_array($league_result)) + { + $schools_league = $league_row['league_id']; + } + //To identify section8 league end + + ?> + style="background-color:#FFCC99;" style="background-color:#FF6;" > + + + + + + + + + + + + + + + + +
Race LevelRoundSexEvent NamePlaceAthlete NameAthlete IdSchoolSchool IdClass yearTime/DistancePerformance data
+ + + );' /> + );' /> + );' /> + + + + + 0) + { + $rowAth = sqlsrv_fetch_array($rsAth); + $ath_class_year=$rowAth['class_year']; + } + ?> + /> + +
+ +
+
+
+ + +   + +   + + + + +
+
+
+ + + +
+
+
+

Step 5: Update Performance Time/Distance

+
+ +
+

+
+ +
+ + +   + +   + + + + +
+
+
+ + + + + + + + + + + + + + + + SQLSRV_CURSOR_KEYSET ); + + /* + if(((isset($_REQUEST['bStep5']) && $_REQUEST['bStep5'] == 'Update Time/Distance') || (isset($_REQUEST['bStep5Reprocess']) && $_REQUEST['bStep5Reprocess'] == 'Reprocess') || (isset($_REQUEST['bStep5Save']) && $_REQUEST['bStep5Save'] == 'Save Changes')) && $step == 5) + $sql = "select * from ath_Importdatatable where athlete_id is null order by id"; + else + $sql = "select * from ath_Importdatatable order by id"; + */ + + $sql = "select * from ath_Importdatatable where + ((isnull(athlete_id,0) > 0 and isnull(event_type,'I')='I') or (isnull(event_type,'')='R')) + and isnull(event_id,0) > 0 + and isnull(school_id,0) > 0 + order by id"; //isnull(perform_time,0) = 0 and + + $result = sqlsrv_query($conn,$sql,$params,$options); + $cnt = sqlsrv_num_rows($result); + $i=0; + while ($row = sqlsrv_fetch_array($result)) + { + ini_set('max_execution_time', 300); + ?> + + + + + + + + + + + + + + + + + +
Race LevelRoundSexEvent NamePlaceAthlete NameAthlete IdSchoolSchool IdTime/DistanceTime/Distance (int)Performance data
+ + + + + + +
+ +
+
+
+ + +   + +   + + + + +
+
+
+ + + +
+
+
+

Step 6: Insert into performance table

+
+ + +
+

+
+
+ +
+ SQLSRV_CURSOR_KEYSET ); + + $sql = "select * from ath_Importdatatable where isnull(perform_time,0) > 0 and (( isnull(athlete_id,0) > 0 and isnull(event_type,'I')='I' ) or (isnull(event_type,'')='R')) and isnull(event_id,0) > 0 and isnull(school_id,0) > 0 order by id"; + + $result = sqlsrv_query($conn,$sql,$params,$options); + $cnt = sqlsrv_num_rows($result); + $i=0; + + + ?> +
+

+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Race LevelRoundSexEvent NameEvent IdPlaceAthlete NameAthlete IdSchoolSchool IdTime/DistanceTime/Distance (int)Performance data
+ +
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..0c6ef0c --- /dev/null +++ b/index.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/js/bootstrap.js b/js/bootstrap.js new file mode 100644 index 0000000..8dff365 --- /dev/null +++ b/js/bootstrap.js @@ -0,0 +1,2276 @@ +/*! + * Bootstrap v3.3.0 (http://getbootstrap.com) + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + */ + +if (typeof jQuery === 'undefined') { + throw new Error('Bootstrap\'s JavaScript requires jQuery') +} + ++function ($) { + var version = $.fn.jquery.split(' ')[0].split('.') + if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1)) { + throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher') + } +}(jQuery); + +/* ======================================================================== + * Bootstrap: transition.js v3.3.0 + * http://getbootstrap.com/javascript/#transitions + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/) + // ============================================================ + + function transitionEnd() { + var el = document.createElement('bootstrap') + + var transEndEventNames = { + WebkitTransition : 'webkitTransitionEnd', + MozTransition : 'transitionend', + OTransition : 'oTransitionEnd otransitionend', + transition : 'transitionend' + } + + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + return { end: transEndEventNames[name] } + } + } + + return false // explicit for ie8 ( ._.) + } + + // http://blog.alexmaccaw.com/css-transitions + $.fn.emulateTransitionEnd = function (duration) { + var called = false + var $el = this + $(this).one('bsTransitionEnd', function () { called = true }) + var callback = function () { if (!called) $($el).trigger($.support.transition.end) } + setTimeout(callback, duration) + return this + } + + $(function () { + $.support.transition = transitionEnd() + + if (!$.support.transition) return + + $.event.special.bsTransitionEnd = { + bindType: $.support.transition.end, + delegateType: $.support.transition.end, + handle: function (e) { + if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments) + } + } + }) + +}(jQuery); + +/* ======================================================================== + * Bootstrap: alert.js v3.3.0 + * http://getbootstrap.com/javascript/#alerts + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // ALERT CLASS DEFINITION + // ====================== + + var dismiss = '[data-dismiss="alert"]' + var Alert = function (el) { + $(el).on('click', dismiss, this.close) + } + + Alert.VERSION = '3.3.0' + + Alert.TRANSITION_DURATION = 150 + + Alert.prototype.close = function (e) { + var $this = $(this) + var selector = $this.attr('data-target') + + if (!selector) { + selector = $this.attr('href') + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7 + } + + var $parent = $(selector) + + if (e) e.preventDefault() + + if (!$parent.length) { + $parent = $this.closest('.alert') + } + + $parent.trigger(e = $.Event('close.bs.alert')) + + if (e.isDefaultPrevented()) return + + $parent.removeClass('in') + + function removeElement() { + // detach from parent, fire event then clean up data + $parent.detach().trigger('closed.bs.alert').remove() + } + + $.support.transition && $parent.hasClass('fade') ? + $parent + .one('bsTransitionEnd', removeElement) + .emulateTransitionEnd(Alert.TRANSITION_DURATION) : + removeElement() + } + + + // ALERT PLUGIN DEFINITION + // ======================= + + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.alert') + + if (!data) $this.data('bs.alert', (data = new Alert(this))) + if (typeof option == 'string') data[option].call($this) + }) + } + + var old = $.fn.alert + + $.fn.alert = Plugin + $.fn.alert.Constructor = Alert + + + // ALERT NO CONFLICT + // ================= + + $.fn.alert.noConflict = function () { + $.fn.alert = old + return this + } + + + // ALERT DATA-API + // ============== + + $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close) + +}(jQuery); + +/* ======================================================================== + * Bootstrap: button.js v3.3.0 + * http://getbootstrap.com/javascript/#buttons + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // BUTTON PUBLIC CLASS DEFINITION + // ============================== + + var Button = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Button.DEFAULTS, options) + this.isLoading = false + } + + Button.VERSION = '3.3.0' + + Button.DEFAULTS = { + loadingText: 'loading...' + } + + Button.prototype.setState = function (state) { + var d = 'disabled' + var $el = this.$element + var val = $el.is('input') ? 'val' : 'html' + var data = $el.data() + + state = state + 'Text' + + if (data.resetText == null) $el.data('resetText', $el[val]()) + + // push to event loop to allow forms to submit + setTimeout($.proxy(function () { + $el[val](data[state] == null ? this.options[state] : data[state]) + + if (state == 'loadingText') { + this.isLoading = true + $el.addClass(d).attr(d, d) + } else if (this.isLoading) { + this.isLoading = false + $el.removeClass(d).removeAttr(d) + } + }, this), 0) + } + + Button.prototype.toggle = function () { + var changed = true + var $parent = this.$element.closest('[data-toggle="buttons"]') + + if ($parent.length) { + var $input = this.$element.find('input') + if ($input.prop('type') == 'radio') { + if ($input.prop('checked') && this.$element.hasClass('active')) changed = false + else $parent.find('.active').removeClass('active') + } + if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change') + } else { + this.$element.attr('aria-pressed', !this.$element.hasClass('active')) + } + + if (changed) this.$element.toggleClass('active') + } + + + // BUTTON PLUGIN DEFINITION + // ======================== + + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.button') + var options = typeof option == 'object' && option + + if (!data) $this.data('bs.button', (data = new Button(this, options))) + + if (option == 'toggle') data.toggle() + else if (option) data.setState(option) + }) + } + + var old = $.fn.button + + $.fn.button = Plugin + $.fn.button.Constructor = Button + + + // BUTTON NO CONFLICT + // ================== + + $.fn.button.noConflict = function () { + $.fn.button = old + return this + } + + + // BUTTON DATA-API + // =============== + + $(document) + .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) { + var $btn = $(e.target) + if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn') + Plugin.call($btn, 'toggle') + e.preventDefault() + }) + .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) { + $(e.target).closest('.btn').toggleClass('focus', e.type == 'focus') + }) + +}(jQuery); + +/* ======================================================================== + * Bootstrap: carousel.js v3.3.0 + * http://getbootstrap.com/javascript/#carousel + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // CAROUSEL CLASS DEFINITION + // ========================= + + var Carousel = function (element, options) { + this.$element = $(element) + this.$indicators = this.$element.find('.carousel-indicators') + this.options = options + this.paused = + this.sliding = + this.interval = + this.$active = + this.$items = null + + this.options.keyboard && this.$element.on('keydown.bs.carousel', $.proxy(this.keydown, this)) + + this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element + .on('mouseenter.bs.carousel', $.proxy(this.pause, this)) + .on('mouseleave.bs.carousel', $.proxy(this.cycle, this)) + } + + Carousel.VERSION = '3.3.0' + + Carousel.TRANSITION_DURATION = 600 + + Carousel.DEFAULTS = { + interval: 5000, + pause: 'hover', + wrap: true, + keyboard: true + } + + Carousel.prototype.keydown = function (e) { + switch (e.which) { + case 37: this.prev(); break + case 39: this.next(); break + default: return + } + + e.preventDefault() + } + + Carousel.prototype.cycle = function (e) { + e || (this.paused = false) + + this.interval && clearInterval(this.interval) + + this.options.interval + && !this.paused + && (this.interval = setInterval($.proxy(this.next, this), this.options.interval)) + + return this + } + + Carousel.prototype.getItemIndex = function (item) { + this.$items = item.parent().children('.item') + return this.$items.index(item || this.$active) + } + + Carousel.prototype.getItemForDirection = function (direction, active) { + var delta = direction == 'prev' ? -1 : 1 + var activeIndex = this.getItemIndex(active) + var itemIndex = (activeIndex + delta) % this.$items.length + return this.$items.eq(itemIndex) + } + + Carousel.prototype.to = function (pos) { + var that = this + var activeIndex = this.getItemIndex(this.$active = this.$element.find('.item.active')) + + if (pos > (this.$items.length - 1) || pos < 0) return + + if (this.sliding) return this.$element.one('slid.bs.carousel', function () { that.to(pos) }) // yes, "slid" + if (activeIndex == pos) return this.pause().cycle() + + return this.slide(pos > activeIndex ? 'next' : 'prev', this.$items.eq(pos)) + } + + Carousel.prototype.pause = function (e) { + e || (this.paused = true) + + if (this.$element.find('.next, .prev').length && $.support.transition) { + this.$element.trigger($.support.transition.end) + this.cycle(true) + } + + this.interval = clearInterval(this.interval) + + return this + } + + Carousel.prototype.next = function () { + if (this.sliding) return + return this.slide('next') + } + + Carousel.prototype.prev = function () { + if (this.sliding) return + return this.slide('prev') + } + + Carousel.prototype.slide = function (type, next) { + var $active = this.$element.find('.item.active') + var $next = next || this.getItemForDirection(type, $active) + var isCycling = this.interval + var direction = type == 'next' ? 'left' : 'right' + var fallback = type == 'next' ? 'first' : 'last' + var that = this + + if (!$next.length) { + if (!this.options.wrap) return + $next = this.$element.find('.item')[fallback]() + } + + if ($next.hasClass('active')) return (this.sliding = false) + + var relatedTarget = $next[0] + var slideEvent = $.Event('slide.bs.carousel', { + relatedTarget: relatedTarget, + direction: direction + }) + this.$element.trigger(slideEvent) + if (slideEvent.isDefaultPrevented()) return + + this.sliding = true + + isCycling && this.pause() + + if (this.$indicators.length) { + this.$indicators.find('.active').removeClass('active') + var $nextIndicator = $(this.$indicators.children()[this.getItemIndex($next)]) + $nextIndicator && $nextIndicator.addClass('active') + } + + var slidEvent = $.Event('slid.bs.carousel', { relatedTarget: relatedTarget, direction: direction }) // yes, "slid" + if ($.support.transition && this.$element.hasClass('slide')) { + $next.addClass(type) + $next[0].offsetWidth // force reflow + $active.addClass(direction) + $next.addClass(direction) + $active + .one('bsTransitionEnd', function () { + $next.removeClass([type, direction].join(' ')).addClass('active') + $active.removeClass(['active', direction].join(' ')) + that.sliding = false + setTimeout(function () { + that.$element.trigger(slidEvent) + }, 0) + }) + .emulateTransitionEnd(Carousel.TRANSITION_DURATION) + } else { + $active.removeClass('active') + $next.addClass('active') + this.sliding = false + this.$element.trigger(slidEvent) + } + + isCycling && this.cycle() + + return this + } + + + // CAROUSEL PLUGIN DEFINITION + // ========================== + + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.carousel') + var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option) + var action = typeof option == 'string' ? option : options.slide + + if (!data) $this.data('bs.carousel', (data = new Carousel(this, options))) + if (typeof option == 'number') data.to(option) + else if (action) data[action]() + else if (options.interval) data.pause().cycle() + }) + } + + var old = $.fn.carousel + + $.fn.carousel = Plugin + $.fn.carousel.Constructor = Carousel + + + // CAROUSEL NO CONFLICT + // ==================== + + $.fn.carousel.noConflict = function () { + $.fn.carousel = old + return this + } + + + // CAROUSEL DATA-API + // ================= + + var clickHandler = function (e) { + var href + var $this = $(this) + var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7 + if (!$target.hasClass('carousel')) return + var options = $.extend({}, $target.data(), $this.data()) + var slideIndex = $this.attr('data-slide-to') + if (slideIndex) options.interval = false + + Plugin.call($target, options) + + if (slideIndex) { + $target.data('bs.carousel').to(slideIndex) + } + + e.preventDefault() + } + + $(document) + .on('click.bs.carousel.data-api', '[data-slide]', clickHandler) + .on('click.bs.carousel.data-api', '[data-slide-to]', clickHandler) + + $(window).on('load', function () { + $('[data-ride="carousel"]').each(function () { + var $carousel = $(this) + Plugin.call($carousel, $carousel.data()) + }) + }) + +}(jQuery); + +/* ======================================================================== + * Bootstrap: collapse.js v3.3.0 + * http://getbootstrap.com/javascript/#collapse + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // COLLAPSE PUBLIC CLASS DEFINITION + // ================================ + + var Collapse = function (element, options) { + this.$element = $(element) + this.options = $.extend({}, Collapse.DEFAULTS, options) + this.$trigger = $(this.options.trigger).filter('[href="#' + element.id + '"], [data-target="#' + element.id + '"]') + this.transitioning = null + + if (this.options.parent) { + this.$parent = this.getParent() + } else { + this.addAriaAndCollapsedClass(this.$element, this.$trigger) + } + + if (this.options.toggle) this.toggle() + } + + Collapse.VERSION = '3.3.0' + + Collapse.TRANSITION_DURATION = 350 + + Collapse.DEFAULTS = { + toggle: true, + trigger: '[data-toggle="collapse"]' + } + + Collapse.prototype.dimension = function () { + var hasWidth = this.$element.hasClass('width') + return hasWidth ? 'width' : 'height' + } + + Collapse.prototype.show = function () { + if (this.transitioning || this.$element.hasClass('in')) return + + var activesData + var actives = this.$parent && this.$parent.find('> .panel').children('.in, .collapsing') + + if (actives && actives.length) { + activesData = actives.data('bs.collapse') + if (activesData && activesData.transitioning) return + } + + var startEvent = $.Event('show.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + if (actives && actives.length) { + Plugin.call(actives, 'hide') + activesData || actives.data('bs.collapse', null) + } + + var dimension = this.dimension() + + this.$element + .removeClass('collapse') + .addClass('collapsing')[dimension](0) + .attr('aria-expanded', true) + + this.$trigger + .removeClass('collapsed') + .attr('aria-expanded', true) + + this.transitioning = 1 + + var complete = function () { + this.$element + .removeClass('collapsing') + .addClass('collapse in')[dimension]('') + this.transitioning = 0 + this.$element + .trigger('shown.bs.collapse') + } + + if (!$.support.transition) return complete.call(this) + + var scrollSize = $.camelCase(['scroll', dimension].join('-')) + + this.$element + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize]) + } + + Collapse.prototype.hide = function () { + if (this.transitioning || !this.$element.hasClass('in')) return + + var startEvent = $.Event('hide.bs.collapse') + this.$element.trigger(startEvent) + if (startEvent.isDefaultPrevented()) return + + var dimension = this.dimension() + + this.$element[dimension](this.$element[dimension]())[0].offsetHeight + + this.$element + .addClass('collapsing') + .removeClass('collapse in') + .attr('aria-expanded', false) + + this.$trigger + .addClass('collapsed') + .attr('aria-expanded', false) + + this.transitioning = 1 + + var complete = function () { + this.transitioning = 0 + this.$element + .removeClass('collapsing') + .addClass('collapse') + .trigger('hidden.bs.collapse') + } + + if (!$.support.transition) return complete.call(this) + + this.$element + [dimension](0) + .one('bsTransitionEnd', $.proxy(complete, this)) + .emulateTransitionEnd(Collapse.TRANSITION_DURATION) + } + + Collapse.prototype.toggle = function () { + this[this.$element.hasClass('in') ? 'hide' : 'show']() + } + + Collapse.prototype.getParent = function () { + return $(this.options.parent) + .find('[data-toggle="collapse"][data-parent="' + this.options.parent + '"]') + .each($.proxy(function (i, element) { + var $element = $(element) + this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element) + }, this)) + .end() + } + + Collapse.prototype.addAriaAndCollapsedClass = function ($element, $trigger) { + var isOpen = $element.hasClass('in') + + $element.attr('aria-expanded', isOpen) + $trigger + .toggleClass('collapsed', !isOpen) + .attr('aria-expanded', isOpen) + } + + function getTargetFromTrigger($trigger) { + var href + var target = $trigger.attr('data-target') + || (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7 + + return $(target) + } + + + // COLLAPSE PLUGIN DEFINITION + // ========================== + + function Plugin(option) { + return this.each(function () { + var $this = $(this) + var data = $this.data('bs.collapse') + var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option) + + if (!data && options.toggle && option == 'show') options.toggle = false + if (!data) $this.data('bs.collapse', (data = new Collapse(this, options))) + if (typeof option == 'string') data[option]() + }) + } + + var old = $.fn.collapse + + $.fn.collapse = Plugin + $.fn.collapse.Constructor = Collapse + + + // COLLAPSE NO CONFLICT + // ==================== + + $.fn.collapse.noConflict = function () { + $.fn.collapse = old + return this + } + + + // COLLAPSE DATA-API + // ================= + + $(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { + var $this = $(this) + + if (!$this.attr('data-target')) e.preventDefault() + + var $target = getTargetFromTrigger($this) + var data = $target.data('bs.collapse') + var option = data ? 'toggle' : $.extend({}, $this.data(), { trigger: this }) + + Plugin.call($target, option) + }) + +}(jQuery); + +/* ======================================================================== + * Bootstrap: dropdown.js v3.3.0 + * http://getbootstrap.com/javascript/#dropdowns + * ======================================================================== + * Copyright 2011-2014 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * ======================================================================== */ + + ++function ($) { + 'use strict'; + + // DROPDOWN CLASS DEFINITION + // ========================= + + var backdrop = '.dropdown-backdrop' + var toggle = '[data-toggle="dropdown"]' + var Dropdown = function (element) { + $(element).on('click.bs.dropdown', this.toggle) + } + + Dropdown.VERSION = '3.3.0' + + Dropdown.prototype.toggle = function (e) { + var $this = $(this) + + if ($this.is('.disabled, :disabled')) return + + var $parent = getParent($this) + var isActive = $parent.hasClass('open') + + clearMenus() + + if (!isActive) { + if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) { + // if mobile we use a backdrop because click events don't delegate + $('