// Ce script est ©2012 Jhiday file1 = !empty($file1) ? $file1 : "2012-10-01"; $this->mode = 1; break; case "2f": $this->file1 = !empty($file1) ? $file1 : "2012-10-01"; $this->file2 = !empty($file2) ? $file2 : "2012-10-01"; $this->mode = 2; break; default: $this->mode = 1; $this->file1 = "2012-10-01"; } } public function run() { $out = $this->doDemographie("vocations/{$this->file1}_carriere.txt", "vocations/{$this->file2}_carriere.txt"); $out .= $this->doStats("vocations/{$this->file1}_carriere.txt", 'CARRIÈRES', "vocations/{$this->file2}_carriere.txt"); $out .= $this->doStats("vocations/{$this->file1}_type.txt", 'TYPES', "vocations/{$this->file2}_type.txt"); $out .= $this->doStats("vocations/{$this->file1}_politique.txt", 'VOCATIONS POLITIQUES', "vocations/{$this->file2}_politique.txt"); $catsCombat = array('Aucune' => array('Novice'), 'Mains Nues' => array('Arts Martiaux', 'Lutteur'), 'Contact' => array('Lame Précise', 'Lame Rapide', 'Lame Violente', 'Lame Défensive', 'Lame avec Panache'), 'Distance' => array("Tireur d'Élite", 'Guérilla', 'Desperado')); $out .= $this->doStatsByCats("vocations/{$this->file1}_combat.txt", $catsCombat, 'TYPES DE COMBATS', "vocations/{$this->file2}_combat.txt"); $out .= $this->doStats("vocations/{$this->file1}_combat.txt", 'COMBATS', "vocations/{$this->file2}_combat.txt"); $catsPouvoir = array('Aucune' => array('Aucune'), 'Sorcellerie' => array('Illusion', 'Métamorphose', 'Élémentalisme - Feu', 'Élémentalisme - Air', 'Élémentalisme - Eau', 'Élémentalisme - Terre', 'Magie Vitale', 'Nécromancie', 'Abjuration', 'Enchantement', 'Altération'), 'Magie Divine' => array('Hasard', 'Charme', 'Démonologie', 'Divination', 'Druidisme', 'Chamanisme', 'Spiritisme', 'Paladinat', 'Bouletitude'), 'Pouvoirs Psychiques' => array('Télékinésie', 'Télépathie')); $out .= $this->doStatsByCats("vocations/{$this->file1}_pouvoir.txt", $catsPouvoir, 'TYPES DE POUVOIRS', "vocations/{$this->file2}_pouvoir.txt"); $out .= $this->doStats("vocations/{$this->file1}_pouvoir.txt", 'POUVOIRS', "vocations/{$this->file2}_pouvoir.txt"); echo $this->output($out); } function load($filename) { if (array_key_exists($filename, $this->data)) return; $this->data[$filename] = array('VOCATIONS' => array(), 'V_BY_E' => array(), 'total_by_E' => array()); $rawdata = file($filename); foreach($rawdata as $num => $line) { $line = utf8_decode($line); $matches = array(); if (preg_match(self::$pattern, $line, $matches)) { $name = str_replace(array('é', 'è', 'ê'), array('é', 'è', 'ê'), $matches[2]); $this->data[$filename]['VOCATIONS'][$name] = $matches[3]; foreach(self::$shortcodes as $key => $code) { $this->data[$filename]['V_BY_E'][$code][$name] = $matches[$key+4]; $this->data[$filename]['total_by_E'][$code] += $matches[$key+4]; } } } ksort($this->data[$filename]['VOCATIONS']); arsort($this->data[$filename]['VOCATIONS']); } function doStats($file, $label, $fileRef = '') { $this->load($file); $VOCATIONS = $this->data[$file]['VOCATIONS']; $V_BY_E = $this->data[$file]['V_BY_E']; $total_by_E = $this->data[$file]['total_by_E']; if ($this->mode == 2) { $this->load($fileRef); $VOCATIONS2 = $this->data[$fileRef]['VOCATIONS']; $V_BY_E2 = $this->data[$fileRef]['V_BY_E']; $total_by_E2 = $this->data[$fileRef]['total_by_E']; } $out = "
";
$classement = 0;
$last = 6000;
$trailing = 1;
$total = $total2 = 0;
foreach($VOCATIONS as $name => $effectif) {
$total += $effectif;
$total2 += $VOCATIONS2[$name];
}
foreach($VOCATIONS as $name => $effectif) {
if (in_array($name, array('Aucun', 'Aucune', 'Novice')))
{
$out .= "[b][navy]{$name}[/navy] ($effectif";
if ($this->mode == 2)
{
$prog1 = $effectif - $VOCATIONS2[$name];
$prog2 = '[/b], '.($prog1 < 0 ? $prog1 : '+'.$prog1).', '.($prog1 < 0 ? '':'+').round($prog1*100/$VOCATIONS2[$name]).'%[b]';
$prog = round(($effectif/$total - $VOCATIONS2[$name]/$total2)*1000)/10;
$prog = ' ('.($prog < 0 ? $prog : '+'.$prog).'pt)';
}
$out .= $prog2.") -- ".(round($effectif*1000/$total)/10)."%{$prog}[/b]
";
$tmp = array();
foreach(self::$shortcodes as $key => $code) {
if ($this->mode == 2)
{
$diff = $V_BY_E[$code][$name] - $V_BY_E2[$code][$name];
$diff = ($diff < 0) ? $diff : "+".$diff;
if ($total_by_E2[$code] > 0)
{
$diff_percent = round(($V_BY_E[$code][$name]/$total_by_E[$code] - $V_BY_E2[$code][$name]/$total_by_E2[$code])*100);
$diff_percent = ($diff_percent < 0) ? $diff_percent : "+".$diff_percent;
}
}
$tmp[] = "[".self::$colors[$key]."][b]".$V_BY_E[$code][$name]."[/b] ".($total_by_E[$code] ? "[".round($V_BY_E[$code][$name]/$total_by_E[$code]*100).'%]' : '').($this->mode == 2 ? " ($diff, {$diff_percent}pt) ": "")."[/".self::$colors[$key]."]";
}
$out .= implode(" | ", $tmp)."
\n";
continue;
}
if ($last != $effectif) {
$last = $effectif;
$classement = $classement + $trailing;
$trailing = 1;
} else {
$trailing++;
}
$out .= "[b]$classement) ".forme_base($name,"navy")." ($effectif";
if ($this->mode == 2)
{
$prog1 = $effectif - $VOCATIONS2[$name];
$prog2 = '[/b], '.($prog1 < 0 ? $prog1 : '+'.$prog1).', '.($prog1 < 0 ? '':'+').round($prog1*100/$VOCATIONS2[$name]).'%[b]';
$prog = round(($effectif/$total - $VOCATIONS2[$name]/$total2)*1000)/10;
$prog = ' ('.($prog < 0 ? $prog : '+'.$prog).'pt)';
}
$out .= $prog2.") -- ".(round($effectif*1000/$total)/10)."%{$prog}[/b]
";
$tmp = array();
foreach(self::$shortcodes as $key => $code) {
$diff = $V_BY_E[$code][$name] - $V_BY_E2[$code][$name];
$diff = ($diff < 0) ? $diff : "+".$diff;
$tmp[] = "[".self::$colors[$key]."][b]".$V_BY_E[$code][$name]."[/b]".($this->mode == 2 ? " ($diff) ": "")."[/".self::$colors[$key]."]";
}
$out .= implode(" | ", $tmp)."
\n";
}
foreach(self::$shortcodes as $key => $code) {
ksort($V_BY_E[$code]);
arsort($V_BY_E[$code]);
$classement = 0;
$last = 6000;
$trailing = 1;
$total_by_E[$code] = 0;
$total_by_E2[$code] = 0;
$out .= "
[".self::$colors[$key]."][b][u]".self::$longnames[$key]."[/u][/b]
";
foreach($V_BY_E[$code] as $name => $effectif) {
if (in_array($name, array('Aucun', 'Aucune', 'Novice')))
{
$out .= "0) [b]{$name}[/b] ($effectif)
";
continue;
}
$total_by_E[$code] += $effectif;
$total_by_E2[$code] += $V_BY_E2[$code][$name];
if ($last != $effectif) {
$classement = $classement + $trailing;
$trailing = 1;
if ($effectif == 0) {
break;
}
$out .= ($last == 6000 ? "" : " ($last)
")."$classement) $name";
$last = $effectif;
} else {
$trailing++;
$out .= ", $name";
}
}
$out .= " ($last)
";
$out .= "[/".self::$colors[$key]."]
";
$classement = 0;
$last = 6000;
$trailing = 1;
$total = 0;
foreach($VOCATIONS as $name => $effectif) {
$total += $effectif;
$total2 += $VOCATIONS2[$name];
}
foreach($VOCATIONS as $name => $effectif) {
if ($last != $effectif) {
$last = $effectif;
$classement = $classement + $trailing;
$trailing = 1;
} else {
$trailing++;
}
if ($this->mode == 2)
{
$prog1 = $effectif - $VOCATIONS2[$name];
$prog2 = '[/b], '.($prog1 < 0 ? $prog1 : '+'.$prog1).', '.($prog1 < 0 ? '':'+').round($prog1*100/$VOCATIONS2[$name]).'%[b]';
$prog = round(($effectif/$total - $VOCATIONS2[$name]/$total2)*1000)/10;
$prog = ' ('.($prog < 0 ? $prog : '+'.$prog).'pt)';
}
$out .= "[b]$classement) ".forme_base($name,"navy")." ($effectif";
$out .= $prog2.") -- ".(round($effectif*1000/$total)/10)."%{$prog}[/b]
";
$tmp = array();
foreach(self::$shortcodes as $key => $code) {
if ($this->mode == 2)
{
$diff = $V_BY_E[$code][$name] - $V_BY_E2[$code][$name];
$diff = ($diff < 0) ? $diff : "+".$diff;
if ($total_by_E2[$code] > 0)
{
$diff_percent = round(($V_BY_E[$code][$name]/$total_by_E[$code] - $V_BY_E2[$code][$name]/$total_by_E2[$code])*100);
$diff_percent = ($diff_percent < 0) ? $diff_percent : "+".$diff_percent;
}
}
$tmp[] = "[".self::$colors[$key]."][b]".$V_BY_E[$code][$name]."[/b] ".($total_by_E[$code] ? "[".round($V_BY_E[$code][$name]/$total_by_E[$code]*100).'%]' : '').($this->mode == 2 ? " ($diff, {$diff_percent}pt) ": "")."[/".self::$colors[$key]."]";
}
$out .= implode(" | ", $tmp)."
\n";
}
$out .= "
";
$prog_by_E = array();
foreach(self::$shortcodes as $key => $code) {
if ($this->mode == 2) {
$prog_by_E[$code] = $total_by_E[$code] - $total_by_E2[$code];
$percent = '';
if ($total_by_E2[$code] > 0)
{
$percent = round($prog_by_E[$code]/$total_by_E2[$code]*100);
$percent = " (".($percent < 0 ? $percent : '+'.$percent).'%)';
}
$prog_by_E[$code] = ", ".(($prog_by_E[$code] < 0) ? $prog_by_E[$code] : "+".$prog_by_E[$code]).$percent;
} else {
$prog_by_E[$code] = "";
}
$out .= "[b][".self::$colors[$key]."]".self::$longnames[$key]." :[/".self::$colors[$key]."] ".$total_by_E[$code]."[/b]".$prog_by_E[$code]."
";
}
if ($this->mode == 2) {
$diff = array_sum($total_by_E) - array_sum($total_by_E2);
$percent = '';
if (($oldtotal = array_sum($total_by_E2)) > 0)
{
$percent = round($diff/$oldtotal*100);
$percent = " (".($percent < 0 ? $percent : '+'.$percent).'%)';
}
$diff = ", ".(($diff < 0) ? $diff : "+".$diff).$percent;
} else {
$diff = "";
}
$out .= "[b] TOTAL : ".array_sum($total_by_E)."[/b]".$diff."
";
$out .= "