Permalink
Browse files

real time implementation of the 'exploration of expressions of emotio…

…ns in commit messages' (from @yaph)
  • Loading branch information...
1 parent 954f3cf commit 6cb4a52cb2489aa7d59453f6ff050e575ac5226a @KuiKui committed Jun 22, 2012
@@ -0,0 +1,138 @@
+<?php
+
+/**
+ * home actions.
+ *
+ * @package stickdown
@jubianchi
jubianchi Jun 22, 2012

stickdown ?! :p

+ * @subpackage board
+ * @author Your name here
+ * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
+ */
+class indexAction extends sfAction
+{
+ public function execute($request)
+ {
+ $this->stats = sfConfig::get('app_stat_item');
+
+ $entities = EntityQuery::create()
+ ->find()
+ ;
+
+ $this->info = array();
+ $this->emotions = array();
+ $order = array();
+
+ foreach($entities as $entity)
+ {
+ if($entity->getName() == 'emotion')
+ {
+ $this->emotions = $this->generateEmotionsExtremesLanguages($entity);
+ }
+
+ if(!isset($this->stats[$entity->getName()]['home']) || !$this->stats[$entity->getName()]['home'])
+ {
+ continue;
+ }
+
+ $gap = $this->getLastDayGapPercentage($entity);
+ $this->info[$entity->getName()] = array(
+ 'total' => number_format($entity->getValue()),
+ 'by-day' => number_format($entity->getValue() / $entity->getNbDay()),
+ 'gap' => $this->getGapInfo($gap),
+ 'icon' => $this->stats[$entity->getName()]['icon'],
+ 'title' => $this->stats[$entity->getName()]['title']
+ );
+ $order[] = $this->stats[$entity->getName()]['order'];
+ }
+ array_multisort($order, SORT_ASC, $this->info);
+ }
+
+ public function getLastDayGapPercentage($entity)
+ {
+ $history = json_decode($entity->getHistory(), true);
+ if(count($history) == 0)
+ {
+ return 0;
+ }
+
+ $lastDay = array_slice($history, -1, 1);
+ $lastDayCount = $lastDay[key($lastDay)]['c'];
+ $average = ($entity->getNbDay()) ? $entity->getValue() / $entity->getNbDay() : 0;
+ $gap = $lastDayCount - $average;
+ $gapPercentage = round(($average) ? $gap * 100 / $average : 0, 0);
+
+ return $gapPercentage;
+ }
+
+ public function getGapInfo($gap)
+ {
+ $info = array(
+ 'state' => 'normal',
+ 'sign-word-1' => '',
+ 'sign-word-2' => '',
+ 'class' => 'normal'
+ );
+
+ if($gap > 0)
+ {
+ $info['sign-word-1'] = 'up';
+ $info['sign-word-2'] = 'above';
+ }
+ else
+ {
+ $info['sign-word-1'] = 'down';
+ $info['sign-word-2'] = 'below';
+ }
+
+ if($gap > 35)
+ {
+ $info['state'] = 'very good';
+ $info['class'] = 'positive';
+ }
+ else if($gap > 15)
+ {
+ $info['state'] = 'good';
+ $info['class'] = 'positive';
+ }
+ else if($gap < -35)
+ {
+ $info['state'] = 'very bad';
+ $info['class'] = 'negative';
+ }
+ else if($gap < -15)
+ {
+ $info['state'] = 'bad';
+ $info['class'] = 'negative';
+ }
+
+ $info['percentage'] = abs($gap);
+
+ return $info;
+ }
+
+ public function generateEmotionsExtremesLanguages($entity)
+ {
+ $history = json_decode($entity->getHistory(), true);
+
+ if(count($history) == 0)
+ {
+ return $history;
+ }
+
+ $results = array();
+
+ $lastDay = array_slice($history, -1, 1);
+ $emotions = $lastDay[key($lastDay)];
+ foreach($emotions as $emotion => $languages)
+ {
+ if(count($languages) > 1)
+ {
+ $languagesLabel = array_keys($languages);
+ $results[$emotion]['first'] = $languagesLabel[count($languagesLabel) - 1];
+ $results[$emotion]['last'] = $languagesLabel[0];
+ }
+ }
+
+ return $results;
+ }
+}
@@ -8,39 +8,9 @@
* @author Your name here
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
-class boardActions extends sfActions
+class statAction extends sfAction
{
- public function executeIndex(sfWebRequest $request)
- {
- $this->stats = sfConfig::get('app_stat_item');
-
- $entities = EntityQuery::create()
- ->find()
- ;
-
- $this->info = array();
- $order = array();
- foreach($entities as $entity)
- {
- if(!isset($this->stats[$entity->getName()]['home']) || !$this->stats[$entity->getName()]['home'])
- {
- continue;
- }
-
- $gap = $this->getLastDayGapPercentage($entity);
- $this->info[$entity->getName()] = array(
- 'total' => number_format($entity->getValue()),
- 'by-day' => number_format($entity->getValue() / $entity->getNbDay()),
- 'gap' => $this->getGapInfo($gap),
- 'icon' => $this->stats[$entity->getName()]['icon'],
- 'title' => $this->stats[$entity->getName()]['title']
- );
- $order[] = $this->stats[$entity->getName()]['order'];
- }
- array_multisort($order, SORT_ASC, $this->info);
- }
-
- public function executeStat(sfWebRequest $request)
+ public function execute($request)
{
$this->stats = sfConfig::get('app_stat_item');
$this->currentStat = $request->getParameter('stat');
@@ -126,67 +96,4 @@ public function computeHistoryTotal($completeHistory)
return $result;
}
-
- public function getLastDayGapPercentage($entity)
- {
- $history = json_decode($entity->getHistory(), true);
- if(count($history) == 0)
- {
- return 0;
- }
-
- $lastDay = array_slice($history, -1, 1);
- $lastDayCount = $lastDay[key($lastDay)]['c'];
- $average = ($entity->getNbDay()) ? $entity->getValue() / $entity->getNbDay() : 0;
- $gap = $lastDayCount - $average;
- $gapPercentage = round(($average) ? $gap * 100 / $average : 0, 0);
-
- return $gapPercentage;
- }
-
- public function getGapInfo($gap)
- {
- $info = array(
- 'state' => 'normal',
- 'sign-word-1' => '',
- 'sign-word-2' => '',
- 'class' => 'normal'
- );
-
- if($gap > 0)
- {
- $info['sign-word-1'] = 'up';
- $info['sign-word-2'] = 'above';
- }
- else
- {
- $info['sign-word-1'] = 'down';
- $info['sign-word-2'] = 'below';
- }
-
- if($gap > 35)
- {
- $info['state'] = 'very good';
- $info['class'] = 'positive';
- }
- else if($gap > 15)
- {
- $info['state'] = 'good';
- $info['class'] = 'positive';
- }
- else if($gap < -35)
- {
- $info['state'] = 'very bad';
- $info['class'] = 'negative';
- }
- else if($gap < -15)
- {
- $info['state'] = 'bad';
- $info['class'] = 'negative';
- }
-
- $info['percentage'] = abs($gap);
-
- return $info;
- }
}
@@ -21,6 +21,17 @@
</li>
<?php endforeach; ?>
</ul>
+ <p>Here is the real time implementation of <a href="http://geeksta.net/geeklog/exploring-expressions-emotions-github-commit-messages/">the exploration of expressions of emotions in commit messages</a>.<br />
+ You can see the languages with the most anger, joy, amusement, surprise, issues and swearing of the day ! And the least too.</p>
+ <ul id="emotions">
+ <?php foreach($emotions as $emotion => $language): ?>
+ <li class="<?php echo $emotion ?>">
+ <div class="title top"><?php echo $emotion ?></div>
+ <div class="language best"><span class="mini-icon arr-up"></span><?php echo $language['first'] ?></div>
+ <div class="language"><span class="mini-icon arr-down"></span><?php echo $language['last'] ?></div>
+ </li>
+ <?php endforeach; ?>
+ </ul>
<p>Octoboard is an <a href="https://github.com/KuiKui/Octoboard">open source project</a> built for the <a href="https://github.com/blog/1118-the-github-data-challenge" title="GitHub Data Challenge">GitHub Data Challenge</a>. Feel free to fork it and add some new stats !<br />By the way, it's a very simple and sketchy project, quickly built with : PHP, MySql, Symfony, <a href="http://lesscss.org/">LESS</a>, <a href="http://www.highcharts.com/">Highcharts</a> and <a href="http://pmsipilot.github.com/jquery-highchartTable-plugin/">highchartTable</a>.</p>
</div>
<div id="footer">by <a title="on GitHub" href="https://github.com/KuiKui">Denis Roussel</a> for <a href="https://github.com/blog/1118-the-github-data-challenge" title="GitHub Data Challenge">GitHub Data Challenge</a></div>
Oops, something went wrong.

5 comments on commit 6cb4a52

@yaph
Contributor
yaph commented on 6cb4a52 Jun 22, 2012

This is cool! 👍

@KuiKui
Owner
KuiKui commented on 6cb4a52 Jun 22, 2012

Thanks!
This code is still sloppy, I will work on it as soon as you approve this commit (regexp, etc.) 😏
I've also coded one detailled screen per emotion with one curve by language, but it's really unreadable...

@yaph
Contributor
yaph commented on 6cb4a52 Jun 22, 2012

@KuiKui I just sent you a pull request with word boundary anchors added to the regexps. I cannot say much about the rest of the code, as I haven't worked with Symfony, it looks okay to me.

is there too much overlap on the detailed screens? What about using bar charts?

@KuiKui
Owner
KuiKui commented on 6cb4a52 Jun 22, 2012

Emotions 1
Emotions 2
Emotions 3

@yaph
Contributor
yaph commented on 6cb4a52 Jun 22, 2012

I see ;)

Maybe showing fewer languages, e.g. top 2 and bottom 2, would make it more usable.

Please sign in to comment.