lundi 18 janvier 2021

Server wont serve pages whenever uploading and parsing data Laravel

I have been developing the Biometric Parsing module for my system I have achieved my goal in reading raw data from the biometric unit into the database. My problem is that whenever a user in my system is uploading a raw biometric file the server wont serve any pages or requests while the upload and reading is being processed. I would like to have some pointers and learn some of the principles in handling this process much better

the biometric file that comes from the unit looks like this

  129   2019-06-23 18:13:10 1   0   0   0
   98   2019-06-23 18:51:46 1   0   0   0
  101   2019-06-23 19:07:29 1   1   0   0
  103   2019-06-23 19:07:37 1   1   0   0
   85   2019-06-23 21:14:01 1   1   0   0
  132   2019-06-23 23:48:54 1   1   0   0
  203   2019-06-24 03:45:44 1   0   0   0
  138   2019-06-24 04:10:06 1   0   0   0
  204   2019-06-24 05:12:57 1   0   0   0
  157   2019-06-24 05:58:07 1   0   0   0

the file has more than 1,700+ lines each line is a biometric record

in my Controller have this to evaluate each line and store it in the database a biometric batch is declared in order to keep track of the biometric data being uploaded

public function store(Request $request)
{
    if(Auth::check()){
        $repeatedRecords =0;
        // evaluate if the file is recieved
        set_time_limit(360);
        if($request->hasFile('BiometricDataFile')){
            $biometricDataLogFile = file($request->BiometricDataFile);
            foreach($biometricDataLogFile as $logFile){
                $BiometricDBRecord = new Biometric;
                $biometricRecord = explode("\t", $logFile);
                $BiometricDBRecord->employee_id = $biometricRecord[0];
                $BiometricDBRecord->location = $request->location;
                $BiometricDBRecord->logDate = Carbon::parse($biometricRecord[1]);
                $date = explode(' ', $biometricRecord[1]);
                $BiometricDBRecord->bioDate = $date[0];
                $BiometricDBRecord->bioTime = $date[1];
                $BiometricDBRecord->uploaded_by = Auth::user()->employee_id;
                if(Biometric::where('logDate','=', $biometricRecord[1])->count() <= 0){
                    $BiometricDBRecord->save();
                }else{
                    $repeatedRecords++;
                }
               
            }

            $newBatch = new BiometricBatch();
            //Setting up data for return to view
            $timeNow = Carbon::now('GMT+8')->toDateTimeString();
            $thirtyMinEarlier = Carbon::now('GMT+8')->subHours(12)->toDateTimeString();
            $biometricDataSaved = Biometric::whereBetween('created_at', [$thirtyMinEarlier, $timeNow])->where('uploaded_by', Auth::user()->employee_id)->get();
            $biometricDataSaved->sortBy('logDate');
            $sortedFirst = $biometricDataSaved->first();
            $sortedLast = $biometricDataSaved->last();
            $newBatch->employee_id = Auth::user()->employee->id;
            $newBatch->batch_upload_date = Carbon::now();
            $newBatch->batch_start_date = $sortedFirst->logDate;
            $newBatch->batch_end_date = $sortedLast->logDate;
            $newBatch->isProcessed = false;
            $newBatch->save();
        }else{ //if the file is not recieved
            return "<h1> File not found </h1>";
        }
            $activityLog = new ActivityLog();
            $activityLog->employee_id = Auth::user()->employee_id;
            $activityLog->action = 'Has uploaded biometric data';
            $activityLog->save();
        
        return view('pages.employeeBiometric')->with('savedLogs', $biometricDataSaved, 'duplicates', $repeatedRecords);
    }else{
        return view('errors.401');
    }
       
}

I have a gut feeling that I should probably do this in javascript or ajax but dont know where to start and how to execute.I would like to learn how to implement this better and learn form my mistakes, thank you have a great day.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3ipKzPx
via IFTTT

Aucun commentaire:

Enregistrer un commentaire