<commit_before><?php
use app\components\grid\GridView;
use yii\data\ArrayDataProvider;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use app\models\Option;
use yii\widgets\DetailView;
use miloschuman\highcharts\Highcharts;

//$options = $model->getOptions()->with(['validVotes'])->all();
//$options = $model->getOptions()->withVoteCount()->all();
$options = $model->getOptions()->all();
$dataProvider = new ArrayDataProvider([
    'allModels' => $options,
    'sort' => [
        'attributes' => [
            'text',
            'validVotesCount',
        ],
    ],
]);

?>

<?php
// Status.

if ($model->isOver()) {
    echo Html::tag('h2', Yii::t('app', 'Status: Finished'), ['class' => 'status status-finished']);
} else if ($model->isOpen()) {
    echo Html::tag('h2', Yii::t('app', 'Status: Open'), ['class' => 'status status-open']);
} else {
    echo Html::tag('h2', Yii::t('app', 'Status: Not Started'), ['class' => 'status status-closed']);
}

?>


<?php
// Column chart.

if ($model->hasStarted()) {

    echo Highcharts::widget([
        'options' => [
            'title' => ['text' => $model->question],
            'chart' => [
                //'type' => 'pie',
                'type' => 'column',
            ],
            'plotOptions' => [
                'column' => [
                    'colorByPoint' => true,
                ],
            ],
            'colors' => [
                '#0044CC',
                '#0088CC',
                '#51A351',
                '#F89406',
                '#BD362F',
            ],
            'credits' => [
                'enabled' => false,
            ],
            'xAxis' => [
                'categories' => ArrayHelper::getColumn($options, 'text'),
            ],
            'yAxis' => [
                'title' => ['text' => 'Votes'],
                'allowDecimals' => false,
            ],
            'series' => [
                [
                    'name' => 'Votes',
                    'data' => ArrayHelper::getColumn($options, function ($option) {
                        return intval($option->getValidVotesCount());
                    }),
                    'showInLegend' => false,
                ],
            ],
        ],
    ]);
}

?>

<?php
// Overview table.

$used = $model->getUsedCodesCount();
$unused = $model->getUnusedCodesCount();
$total = $model->getValidCodesCount();
echo Html::tag('h2', Yii::t('app', 'Overview'));
echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        [
            'label' => Yii::t('app', 'Total Number of Voters'),
            'value' => $total,
        ],
        [
            'label' => Yii::t('app', 'Votes Submitted'),
            'value' => $used,
        ],
        [
            'label' => Yii::t('app', 'Votes Not Yet Submitted'),
            'value' => $unused,
        ],
        [
            'label' => Yii::t('app', 'Participation'),
            'format' => ['percent', '2'],
            'value' => $total > 0 ? ($used / $total) : 0,
        ],
    ],
]);

?>

<?php
// Standings.

echo Html::tag('h2', Yii::t('app', 'Standings'));
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'text',
        [
            'attribute' => 'validVotesCount',
            'headerOptions'=> ['class'=>'sort-numerical'],
            'label' => 'Votes',
        ],
    ],
]);

?>



<?php
// Pie chart.

//echo Highcharts::widget([
    //'options' => [
        //'title' => ['text' => $model->question],
        //'chart' => [
            //'type' => 'pie',
            ////'type' => 'column',
        //],
        ////'colors' => [
            ////'#0044CC',
            ////'#0088CC',
            ////'#51A351',
            ////'#F89406',
            ////'#BD362F',<commit_msg>Sort results by vote count<commit_after><?php
use app\components\grid\GridView;
use yii\data\ArrayDataProvider;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use app\models\Option;
use yii\widgets\DetailView;
use miloschuman\highcharts\Highcharts;

//$options = $model->getOptions()->with(['validVotes'])->all();
//$options = $model->getOptions()->withVoteCount()->all();
$options = $model->getOptions()->all();
usort($options, function ($a, $b) {
    return $a->getValidVotesCount() < $b->getValidVotesCount();
});
$dataProvider = new ArrayDataProvider([
    'allModels' => $options,
    'sort' => [
        'attributes' => [
            'text',
            'validVotesCount',
        ],
    ],
]);

?>

<?php
// Status.

if ($model->isOver()) {
    echo Html::tag('h2', Yii::t('app', 'Status: Finished'), ['class' => 'status status-finished']);
} else if ($model->isOpen()) {
    echo Html::tag('h2', Yii::t('app', 'Status: Open'), ['class' => 'status status-open']);
} else {
    echo Html::tag('h2', Yii::t('app', 'Status: Not Started'), ['class' => 'status status-closed']);
}

?>


<?php
// Column chart.

if ($model->hasStarted()) {

    echo Highcharts::widget([
        'options' => [
            'title' => ['text' => $model->question],
            'chart' => [
                //'type' => 'pie',
                'type' => 'column',
            ],
            'plotOptions' => [
                'column' => [
                    'colorByPoint' => true,
                ],
            ],
            'colors' => [
                '#0044CC',
                '#0088CC',
                '#51A351',
                '#F89406',
                '#BD362F',
            ],
            'credits' => [
                'enabled' => false,
            ],
            'xAxis' => [
                'categories' => ArrayHelper::getColumn($options, 'text'),
            ],
            'yAxis' => [
                'title' => ['text' => 'Votes'],
                'allowDecimals' => false,
            ],
            'series' => [
                [
                    'name' => 'Votes',
                    'data' => ArrayHelper::getColumn($options, function ($option) {
                        return intval($option->getValidVotesCount());
                    }),
                    'showInLegend' => false,
                ],
            ],
        ],
    ]);
}

?>

<?php
// Overview table.

$used = $model->getUsedCodesCount();
$unused = $model->getUnusedCodesCount();
$total = $model->getValidCodesCount();
echo Html::tag('h2', Yii::t('app', 'Overview'));
echo DetailView::widget([
    'model' => $model,
    'attributes' => [
        [
            'label' => Yii::t('app', 'Total Number of Voters'),
            'value' => $total,
        ],
        [
            'label' => Yii::t('app', 'Votes Submitted'),
            'value' => $used,
        ],
        [
            'label' => Yii::t('app', 'Votes Not Yet Submitted'),
            'value' => $unused,
        ],
        [
            'label' => Yii::t('app', 'Participation'),
            'format' => ['percent', '2'],
            'value' => $total > 0 ? ($used / $total) : 0,
        ],
    ],
]);

?>

<?php
// Votes.

echo Html::tag('h2', Yii::t('app', 'Votes'));
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'text',
        [
            'attribute' => 'validVotesCount',
            'headerOptions'=> ['class' => 'sort-numerical'],
            'label' => 'Votes',
        ],
    ],
]);

?>



<?php
// Pie chart.

//echo Highcharts::widget([
    //'options' => [
        //'title' => ['text' => $model->question],
        //'chart' => [
            //'type' => 'pie',
            ////'type' => 'column',
        //],
        ////'colors' => [
            ////'#0044CC',
            ////'#0088CC',
            ////'#51A351',
            ////'#F89406',
            ////'#BD362F',
{'fraction_non_alphanumeric': 0.21548909494580124, 'fraction_numerical': 0.013059945148230378, 'mean_word_length': 1.6109785202863962, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 155, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4910231', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2359, 'n_words': 417}