Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
0 results Searching
Select Git revision
Loading items
Show changes
127 files
+ 132618
1
Compare changes
  • Side-by-side
  • Inline

Files

.editorconfig

0 → 100644
+15 −0
Original line number Original line Diff line number Diff line
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

.env.example

0 → 100644
+50 −0
Original line number Original line Diff line number Diff line
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

SIGN_UP=false
FORGETTING_FACTOR=0.99
FOLLOWER_FACTOR=100

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

.gitattributes

0 → 100644
+5 −0
Original line number Original line Diff line number Diff line
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore

.gitignore

0 → 100644
+14 −0
Original line number Original line Diff line number Diff line
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
checkout.sh

.styleci.yml

0 → 100644
+13 −0
Original line number Original line Diff line number Diff line
php:
  preset: laravel
  disabled:
    - unused_use
  finder:
    not-name:
      - index.php
      - server.php
js:
  finder:
    not-name:
      - webpack.mix.js
css: true
+0 −1
Original line number Original line Diff line number Diff line
@@ -23,4 +23,3 @@ Tomasz Rudowski
For open source projects, say how it is licensed.
For open source projects, say how it is licensed.


## Project status
## Project status

app/Console/Kernel.php

0 → 100644
+41 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
+35 −0
Original line number Original line Diff line number Diff line
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class DelegationOneVote extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'election_id',
        'voter_id',
        'vote_direct',
        'vote_delegation',
        'vote_weight',
        'vote_final'
    ];

    protected $appends = [
        //'final_delegation_one_vote'
    ];

    public function parentDelegationOneVote() {
        return $this->belongsTo(DelegationOneVote::class, 'vote_delegation', 'id');
    }

    public function getFinalDelegationOneVoteAttribute() {
        return $this->parentDelegationOneVote()->exists() ? $this->parentDelegationOneVote->vote_direct : $this->vote_direct;
    }

    public function election() {
        return $this->belongsTo(Election::class, 'election_id', 'id');
    }
}

app/Election.php

0 → 100644
+17 −0
Original line number Original line Diff line number Diff line
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Election extends Model
{
    protected $fillable = [
        'population_id',
        'type'
    ];

    public function extension() {
        return $this->hasOne(ExtensionDelegationElection::class, 'election_id', 'id');
    }
}
+55 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Throwable  $exception
     * @return void
     *
     * @throws \Throwable
     */
    public function report(Throwable $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Throwable  $exception
     * @return \Symfony\Component\HttpFoundation\Response
     *
     * @throws \Throwable
     */
    public function render($request, Throwable $exception)
    {
        return parent::render($request, $exception);
    }
}
+23 −0
Original line number Original line Diff line number Diff line
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class ExtensionDelegationElection extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'election_id',
        'initial_correct',
        'initial_incorrect',
        'as_delegate',
        'as_follower',
        'as_independent',
        'weight_a',
        'weight_b',
        'reputation_a',
        'reputation_b'
    ];
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ConfirmsPasswords;

class ConfirmPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Confirm Password Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password confirmations and
    | uses a simple trait to include the behavior. You're free to explore
    | this trait and override any functions that require customization.
    |
    */

    use ConfirmsPasswords;

    /**
     * Where to redirect users when the intended url fails.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset emails and
    | includes a trait which assists in sending these notifications from
    | your application to your users. Feel free to explore this trait.
    |
    */

    use SendsPasswordResetEmails;
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after resetting their password.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Email Verification Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling email verification for any
    | user that recently registered with the application. Emails may also
    | be re-sent if the user didn't receive the original email message.
    |
    */

    use VerifiesEmails;

    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
}
+13 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
+38 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('home');
    }

    public function showPopulationTemplate()
    {
        return view('population-template-details');
    }

    public function showPopulation()
    {
        return view('population-details');
    }
}

app/Http/Kernel.php

0 → 100644
+67 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        // \App\Http\Middleware\TrustHosts::class,
        \App\Http\Middleware\TrustProxies::class,
        \Fruitcake\Cors\HandleCors::class,
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
    ];
}
+21 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return string|null
     */
    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;

class CheckForMaintenanceMode extends Middleware
{
    /**
     * The URIs that should be reachable while maintenance mode is enabled.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}
+17 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;

class EncryptCookies extends Middleware
{
    /**
     * The names of the cookies that should not be encrypted.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string|null  $guard
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect(RouteServiceProvider::HOME);
        }

        return $next($request);
    }
}
+18 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;

class TrimStrings extends Middleware
{
    /**
     * The names of the attributes that should not be trimmed.
     *
     * @var array
     */
    protected $except = [
        'password',
        'password_confirmation',
    ];
}
+20 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Middleware\TrustHosts as Middleware;

class TrustHosts extends Middleware
{
    /**
     * Get the host patterns that should be trusted.
     *
     * @return array
     */
    public function hosts()
    {
        return [
            $this->allSubdomainsOfApplicationUrl(),
        ];
    }
}
+23 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array|string|null
     */
    protected $proxies;

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}
+17 −0
Original line number Original line Diff line number Diff line
<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        //
    ];
}

app/MajorityVote.php

0 → 100644
+16 −0
Original line number Original line Diff line number Diff line
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class MajorityVote extends Model
{
    public $timestamps = false;

    protected $fillable = [
        'election_id',
        'voter_id',
        'vote'
    ];
}

app/Population.php

0 → 100644
+179 −0
Original line number Original line Diff line number Diff line
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Population extends Model
{
    protected $fillable =[
        'name',
        'parent_id',
        'stage',
        'election_type',
        'follower_factor',
        'forgetting_factor'
    ];

    protected $appends = [
        //'no_of_voters'
    ];

    public function voters() {
        return $this->hasMany(Voter::class, 'population_id', 'id');
    }

    public function childPopulations() {
        return $this->hasMany(Population::class, 'parent_id', 'id');
    }

    public function getChildrenCountAttribute() {
        return $this->childPopulations()->count();
    }

    public function getChildPopulationsStatsAttribute() {
        $data = [
            'm' => [
                'info' => 'Majority',
                'count' => 0,
                'learning_stage_count' => 0,
                'performance_stage_count' => 0
            ],
            'd1' => [
                'info' => 'Delegation Performance (d1)',
                'count' => 0,
                'learning_stage_count' => 0,
                'performance_stage_count' => 0
            ],
            'd2' => [
                'info' => 'Delegation Learning (d2)',
                'count' => 0,
                'learning_stage_count' => 0,
                'performance_stage_count' => 0
            ],
            'd3' => [
                'info' => 'Delegation Learning (d3)',
                'count' => 0,
                'learning_stage_count' => 0,
                'performance_stage_count' => 0
            ]
        ];
        foreach ($this->childPopulations as $childPopulation) {
            if (isset($childPopulation->election_type) && isset($data[$childPopulation->election_type])) {
                $data[$childPopulation->election_type]['count']++;

                switch($childPopulation->stage) {
                    case 'l':
                        $data[$childPopulation->election_type]['learning_stage_count']++;
                        break;
                    case 'p':
                        $data[$childPopulation->election_type]['performance_stage_count']++;
                        break;
                    default:
                        break;
                }
            }
        }
        return $data;
    }

    public function getNoOfVotersAttribute() {
        return $this->voters()->count();
    }

    public function getVotersStatsAttribute() {
        $groupNames = $this->voters()->pluck('group')->unique();
        $groups = array();
        foreach ($groupNames as $name) {
            $newGroup = new \stdClass();
            $newGroup->name = $name;
            $newGroup->no_of_voters = $this->voters()->where('group', '=', $name)->count();
            $newGroup->expertise_average = $this->voters()->where('group', '=', $name)->average('expertise');
            $newGroup->confidence_average = $this->voters()->where('group', '=', $name)->average('confidence');
            $newGroup->following_average = $this->voters()->where('group', '=', $name)->average('following');
            $newGroup->leadership_average = $this->voters()->where('group', '=', $name)->average('leadership');
            $groups[] = $newGroup;
        }
        return [
            'groups' => $groups,
            'no_of_voters' => $this->voters()->count(),
            'expertise_max' => $this->voters()->max('expertise'),
            'expertise_average' => $this->voters()->average('expertise'),
            'confidence_average' => $this->voters()->average('confidence'),
            'following_average' => $this->voters()->average('following'),
            'leadership_average' => $this->voters()->average('leadership')
        ];
    }

    public function elections() {
        return $this->hasMany(Election::class, 'population_id', 'id');
    }

    public function getElectionsStatsAttribute() {
        $noOfCorrectAvgM = $this->elections()->where('type', '=', 'm')->average('total_correct');
        $noOfIncorrectAvgM = $this->elections()->where('type', '=', 'm')->average('total_incorrect');
        $sumM = $noOfCorrectAvgM+ $noOfIncorrectAvgM;
        if ($sumM > 0) {
            $percentCorrectM = 100 * $noOfCorrectAvgM / $sumM;
        } else {
            $percentCorrectM = null;
        }
        $noOfCorrectAvgD1 = $this->elections()->where('type', '=', 'd1')->average('total_correct');
        $noOfIncorrectAvgD1 = $this->elections()->where('type', '=', 'd1')->average('total_incorrect');
        $sumD1 = $noOfCorrectAvgD1 + $noOfIncorrectAvgD1;
        if ($sumD1 > 0) {
            $percentCorrectD1 = 100 * $noOfCorrectAvgD1 / $sumD1;
        } else {
            $percentCorrectD1 = null;
        }

        $noOfCorrectAvgD2 = $this->elections()->where('type', '=', 'd2')->average('total_correct');
        $noOfIncorrectAvgD2 = $this->elections()->where('type', '=', 'd2')->average('total_incorrect');
        $sumD2 = $noOfCorrectAvgD2 + $noOfIncorrectAvgD2;
        if ($sumD2 > 0) {
            $percentCorrectD2 = 100 * $noOfCorrectAvgD2 / $sumD2;
        } else {
            $percentCorrectD2 = null;
        }

        $noOfCorrectAvgD3 = $this->elections()->where('type', '=', 'd3')->average('total_correct');
        $noOfIncorrectAvgD3 = $this->elections()->where('type', '=', 'd3')->average('total_incorrect');
        $sumD3 = $noOfCorrectAvgD3 + $noOfIncorrectAvgD3;
        if ($sumD3 > 0) {
            $percentCorrectD3 = 100 * $noOfCorrectAvgD3 / $sumD3;
        } else {
            $percentCorrectD3 = null;
        }

        return [
            [