Artificial Intelligence Programs For Programming in Python

Traveling Salesman Problem ( TSP )] Artificial Intelligence Programs For Master Leval Programming in Python from iter tools import permutations def distance(point1, point2): >>> distance([3,4],[0,0]) 5.0 >>> distance([3,6],[10,6]) 7.0 return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) ** 0.5 def total_distance(points): all the points are in the given order. >>> total_distance([[1,2],[4,6]]) 5.0 >>> total_distance([[3,6],[7,6],[12,6]]) 9.0 return sum([distance(point, points[index + 1]) for index, point in enumerate(points[:-1])]) def travelling_salesman(points, start=None): Time complexity is O(N!), so never use on long lists. >>> travelling_salesman([[0,0],[10,0],[6,0]]) ([0, 0], [6, 0], [10, 0]) >>> travelling_salesman([[0,0],[6,0],[2,3],[3,7],[0.5,9],[3,5],[9,1]]) ([0, 0], [6, 0], [9, 1], [2, 3], [3, 5], [3, 7], [0.5, 9]) """ if the start is None: start = points[0] return min([perm for perm ...

Laravel 8 Import Excel to MySQL Database Excel file - Codingonly4u

 

Laravel Import Excel to MySQL Database

Laravel 8 Import Excel to MySQL Database Excel file 

  1. Install the new laravel 8 project 
  2. Configure Database details and model
  3. Install maatwebsite/excel package for excel
  4. Create Routes for import
  5. Create controller 
  6. Create blade / view files
  7. Run laravel project with import excelsheet
1. Install laravel project:
In step first, create a new laravel project named excelimport. Use the below command for creating a project

composer create-project laravel/laravel excelimport

2.Configure Database details and make a model:
In the second step, set up database configuration in the .env file in laravel 8.

3. Install maatwebsite/excel Package

composer require maatwebsite/excel

 config/app.php
    'providers' => [ 
      Maatwebsite\Excel\ExcelServiceProvider::class, ], 
    'aliases' => [ 
      'Excel' => 
      Maatwebsite\Excel\Facades\Excel::class, ],

3. Create Route and Files in the Resource view folder
4. Create the Controller method below like this.

in controller first, convert excel to an array using the below command

$data = Excel::toArray(new User(), $request->file('meeting_file'));

Excel has multiple sheets you can select particular sheet like this.
Get Excel Sheet 1 $data[0]
Get Excel Sheet 2 $data[1]
Get Excel Sheet 3 $data[2]

Now Insert data using foreach

foreach($data as $k=>$row)
  {
           //$i = 0;
        foreach($row as $k1=>$row1)
         {
                    /*Skip Heading*/
                    if($k1 == 0)
                        continue;
            
                    $first_excel_column = $row[$k1][0];
                    $second_excel_column = $row[$k1][1];
                    $third_excel_column = $row[$k1][2];
                        
                    // if Excel column has date/time then convert like this
                            
                            $datetime=$second_excel_column ;
                            $unix_date = ($datetime - 25569) * 86400;
                            $datetime = 25569 + ($unix_date / 86400);
                            $unix_date = ($datetime - 25569) * 86400;
                            $datetime_val =  gmdate("Y-m-d H:i:s", $unix_date);

                    $modal=new Modal();
                    $modal->column1=$first_excel_column;
                    $modal->column1=$datetime_val ;
                    $modal->column1=$third_excel_column ;
                    $modal->save();

        }
}



Comments

Popular posts from this blog

MongoDB Exercises Practice Solution Exercise First

Simple Basic Commands For MongoDB

Artificial Intelligence Programs For Programming in Python