Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 73e638a59cfc0eb2b8ac66f967a44986fb141753 antoine@vupar.fr committed May 17, 2011
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) Antoine Berranger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,92 @@
+SC2Chart - Building charts for SC2Replays - PHP 5.3
+===================================================
+
+Usage
+-----
+
+ use SC2Chart\SC2Chart;
+ use SC2Chart\Bridge\SC2Replay\Analyzer; // the library you want to use. Be sure that the proper library is loaded
+ use SC2Chart\Charter\GDCharter; // the charter you want to use. Only libGD available yet
+
+ // creating dependencies
+ $analyzer = new Analyzer();
+ $charter = new GDCharter();
+
+ // creating chart
+ $sc2chart = new SC2chart($analyzer, $charter);
+ $sc2chart->populate($src_replay, $dest_chart_filepath);
+
+ // options
+ $sc2chart->setChartWidth(); // width of your graph
+ $sc2chart->setChartHeight(); // height of your graph
+ $sc2chart->setChartPrecision(); // precision you want to apply, from 1 to 60. If you set precision to 1, you will get apm for every seconds, your chart maybe pixellised.
+
+You can your own analyzers and charters if u want to do so.
+
+Implementing an analyzer
+------------------------
+
+ use SC2Chart\Analyzer\AnalyzerInterface;
+ use SC2Chart\Analyzer\AbstractAnalyzer; // if you want help :p
+
+ class myAnalyzer extends AbstractAnalyzer implements AnalyzerInterface
+ {
+ /**
+ * Implement this method to transform a replay file to an object
+ * This object must be an instance of a class implementing SC2Chart\Replay\ReplayInterface
+ *
+ * @param string $replayFile Path to the source replay file
+ * @return ReplayInterface $replay
+ */
+ public function buildReplay($replayFile)
+ {
+ // ...
+ }
+ }
+
+Implementing an charter
+-----------------------
+
+ use SC2Chart\Chart\CharterInterface;
+
+ class myCharter implements CharterInterface
+ {
+ /**
+ * Implement this method to transform a ReplayInterface into a chart.
+ *
+ * @param ReplayInterface $replay The Replay object to process
+ * @param string $filename The name of the image chart to create
+ * @param SC2Chart $sc2chart The core object, here to access configuration variables
+ * @return null
+ */
+ public function create(ReplayInterface $replay, $filename, SC2Chart $sc2chart)
+ {
+ // ...
+ }
+ }
+
+You can also extends the SC2Chart\Chart\GDChart class. I'll try to clean up that class so that it'll be easier to customize.
+
+Todo
+----
+
+- debug debug debug
+- write PHPUnit tests
+- enable colors personnalization
+- enable custom fonts
+
+
+Requirements
+------------
+
+PHP 5.3 rules !
+
+Author
+------
+
+Antoine Berranger - <antoine@ihqs.net> - <http://twitter.com/ihqs>
+
+License
+-------
+
+SC2Chart is licensed under the MIT License - see the LICENSE file for details
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit bootstrap="tests/bootstrap.php">
+ <testsuites>
+ <testsuite name="SC2Chart Test Suite">
+ <directory>tests/SC2Chart/</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory suffix=".php">src/SC2Chart/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
@@ -0,0 +1,91 @@
+<?php
+/*
+ * This file is part of the SC2Chart package.
+ *
+ * (c) Antoine Berranger <antoine@ihqs.net>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace SC2Chart\Analyzer;
+
+use SC2Chart\SC2Chart;
+use SC2Chart\Replay\ReplayInterface;
+use SC2Chart\Player\PlayerInterface;
+
+abstract class AbstractAnalyzer implements AnalyzerInterface
+{
+ protected $sc2chart;
+
+ protected $replay;
+ protected $plots;
+
+ protected $pix_per_seconds;
+
+ public function __construct()
+ {
+ }
+
+ public function process($replayFile, SC2Chart $sc2chart)
+ {
+ $this->sc2chart = $sc2chart;
+
+ $replay = $this->buildReplay($replayFile);
+ $this->parseReplay($replay);
+
+ return $replay;
+ }
+
+ public function parseReplay(ReplayInterface $replay)
+ {
+ $this->pix_per_seconds = $this->sc2chart->getChartWidth() / $replay->getGameLength();
+
+ $players = $replay->getPlayers();
+ foreach($players as $player)
+ {
+ if ($player->isObs()) { continue; }
+ $this->parsePlayer($player);
+ }
+ }
+
+ public function parsePlayer(PlayerInterface $player)
+ {
+ $actions = $player->getActions();
+
+ foreach(range($this->sc2chart->getChartPrecision() + 1, $this->sc2chart->getChartWidth(), $this->sc2chart->getChartPrecision()) as $x)
+ {
+ $seconds_to_consider = ceil($x / $this->pix_per_seconds);
+ $apm = 0;
+
+ // less than 60 seconds to consider for this pixel
+ if ($seconds_to_consider < 60)
+ {
+ for ($tmp = 0; $tmp < $seconds_to_consider; $tmp++)
+ {
+ if (!isset($actions[$tmp])){ continue; }
+ $apm += $actions[$tmp];
+ }
+ $apm = $apm / $seconds_to_consider * 60;
+ }
+
+ // more than 60 seconds to consider for this pixel
+ else
+ {
+ for ($tmp = $seconds_to_consider - 60; $tmp < $seconds_to_consider; $tmp++)
+ {
+ if (!isset($actions[$tmp])) { continue; }
+ $apm += $actions[$tmp];
+ }
+ }
+
+ if($apm > $player->getMaxApm())
+ {
+ $player->setMaxApm($apm);
+ }
+
+ // adding point to the data
+ $player->addPlot($x, $apm);
+ }
+ }
+}
@@ -0,0 +1,59 @@
+<?php
+/*
+ * This file is part of the SC2Chart package.
+ *
+ * (c) Antoine Berranger <antoine@ihqs.net>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace SC2Chart\Analyzer;
+
+use SC2Chart\SC2Chart;
+use SC2Chart\Replay\ReplayInterface;
+use SC2Chart\Player\PlayerInterface;
+
+/**
+ * Analyzer Interface
+ * Implement this class in order to create your own analyzers based on the libraries you want to use. Or just create an SC2Replay file reader in it !
+ *
+ * @version 0.1
+ * @author Antoine Berranger <antoine@ihqs.net>
+ */
+interface AnalyzerInterface
+{
+ /**
+ * Implement this core method. Basically it must launch the buildReplay method and use properly the parseReplay and parsePlayer methods.
+ * It must return a ReplayInterface instance
+ *
+ * @param string $replayFile Path to the source replay file
+ * @param SC2Chart $sc2chart The core object, here to access configuration variables
+ * @return ReplayInterface $replay
+ */
+ function process($replayFile, SC2Chart $sc2chart);
+
+ /**
+ * Implement this method to transform a replay file to an object
+ * This object must be an instance of a class implementing SC2Chart\Replay\ReplayInterface
+ * It must return a ReplayInterface instance
+ *
+ * @param string $replayFile Path to the source replay file
+ * @return ReplayInterface $replay
+ */
+ function buildReplay($replayFile);
+
+ /**
+ * Parse a Replay to extract useful informations
+ *
+ * @param ReplayInterface $replay The replay object to parse
+ */
+ function parseReplay(ReplayInterface $replay);
+
+ /**
+ * Parse a Player to extract useful informations
+ *
+ * @param PlayerInterface $player The player object to parse
+ */
+ function parsePlayer(PlayerInterface $player);
+}
@@ -0,0 +1,35 @@
+<?php
+/*
+ * This file is part of the SC2Chart package.
+ *
+ * (c) Antoine Berranger <antoine@ihqs.net>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace SC2Chart\Bridge\SC2Replay;
+
+use SC2Chart\Analyzer\AbstractAnalyzer;
+use SC2Chart\Analyzer\AnalyzerInterface;
+
+class Analyzer extends AbstractAnalyzer implements AnalyzerInterface
+{
+ /**
+ * @param string $replayFile Path to the source replay file
+ * @return ReplayInterface $replay
+ */
+ public function buildReplay($replayFile)
+ {
+ if(!class_exists("\MPQFile"))
+ {
+ throw new \RuntimeException('Please require the SC2Replay MPQFile class');
+ }
+
+ $mpq = new \MPQFile($replayFile);
+
+ $sc2replay = new Replay();
+ $sc2replay->parseReplay($mpq);
+ return $sc2replay;
+ }
+}
@@ -0,0 +1,18 @@
+<?php
+/*
+ * This file is part of the SC2Chart package.
+ *
+ * (c) Antoine Berranger <antoine@ihqs.net>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace SC2Chart\Bridge\SC2Replay;
+
+use SC2Chart\Player\AbstractPlayer;
+use SC2Chart\Player\PlayerInterface;
+
+class Player extends AbstractPlayer implements PlayerInterface
+{
+}
Oops, something went wrong.

0 comments on commit 73e638a

Please sign in to comment.