99 lines
2.6 KiB
PHP
99 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use League\Csv\Reader;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Log;
|
|
|
|
class importmetricdata extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'import:metric';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
protected $authkey = '6bf9faa1-408e-4905-9da4-660b45a2331c';
|
|
protected $source_identifier = 'test_metric_data';
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$csv = Reader::createFromPath(storage_path('app') .'/import/test_metric_data.csv', 'r');
|
|
$csv->setHeaderOffset(0);
|
|
|
|
$header = $csv->getHeader(); //returns the CSV header record
|
|
$records = $csv->getRecords(); //returns all the CSV records as an Iterator object
|
|
//$fields = $this->get_import_fields($records);
|
|
echo '<pre>';
|
|
foreach($records as $record){
|
|
$data = [];
|
|
$data['authkey'] = $this->authkey;
|
|
$data['source_identifier'] = $this->source_identifier;
|
|
$data['user_email'] = $record['user_email'];
|
|
$data['source_record_identifier'] = $record['source_record_identifier'];
|
|
$date = explode('/', $record['record_date']);
|
|
$data['record_date'] = $date[2].'-'.$date[1].'-'.$date[0] ;
|
|
|
|
unset($record['user_email']);
|
|
unset($record['source_record_identifier']);
|
|
unset($record['record_date']);
|
|
foreach($record as $k => $v) {
|
|
if(!empty($v) && $v != "") {
|
|
$data[$k] = $v;
|
|
}
|
|
}
|
|
|
|
print_r($data);
|
|
$response = Http::post('https://rapportapi.click/metric/metric/injest', $data);
|
|
$response = json_decode($response->getBody()->getContents());
|
|
|
|
print_r($response);
|
|
|
|
//sleep(1);
|
|
}
|
|
exit;
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
"authkey":"6bf9faa1-408e-4905-9da4-660b45a2331c",
|
|
"user_email":"Sooraj.N@Cipla.com",
|
|
"source_identifier":"test_metric_data",
|
|
"source_record_identifier":"10000",
|
|
"record_date":"2022-02-10",
|
|
"duova_rx":0,
|
|
"glycohale_fb_rx":5,
|
|
"maxiflo_rx":5,
|
|
"maxiflo_sb_rx":5,
|
|
"nistami_rx":0,
|
|
"tiova_rx":5,
|
|
"tiova_sb_rx":0,
|
|
"triohale_rx":3
|
|
*/ |