Maintain the statistic on the course of training on the server



  • In the distance learning system, user statistics are collected. Statistics, to date, are presented in one general table.

    /** Формирование статистики **/
        $data = [];
        foreach($users as $user) {
            $id = $user->id;
            $data[$id] = [
                'fio' => $user->last_name.' '.$user->first_name.' '.$user->second_name,
            ];
            /** Входная статистика */
            $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$enter_exam->id)->latest()->first();
            $data = $this->addStat($stat, $data, $id, 'course', 'enter');
            /** Заключительная статистика */
            $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$finish_exam->id)->latest()->first();
            $data = $this->addStat($stat, $data, $id, 'course', 'finish');
            /** Статистика по Лекциям */
            if(count($lectures)) {
                foreach($lectures as $lecture) {
                    $exam = $lecture->exam()->firstOrFail();
                    $stat = Result::whereRaw('user_id = '.$id.' and exam_id = '.$exam->id)->latest()->first();
                    $data = $this->addStat($stat, $data, $id, 'lectures', $lecture->slug);
                }
            } else {
                $data[$id]['lectures'] = null;
            }
    

    It is necessary, at the end of the course, to keep the statistics in the file and to post it on the server for further downloading by the administrator as necessary.



  • Algorithm is like this.

    1. Take data from the OBD.
    2. Keep the file down.

    You can do that. Set up the file.

    Add config/filesystems.php

    'disks' => [
      'csv' => [
        'driver' => 'local',
        'root'   => storage_path().'/csv',
      ],
    ],
    

    And keep the data in that way.

    Storage::disk('csv')->put('file.csv', $content);
    $content = Storage::disk('csv')->get('file.csv');
    

    Reading too. Storage

    1. To make a robot who id reads this file and gives it to the client. (and better on the ram house to avoid the bulkhead)



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2